diff --git a/api/js/etemplate/et2_widget_dialog.js b/api/js/etemplate/et2_widget_dialog.js index 64bdc16081..1ca21aa9c0 100644 --- a/api/js/etemplate/et2_widget_dialog.js +++ b/api/js/etemplate/et2_widget_dialog.js @@ -650,10 +650,11 @@ jQuery.extend(et2_dialog, //(function(){ "use strict"; return * @param {widget} _senders widget that has been clicked * @param {String} _dialogMsg message shows in dialog box * @param {String} _titleMsg message shows as a title of the dialog box + * @param {Bool} _postSubmit true: use postSubmit instead of submit * * @description submit the form contents including the button that has been pressed */ - confirm: function(_senders,_dialogMsg, _titleMsg) + confirm: function(_senders,_dialogMsg, _titleMsg, _postSubmit) { var senders = _senders; var buttonId = _senders.id; @@ -664,7 +665,14 @@ jQuery.extend(et2_dialog, //(function(){ "use strict"; return { if (button_id == et2_dialog.YES_BUTTON ) { - senders.getRoot().getInstanceManager().submit(buttonId); + if (_postSubmit) + { + senders.getRoot().getInstanceManager().postSubmit(buttonId); + } + else + { + senders.getRoot().getInstanceManager().submit(buttonId); + } } }; et2_dialog.show_dialog(callbackDialog, egw.lang(dialogMsg), egw.lang(titleMsg), {}, @@ -764,7 +772,7 @@ jQuery.extend(et2_dialog, //(function(){ "use strict"; return .text(response.data) .appendTo(log); - totals.failed++ + totals.failed++; // Ask to retry / ignore / abort et2_createWidget("dialog", { diff --git a/api/js/etemplate/etemplate2.js b/api/js/etemplate/etemplate2.js index d175f016a9..90b094f505 100644 --- a/api/js/etemplate/etemplate2.js +++ b/api/js/etemplate/etemplate2.js @@ -672,6 +672,54 @@ etemplate2.prototype.autocomplete_fixer = function () } }; +etemplate2.prototype._set_button = function (button, values) +{ + 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. + if(button && !values.button) + { + values.button = {}; + 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 || button.id.indexOf('[') != -1 && path.length == 0) + { + 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); + } + } + 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]; + } + } + else if (typeof values.button == 'undefined' || jQuery.isEmptyObject(values.button)) + { + delete values.button; + values[button.id] = true; + } + } +}; + /** * Submit form via ajax * @@ -714,50 +762,7 @@ etemplate2.prototype.submit = function(button, async, no_validation, _container) 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. - if(button && !values.button) - { - values.button = {}; - 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 || button.id.indexOf('[') != -1 && path.length == 0) - { - 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); - } - } - 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]; - } - } - else if (typeof values.button == 'undefined' || jQuery.isEmptyObject(values.button)) - { - delete values.button; - values[button.id] = true; - } - } + if (button) this._set_button(button, values); // Create the request object if (this.menuaction) @@ -788,8 +793,10 @@ etemplate2.prototype.submit = function(button, async, no_validation, _container) * * Only use this one if you need it, use the ajax submit() instead. * It ensures eT2 session continues to exist on server by unbinding unload handler and rebinding it. + * + * @param {(et2_button|string)} button button widget or string with id */ -etemplate2.prototype.postSubmit = function() +etemplate2.prototype.postSubmit = function(button) { // Get the form values var values = this.getValues(this.widgetContainer); @@ -805,6 +812,8 @@ etemplate2.prototype.postSubmit = function() if (canSubmit) { + if (button) this._set_button(button, values); + // unbind our session-destroy handler, as we are submitting this.unbind_unload();