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;
|
2014-09-30 23:37:45 +02:00
|
|
|
et2_widget_entry;
|
2011-08-24 12:18:07 +02:00
|
|
|
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;
|
2013-10-04 09:29:38 +02:00
|
|
|
et2_widget_toolbar;
|
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;
|
2014-08-19 12:10:09 +02:00
|
|
|
et2_widget_video;
|
2015-08-25 17:28:30 +02:00
|
|
|
et2_widget_barcode;
|
2012-07-14 17:38:02 +02:00
|
|
|
et2_widget_itempicker;
|
2015-01-23 20:32:32 +01:00
|
|
|
et2_widget_script;
|
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
|
2014-02-06 18:27:01 +01:00
|
|
|
* @param _menuaction is the URL to which the form data should be submitted.
|
2011-08-15 14:34:00 +02:00
|
|
|
*/
|
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-11-26 23:34:32 +01:00
|
|
|
_menuaction = "home.etemplate_new.ajax_process_content.etemplate";
|
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-10-30 15:07:29 +01:00
|
|
|
|
2013-07-18 11:13:15 +02:00
|
|
|
// Unique ID to prevent DOM collisions across multiple templates
|
2013-08-26 21:08:02 +02:00
|
|
|
this.uniqueId = _container.getAttribute("id") ? _container.getAttribute("id").replace('.','-') : '';
|
2013-10-30 15:07:29 +01:00
|
|
|
|
2014-03-20 10:40:37 +01:00
|
|
|
/**
|
|
|
|
* Preset the object variable
|
|
|
|
* @type {et2_container}
|
|
|
|
*/
|
2011-08-15 14:34:00 +02:00
|
|
|
this.widgetContainer = null;
|
2011-08-16 20:18:18 +02:00
|
|
|
|
2011-08-15 14:34:00 +02:00
|
|
|
}
|
|
|
|
|
2015-08-20 16:57:18 +02:00
|
|
|
// List of templates (XML) that are known, not always used. Indexed by id.
|
|
|
|
// We share list of templates with iframes and popups
|
|
|
|
try {
|
|
|
|
if (opener && opener.etemplate2)
|
2015-01-23 15:32:47 +01:00
|
|
|
{
|
2015-08-20 16:57:18 +02:00
|
|
|
etemplate2.prototype.templates = opener.etemplate2.prototype.templates;
|
2015-01-23 15:32:47 +01:00
|
|
|
}
|
2015-10-26 22:13:34 +01:00
|
|
|
else if (top.etemplate2)
|
|
|
|
{
|
|
|
|
etemplate2.prototype.templates = top.etemplate2.prototype.templates;
|
|
|
|
}
|
2015-08-20 16:57:18 +02:00
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
// catch security exception if opener is from a different domain
|
2015-10-26 22:13:34 +01:00
|
|
|
console.log('Security exception accessing etemplate2.prototype of opener or top!');
|
2015-08-20 16:57:18 +02:00
|
|
|
}
|
|
|
|
if (typeof etemplate2.prototype.templates == "undefined")
|
2015-08-20 10:45:21 +02:00
|
|
|
{
|
2015-10-26 22:13:34 +01:00
|
|
|
etemplate2.prototype.templates = {};
|
2015-08-20 16:57:18 +02:00
|
|
|
}
|
|
|
|
|
2011-08-25 17:54:15 +02:00
|
|
|
/**
|
|
|
|
* Calls the resize event of all widgets
|
2015-01-23 15:32:47 +01:00
|
|
|
*
|
|
|
|
* @param {jQuery.event} e
|
2011-08-25 17:54:15 +02:00
|
|
|
*/
|
2014-12-05 18:29:41 +01:00
|
|
|
etemplate2.prototype.resize = function(e)
|
2011-08-25 17:54:15 +02:00
|
|
|
{
|
2014-12-08 18:04:41 +01:00
|
|
|
var event = e;
|
|
|
|
var self = this;
|
2014-12-09 17:07:51 +01:00
|
|
|
var excess_height = false;
|
2015-01-23 15:32:47 +01:00
|
|
|
|
2014-12-09 17:07:51 +01:00
|
|
|
// Check if the framework has an specific excess height calculation
|
|
|
|
if (typeof window.framework != 'undefined' && typeof window.framework.get_wExcessHeight != 'undefined')
|
|
|
|
{
|
|
|
|
excess_height = window.framework.get_wExcessHeight(window);
|
|
|
|
}
|
2015-01-23 15:32:47 +01:00
|
|
|
|
|
|
|
//@TODO implement getaccess height for other framework and remove
|
2014-12-09 12:20:38 +01:00
|
|
|
if (typeof event != 'undefined' && event.type == 'resize')
|
|
|
|
{
|
2016-02-11 21:20:46 +01:00
|
|
|
if(this.resize_timeout)
|
|
|
|
{
|
|
|
|
clearTimeout(this.resize_timeout);
|
|
|
|
}
|
|
|
|
this.resize_timeout = setTimeout(function(){
|
|
|
|
self.resize_timeout = false;
|
2014-12-09 12:20:38 +01:00
|
|
|
if (self.widgetContainer)
|
|
|
|
{
|
|
|
|
var appHeader = $j('#divAppboxHeader');
|
2014-12-08 18:04:41 +01:00
|
|
|
|
2014-12-09 12:20:38 +01:00
|
|
|
//Calculate the excess height
|
2016-02-10 17:50:42 +01:00
|
|
|
excess_height = egw(window).is_popup()? $j(window).height() - $j(self.DOMContainer).height() - appHeader.outerHeight()+11: false;
|
2014-12-09 17:07:51 +01:00
|
|
|
// Recalculate excess height if the appheader is shown
|
2014-12-09 12:20:38 +01:00
|
|
|
if (appHeader.length > 0 && appHeader.is(':visible')) excess_height -= appHeader.outerHeight()-9;
|
2014-12-08 18:04:41 +01:00
|
|
|
|
2015-02-09 12:28:20 +01:00
|
|
|
// Do not resize if the template height is bigger than screen available height
|
|
|
|
// For templates which have sub templates and they are bigger than screenHeight
|
2016-02-10 17:50:42 +01:00
|
|
|
if(screen.availHeight < $j(self.DOMContainer).height()) excess_height = 0;
|
2015-02-09 12:28:20 +01:00
|
|
|
|
2014-12-09 12:20:38 +01:00
|
|
|
// Call the "resize" event of all functions which implement the
|
|
|
|
// "IResizeable" interface
|
|
|
|
self.widgetContainer.iterateOver(function(_widget) {
|
2016-02-10 17:50:42 +01:00
|
|
|
_widget.resize(excess_height);
|
2014-12-09 12:20:38 +01:00
|
|
|
}, self, et2_IResizeable);
|
|
|
|
}
|
|
|
|
},100);
|
|
|
|
}
|
|
|
|
// Initial resize needs to be resized immediately (for instance for nextmatch resize)
|
|
|
|
else if(this.widgetContainer)
|
|
|
|
{
|
|
|
|
// Call the "resize" event of all functions which implement the
|
|
|
|
// "IResizeable" interface
|
|
|
|
this.widgetContainer.iterateOver(function(_widget) {
|
2014-12-08 18:04:41 +01:00
|
|
|
|
2014-12-09 17:07:51 +01:00
|
|
|
_widget.resize(excess_height);
|
2014-12-09 12:20:38 +01:00
|
|
|
}, 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()
|
|
|
|
{
|
2014-07-28 22:51:49 +02:00
|
|
|
$j(this.DOMContainer).trigger('clear');
|
2014-10-08 22:02:59 +02:00
|
|
|
|
2014-01-10 16:54:35 +01:00
|
|
|
// Remove any handlers on window (resize)
|
2014-01-11 12:42:23 +01:00
|
|
|
if(this.uniqueId)
|
|
|
|
{
|
|
|
|
$j(window).off("."+this.uniqueId);
|
|
|
|
}
|
2014-01-16 13:13:16 +01:00
|
|
|
|
2014-01-16 13:52:25 +01:00
|
|
|
// call our destroy_session handler, if it is not already unbind, and unbind it after
|
|
|
|
if (this.destroy_session)
|
|
|
|
{
|
|
|
|
this.destroy_session();
|
|
|
|
this.unbind_unload();
|
|
|
|
}
|
2011-08-15 14:34:00 +02:00
|
|
|
if (this.widgetContainer != null)
|
|
|
|
{
|
2013-10-28 21:16:49 +01:00
|
|
|
// Un-register handler
|
|
|
|
this.widgetContainer.egw().unregisterJSONPlugin(etemplate2_handle_assign, this, 'assign');
|
2013-10-30 15:07:29 +01:00
|
|
|
|
2011-08-25 15:35:53 +02:00
|
|
|
this.widgetContainer.free();
|
2011-08-15 14:34:00 +02:00
|
|
|
this.widgetContainer = null;
|
|
|
|
}
|
2013-09-16 17:20:22 +02:00
|
|
|
$j(this.DOMContainer).empty();
|
2015-01-26 15:32:39 +01:00
|
|
|
|
|
|
|
// Remove self from the index
|
2015-08-20 16:57:18 +02:00
|
|
|
for(name in this.templates)
|
2015-01-26 15:32:39 +01:00
|
|
|
{
|
2015-08-20 16:57:18 +02:00
|
|
|
if(typeof etemplate2._byTemplate[name] == "undefined") continue;
|
2015-01-26 15:32:39 +01:00
|
|
|
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".
|
2014-02-06 18:27:01 +01:00
|
|
|
*
|
|
|
|
* @param {object} _data object with values for attributes content, sel_options, readonlys, modifications
|
2011-08-15 14:34:00 +02:00
|
|
|
*/
|
|
|
|
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]);
|
2014-02-19 01:28:38 +01:00
|
|
|
result[key].perspectiveData.owner = this.widgetContainer;
|
2011-08-16 14:31:18 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result[key] = new et2_arrayMgr(_data[key]);
|
2014-02-19 01:28:38 +01:00
|
|
|
result[key].perspectiveData.owner = this.widgetContainer;
|
2011-08-16 14:31:18 +02:00
|
|
|
}
|
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
|
|
|
|
2014-01-16 13:13:16 +01:00
|
|
|
/**
|
|
|
|
* Bind our unload handler to notify server that eT session/request no longer needed
|
2014-01-17 18:51:17 +01:00
|
|
|
*
|
|
|
|
* We only bind, if we have an etemplate_exec_id: not the case for pure client-side
|
|
|
|
* calls, eg. via et2_dialog.
|
2014-01-16 13:13:16 +01:00
|
|
|
*/
|
|
|
|
etemplate2.prototype.bind_unload = function()
|
|
|
|
{
|
2014-01-17 18:51:17 +01:00
|
|
|
if (this.etemplate_exec_id)
|
2014-01-16 13:52:25 +01:00
|
|
|
{
|
2014-01-17 18:51:17 +01:00
|
|
|
this.destroy_session = jQuery.proxy(function(ev)
|
|
|
|
{
|
|
|
|
var request = egw.json(this.app+".etemplate_new.ajax_destroy_session.etemplate",
|
|
|
|
[this.etemplate_exec_id], null, null, false);
|
|
|
|
request.sendRequest();
|
|
|
|
}, this);
|
2014-01-16 13:52:25 +01:00
|
|
|
|
2014-01-17 18:51:17 +01:00
|
|
|
if (!window.onbeforeunload)
|
|
|
|
{
|
|
|
|
window.onbeforeunload = this.destroy_session;
|
|
|
|
}
|
2014-01-16 13:13:16 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unbind our unload handler
|
|
|
|
*/
|
|
|
|
etemplate2.prototype.unbind_unload = function()
|
|
|
|
{
|
|
|
|
if (window.onbeforeunload === this.destroy_session)
|
|
|
|
{
|
|
|
|
window.onbeforeunload = null;
|
|
|
|
}
|
2014-01-16 13:52:25 +01:00
|
|
|
delete this.destroy_session;
|
2014-01-16 13:13:16 +01:00
|
|
|
};
|
|
|
|
|
2014-10-08 22:02:59 +02:00
|
|
|
/**
|
|
|
|
* Download a URL not triggering our unload handler and therefore destroying our et2 request
|
|
|
|
*
|
|
|
|
* @param {string} _url
|
|
|
|
*/
|
|
|
|
etemplate2.prototype.download = function(_url)
|
|
|
|
{
|
|
|
|
// need to unbind unload handler to NOT destroy et2 session
|
|
|
|
this.unbind_unload();
|
|
|
|
|
|
|
|
document.location = _url;
|
|
|
|
|
|
|
|
// bind unload handler again (can NOT do it direct, as this would be quick enough to be still triggered!)
|
|
|
|
window.setTimeout(jQuery.proxy(this.bind_unload, this), 100);
|
|
|
|
};
|
|
|
|
|
2011-08-15 14:34:00 +02:00
|
|
|
/**
|
|
|
|
* Loads the template from the given URL and sets the data object
|
2014-02-06 18:27:01 +01:00
|
|
|
*
|
|
|
|
* @param {string} _name name of template
|
|
|
|
* @param {string} _url url to load template
|
|
|
|
* @param {object} _data object with attributes content, langRequire, etemplate_exec_id, ...
|
|
|
|
* @param {function} _callback called after tempalte is loaded
|
2016-03-03 15:10:08 +01:00
|
|
|
* @param {object} _app local app object
|
2016-03-21 16:31:02 +01:00
|
|
|
* @param {boolean} _no_et2_ready true: do not send et2_ready, used by et2_dialog to not overwrite app.js et2 object
|
2011-08-15 14:34:00 +02:00
|
|
|
*/
|
2016-03-21 16:31:02 +01:00
|
|
|
etemplate2.prototype.load = function(_name, _url, _data, _callback, _app, _no_et2_ready)
|
2011-08-15 14:34:00 +02:00
|
|
|
{
|
2016-03-03 15:10:08 +01:00
|
|
|
var app = _app || window.app;
|
2014-02-25 14:04:28 +01:00
|
|
|
this.name = _name; // store top-level template name to have it available in widgets
|
2014-11-05 14:07:13 +01:00
|
|
|
// store template base url, in case initial template is loaded via webdav, to use that for further loads too
|
2015-01-28 11:14:52 +01:00
|
|
|
// need to split off domain first, as it could contain app-name part of template eg. stylite.report.xet and https://my.stylite.de/egw/...
|
2015-02-03 00:28:27 +01:00
|
|
|
if (_url && _url[0] != '/')
|
2015-01-28 11:14:52 +01:00
|
|
|
{
|
|
|
|
this.template_base_url = _url.match(/https?:\/\/[^/]+/).shift();
|
|
|
|
_url = _url.split(this.template_base_url)[1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.template_base_url = '';
|
|
|
|
}
|
|
|
|
this.template_base_url += _url.split(_name.split('.').shift())[0];
|
2014-02-25 14:04:28 +01:00
|
|
|
|
2012-05-07 19:40:59 +02:00
|
|
|
egw().debug("info", "Loaded data", _data);
|
2016-02-22 14:03:57 +01:00
|
|
|
var currentapp = this.app = _data.currentapp || egw().app_name();
|
2016-03-17 19:12:36 +01:00
|
|
|
var appname = _name.split('.')[0];
|
|
|
|
// if no app object provided and template app is not currentapp (eg. infolog CRM view)
|
|
|
|
// create private app object / closure with just classes / prototypes
|
|
|
|
if (!_app && appname && appname != currentapp) app = { classes: window.app.classes };
|
|
|
|
// remember used app object, to eg. use: onchange="widget.getInstanceMgr().app_object[app].callback()"
|
|
|
|
this.app_obj = app;
|
2013-10-30 15:07:29 +01:00
|
|
|
|
2014-02-06 18:27:01 +01:00
|
|
|
// extract $content['msg'] and call egw.message() with it
|
|
|
|
var msg = _data.content.msg;
|
|
|
|
if (typeof msg != 'undefined')
|
|
|
|
{
|
|
|
|
egw(window).message(msg);
|
|
|
|
delete _data.content.msg;
|
|
|
|
}
|
|
|
|
|
2013-10-28 21:16:49 +01:00
|
|
|
// Register a handler for AJAX responses
|
|
|
|
egw(currentapp, window).registerJSONPlugin(etemplate2_handle_assign, this, 'assign');
|
2013-10-30 15:07:29 +01:00
|
|
|
|
2015-08-25 18:19:40 +02:00
|
|
|
if(egw.debug_level() >= 3)
|
2013-10-28 21:16:49 +01:00
|
|
|
{
|
2015-08-25 18:19:40 +02:00
|
|
|
if(console.groupCollapsed)
|
|
|
|
{
|
|
|
|
egw.window.console.groupCollapsed("Loading %s into ", _name, '#'+this.DOMContainer.id);
|
|
|
|
}
|
2014-01-09 17:44:34 +01:00
|
|
|
}
|
2015-08-25 18:19:40 +02:00
|
|
|
// Timing & profiling on debug level 'log' (4)
|
|
|
|
if(egw.debug_level() >= 4)
|
2014-01-09 17:53:42 +01:00
|
|
|
{
|
2015-08-25 18:19:40 +02:00
|
|
|
if(console.time)
|
|
|
|
{
|
|
|
|
console.time(_name);
|
|
|
|
}
|
|
|
|
if(console.profile)
|
|
|
|
{
|
|
|
|
console.profile(_name);
|
|
|
|
}
|
|
|
|
var start_time = (new Date).getTime();
|
2014-01-09 14:38:32 +01:00
|
|
|
}
|
2013-10-30 15:07:29 +01:00
|
|
|
|
2013-10-07 19:00:03 +02:00
|
|
|
// require necessary translations from server, if not already loaded
|
2013-10-08 10:55:15 +02:00
|
|
|
if (!$j.isArray(_data.langRequire)) _data.langRequire = [];
|
|
|
|
egw(currentapp, window).langRequire(window, _data.langRequire, function()
|
2013-10-07 19:00:03 +02:00
|
|
|
{
|
2013-10-08 10:55:15 +02:00
|
|
|
// Initialize application js
|
|
|
|
var app_callback = null;
|
|
|
|
// Only initialize once
|
2013-11-04 21:54:23 +01:00
|
|
|
// new app class with constructor function in app.classes[appname]
|
|
|
|
if (typeof app[appname] !== 'object' && typeof app.classes[appname] == 'function')
|
|
|
|
{
|
|
|
|
app[appname] = new app.classes[appname]();
|
|
|
|
}
|
|
|
|
// old app class with constructor function in app[appname] (deprecated)
|
|
|
|
else if(typeof app[appname] == "function")
|
2013-02-12 16:46:14 +01:00
|
|
|
{
|
2013-10-08 10:55:15 +02:00
|
|
|
(function() { new app[appname]();}).call();
|
2013-02-12 16:46:14 +01:00
|
|
|
}
|
2016-03-17 19:12:36 +01:00
|
|
|
else if (appname && typeof app[appname] !== "object")
|
2013-04-09 10:45:59 +02:00
|
|
|
{
|
2013-10-30 15:07:29 +01:00
|
|
|
egw.debug("warn", "Did not load '%s' JS object",appname);
|
2013-04-09 10:45:59 +02:00
|
|
|
}
|
2014-11-28 18:34:38 +01:00
|
|
|
// If etemplate current app does not match app owning the template,
|
|
|
|
// initialize the current app too
|
|
|
|
if (typeof app[this.app] !== 'object' && typeof app.classes[this.app] == 'function')
|
|
|
|
{
|
|
|
|
app[this.app] = new app.classes[this.app]();
|
|
|
|
}
|
2013-10-08 10:55:15 +02:00
|
|
|
if(typeof app[appname] == "object")
|
2013-07-20 15:57:53 +02:00
|
|
|
{
|
2014-02-17 15:58:20 +01:00
|
|
|
app_callback = function(_et2, _name) {
|
|
|
|
app[appname].et2_ready(_et2, _name);
|
|
|
|
};
|
2013-07-20 15:57:53 +02:00
|
|
|
}
|
2013-10-30 15:07:29 +01:00
|
|
|
|
2013-10-08 10:55:15 +02:00
|
|
|
// Create the document fragment into which the HTML will be injected
|
|
|
|
var frag = document.createDocumentFragment();
|
2013-10-30 15:07:29 +01:00
|
|
|
|
|
|
|
|
2013-10-08 10:55:15 +02:00
|
|
|
// Clear any existing instance
|
|
|
|
this.clear();
|
2013-10-30 15:07:29 +01:00
|
|
|
|
2013-10-08 10:55:15 +02:00
|
|
|
// Create the basic widget container and attach it to the DOM
|
|
|
|
this.widgetContainer = new et2_container(null);
|
|
|
|
this.widgetContainer.setApiInstance(egw(currentapp, egw.elemWindow(this.DOMContainer)));
|
|
|
|
this.widgetContainer.setInstanceManager(this);
|
|
|
|
this.widgetContainer.setParentDOMNode(this.DOMContainer);
|
2013-10-30 15:07:29 +01:00
|
|
|
|
2013-10-08 10:55:15 +02:00
|
|
|
// store the id to submit it back to server
|
|
|
|
if(_data) {
|
|
|
|
this.etemplate_exec_id = _data.etemplate_exec_id;
|
|
|
|
// set app_header
|
2013-12-13 02:15:41 +01:00
|
|
|
if (typeof _data.app_header == 'string')
|
|
|
|
{
|
|
|
|
window.egw_app_header(_data.app_header);
|
|
|
|
}
|
2014-01-16 13:52:25 +01:00
|
|
|
// bind our unload handler
|
|
|
|
this.bind_unload();
|
2013-10-08 10:55:15 +02:00
|
|
|
}
|
2013-10-30 15:07:29 +01:00
|
|
|
|
2013-10-08 10:55:15 +02:00
|
|
|
var _load = function() {
|
2013-10-28 21:16:49 +01:00
|
|
|
egw.debug("log", "Loading template...");
|
2015-08-25 18:19:40 +02:00
|
|
|
if(egw.debug_level() >= 4 && console.timeStamp)
|
2014-01-10 15:27:21 +01:00
|
|
|
{
|
|
|
|
console.timeStamp("Begin rendering template");
|
|
|
|
}
|
2013-10-30 15:07:29 +01:00
|
|
|
|
2013-12-13 00:37:12 +01:00
|
|
|
// Add into indexed list - do this before, so anything looking can find it,
|
|
|
|
// even if it's not loaded
|
|
|
|
if(typeof etemplate2._byTemplate[_name] == "undefined")
|
|
|
|
{
|
|
|
|
etemplate2._byTemplate[_name] = [];
|
|
|
|
}
|
|
|
|
etemplate2._byTemplate[_name].push(this);
|
|
|
|
|
2015-08-20 16:57:18 +02:00
|
|
|
// Read the XML structure of the requested template
|
|
|
|
this.widgetContainer.loadFromXML(this.templates[this.name]);
|
2013-10-30 15:07:29 +01:00
|
|
|
|
2013-10-16 22:48:05 +02:00
|
|
|
// List of Promises from widgets that are not quite fully loaded
|
|
|
|
var deferred = [];
|
2013-10-30 15:07:29 +01:00
|
|
|
|
2013-10-08 10:55:15 +02:00
|
|
|
// Inform the widget tree that it has been successfully loaded.
|
2013-10-16 22:48:05 +02:00
|
|
|
this.widgetContainer.loadingFinished(deferred);
|
2013-10-30 15:07:29 +01:00
|
|
|
|
2014-01-10 16:54:35 +01:00
|
|
|
// Connect to the window resize event
|
2014-12-05 18:29:41 +01:00
|
|
|
$j(window).on("resize."+this.uniqueId, this, function(e) {e.data.resize(e);});
|
2014-01-16 13:13:16 +01:00
|
|
|
|
2013-10-08 10:55:15 +02:00
|
|
|
// Insert the document fragment to the DOM Container
|
|
|
|
this.DOMContainer.appendChild(frag);
|
2013-10-30 15:07:29 +01:00
|
|
|
|
2015-09-01 00:32:50 +02:00
|
|
|
if(egw.debug_level() >= 3 && console.groupEnd)
|
2013-10-28 21:16:49 +01:00
|
|
|
{
|
|
|
|
egw.window.console.groupEnd();
|
|
|
|
}
|
|
|
|
if(deferred.length > 0)
|
|
|
|
{
|
|
|
|
var still_deferred = 0;
|
|
|
|
$j(deferred).each(function() {if(this.state() == "pending") still_deferred++;});
|
|
|
|
if(still_deferred > 0)
|
|
|
|
{
|
|
|
|
egw.debug("log", "Template loaded, waiting for %d/%d deferred to finish...",still_deferred, deferred.length);
|
|
|
|
}
|
|
|
|
}
|
2013-10-30 15:07:29 +01:00
|
|
|
|
2013-10-16 22:48:05 +02:00
|
|
|
// Wait for everything to be loaded, then finish it up
|
2014-05-27 00:27:57 +02:00
|
|
|
jQuery.when.apply(jQuery, deferred).done(jQuery.proxy(function() {
|
2013-10-28 21:16:49 +01:00
|
|
|
egw.debug("log", "Finished loading %s, triggering load event", _name);
|
2015-01-23 15:32:47 +01:00
|
|
|
|
2014-12-10 16:59:34 +01:00
|
|
|
if (typeof window.framework != 'undefined' && typeof window.framework.et2_loadingFinished != 'undefined')
|
2014-12-10 16:53:28 +01:00
|
|
|
{
|
|
|
|
//Call loading finished method of the framework with local window
|
|
|
|
window.framework.et2_loadingFinished(egw(window).window);
|
|
|
|
}
|
2013-10-16 22:48:05 +02:00
|
|
|
// Trigger the "resize" event
|
|
|
|
this.resize();
|
|
|
|
|
2014-12-04 00:43:34 +01:00
|
|
|
// Automatically set focus to first visible input for popups
|
|
|
|
if(this.widgetContainer._egw.is_popup() && $j('[autofocus]',this.DOMContainer).focus().length == 0)
|
|
|
|
{
|
2015-03-18 17:55:53 +01:00
|
|
|
var $input = $j('input:visible',this.DOMContainer)
|
2014-12-04 00:43:34 +01:00
|
|
|
// Date fields open the calendar popup on focus
|
|
|
|
.not('.et2_date')
|
|
|
|
.filter(function() {
|
|
|
|
// Skip inputs that are out of tab ordering
|
2015-03-30 15:41:12 +02:00
|
|
|
var $this = $j(this);
|
2014-12-04 00:43:34 +01:00
|
|
|
return !$this.attr('tabindex') || $this.attr('tabIndex')>=0;
|
2015-03-18 17:55:53 +01:00
|
|
|
}).first();
|
2015-03-20 03:12:33 +01:00
|
|
|
|
2015-03-18 17:55:53 +01:00
|
|
|
// mobile device, focus only if the field is empty (usually means new entry)
|
|
|
|
// should focus always for non-mobile one
|
|
|
|
if (egwIsMobile() && $input.val() == "" || !egwIsMobile()) $input.focus();
|
|
|
|
}
|
2015-01-23 15:32:47 +01:00
|
|
|
|
2013-10-16 22:48:05 +02:00
|
|
|
// Tell others about it
|
|
|
|
if(typeof _callback == "function")
|
|
|
|
{
|
2014-02-17 15:58:20 +01:00
|
|
|
_callback.call(window,this,_name);
|
2013-10-16 22:48:05 +02:00
|
|
|
}
|
2016-03-21 16:31:02 +01:00
|
|
|
if(app_callback && _callback != app_callback && !_no_et2_ready)
|
2013-10-16 22:48:05 +02:00
|
|
|
{
|
2014-02-17 15:58:20 +01:00
|
|
|
app_callback.call(window,this,_name);
|
2013-10-16 22:48:05 +02:00
|
|
|
}
|
2016-03-21 16:31:02 +01:00
|
|
|
if(appname && appname != this.app && typeof app[this.app] == "object" && !_no_et2_ready)
|
2014-11-19 00:10:41 +01:00
|
|
|
{
|
|
|
|
// Loaded a template from a different application?
|
|
|
|
// Let the application that loaded it know too
|
2016-03-17 19:12:36 +01:00
|
|
|
app[this.app].et2_ready(this, this.name);
|
2014-11-19 00:10:41 +01:00
|
|
|
}
|
2013-10-16 22:48:05 +02:00
|
|
|
|
|
|
|
$j(this.DOMContainer).trigger('load', this);
|
2014-01-09 13:20:13 +01:00
|
|
|
|
2014-01-10 15:27:21 +01:00
|
|
|
// Profiling
|
2015-08-25 18:19:40 +02:00
|
|
|
if(egw.debug_level() >= 4)
|
2014-01-10 15:27:21 +01:00
|
|
|
{
|
2015-08-25 18:19:40 +02:00
|
|
|
if(console.timeEnd)
|
|
|
|
{
|
|
|
|
console.timeEnd(_name);
|
|
|
|
}
|
|
|
|
if(console.profileEnd)
|
|
|
|
{
|
|
|
|
console.profileEnd(_name);
|
|
|
|
}
|
|
|
|
var end_time = (new Date).getTime();
|
|
|
|
var gen_time_div = $j('#divGenTime_'+appname);
|
|
|
|
if (!gen_time_div.length) gen_time_div = $j('.pageGenTime');
|
|
|
|
gen_time_div.find('.et2RenderTime').remove();
|
|
|
|
gen_time_div.append('<span class="et2RenderTime">'+egw.lang('eT2 rendering took %1s', (end_time-start_time)/1000)+'</span>');
|
2014-01-10 15:27:21 +01:00
|
|
|
}
|
2013-10-16 22:48:05 +02:00
|
|
|
},this));
|
2014-01-24 10:27:52 +01:00
|
|
|
};
|
2013-10-30 15:07:29 +01:00
|
|
|
|
|
|
|
|
2013-10-08 10:55:15 +02:00
|
|
|
// Load & process
|
2015-10-26 22:13:34 +01:00
|
|
|
try {
|
|
|
|
if (this.templates[_name])
|
|
|
|
{
|
|
|
|
// Set array managers first, or errors will happen
|
|
|
|
this.widgetContainer.setArrayMgrs(this._createArrayManagers(_data));
|
2013-10-30 15:07:29 +01:00
|
|
|
|
2015-10-26 22:13:34 +01:00
|
|
|
// Already have it
|
|
|
|
_load.apply(this,[]);
|
|
|
|
return;
|
|
|
|
}
|
2013-10-08 10:55:15 +02:00
|
|
|
}
|
2015-10-26 22:13:34 +01:00
|
|
|
catch (e) {
|
|
|
|
// wired security exception in IE denying access to template cache in opener
|
2015-10-27 14:39:01 +01:00
|
|
|
if (e.message == 'Permission denied')
|
|
|
|
{
|
|
|
|
etemplate2.prototype.templates = {};
|
|
|
|
}
|
|
|
|
// other error eg. in app.js et2_ready or event handlers --> rethrow it
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw e;
|
|
|
|
}
|
2013-10-08 10:55:15 +02:00
|
|
|
}
|
2015-10-26 22:13:34 +01:00
|
|
|
// 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) this.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));
|
2013-10-08 10:55:15 +02:00
|
|
|
}, this);
|
2013-04-13 21:00:13 +02:00
|
|
|
};
|
2011-08-15 14:34:00 +02:00
|
|
|
|
2013-08-23 17:15:30 +02:00
|
|
|
/**
|
|
|
|
* Check if template contains any dirty (unsaved) content
|
2013-10-30 15:07:29 +01:00
|
|
|
*
|
2013-08-23 17:15:30 +02:00
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
etemplate2.prototype.isDirty = function()
|
|
|
|
{
|
|
|
|
var dirty = false;
|
|
|
|
this.widgetContainer.iterateOver(function(_widget) {
|
|
|
|
if (_widget.isDirty && _widget.isDirty())
|
|
|
|
{
|
|
|
|
dirty = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return dirty;
|
|
|
|
};
|
|
|
|
|
2015-02-03 18:42:32 +01:00
|
|
|
/**
|
|
|
|
* Submit the et2_container form to a blank iframe in order to activate browser autocomplete
|
|
|
|
*/
|
|
|
|
etemplate2.prototype.autocomplete_fixer = function ()
|
|
|
|
{
|
|
|
|
var self = this;
|
|
|
|
var form = self.DOMContainer;
|
2015-10-26 22:13:34 +01:00
|
|
|
|
2015-09-23 17:51:46 +02:00
|
|
|
// Safari always do the autofill for password field regardless of autocomplete = off
|
|
|
|
// and since there's no other way to switch the autocomplete of, we should switch the
|
|
|
|
// form autocomplete off (e.g. compose dialog, attachment password field)
|
|
|
|
if (navigator.userAgent.match(/safari/i) && !navigator.userAgent.match(/chrome/i)
|
|
|
|
&& jQuery('input[type="password"]').length > 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-10-26 22:13:34 +01:00
|
|
|
|
2015-02-03 18:42:32 +01:00
|
|
|
if (form)
|
|
|
|
{
|
2015-09-01 14:05:40 +02:00
|
|
|
// Stop submit propagation in order to not fire other possible submit events
|
|
|
|
// for instance, CKEditor has its own submit event handler which we do not want to
|
|
|
|
// fire that on submit
|
|
|
|
form.onsubmit = function(e){e.stopPropagation();};
|
|
|
|
|
2015-02-03 18:42:32 +01:00
|
|
|
// Firefox give a security warning when transmitting to "about:blank" from a https site
|
|
|
|
// we work around that by giving existing etemplate/empty.html url
|
2015-02-20 20:04:58 +01:00
|
|
|
// Safari shows same warning, thought Chrome userAgent also includes Safari
|
2015-03-31 14:30:43 +02:00
|
|
|
if (navigator.userAgent.match(/(firefox|safari|iceweasel)/i) && !navigator.userAgent.match(/chrome/i))
|
2015-02-20 20:04:58 +01:00
|
|
|
{
|
|
|
|
jQuery(form).attr({action: egw.webserverUrl+'/etemplate/empty.html',method:'post'});
|
|
|
|
}
|
2015-09-01 14:05:40 +02:00
|
|
|
// need to trigger submit because submit() would not trigger onsubmit event
|
|
|
|
// since the submit does not get fired directly via user interaction.
|
|
|
|
jQuery(form).trigger('submit');
|
2015-02-03 18:42:32 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-10-30 15:07:29 +01:00
|
|
|
/**
|
|
|
|
* Submit form via ajax
|
|
|
|
*
|
2014-02-06 18:27:01 +01:00
|
|
|
* @param {(et2_button|string)} button button widget or string with id
|
|
|
|
* @param {boolean} async true: do an asynchronious submit, default is synchronious
|
2014-04-02 20:49:43 +02:00
|
|
|
* @param {boolean} no_validation - Do not do individual widget validation, just submit their current values
|
2015-03-20 03:12:33 +01:00
|
|
|
* @param {et2_widget|undefined} _container container to submit, default whole template
|
2014-02-06 18:27:01 +01:00
|
|
|
* @return {boolean} true if submit was send, false if eg. validation stoped submit
|
2013-10-30 15:07:29 +01:00
|
|
|
*/
|
2015-03-20 03:12:33 +01:00
|
|
|
etemplate2.prototype.submit = function(button, async, no_validation, _container)
|
2011-08-15 16:29:58 +02:00
|
|
|
{
|
2014-04-02 20:49:43 +02:00
|
|
|
if(typeof no_validation == 'undefined')
|
|
|
|
{
|
|
|
|
no_validation = false;
|
|
|
|
}
|
2015-03-20 03:12:33 +01:00
|
|
|
var container = _container || this.widgetContainer;
|
2014-04-02 20:49:43 +02:00
|
|
|
|
2011-08-15 16:29:58 +02:00
|
|
|
// Get the form values
|
2015-03-20 03:12:33 +01:00
|
|
|
var values = this.getValues(container);
|
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;
|
2014-04-02 20:49:43 +02:00
|
|
|
if(!no_validation)
|
|
|
|
{
|
2015-03-20 03:12:33 +01:00
|
|
|
container.iterateOver(function(_widget) {
|
2014-04-02 20:49:43 +02:00
|
|
|
if (_widget.submit(values) === false)
|
|
|
|
{
|
|
|
|
canSubmit = false;
|
|
|
|
}
|
|
|
|
}, this, et2_ISubmitListener);
|
|
|
|
}
|
2011-08-26 11:58:25 +02:00
|
|
|
|
|
|
|
if (canSubmit)
|
2011-08-15 16:29:58 +02:00
|
|
|
{
|
2013-10-30 15:07:29 +01:00
|
|
|
if (typeof button == 'string')
|
|
|
|
{
|
|
|
|
button = this.widgetContainer.getWidgetById(button);
|
|
|
|
}
|
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-12-04 01:15:50 +01:00
|
|
|
values.button = {};
|
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]];
|
|
|
|
}
|
2013-12-04 01:15:50 +01:00
|
|
|
if(target != values || button.id.indexOf('[') != -1 && path.length == 0)
|
2011-11-09 22:34:02 +01:00
|
|
|
{
|
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];
|
|
|
|
}
|
|
|
|
}
|
2014-07-07 15:25:20 +02:00
|
|
|
else if (typeof values.button == 'undefined' || jQuery.isEmptyObject(values.button))
|
2013-12-04 01:15:50 +01:00
|
|
|
{
|
2014-07-07 15:25:20 +02:00
|
|
|
delete values.button;
|
|
|
|
values[button.id] = true;
|
2013-12-04 01:15:50 +01:00
|
|
|
}
|
2011-11-09 22:34:02 +01:00
|
|
|
}
|
|
|
|
|
2011-08-16 20:18:18 +02:00
|
|
|
// Create the request object
|
2013-09-10 20:56:50 +02:00
|
|
|
if (this.menuaction)
|
2011-08-16 20:18:18 +02:00
|
|
|
{
|
2015-02-03 18:42:32 +01:00
|
|
|
|
|
|
|
//Autocomplete
|
|
|
|
this.autocomplete_fixer();
|
|
|
|
|
2014-01-16 13:13:16 +01:00
|
|
|
// unbind our session-destroy handler, as we are submitting
|
|
|
|
this.unbind_unload();
|
|
|
|
|
2012-03-06 14:22:01 +01:00
|
|
|
var api = this.widgetContainer.egw();
|
2014-04-02 21:30:33 +02:00
|
|
|
var request = api.json(this.menuaction, [this.etemplate_exec_id, values, no_validation], null, this, async);
|
2012-03-05 16:02:32 +01:00
|
|
|
request.sendRequest();
|
2011-08-16 20:18:18 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-10 20:56:50 +02:00
|
|
|
this.widgetContainer.egw().debug("warn", "Missing menuaction for submit. Values: ", values);
|
2011-08-16 20:18:18 +02:00
|
|
|
}
|
2011-08-15 16:29:58 +02:00
|
|
|
}
|
2013-10-30 15:07:29 +01:00
|
|
|
return canSubmit;
|
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)
|
|
|
|
{
|
2014-01-16 13:13:16 +01:00
|
|
|
// unbind our session-destroy handler, as we are submitting
|
|
|
|
this.unbind_unload();
|
|
|
|
|
2013-10-30 15:07:29 +01:00
|
|
|
var form = jQuery("<form id='form' action='"+egw().webserverUrl +
|
2013-08-19 21:53:45 +02:00
|
|
|
"/etemplate/process_exec.php?menuaction=" + this.widgetContainer.egw().getAppName()+ "&ajax=true' 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.
|
2014-02-06 18:27:01 +01:00
|
|
|
*
|
|
|
|
* @param {et2_widget} _root widget to start iterating
|
2011-08-23 16:59:49 +02:00
|
|
|
*/
|
|
|
|
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();
|
2013-10-30 15:07:29 +01:00
|
|
|
|
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
|
|
|
|
{
|
2013-10-30 15:07:29 +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
|
|
|
{
|
2013-11-08 17:28:07 +01:00
|
|
|
// Don't warn about children of nextmatch header - they're part of nm value
|
|
|
|
if(!_widget.getParent().instanceOf(et2_nextmatch_header_bar))
|
|
|
|
{
|
|
|
|
egw.debug("warn", _widget, "Overwriting value of '" + _widget.id +
|
|
|
|
"', id exists twice!");
|
|
|
|
}
|
2011-08-23 16:59:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
2014-05-23 18:00:17 +02:00
|
|
|
if(typeof _target[id] == 'object' && typeof value == 'object')
|
2012-07-05 00:41:51 +02:00
|
|
|
{
|
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.
|
2013-10-30 15:07:29 +01:00
|
|
|
*
|
2014-05-23 10:21:11 +02:00
|
|
|
* @see egw_message.refresh()
|
|
|
|
*
|
2014-02-06 18:27:01 +01:00
|
|
|
* @param {string} msg message to try to display. eg: "Entry added" (not used anymore, handeled by egw_refresh and egw_message)
|
|
|
|
* @param {string} app app-name
|
|
|
|
* @param {(string|null)} id application specific entry ID to try to refresh
|
|
|
|
* @param {(string|null)} type type of change. One of 'update','edit', 'delete', 'add' or null
|
2014-05-23 10:21:11 +02:00
|
|
|
* @return {boolean} true if nextmatch found and refreshed, false if not
|
2013-02-12 16:46:14 +01:00
|
|
|
*/
|
2013-02-14 12:25:24 +01:00
|
|
|
etemplate2.prototype.refresh = function(msg, app, id, type)
|
2013-02-12 16:46:14 +01:00
|
|
|
{
|
2014-02-06 18:27:01 +01:00
|
|
|
msg, app; // unused but required by function signature
|
2014-02-14 16:01:45 +01:00
|
|
|
var refresh_done = false;
|
|
|
|
|
2013-02-25 21:35:17 +01:00
|
|
|
// Refresh nextmatches
|
|
|
|
this.widgetContainer.iterateOver(function(_widget) {
|
|
|
|
// Trigger refresh
|
|
|
|
_widget.refresh(id,type);
|
2014-02-14 16:01:45 +01:00
|
|
|
refresh_done = true;
|
2013-02-25 21:35:17 +01:00
|
|
|
}, this, et2_nextmatch);
|
2014-02-14 16:01:45 +01:00
|
|
|
|
|
|
|
return refresh_done;
|
2013-04-13 21:00:13 +02:00
|
|
|
};
|
2013-02-12 16:46:14 +01:00
|
|
|
|
2014-05-23 10:21:11 +02:00
|
|
|
/**
|
|
|
|
* "Intelligently" refresh a given app
|
|
|
|
*
|
|
|
|
* @see egw_message.refresh()
|
|
|
|
*
|
|
|
|
* @param {string} _msg message to try to display. eg: "Entry added" (not used anymore, handeled by egw_refresh and egw_message)
|
|
|
|
* @param {string} _app app-name
|
|
|
|
* @param {(string|null)} _id application specific entry ID to try to refresh
|
|
|
|
* @param {(string|null)} _type type of change. One of 'update','edit', 'delete', 'add' or null
|
|
|
|
* @return {boolean} true if nextmatch found and refreshed, false if not
|
|
|
|
*/
|
|
|
|
etemplate2.app_refresh = function(_msg, _app, _id, _type)
|
|
|
|
{
|
|
|
|
var refresh_done = false;
|
|
|
|
var et2 = etemplate2.getByApplication(_app);
|
|
|
|
for(var i = 0; i < et2.length; i++)
|
|
|
|
{
|
|
|
|
refresh_done = et2[i].refresh(_msg,_app,_id,_type) || refresh_done;
|
|
|
|
}
|
|
|
|
return refresh_done;
|
|
|
|
};
|
|
|
|
|
2015-01-27 17:26:59 +01:00
|
|
|
/**
|
2015-02-11 19:05:14 +01:00
|
|
|
* "Intelligently" print a given etemplate
|
2015-01-27 17:26:59 +01:00
|
|
|
*
|
|
|
|
* Mostly, we let the nextmatch change how many rows it's showing, so you don't
|
|
|
|
* get just one printed page.
|
2015-02-11 19:05:14 +01:00
|
|
|
*
|
|
|
|
* @return {Deferred[]} A list of Deferred objects that must complete before
|
|
|
|
* actual printing can begin.
|
2015-01-27 17:26:59 +01:00
|
|
|
*/
|
2015-02-11 19:05:14 +01:00
|
|
|
etemplate2.prototype.print = function()
|
2015-01-27 17:26:59 +01:00
|
|
|
{
|
|
|
|
// Sometimes changes take time
|
|
|
|
var deferred = [];
|
|
|
|
|
2015-02-11 19:05:14 +01:00
|
|
|
// Skip hidden etemplates
|
2016-03-31 22:55:41 +02:00
|
|
|
if(jQuery(this.DOMContainer).filter(':visible').length === 0) return [];
|
2015-02-11 19:05:14 +01:00
|
|
|
|
|
|
|
// Allow any widget to change for printing
|
|
|
|
this.widgetContainer.iterateOver(function(_widget) {
|
|
|
|
// Skip widgets from a different etemplate (home)
|
|
|
|
if(_widget.getInstanceManager() != this) return;
|
|
|
|
var result = _widget.beforePrint();
|
|
|
|
if (typeof result == "object" && result.done)
|
2015-01-27 17:26:59 +01:00
|
|
|
{
|
2015-02-11 19:05:14 +01:00
|
|
|
deferred.push(result);
|
2015-01-27 17:26:59 +01:00
|
|
|
}
|
2015-02-11 19:05:14 +01:00
|
|
|
},this,et2_IPrint);
|
|
|
|
|
|
|
|
return deferred;
|
2015-02-20 20:04:58 +01:00
|
|
|
};
|
2015-01-27 17:26:59 +01: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
|
2013-10-30 15:07:29 +01:00
|
|
|
*
|
2013-02-12 16:46:14 +01:00
|
|
|
* "Associated" is determined by the first part of the template
|
|
|
|
*
|
2014-02-06 18:27:01 +01:00
|
|
|
* @param {string} app app-name
|
|
|
|
* @return {array} list of etemplate2 that have that app as the first part of their loaded template
|
2013-02-12 16:46:14 +01:00
|
|
|
*/
|
|
|
|
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
|
|
|
|
2014-03-11 16:28:18 +01:00
|
|
|
/**
|
|
|
|
* Get a etemplate2 object from the given DOM ID
|
|
|
|
*
|
|
|
|
* @param {string} id DOM ID of the container node
|
|
|
|
* @returns {etemplate2|null}
|
|
|
|
*/
|
|
|
|
etemplate2.getById = function(id)
|
|
|
|
{
|
|
|
|
for( var name in etemplate2._byTemplate)
|
|
|
|
{
|
|
|
|
for(var i = 0; i < etemplate2._byTemplate[name].length; i++)
|
|
|
|
{
|
|
|
|
var et = etemplate2._byTemplate[name][i];
|
|
|
|
|
|
|
|
if(et.DOMContainer.getAttribute("id") == id)
|
|
|
|
{
|
|
|
|
return et;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
2014-03-12 10:47:40 +01:00
|
|
|
};
|
2014-03-11 16:28:18 +01:00
|
|
|
|
2013-08-20 14:06:41 +02:00
|
|
|
/**
|
|
|
|
* Plugin for egw.json type "et2_load"
|
2013-10-30 15:07:29 +01:00
|
|
|
*
|
2013-08-20 14:06:41 +02:00
|
|
|
* @param _type
|
|
|
|
* @param _response
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
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;
|
2013-10-30 15:07:29 +01:00
|
|
|
|
2013-08-20 14:06:41 +02:00
|
|
|
// handle egw_framework::refresh_opener()
|
|
|
|
if (jQuery.isArray(data['refresh-opener']))
|
|
|
|
{
|
2014-05-22 17:29:14 +02:00
|
|
|
if (window.opener)// && typeof window.opener.egw_refresh == 'function')
|
2013-08-20 14:06:41 +02:00
|
|
|
{
|
2014-05-22 17:29:14 +02:00
|
|
|
var egw = window.egw(opener);
|
|
|
|
egw.refresh.apply(egw, data['refresh-opener']);
|
2013-08-20 14:06:41 +02:00
|
|
|
}
|
|
|
|
}
|
2014-05-22 17:29:14 +02:00
|
|
|
var egw = window.egw(window);
|
2013-08-20 14:06:41 +02:00
|
|
|
|
2013-12-13 02:15:41 +01:00
|
|
|
// need to set app_header before message, as message temp. replaces app_header
|
2013-12-16 19:11:53 +01:00
|
|
|
if (typeof data.data == 'object' && typeof data.data.app_header == 'string')
|
2013-12-13 02:15:41 +01:00
|
|
|
{
|
2014-05-22 17:29:14 +02:00
|
|
|
egw.app_header(data.data.app_header, data.data.currentapp||null);
|
2013-12-13 02:15:41 +01:00
|
|
|
delete data.data.app_header;
|
|
|
|
}
|
|
|
|
|
2013-10-03 11:09:24 +02:00
|
|
|
// handle egw_framework::message()
|
2013-12-13 02:15:41 +01:00
|
|
|
if (jQuery.isArray(data.message))
|
2013-10-03 11:09:24 +02:00
|
|
|
{
|
2014-05-22 17:29:14 +02:00
|
|
|
egw.message.apply(egw, data.message);
|
2013-10-03 11:09:24 +02:00
|
|
|
}
|
|
|
|
|
2013-08-20 15:25:36 +02:00
|
|
|
// handle egw_framework::window_close(), this will terminate execution
|
2013-08-20 14:06:41 +02:00
|
|
|
if (data['window-close'])
|
|
|
|
{
|
2013-08-26 12:24:11 +02:00
|
|
|
if (typeof data['window-close'] == 'string' && data['window-close'] !== 'true')
|
|
|
|
{
|
|
|
|
alert(data['window-close']);
|
|
|
|
}
|
2014-12-01 11:45:24 +01:00
|
|
|
egw.close();
|
2014-01-13 16:07:03 +01:00
|
|
|
return true;
|
2013-08-20 14:06:41 +02:00
|
|
|
}
|
2013-10-30 15:07:29 +01:00
|
|
|
|
2013-08-20 15:25:36 +02:00
|
|
|
// handle egw_framework::window_focus()
|
|
|
|
if (data['window-focus'])
|
|
|
|
{
|
|
|
|
window.focus();
|
|
|
|
}
|
2013-10-07 19:00:03 +02:00
|
|
|
|
|
|
|
// handle framework.setSidebox calls
|
2013-12-13 00:32:30 +01:00
|
|
|
if (window.framework && jQuery.isArray(data.setSidebox))
|
2013-10-07 19:00:03 +02:00
|
|
|
{
|
2013-12-13 00:32:30 +01:00
|
|
|
window.framework.setSidebox.apply(window.framework, data.setSidebox);
|
2013-10-07 19:00:03 +02:00
|
|
|
}
|
2014-01-09 13:20:13 +01:00
|
|
|
|
2013-08-20 14:06:41 +02:00
|
|
|
// regular et2 re-load
|
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)
|
|
|
|
{
|
2016-02-23 22:18:33 +01:00
|
|
|
if(node.children.length)
|
|
|
|
{
|
|
|
|
// Node has children already? Check for loading over an
|
|
|
|
// existing etemplate
|
|
|
|
var old = etemplate2.getById(node.id);
|
|
|
|
if(old) old.clear();
|
|
|
|
}
|
2013-11-26 23:34:32 +01:00
|
|
|
var et2 = new etemplate2(node);
|
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
|
|
|
}
|
|
|
|
|
2013-08-20 14:06:41 +02:00
|
|
|
/**
|
|
|
|
* Plugin for egw.json type "et2_validation_error"
|
2013-10-30 15:07:29 +01:00
|
|
|
*
|
2013-08-20 14:06:41 +02:00
|
|
|
* @param _type
|
|
|
|
* @param _response
|
|
|
|
*/
|
2012-03-05 16:02:32 +01:00
|
|
|
function etemplate2_handle_validation_error(_type, _response)
|
|
|
|
{
|
|
|
|
// Display validation errors
|
2013-12-02 21:35:32 +01:00
|
|
|
for(var id in _response.data)
|
|
|
|
{
|
|
|
|
var widget = this.widgetContainer.getWidgetById(id);
|
|
|
|
if(widget)
|
|
|
|
{
|
|
|
|
widget.showMessage(_response.data[id],'validation_error');
|
2014-08-18 14:05:04 +02:00
|
|
|
|
|
|
|
// Handle validation_error (messages coming back from server as a response) if widget is children of a tabbox
|
|
|
|
var tmpWidget = widget;
|
|
|
|
while(tmpWidget._parent && tmpWidget._type != 'tabbox')
|
|
|
|
{
|
|
|
|
tmpWidget = tmpWidget._parent;
|
|
|
|
}
|
|
|
|
//Acvtivate the tab where the widget with validation error is located
|
|
|
|
if (tmpWidget._type == 'tabbox') tmpWidget.activateTab(widget);
|
|
|
|
|
2013-12-02 21:35:32 +01:00
|
|
|
}
|
|
|
|
}
|
2012-06-19 00:56:20 +02:00
|
|
|
egw().debug("warn","Validation errors", _response.data);
|
2012-03-05 16:02:32 +01:00
|
|
|
}
|
2013-10-09 14:56:49 +02:00
|
|
|
/**
|
|
|
|
* Handle assign for attributes on etemplate2 widgets
|
2013-10-30 15:07:29 +01:00
|
|
|
*
|
2014-02-06 18:27:01 +01:00
|
|
|
* @param {string} type "assign"
|
|
|
|
* @param {object} res Response
|
|
|
|
* res.data.id {String} Widget ID
|
|
|
|
* res.data.key {String} Attribute name
|
|
|
|
* res.data.value New value for widget
|
|
|
|
* res.data.etemplate_exec_id
|
|
|
|
* @param {object} req
|
2013-10-09 14:56:49 +02:00
|
|
|
* @returns {Boolean} Handled by this plugin
|
|
|
|
* @throws Invalid parameters if the required res.data parameters are missing
|
|
|
|
*/
|
|
|
|
function etemplate2_handle_assign(type, res, req)
|
|
|
|
{
|
2014-02-06 18:27:01 +01:00
|
|
|
type, req; // unused, but required by plugin signature
|
|
|
|
|
2013-10-09 14:56:49 +02:00
|
|
|
//Check whether all needed parameters have been passed and call the alertHandler function
|
2013-10-30 15:07:29 +01:00
|
|
|
if ((typeof res.data.id != 'undefined') &&
|
2013-10-09 14:56:49 +02:00
|
|
|
(typeof res.data.key != 'undefined') &&
|
|
|
|
(typeof res.data.value != 'undefined')
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if(typeof res.data.etemplate_exec_id == 'undefined' ||
|
|
|
|
res.data.etemplate_exec_id != this.etemplate_exec_id)
|
|
|
|
{
|
|
|
|
// Not for this etemplate, but not an error
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-11 13:20:21 +02:00
|
|
|
if (res.data.key == 'etemplate_exec_id')
|
|
|
|
{
|
|
|
|
this.etemplate_exec_id = res.data.value;
|
|
|
|
return true;
|
|
|
|
}
|
2014-04-01 23:42:06 +02:00
|
|
|
if(this.widgetContainer == null)
|
|
|
|
{
|
|
|
|
// Right etemplate, but it's already been cleared.
|
|
|
|
egw.debug('warn', "Tried to call assign on an un-loaded etemplate", res.data);
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-09 14:56:49 +02:00
|
|
|
var widget = this.widgetContainer.getWidgetById(res.data.id);
|
|
|
|
if (widget)
|
|
|
|
{
|
2014-01-13 16:07:03 +01:00
|
|
|
if(typeof widget['set_' + res.data.key] != 'function')
|
|
|
|
{
|
|
|
|
egw.debug('warn', "Cannot set %s attribute %s via JSON assign, no set_%s()",res.data.id,res.data.key,res.data.key);
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-09 14:56:49 +02:00
|
|
|
try
|
|
|
|
{
|
2013-10-09 19:15:44 +02:00
|
|
|
widget['set_' + res.data.key].call(widget,res.data.value);
|
2013-10-09 14:56:49 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
2014-02-05 18:19:18 +01:00
|
|
|
egw.debug("error", "When assigning %s on %s via AJAX, \n"+(e.message||e+""),res.data.key,res.data.id,widget);
|
2013-10-09 14:56:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
throw 'Invalid parameters';
|
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
}
|