mirror of https://github.com/abpframework/abp.git
3 changed files with 57 additions and 1 deletions
@ -0,0 +1,47 @@ |
|||
(function ($) { |
|||
if (!$ || !$.fn.ajaxForm) { |
|||
return; |
|||
} |
|||
|
|||
$.fn.abpAjaxForm = function (userOptions) { |
|||
userOptions = userOptions || {}; |
|||
|
|||
var options = $.extend({}, $.fn.abpAjaxForm.defaults, userOptions); |
|||
|
|||
options.beforeSubmit = function (arr, $form) { |
|||
userOptions.beforeSubmit && userOptions.beforeSubmit.apply(this, arguments); |
|||
$form.find("button[type='submit']").buttonBusy(true); |
|||
//TODO: Disable other buttons..?
|
|||
}; |
|||
|
|||
options.error = function (jqXhr) { |
|||
if (jqXhr.getResponseHeader('_AbpErrorFormat') === 'true') { |
|||
abp.ajax.logError(jqXhr.responseJSON.error); |
|||
var messagePromise = abp.ajax.showError(jqXhr.responseJSON.error); |
|||
if (jqXhr.status === 401) { |
|||
abp.ajax.handleUnAuthorizedRequest(messagePromise); |
|||
} |
|||
} else { |
|||
abp.ajax.handleErrorStatusCode(jqXhr.status); |
|||
} |
|||
}; |
|||
|
|||
//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..?
|
|||
} |
|||
|
|||
userOptions.complete && userOptions.complete.apply(this, arguments); |
|||
}; |
|||
|
|||
return this.ajaxForm(options); |
|||
}; |
|||
|
|||
$.fn.abpAjaxForm.defaults = { |
|||
method: 'POST' |
|||
}; |
|||
|
|||
})(jQuery); |
|||
Loading…
Reference in new issue