js: add support for inplace submit of simple forms popups (#8395)

This commit is contained in:
Frédéric Péters 2015-09-28 10:38:18 +02:00
parent 53d0c5c3e2
commit c1175029b0
1 changed files with 22 additions and 1 deletions

View File

@ -31,11 +31,16 @@
* behaviour.
*
* The JSON support depends on the presence of the jQuery Form plugin.
*
* Submit is done in place if the $anchor has a data-inplace-submit="true"
* attribute, a gadjo:dialog-done event is triggered on success, a
* gadjo:dialog-submit-error event is triggered on failure.
*/
var $anchor = $(this);
var url = $anchor.attr('href') || $anchor.data('url');
var selector = $anchor.data('selector') || 'form:not(.gadjo-popup-ignore)';
var title_selector = $anchor.data('title-selector') || '#appbar h2';
var inplace_submit = $anchor.data('inplace-submit');
function show_error(message) {
/* Add a div to body to show an error message and fade it out after 3
@ -132,7 +137,23 @@
* anything to server, just close the dialog */
button.click = function() { $form.dialog('destroy'); return false; };
} else {
button.click = function() { $form.find('button').click(); return false; };
button.click = function() {
if (inplace_submit) {
var action_url = $form.attr('action');
$.ajax({
type: 'POST',
url: action_url,
data: $form.serialize(),
}).success(function() {
$anchor.trigger('gadjo:dialog-done');
$form.dialog('destroy');
}).fail(function() { $anchor.trigger('gadjo:dialog-submit-error');
});
} else {
$form.find('button').click();
}
return false;
};
}
/* add custom classes to some buttons */