From c62474dc137924ed4f275e6261fa5fb3c5521fee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 30 Apr 2018 17:36:49 +0300 Subject: [PATCH] Add jquery-form extensions. --- .../AbpAspNetCoreMvcUiThemeSharedModule.cs | 1 + .../jquery-form/jquery-form-extensions.js | 47 +++++++++++++++++++ .../jquery/jquery-extensions.js | 10 +++- 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore.mvc.ui.theme.shared/jquery-form/jquery-form-extensions.js diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/AbpAspNetCoreMvcUiThemeSharedModule.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/AbpAspNetCoreMvcUiThemeSharedModule.cs index d9895526de..0f351649a7 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/AbpAspNetCoreMvcUiThemeSharedModule.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/AbpAspNetCoreMvcUiThemeSharedModule.cs @@ -44,6 +44,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared "/libs/abp/jquery/abp.ajax.js", "/libs/abp/jquery/abp.resource-loader.js", "/libs/abp/aspnetcore.mvc.ui.theme.shared/jquery/jquery-extensions.js", + "/libs/abp/aspnetcore.mvc.ui.theme.shared/jquery-form/jquery-form-extensions.js", "/libs/abp/aspnetcore.mvc.ui.theme.shared/bootstrap/dom-event-handlers.js", "/libs/abp/aspnetcore.mvc.ui.theme.shared/bootstrap/modal-manager.js", "/libs/abp/aspnetcore.mvc.ui.theme.shared/datatables/datatables-extensions.js" 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 new file mode 100644 index 0000000000..efcc636b44 --- /dev/null +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore.mvc.ui.theme.shared/jquery-form/jquery-form-extensions.js @@ -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); \ 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/jquery/jquery-extensions.js b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore.mvc.ui.theme.shared/jquery/jquery-extensions.js index c066535737..e94dadf9a5 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore.mvc.ui.theme.shared/jquery/jquery-extensions.js +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore.mvc.ui.theme.shared/jquery/jquery-extensions.js @@ -80,6 +80,14 @@ return obj; }; - + $.fn.focusEndOfText = function () { + return this.each(function () { + var $this = $(this); + setTimeout(function () { + $this.focus(); + $this[0].selectionStart = $this[0].selectionEnd = 10000; + }, 0); + }); + }; })(jQuery); \ No newline at end of file