allow et2_dialog.confirm to postSubmit (to download something)

This commit is contained in:
Ralf Becker 2019-03-03 18:14:10 +01:00
parent 86444c5dff
commit 520e17c1b2
2 changed files with 65 additions and 48 deletions

View File

@ -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;
@ -663,9 +664,16 @@ jQuery.extend(et2_dialog, //(function(){ "use strict"; return
var callbackDialog = function (button_id)
{
if (button_id == et2_dialog.YES_BUTTON )
{
if (_postSubmit)
{
senders.getRoot().getInstanceManager().postSubmit(buttonId);
}
else
{
senders.getRoot().getInstanceManager().submit(buttonId);
}
}
};
et2_dialog.show_dialog(callbackDialog, egw.lang(dialogMsg), egw.lang(titleMsg), {},
et2_dialog.BUTTON_YES_NO, et2_dialog.WARNING_MESSAGE, undefined, egw);
@ -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", {

View File

@ -672,48 +672,8 @@ etemplate2.prototype.autocomplete_fixer = function ()
}
};
/**
* Submit form via ajax
*
* @param {(et2_button|string)} button button widget or string with id
* @param {boolean|string} async true: do an asynchronious submit, string: spinner message (please wait...)
* default is asynchronoush with message
* @param {boolean} no_validation - Do not do individual widget validation, just submit their current values
* @param {et2_widget|undefined} _container container to submit, default whole template
* @return {boolean} true if submit was send, false if eg. validation stoped submit
*/
etemplate2.prototype.submit = function(button, async, no_validation, _container)
etemplate2.prototype._set_button = function (button, values)
{
var api = this.widgetContainer.egw();
if (typeof async == 'undefined' || typeof async == 'string')
{
api.loading_prompt('et2_submit_spinner', true, api.lang(typeof async == 'string' ? async : 'Please wait...'));
async = true;
}
if(typeof no_validation == 'undefined')
{
no_validation = false;
}
var container = _container || this.widgetContainer;
// Get the form values
var values = this.getValues(container);
// Trigger the submit event
var canSubmit = true;
if(!no_validation)
{
container.iterateOver(function(_widget) {
if (_widget.submit(values) === false)
{
canSubmit = false;
}
}, this, et2_ISubmitListener);
}
if (canSubmit)
{
if (typeof button == 'string')
{
button = this.widgetContainer.getWidgetById(button);
@ -758,6 +718,51 @@ etemplate2.prototype.submit = function(button, async, no_validation, _container)
values[button.id] = true;
}
}
};
/**
* Submit form via ajax
*
* @param {(et2_button|string)} button button widget or string with id
* @param {boolean|string} async true: do an asynchronious submit, string: spinner message (please wait...)
* default is asynchronoush with message
* @param {boolean} no_validation - Do not do individual widget validation, just submit their current values
* @param {et2_widget|undefined} _container container to submit, default whole template
* @return {boolean} true if submit was send, false if eg. validation stoped submit
*/
etemplate2.prototype.submit = function(button, async, no_validation, _container)
{
var api = this.widgetContainer.egw();
if (typeof async == 'undefined' || typeof async == 'string')
{
api.loading_prompt('et2_submit_spinner', true, api.lang(typeof async == 'string' ? async : 'Please wait...'));
async = true;
}
if(typeof no_validation == 'undefined')
{
no_validation = false;
}
var container = _container || this.widgetContainer;
// Get the form values
var values = this.getValues(container);
// Trigger the submit event
var canSubmit = true;
if(!no_validation)
{
container.iterateOver(function(_widget) {
if (_widget.submit(values) === false)
{
canSubmit = false;
}
}, this, et2_ISubmitListener);
}
if (canSubmit)
{
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();