diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore.mvc.ui.theme.shared/bootstrap/dom-event-handlers.js b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore.mvc.ui.theme.shared/bootstrap/dom-event-handlers.js index cdeb952319..0f49b3b928 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore.mvc.ui.theme.shared/bootstrap/dom-event-handlers.js +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore.mvc.ui.theme.shared/bootstrap/dom-event-handlers.js @@ -1,5 +1,21 @@ -(function($) { - +(function ($) { + + function enableAjaxForm($forms, validate) { + if ($forms.length) { + $forms.each(function () { + var $form = $(this); + + if (validate === true) { + $.validator.unobtrusive.parse($form); + } + + if ($form.attr('data-ajaxForm') === 'true') { + $form.abpAjaxForm(); + } + }); + } + } + abp.dom.onNodeAdded(function (args) { args.$el.findWithSelf('[data-toggle="tooltip"]').tooltip({ container: 'body' @@ -9,12 +25,7 @@ container: 'body' }); - var $forms = args.$el.findWithSelf('form'); - if ($forms.length) { - $forms.each(function() { - $.validator.unobtrusive.parse($(this)); - }); - } + enableAjaxForm(args.$el.findWithSelf('form'), true); }); abp.dom.onNodeRemoved(function (args) { @@ -31,6 +42,8 @@ $('[data-toggle="popover"]').popover({ container: 'body' }); + + enableAjaxForm($('form')); }); })(jQuery); \ No newline at end of file diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore.mvc.ui.theme.shared/bootstrap/modal-manager.js b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore.mvc.ui.theme.shared/bootstrap/modal-manager.js index 43d4bd10c3..2a3f899f96 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore.mvc.ui.theme.shared/bootstrap/modal-manager.js +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore.mvc.ui.theme.shared/bootstrap/modal-manager.js @@ -66,18 +66,19 @@ $.validator.defaults.ignore = ''; //TODO: Would be better if we can apply only f _$modal = _$modalContainer.find('.modal'); _$form = _$modalContainer.find('form'); if (_$form.length) { - if (_$form.attr('data-ajaxForm') !== 'false') { - _$form.abpAjaxForm({ - success: function() { - _publicApi.setResult.apply(_publicApi, arguments); - _$modal.modal('hide'); - } - }); + if (_$form.attr('data-ajaxForm') === undefined || _$form.attr('data-ajaxForm') === false) { + _$form.abpAjaxForm(); } + + _$form.on('abp-ajax-success', + function() { + _publicApi.setResult.apply(_publicApi, arguments); + _$modal.modal('hide'); + }); } else { _$form = null; } - + _$modal.modal({ backdrop: 'static' }); diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore.mvc.ui.theme.shared/jquery-form/jquery-form-extensions.js b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore.mvc.ui.theme.shared/jquery-form/jquery-form-extensions.js index e767359bc6..f51e848e88 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore.mvc.ui.theme.shared/jquery-form/jquery-form-extensions.js +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore.mvc.ui.theme.shared/jquery-form/jquery-form-extensions.js @@ -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 = {