diff --git a/etemplate/js/etemplate2.js b/etemplate/js/etemplate2.js index de4686163c..19b4b6d796 100644 --- a/etemplate/js/etemplate2.js +++ b/etemplate/js/etemplate2.js @@ -84,16 +84,16 @@ function etemplate2(_container, _menuaction) // Copy the given parameters this.DOMContainer = _container; this.menuaction = _menuaction; - + // Unique ID to prevent DOM collisions across multiple templates this.uniqueId = _container.getAttribute("id") ? _container.getAttribute("id").replace('.','-') : ''; - + // Preset the object variable this.widgetContainer = null; // List of templates (XML) that are known, but not used. Indexed by id. this.templates = {}; - + // Connect to the window resize event $j(window).resize(this, function(e) {e.data.resize();}); } @@ -122,12 +122,12 @@ etemplate2.prototype.clear = function() { // Un-register handler this.widgetContainer.egw().unregisterJSONPlugin(etemplate2_handle_assign, this, 'assign'); - + this.widgetContainer.free(); this.widgetContainer = null; } $j(this.DOMContainer).empty(); - + // Remove self from the index for(name in this.templates) { @@ -194,15 +194,15 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback) { egw().debug("info", "Loaded data", _data); var currentapp = _data.currentapp || window.egw_appName; - + // Register a handler for AJAX responses egw(currentapp, window).registerJSONPlugin(etemplate2_handle_assign, this, 'assign'); - + if(console.groupCollapsed) { egw.window.console.groupCollapsed("Loading %s", _name); } - + // require necessary translations from server, if not already loaded if (!$j.isArray(_data.langRequire)) _data.langRequire = []; egw(currentapp, window).langRequire(window, _data.langRequire, function() @@ -210,7 +210,7 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback) // Appname should be first part of the template name var split = _name.split('.'); var appname = split[0]; - + // Initialize application js var app_callback = null; // Only initialize once @@ -220,48 +220,48 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback) } else if (typeof app[appname] !== "object") { - egw.debug("warn", "Did not load '%s' JS object",appname); + egw.debug("warn", "Did not load '%s' JS object",appname); } if(typeof app[appname] == "object") { app_callback = function(et2) {app[appname].et2_ready(et2);}; } - + // Create the document fragment into which the HTML will be injected var frag = document.createDocumentFragment(); - - + + // 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(currentapp, 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 window.egw_app_header(_data.app_header); } - + var _load = function() { egw.debug("log", "Loading template..."); - + // Read the XML structure of the requested template this.widgetContainer.loadFromXML(this.templates[_name || missing_name]); - + // List of Promises from widgets that are not quite fully loaded var deferred = []; - + // Inform the widget tree that it has been successfully loaded. this.widgetContainer.loadingFinished(deferred); - + // Insert the document fragment to the DOM Container this.DOMContainer.appendChild(frag); - + // Add into indexed list if(typeof etemplate2._byTemplate[_name] == "undefined") { @@ -282,11 +282,11 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback) egw.debug("log", "Template loaded, waiting for %d/%d deferred to finish...",still_deferred, deferred.length); } } - + // Wait for everything to be loaded, then finish it up jQuery.when.apply(null, deferred).done(jQuery.proxy(function() { egw.debug("log", "Finished loading %s, triggering load event", _name); - + // Trigger the "resize" event this.resize(); @@ -303,14 +303,14 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback) $j(this.DOMContainer).trigger('load', this); },this)); }; - - + + // Load & process if(!this.templates[_name]) { - // Asynchronously load the XET file + // 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]; @@ -320,7 +320,7 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback) } _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)); @@ -329,7 +329,7 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback) { // Set array managers first, or errors will happen this.widgetContainer.setArrayMgrs(this._createArrayManagers(_data)); - + // Already have it _load.apply(this,[]); } @@ -338,7 +338,7 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback) /** * Check if template contains any dirty (unsaved) content - * + * * @returns {Boolean} */ etemplate2.prototype.isDirty = function() @@ -354,7 +354,14 @@ etemplate2.prototype.isDirty = function() return dirty; }; -etemplate2.prototype.submit = function(button) +/** + * Submit form via ajax + * + * @param et2_button|string button button widget or string with id + * @param boolean async true: do an asynchronious submit, default is synchronious + * @return boolean true if submit was send, false if eg. validation stoped submit + */ +etemplate2.prototype.submit = function(button, async) { // Get the form values var values = this.getValues(this.widgetContainer); @@ -370,6 +377,10 @@ etemplate2.prototype.submit = function(button) if (canSubmit) { + if (typeof button == 'string') + { + button = this.widgetContainer.getWidgetById(button); + } // Button parameter used for submit buttons in datagrid // TODO: This should probably go in nextmatch's getValues(), along with selected rows somehow. // I'm just not sure how. @@ -383,7 +394,7 @@ etemplate2.prototype.submit = function(button) if(!values[path[i]]) values[path[i]] = {}; target = values[path[i]]; } - if(target != values) + if(target != values) { var indexes = button.id.split('['); if (indexes.length > 1) @@ -410,7 +421,7 @@ etemplate2.prototype.submit = function(button) if (this.menuaction) { var api = this.widgetContainer.egw(); - var request = api.json(this.menuaction, [this.etemplate_exec_id,values], null, this); + var request = api.json(this.menuaction, [this.etemplate_exec_id,values], null, this, async); request.sendRequest(); } else @@ -418,6 +429,7 @@ etemplate2.prototype.submit = function(button) this.widgetContainer.egw().debug("warn", "Missing menuaction for submit. Values: ", values); } } + return canSubmit; }; /** @@ -440,7 +452,7 @@ etemplate2.prototype.postSubmit = function() if (canSubmit) { - var form = jQuery("