2011-08-15 14:34:00 +02:00
|
|
|
/**
|
2011-09-09 14:39:27 +02:00
|
|
|
* EGroupware eTemplate2 - JS file which contains the complete et2 module
|
2011-08-15 14:34:00 +02:00
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @subpackage api
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Andreas Stöckel
|
|
|
|
* @copyright Stylite 2011
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*egw:uses
|
|
|
|
// Include all widget classes here
|
2011-08-24 12:18:07 +02:00
|
|
|
et2_widget_template;
|
|
|
|
et2_widget_grid;
|
|
|
|
et2_widget_box;
|
|
|
|
et2_widget_hbox;
|
2012-03-19 22:06:02 +01:00
|
|
|
et2_widget_groupbox;
|
2013-02-22 01:25:41 +01:00
|
|
|
et2_widget_split;
|
2011-08-24 12:18:07 +02:00
|
|
|
et2_widget_button;
|
2012-05-02 21:12:45 +02:00
|
|
|
et2_widget_color;
|
2011-08-24 12:18:07 +02:00
|
|
|
et2_widget_description;
|
|
|
|
et2_widget_textbox;
|
|
|
|
et2_widget_number;
|
2011-08-26 00:42:07 +02:00
|
|
|
et2_widget_url;
|
2011-08-24 12:18:07 +02:00
|
|
|
et2_widget_selectbox;
|
|
|
|
et2_widget_checkbox;
|
|
|
|
et2_widget_radiobox;
|
|
|
|
et2_widget_date;
|
2013-04-16 20:50:43 +02:00
|
|
|
et2_widget_dialog;
|
2012-05-24 17:45:29 +02:00
|
|
|
et2_widget_diff;
|
2013-02-25 19:51:57 +01:00
|
|
|
et2_widget_dropdown_button;
|
2011-08-24 12:18:07 +02:00
|
|
|
et2_widget_styles;
|
2013-03-12 23:57:42 +01:00
|
|
|
et2_widget_favorites;
|
2011-08-24 12:18:07 +02:00
|
|
|
et2_widget_html;
|
2012-06-06 06:13:19 +02:00
|
|
|
et2_widget_htmlarea;
|
2011-08-24 12:18:07 +02:00
|
|
|
et2_widget_tabs;
|
2013-07-18 17:27:39 +02:00
|
|
|
et2_widget_taglist;
|
2012-03-08 17:55:12 +01:00
|
|
|
et2_widget_tree;
|
2012-05-24 17:45:29 +02:00
|
|
|
et2_widget_historylog;
|
2011-08-24 12:18:07 +02:00
|
|
|
et2_widget_hrule;
|
2011-08-30 22:56:01 +02:00
|
|
|
et2_widget_image;
|
2013-02-20 21:53:15 +01:00
|
|
|
et2_widget_iframe;
|
2011-09-01 01:37:30 +02:00
|
|
|
et2_widget_file;
|
2011-09-08 01:32:24 +02:00
|
|
|
et2_widget_link;
|
2011-09-09 14:39:27 +02:00
|
|
|
et2_widget_progress;
|
2013-05-22 22:13:12 +02:00
|
|
|
et2_widget_portlet;
|
2012-03-14 20:02:28 +01:00
|
|
|
et2_widget_selectAccount;
|
2012-03-23 00:31:31 +01:00
|
|
|
et2_widget_ajaxSelect;
|
2012-03-26 21:46:51 +02:00
|
|
|
et2_widget_vfs;
|
2012-07-14 17:38:02 +02:00
|
|
|
et2_widget_itempicker;
|
2011-08-15 14:34:00 +02:00
|
|
|
|
2011-08-25 15:35:53 +02:00
|
|
|
et2_extension_nextmatch;
|
2011-10-06 18:33:55 +02:00
|
|
|
et2_extension_customfields;
|
2011-08-25 15:35:53 +02:00
|
|
|
|
2011-08-15 14:34:00 +02:00
|
|
|
// Requirements for the etemplate2 object
|
2011-08-30 22:56:01 +02:00
|
|
|
et2_core_common;
|
2011-08-24 12:18:07 +02:00
|
|
|
et2_core_xml;
|
|
|
|
et2_core_arrayMgr;
|
2011-08-25 17:54:15 +02:00
|
|
|
et2_core_interfaces;
|
2012-03-06 16:26:11 +01:00
|
|
|
et2_core_legacyJSFunctions;
|
2012-03-02 11:44:56 +01:00
|
|
|
|
|
|
|
// Include the client side api core
|
2012-03-05 16:02:32 +01:00
|
|
|
jsapi.egw_core;
|
|
|
|
jsapi.egw_json;
|
2011-08-15 14:34:00 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The etemplate2 class manages a certain etemplate2 instance.
|
|
|
|
*
|
|
|
|
* @param _container is the DOM-Node into which the DOM-Nodes of this instance
|
|
|
|
* should be inserted
|
|
|
|
* @param _submitURL is the URL to which the form data should be submitted.
|
|
|
|
*/
|
2011-08-15 16:29:58 +02:00
|
|
|
function etemplate2(_container, _menuaction)
|
2011-08-15 14:34:00 +02:00
|
|
|
{
|
2011-08-15 16:29:58 +02:00
|
|
|
if (typeof _menuaction == "undefined")
|
|
|
|
{
|
2013-07-30 14:21:19 +02:00
|
|
|
_menuaction = "etemplate_new::ajax_process_content";
|
2011-08-15 16:29:58 +02:00
|
|
|
}
|
|
|
|
|
2011-08-15 14:34:00 +02:00
|
|
|
// Copy the given parameters
|
|
|
|
this.DOMContainer = _container;
|
2011-08-15 16:29:58 +02:00
|
|
|
this.menuaction = _menuaction;
|
2013-07-18 11:13:15 +02:00
|
|
|
|
|
|
|
// Unique ID to prevent DOM collisions across multiple templates
|
2013-07-18 11:21:07 +02:00
|
|
|
this.uniqueId = _container.getAttribute("id").replace('.','-');
|
2013-07-18 11:13:15 +02:00
|
|
|
|
2011-08-15 14:34:00 +02:00
|
|
|
// Preset the object variable
|
|
|
|
this.widgetContainer = null;
|
2011-08-16 20:18:18 +02:00
|
|
|
|
2012-03-14 22:27:23 +01:00
|
|
|
// List of templates (XML) that are known, but not used. Indexed by id.
|
|
|
|
this.templates = {};
|
2013-06-26 22:50:10 +02:00
|
|
|
|
2011-08-25 17:54:15 +02:00
|
|
|
// Connect to the window resize event
|
2013-04-13 21:00:13 +02:00
|
|
|
$j(window).resize(this, function(e) {e.data.resize();});
|
2011-08-15 14:34:00 +02:00
|
|
|
}
|
|
|
|
|
2011-08-25 17:54:15 +02:00
|
|
|
/**
|
|
|
|
* Calls the resize event of all widgets
|
|
|
|
*/
|
|
|
|
etemplate2.prototype.resize = function()
|
|
|
|
{
|
|
|
|
if (this.widgetContainer)
|
|
|
|
{
|
|
|
|
// Call the "resize" event of all functions which implement the
|
|
|
|
// "IResizeable" interface
|
|
|
|
this.widgetContainer.iterateOver(function(_widget) {
|
|
|
|
_widget.resize();
|
|
|
|
}, this, et2_IResizeable);
|
|
|
|
}
|
2013-04-13 21:00:13 +02:00
|
|
|
};
|
2011-08-25 17:54:15 +02:00
|
|
|
|
2011-08-15 14:34:00 +02:00
|
|
|
/**
|
|
|
|
* Clears the current instance.
|
|
|
|
*/
|
|
|
|
etemplate2.prototype.clear = function()
|
|
|
|
{
|
|
|
|
if (this.widgetContainer != null)
|
|
|
|
{
|
2011-08-25 15:35:53 +02:00
|
|
|
this.widgetContainer.free();
|
2011-08-15 14:34:00 +02:00
|
|
|
this.widgetContainer = null;
|
|
|
|
}
|
2013-06-26 22:50:10 +02:00
|
|
|
|
2013-02-12 16:46:14 +01:00
|
|
|
// Remove self from the index
|
|
|
|
for(name in this.templates)
|
|
|
|
{
|
|
|
|
if(typeof etemplate2._byTemplate[name] == "undefined") continue;
|
|
|
|
for(var i = 0; i < etemplate2._byTemplate[name].length; i++)
|
|
|
|
{
|
|
|
|
if(etemplate2._byTemplate[name][i] == this)
|
|
|
|
{
|
|
|
|
etemplate2._byTemplate[name].splice(i,1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-13 21:00:13 +02:00
|
|
|
};
|
2011-08-15 14:34:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an associative array containing the data array managers for each part
|
|
|
|
* of the associative data array. A part is something like "content", "readonlys"
|
|
|
|
* or "sel_options".
|
|
|
|
*/
|
|
|
|
etemplate2.prototype._createArrayManagers = function(_data)
|
|
|
|
{
|
2011-08-15 14:46:27 +02:00
|
|
|
if (typeof _data == "undefined")
|
|
|
|
{
|
|
|
|
_data = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create all neccessary _data entries
|
2011-08-23 17:27:34 +02:00
|
|
|
var neededEntries = ["content", "sel_options", "readonlys", "modifications",
|
|
|
|
"validation_errors"];
|
2011-08-15 14:46:27 +02:00
|
|
|
for (var i = 0; i < neededEntries.length; i++)
|
|
|
|
{
|
2011-09-09 11:28:48 +02:00
|
|
|
if (typeof _data[neededEntries[i]] == "undefined" || !_data[neededEntries[i]])
|
2011-08-15 14:46:27 +02:00
|
|
|
{
|
2012-03-05 14:07:38 +01:00
|
|
|
egw.debug("log", "Created not passed entry '" + neededEntries[i] +
|
2011-08-23 17:27:34 +02:00
|
|
|
"' in data array.");
|
2011-08-15 14:46:27 +02:00
|
|
|
_data[neededEntries[i]] = {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-15 14:34:00 +02:00
|
|
|
var result = {};
|
|
|
|
|
|
|
|
// Create an array manager object for each part of the _data array.
|
|
|
|
for (var key in _data)
|
|
|
|
{
|
2011-08-16 14:31:18 +02:00
|
|
|
switch (key) {
|
2011-08-16 21:40:48 +02:00
|
|
|
case "etemplate_exec_id": // already processed
|
|
|
|
case "app_header":
|
|
|
|
break;
|
2011-08-16 14:31:18 +02:00
|
|
|
case "readonlys":
|
|
|
|
result[key] = new et2_readonlysArrayMgr(_data[key]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result[key] = new et2_arrayMgr(_data[key]);
|
|
|
|
}
|
2011-08-15 14:34:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2013-04-13 21:00:13 +02:00
|
|
|
};
|
2011-08-15 14:34:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the template from the given URL and sets the data object
|
|
|
|
*/
|
2013-04-09 10:45:59 +02:00
|
|
|
etemplate2.prototype.load = function(_name, _url, _data, _callback)
|
2011-08-15 14:34:00 +02:00
|
|
|
{
|
2012-05-07 19:40:59 +02:00
|
|
|
|
|
|
|
egw().debug("info", "Loaded data", _data);
|
|
|
|
|
2012-03-20 22:42:25 +01:00
|
|
|
// Appname should be first part of the template name
|
|
|
|
var split = _name.split('.');
|
|
|
|
var appname = split[0];
|
|
|
|
|
2013-07-20 15:57:53 +02:00
|
|
|
// Initialize application js
|
|
|
|
var app_callback = null;
|
|
|
|
// Only initialize once
|
|
|
|
if(typeof app[appname] == "function")
|
|
|
|
{
|
|
|
|
(function() { new app[appname]();}).call();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
egw.debug("warn", "Did not load '%s' JS object",appname);
|
|
|
|
}
|
|
|
|
if(typeof app[appname] == "object")
|
|
|
|
{
|
2013-07-30 14:21:19 +02:00
|
|
|
app_callback = function(et2) {app[appname].et2_ready(et2);};
|
2013-07-20 15:57:53 +02:00
|
|
|
}
|
|
|
|
|
2012-03-07 16:33:21 +01:00
|
|
|
// Create the document fragment into which the HTML will be injected
|
|
|
|
var frag = document.createDocumentFragment();
|
|
|
|
|
2013-04-01 20:35:49 +02:00
|
|
|
|
|
|
|
// Clear any existing instance
|
|
|
|
this.clear();
|
|
|
|
|
|
|
|
// Create the basic widget container and attach it to the DOM
|
|
|
|
this.widgetContainer = new et2_container(null);
|
|
|
|
this.widgetContainer.setApiInstance(egw(appname, egw.elemWindow(this.DOMContainer)));
|
|
|
|
this.widgetContainer.setInstanceManager(this);
|
|
|
|
this.widgetContainer.setParentDOMNode(this.DOMContainer);
|
|
|
|
|
|
|
|
// store the id to submit it back to server
|
|
|
|
if(_data) {
|
|
|
|
this.etemplate_exec_id = _data.etemplate_exec_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set app_header
|
2013-04-16 20:42:53 +02:00
|
|
|
if (window.opener && _data) { // popup
|
2013-04-01 20:35:49 +02:00
|
|
|
document.title = _data.app_header;
|
|
|
|
} else {
|
|
|
|
// todo for idots or jdots framework
|
|
|
|
}
|
2013-07-20 15:57:53 +02:00
|
|
|
|
|
|
|
var _load = function() {
|
2012-03-14 22:27:23 +01:00
|
|
|
// Read the XML structure of the requested template
|
2013-04-16 20:42:53 +02:00
|
|
|
this.widgetContainer.loadFromXML(this.templates[_name || missing_name]);
|
2011-08-25 17:54:15 +02:00
|
|
|
|
2011-08-19 18:00:44 +02:00
|
|
|
// Inform the widget tree that it has been successfully loaded.
|
|
|
|
this.widgetContainer.loadingFinished();
|
2011-08-25 17:54:15 +02:00
|
|
|
|
2012-03-07 16:33:21 +01:00
|
|
|
// Insert the document fragment to the DOM Container
|
|
|
|
this.DOMContainer.appendChild(frag);
|
|
|
|
|
2013-02-12 16:46:14 +01:00
|
|
|
// Add into indexed list
|
|
|
|
if(typeof etemplate2._byTemplate[_name] == "undefined")
|
|
|
|
{
|
|
|
|
etemplate2._byTemplate[_name] = [];
|
|
|
|
}
|
|
|
|
etemplate2._byTemplate[_name].push(this);
|
|
|
|
|
2011-08-25 17:54:15 +02:00
|
|
|
// Trigger the "resize" event
|
|
|
|
this.resize();
|
2013-04-09 10:45:59 +02:00
|
|
|
|
|
|
|
if(typeof _callback == "function")
|
|
|
|
{
|
|
|
|
_callback.call(window,this);
|
|
|
|
}
|
2013-07-20 15:57:53 +02:00
|
|
|
if(_callback != app_callback)
|
|
|
|
{
|
|
|
|
app_callback.call(window,this);
|
|
|
|
}
|
2013-06-17 16:44:55 +02:00
|
|
|
|
|
|
|
$j(this.DOMContainer).trigger('load', this);
|
2013-07-20 15:57:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Load & process
|
|
|
|
if(!this.templates[_name])
|
|
|
|
{
|
|
|
|
// Asynchronously load the XET file
|
|
|
|
et2_loadXMLFromURL(_url, function(_xmldoc) {
|
|
|
|
|
|
|
|
// Scan for templates and store them
|
|
|
|
for(var i = 0; i < _xmldoc.childNodes.length; i++) {
|
|
|
|
var template = _xmldoc.childNodes[i];
|
|
|
|
if(template.nodeName.toLowerCase() != "template") continue;
|
|
|
|
this.templates[template.getAttribute("id")] = template;
|
|
|
|
if(!_name) missing_name = template.getAttribute("id");
|
|
|
|
}
|
|
|
|
_load.apply(this,[]);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
// Split the given data into array manager objects and pass those to the
|
|
|
|
// widget container - do this here because file is loaded async
|
|
|
|
this.widgetContainer.setArrayMgrs(this._createArrayManagers(_data));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Set array managers first, or errors will happen
|
|
|
|
this.widgetContainer.setArrayMgrs(this._createArrayManagers(_data));
|
|
|
|
|
|
|
|
// Already have it
|
|
|
|
_load.apply(this,[]);
|
|
|
|
}
|
|
|
|
|
2011-08-15 14:34:00 +02:00
|
|
|
|
2013-04-13 21:00:13 +02:00
|
|
|
};
|
2011-08-15 14:34:00 +02:00
|
|
|
|
2011-11-09 22:34:02 +01:00
|
|
|
etemplate2.prototype.submit = function(button)
|
2011-08-15 16:29:58 +02:00
|
|
|
{
|
|
|
|
// Get the form values
|
2011-08-23 16:59:49 +02:00
|
|
|
var values = this.getValues(this.widgetContainer);
|
2011-08-15 16:29:58 +02:00
|
|
|
|
2011-08-16 20:18:18 +02:00
|
|
|
// Trigger the submit event
|
2011-08-26 11:58:25 +02:00
|
|
|
var canSubmit = true;
|
|
|
|
this.widgetContainer.iterateOver(function(_widget) {
|
|
|
|
if (_widget.submit(values) === false)
|
|
|
|
{
|
|
|
|
canSubmit = false;
|
|
|
|
}
|
|
|
|
}, this, et2_ISubmitListener);
|
|
|
|
|
|
|
|
if (canSubmit)
|
2011-08-15 16:29:58 +02:00
|
|
|
{
|
2011-11-09 22:34:02 +01:00
|
|
|
// Button parameter used for submit buttons in datagrid
|
2011-11-14 23:57:06 +01:00
|
|
|
// TODO: This should probably go in nextmatch's getValues(), along with selected rows somehow.
|
|
|
|
// I'm just not sure how.
|
2012-03-02 19:35:49 +01:00
|
|
|
if(button && !values.button)
|
2011-11-09 22:34:02 +01:00
|
|
|
{
|
2013-04-13 21:00:13 +02:00
|
|
|
values.button = button.id;
|
2011-11-09 22:34:02 +01:00
|
|
|
var path = button.getPath();
|
|
|
|
var target = values;
|
|
|
|
for(var i = 0; i < path.length; i++)
|
|
|
|
{
|
|
|
|
if(!values[path[i]]) values[path[i]] = {};
|
|
|
|
target = values[path[i]];
|
|
|
|
}
|
|
|
|
if(target != values)
|
|
|
|
{
|
2011-11-14 23:57:06 +01:00
|
|
|
var indexes = button.id.split('[');
|
|
|
|
if (indexes.length > 1)
|
|
|
|
{
|
|
|
|
indexes = [indexes.shift(), indexes.join('[')];
|
|
|
|
indexes[1] = indexes[1].substring(0,indexes[1].length-1);
|
|
|
|
var children = indexes[1].split('][');
|
|
|
|
if(children.length)
|
|
|
|
{
|
|
|
|
indexes = jQuery.merge([indexes[0]], children);
|
|
|
|
}
|
|
|
|
}
|
2011-11-09 22:34:02 +01:00
|
|
|
var idx = '';
|
|
|
|
for(var i = 0; i < indexes.length; i++)
|
|
|
|
{
|
|
|
|
idx = indexes[i];
|
|
|
|
if(!target[idx] || target[idx]['$row_cont']) target[idx] = i < indexes.length -1 ? {} : true;
|
|
|
|
target = target[idx];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-16 20:18:18 +02:00
|
|
|
// Create the request object
|
2011-08-30 22:56:01 +02:00
|
|
|
if (typeof egw_json_request != "undefined" && this.menuaction)
|
2011-08-16 20:18:18 +02:00
|
|
|
{
|
2012-03-06 14:22:01 +01:00
|
|
|
var api = this.widgetContainer.egw();
|
2012-03-05 16:02:32 +01:00
|
|
|
var request = api.json(this.menuaction, [this.etemplate_exec_id,values], null, this);
|
|
|
|
request.sendRequest();
|
2011-08-16 20:18:18 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-05 14:07:38 +01:00
|
|
|
egw.debug("info", "Form got submitted with values: ", values);
|
2011-08-16 20:18:18 +02:00
|
|
|
}
|
2011-08-15 16:29:58 +02:00
|
|
|
}
|
2013-04-13 21:00:13 +02:00
|
|
|
};
|
2011-08-16 20:18:18 +02:00
|
|
|
|
2012-04-18 00:56:04 +02:00
|
|
|
/**
|
|
|
|
* Does a full form post submit.
|
|
|
|
* Only use this one if you need it, use the ajax submit() instead
|
|
|
|
*/
|
|
|
|
etemplate2.prototype.postSubmit = function()
|
|
|
|
{
|
|
|
|
// Get the form values
|
|
|
|
var values = this.getValues(this.widgetContainer);
|
|
|
|
|
|
|
|
// Trigger the submit event
|
|
|
|
var canSubmit = true;
|
|
|
|
this.widgetContainer.iterateOver(function(_widget) {
|
|
|
|
if (_widget.submit(values) === false)
|
|
|
|
{
|
|
|
|
canSubmit = false;
|
|
|
|
}
|
|
|
|
}, this, et2_ISubmitListener);
|
|
|
|
|
|
|
|
if (canSubmit)
|
|
|
|
{
|
2012-04-24 21:47:23 +02:00
|
|
|
var form = jQuery("<form id='form' action='"+egw().webserverUrl +
|
|
|
|
"/etemplate/process_exec.php?menuaction=" + this.widgetContainer.egw().getAppName()+ "' method='POST'>");
|
2012-04-18 00:56:04 +02:00
|
|
|
|
2012-04-23 22:25:21 +02:00
|
|
|
var etemplate_id = jQuery(document.createElement("input"))
|
|
|
|
.attr("name",'etemplate_exec_id')
|
2012-05-22 22:16:33 +02:00
|
|
|
.attr("type",'hidden')
|
2012-04-23 22:25:21 +02:00
|
|
|
.val(this.etemplate_exec_id)
|
|
|
|
.appendTo(form);
|
2012-04-18 00:56:04 +02:00
|
|
|
|
|
|
|
var input = document.createElement("input");
|
2012-05-14 18:55:38 +02:00
|
|
|
input.type = "hidden";
|
2012-04-18 00:56:04 +02:00
|
|
|
input.name = 'value';
|
|
|
|
input.value = egw().jsonEncode(values);
|
2012-04-23 22:25:21 +02:00
|
|
|
form.append(input);
|
|
|
|
form.appendTo(jQuery('body')).submit();
|
2012-04-18 00:56:04 +02:00
|
|
|
}
|
2013-04-13 21:00:13 +02:00
|
|
|
};
|
2012-04-18 00:56:04 +02:00
|
|
|
|
2011-08-23 16:59:49 +02:00
|
|
|
/**
|
|
|
|
* Fetches all input element values and returns them in an associative
|
|
|
|
* array. Widgets which introduce namespacing can use the internal _target
|
|
|
|
* parameter to add another layer.
|
|
|
|
*/
|
|
|
|
etemplate2.prototype.getValues = function(_root)
|
|
|
|
{
|
|
|
|
var result = {};
|
|
|
|
|
|
|
|
// Iterate over the widget tree
|
|
|
|
_root.iterateOver(function(_widget) {
|
|
|
|
|
|
|
|
// The widget must have an id to be included in the values array
|
|
|
|
if (_widget.id == "")
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the path to the node we have to store the value at
|
2011-10-06 18:33:55 +02:00
|
|
|
var path = _widget.getPath();
|
2011-08-23 16:59:49 +02:00
|
|
|
|
|
|
|
// check if id contains a hierachical name, eg. "button[save]"
|
|
|
|
var id = _widget.id;
|
2012-03-23 19:17:15 +01:00
|
|
|
var indexes = id.split('[');
|
2011-11-14 23:57:06 +01:00
|
|
|
if (indexes.length > 1)
|
2011-08-23 16:59:49 +02:00
|
|
|
{
|
2012-03-23 19:17:15 +01:00
|
|
|
indexes = [indexes.shift(), indexes.join('[')];
|
|
|
|
indexes[1] = indexes[1].substring(0,indexes[1].length-1);
|
2012-03-02 19:35:49 +01:00
|
|
|
var children = indexes[1].split('][');
|
2011-11-14 23:57:06 +01:00
|
|
|
if(children.length)
|
|
|
|
{
|
|
|
|
indexes = jQuery.merge([indexes[0]], children);
|
|
|
|
}
|
|
|
|
path = path.concat(indexes);
|
2012-03-02 19:35:49 +01:00
|
|
|
// Take the last one as the ID
|
|
|
|
id = path.pop();
|
2011-08-23 16:59:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set the _target variable to that node
|
|
|
|
var _target = result;
|
|
|
|
for (var i = 0; i < path.length; i++)
|
|
|
|
{
|
|
|
|
// Create a new object for not-existing path nodes
|
2012-03-06 14:22:01 +01:00
|
|
|
if (typeof _target[path[i]] === 'undefined')
|
2011-08-23 16:59:49 +02:00
|
|
|
{
|
|
|
|
_target[path[i]] = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether the path node is really an object
|
2012-03-06 14:22:01 +01:00
|
|
|
if (typeof _target[path[i]] === 'object')
|
2011-08-23 16:59:49 +02:00
|
|
|
{
|
|
|
|
_target = _target[path[i]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-05 14:07:38 +01:00
|
|
|
egw.debug("error", "ID collision while writing at path " +
|
2011-08-23 16:59:49 +02:00
|
|
|
"node '" + path[i] + "'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-23 19:17:15 +01:00
|
|
|
// Handle arrays, eg radio[]
|
|
|
|
if(id === "")
|
|
|
|
{
|
2012-07-03 00:58:02 +02:00
|
|
|
id = typeof _target == "undefined" ? 0 : Object.keys(_target).length;
|
2012-03-23 19:17:15 +01:00
|
|
|
}
|
|
|
|
|
2012-07-05 00:41:51 +02:00
|
|
|
var value = _widget.getValue();
|
|
|
|
|
2011-08-23 16:59:49 +02:00
|
|
|
// Check whether the entry is really undefined
|
2012-07-05 00:41:51 +02:00
|
|
|
if (typeof _target[id] != "undefined" && (typeof _target[id] != 'object' || typeof value != 'object'))
|
2011-08-23 16:59:49 +02:00
|
|
|
{
|
2012-03-05 14:07:38 +01:00
|
|
|
egw.debug("error", _widget, "Overwriting value of '" + _widget.id +
|
2011-08-23 16:59:49 +02:00
|
|
|
"', id exists twice!");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store the value of the widget and reset its dirty flag
|
|
|
|
if (value !== null)
|
|
|
|
{
|
2012-07-05 00:41:51 +02:00
|
|
|
// Merge, if possible (link widget)
|
|
|
|
if(typeof _target[id] == 'object' && typeof value == 'object')
|
|
|
|
{
|
2013-02-05 10:53:06 +01:00
|
|
|
_target[id] = jQuery.extend({},_target[id],value);
|
2012-07-05 00:41:51 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_target[id] = value;
|
|
|
|
}
|
2011-08-23 16:59:49 +02:00
|
|
|
}
|
2012-03-30 21:42:01 +02:00
|
|
|
else if (jQuery.isEmptyObject(_target))
|
|
|
|
{
|
|
|
|
// Avoid sending back empty sub-arrays
|
2013-04-13 21:00:13 +02:00
|
|
|
_target = result;
|
2012-03-30 21:42:01 +02:00
|
|
|
for (var i = 0; i < path.length-1; i++)
|
|
|
|
{
|
|
|
|
_target = _target[path[i]];
|
|
|
|
}
|
|
|
|
delete _target[path[path.length-1]];
|
|
|
|
}
|
2011-08-23 16:59:49 +02:00
|
|
|
_widget.resetDirty();
|
|
|
|
|
|
|
|
}, this, et2_IInput);
|
|
|
|
|
2012-05-14 18:55:38 +02:00
|
|
|
egw().debug("info", "Value", result);
|
2011-08-23 16:59:49 +02:00
|
|
|
return result;
|
2013-04-13 21:00:13 +02:00
|
|
|
};
|
2011-08-23 16:59:49 +02:00
|
|
|
|
2013-02-12 16:46:14 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* "Intelligently" refresh the template based on the given ID
|
|
|
|
*
|
|
|
|
* Rather than blindly re-load the entire template, we try to be a little smarter about it.
|
|
|
|
* If there's a message provided, we try to find where it goes and set it directly. Then
|
|
|
|
* we look for a nextmatch widget, and tell it to refresh its data based on that ID.
|
|
|
|
*
|
|
|
|
* @param msg String Message to try to display. eg: "Entry added"
|
|
|
|
* @param id String|null Application specific entry ID to try to refresh
|
|
|
|
* @param type String|null Type of change. One of 'edit', 'delete', 'add' or null
|
|
|
|
*
|
|
|
|
* @see jsapi.egw_refresh()
|
|
|
|
* @see egw_fw.egw_refresh()
|
|
|
|
*/
|
2013-02-14 12:25:24 +01:00
|
|
|
etemplate2.prototype.refresh = function(msg, app, id, type)
|
2013-02-12 16:46:14 +01:00
|
|
|
{
|
|
|
|
// We use et2_baseWidget in case the app uses something like HTML instead of label
|
2013-02-13 10:03:28 +01:00
|
|
|
var msg_widget = this.widgetContainer.getWidgetById("msg");
|
|
|
|
if(msg_widget)
|
|
|
|
{
|
2013-02-13 10:23:33 +01:00
|
|
|
msg_widget.set_value(msg);
|
2013-02-13 10:03:28 +01:00
|
|
|
msg_widget.set_disabled(msg.trim().length == 0);
|
|
|
|
|
|
|
|
// In case parent(s) have been disabled, just show it all
|
|
|
|
// TODO: Fix this so messages go in a single, well defined place that don't get disabled
|
|
|
|
$j(msg_widget.getDOMNode()).parents().show();
|
|
|
|
}
|
2013-02-12 16:46:14 +01:00
|
|
|
|
2013-02-25 21:35:17 +01:00
|
|
|
// Refresh nextmatches
|
|
|
|
this.widgetContainer.iterateOver(function(_widget) {
|
|
|
|
// Trigger refresh
|
|
|
|
_widget.refresh(id,type);
|
|
|
|
}, this, et2_nextmatch);
|
2013-04-13 21:00:13 +02:00
|
|
|
};
|
2013-02-12 16:46:14 +01:00
|
|
|
|
|
|
|
// Some static things to make getting into widget context a little easier //
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of etemplates by loaded template
|
|
|
|
*/
|
|
|
|
etemplate2._byTemplate = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of etemplate2 objects that loaded the given template name
|
|
|
|
*
|
|
|
|
* @param template String Name of the template that was loaded
|
|
|
|
*
|
|
|
|
* @return Array list of etemplate2 that have that template
|
|
|
|
*/
|
|
|
|
|
|
|
|
etemplate2.getByTemplate = function(template)
|
|
|
|
{
|
|
|
|
if(typeof etemplate2._byTemplate[template] != "undefined")
|
|
|
|
{
|
|
|
|
return etemplate2._byTemplate[template];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Return empty array so you can always iterate over results
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of etemplate2 objects that are associated with the given application
|
|
|
|
*
|
|
|
|
* "Associated" is determined by the first part of the template
|
|
|
|
*
|
|
|
|
* @param template String Name of the template that was loaded
|
|
|
|
*
|
|
|
|
* @return Array list of etemplate2 that have that app as the first part of their loaded template
|
|
|
|
*/
|
|
|
|
etemplate2.getByApplication = function(app)
|
|
|
|
{
|
|
|
|
var list = [];
|
|
|
|
for(var name in etemplate2._byTemplate)
|
|
|
|
{
|
|
|
|
if(name.indexOf(app + ".") == 0)
|
|
|
|
{
|
|
|
|
list = list.concat(etemplate2._byTemplate[name]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
2013-04-13 21:00:13 +02:00
|
|
|
};
|
2013-02-12 16:46:14 +01:00
|
|
|
|
2012-03-05 16:02:32 +01:00
|
|
|
function etemplate2_handle_load(_type, _response)
|
2011-08-15 16:29:58 +02:00
|
|
|
{
|
2012-03-05 16:02:32 +01:00
|
|
|
// Check the parameters
|
|
|
|
var data = _response.data;
|
2012-03-06 14:22:01 +01:00
|
|
|
if (typeof data.url == "string" && typeof data.data === 'object')
|
2011-08-15 16:29:58 +02:00
|
|
|
{
|
2013-07-20 15:57:53 +02:00
|
|
|
if(typeof this.load == 'function')
|
|
|
|
{
|
|
|
|
// Called from etemplate
|
|
|
|
this.load(data.name, data.url, data.data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Not etemplate
|
|
|
|
var node = document.getElementById(data.DOMNodeID);
|
|
|
|
if(node)
|
|
|
|
{
|
2013-07-30 14:21:19 +02:00
|
|
|
var et2 = new etemplate2(node, "etemplate_new::ajax_process_content");
|
2013-07-20 15:57:53 +02:00
|
|
|
et2.load(data.name, data.url, data.data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
egw.debug("error", "Could not find target node %s", data.DOMNodeId);
|
|
|
|
}
|
|
|
|
}
|
2011-08-15 16:29:58 +02:00
|
|
|
}
|
|
|
|
|
2012-03-05 16:02:32 +01:00
|
|
|
throw("Error while parsing et2_load response");
|
2011-08-15 16:29:58 +02:00
|
|
|
}
|
|
|
|
|
2012-03-05 16:02:32 +01:00
|
|
|
function etemplate2_handle_validation_error(_type, _response)
|
|
|
|
{
|
|
|
|
// Display validation errors
|
|
|
|
//$j(':input',this.DOMContainer).data("validator").invalidate(_response.data);
|
2012-06-19 00:56:20 +02:00
|
|
|
egw().debug("warn","Validation errors", _response.data);
|
2012-03-05 16:02:32 +01:00
|
|
|
}
|
|
|
|
|
2012-03-06 14:22:01 +01:00
|
|
|
// Calls etemplate2_handle_response in the context of the object which
|
|
|
|
// requested the response from the server
|
|
|
|
egw(window).registerJSONPlugin(etemplate2_handle_load, null, 'et2_load');
|
|
|
|
egw(window).registerJSONPlugin(etemplate2_handle_validation_error, null, 'et2_validation_error');
|
2012-03-05 16:02:32 +01:00
|
|
|
|
2013-03-25 17:56:10 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Compatability function for etemplate
|
|
|
|
*
|
|
|
|
* When we're fully on et2, replace each useage with a call to etemplate2 widget.getInstanceManager().submit()
|
|
|
|
* @param obj DOM Node, usually a button
|
|
|
|
* @param widget et2_widget
|
|
|
|
*/
|
|
|
|
function xajax_eT_wrapper(obj,widget)
|
|
|
|
{
|
|
|
|
egw().debug("warn", "xajax_eT_wrapper() is deprecated, replace with widget.getInstanceManager().submit()");
|
|
|
|
if(typeof obj == "object")
|
|
|
|
{
|
|
|
|
$j("div.popupManual div.noPrint").hide();
|
|
|
|
$j("div.ajax-loader").show();
|
|
|
|
if(typeof widget == "undefined" && obj.id)
|
|
|
|
{
|
|
|
|
// Try to find the widget by ID so we don't have to change every call
|
|
|
|
var et2 = etemplate2.getByApplication(egw_getAppName());
|
|
|
|
for(var i = 0; i < et2.length; i++)
|
|
|
|
{
|
|
|
|
widget = et2[i].widgetContainer.getWidgetById(obj.id);
|
|
|
|
if(widget.getInstanceManager) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
widget.getInstanceManager().submit(this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$j("div.popupManual div.noPrint").show();
|
|
|
|
$j("div.ajax-loader").hide();
|
|
|
|
}
|
|
|
|
}
|