|
|
|
@ -4,12 +4,13 @@
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$.fn.abpAjaxForm = function (userOptions) {
|
|
|
|
|
var $form = $(this);
|
|
|
|
|
userOptions = userOptions || {};
|
|
|
|
|
|
|
|
|
|
var options = $.extend({}, $.fn.abpAjaxForm.defaults, userOptions);
|
|
|
|
|
|
|
|
|
|
options.beforeSubmit = function (arr, $form) {
|
|
|
|
|
if (userOptions.beforeSubmit && userOptions.beforeSubmit.apply(this, arguments) === false) {
|
|
|
|
|
if ((userOptions.beforeSubmit && userOptions.beforeSubmit.apply(this, arguments)) === false) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -19,10 +20,26 @@
|
|
|
|
|
|
|
|
|
|
$form.find("button[type='submit']").buttonBusy(true);
|
|
|
|
|
//TODO: Disable other buttons..?
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
options.success = function (responseText, statusText, xhr, $form) {
|
|
|
|
|
userOptions.success && userOptions.success.apply(this, arguments);
|
|
|
|
|
$form.trigger('abp-ajax-success',
|
|
|
|
|
{
|
|
|
|
|
responseText: responseText,
|
|
|
|
|
statusText: statusText,
|
|
|
|
|
xhr: xhr,
|
|
|
|
|
$form: $form
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
options.error = function (jqXhr) {
|
|
|
|
|
if ((userOptions.error && userOptions.error.apply(this, arguments)) === false) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (jqXhr.getResponseHeader('_AbpErrorFormat') === 'true') {
|
|
|
|
|
abp.ajax.logError(jqXhr.responseJSON.error);
|
|
|
|
|
var messagePromise = abp.ajax.showError(jqXhr.responseJSON.error);
|
|
|
|
@ -34,18 +51,23 @@
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//TODO: Error?
|
|
|
|
|
|
|
|
|
|
options.complete = function (jqXhr, status, $form) {
|
|
|
|
|
if ($.contains(document, $form[0])) {
|
|
|
|
|
$form.find("button[type='submit']").buttonBusy(false);
|
|
|
|
|
//TODO: Re-enable other buttons..?
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$form.trigger('abp-ajax-complete',
|
|
|
|
|
{
|
|
|
|
|
status: status,
|
|
|
|
|
jqXhr: jqXhr,
|
|
|
|
|
$form: $form
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
userOptions.complete && userOptions.complete.apply(this, arguments);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return this.ajaxForm(options);
|
|
|
|
|
return $form.ajaxForm(options);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$.fn.abpAjaxForm.defaults = {
|
|
|
|
|