From 06b96677ba12de1aa978c31bcc8b4c2a1796a628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 18 Sep 2017 17:29:10 +0300 Subject: [PATCH] Make abp.ajax and abp.services working via jquery service proxies. --- .../AbpDesk/Tickets/TicketAppService.cs | 3 +- .../AbpDesk.Web.Mvc/AbpDeskWebMvcModule.cs | 6 + .../AbpAspNetCoreMvcUiBootstrapModule.cs | 6 +- .../AbpAspNetCoreMvcUiModule.cs | 20 +- .../Volo.Abp.AspNetCore.Mvc.UI.csproj | 10 + .../wwwroot/abp/abp.jquery.js | 246 +++++++++ .../wwwroot/abp/abp.js | 478 ++++++++++++++++++ .../JQuery/JQueryProxyScriptGenerator.cs | 2 + 8 files changed, 767 insertions(+), 4 deletions(-) create mode 100644 src/Volo.Abp.AspNetCore.Mvc.UI/wwwroot/abp/abp.jquery.js create mode 100644 src/Volo.Abp.AspNetCore.Mvc.UI/wwwroot/abp/abp.js diff --git a/src/AbpDesk/AbpDesk.Application/AbpDesk/Tickets/TicketAppService.cs b/src/AbpDesk/AbpDesk.Application/AbpDesk/Tickets/TicketAppService.cs index 8f6108e6a9..dcc897d516 100644 --- a/src/AbpDesk/AbpDesk.Application/AbpDesk/Tickets/TicketAppService.cs +++ b/src/AbpDesk/AbpDesk.Application/AbpDesk/Tickets/TicketAppService.cs @@ -23,7 +23,8 @@ namespace AbpDesk.Tickets _asyncQueryableExecuter = asyncQueryableExecuter; } - public async Task> GetAll(GetAllTicketsInput input) + //TODO: No need to virtual once we implement UOW filter for AspNet Core! + public virtual async Task> GetAll(GetAllTicketsInput input) { var tickets = await _asyncQueryableExecuter.ToListAsync(_ticketRepository .WhereIf( diff --git a/src/AbpDesk/AbpDesk.Web.Mvc/AbpDeskWebMvcModule.cs b/src/AbpDesk/AbpDesk.Web.Mvc/AbpDeskWebMvcModule.cs index 0a4062e137..115470ac5d 100644 --- a/src/AbpDesk/AbpDesk.Web.Mvc/AbpDeskWebMvcModule.cs +++ b/src/AbpDesk/AbpDesk.Web.Mvc/AbpDeskWebMvcModule.cs @@ -10,6 +10,7 @@ using Microsoft.Extensions.DependencyInjection; using Volo.Abp; using Volo.Abp.AspNetCore.EmbeddedFiles; using Volo.Abp.AspNetCore.Modularity; +using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.Bundling; using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap; using Volo.Abp.Autofac; @@ -59,6 +60,11 @@ namespace AbpDesk.Web.Mvc "/AbpServiceProxies/GetAll?_v=" + DateTime.Now.Ticks }); }); + + services.Configure(options => + { + options.AppServiceControllers.CreateFor(typeof(AbpDeskApplicationModule).Assembly); + }); } public override void OnApplicationInitialization(ApplicationInitializationContext context) diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/AbpAspNetCoreMvcUiBootstrapModule.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/AbpAspNetCoreMvcUiBootstrapModule.cs index 91e04b6b2d..3c384f3dbd 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/AbpAspNetCoreMvcUiBootstrapModule.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/AbpAspNetCoreMvcUiBootstrapModule.cs @@ -1,4 +1,5 @@ -using System.Reflection; +using System; +using System.Reflection; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.AspNetCore.Mvc.Bundling; using Volo.Abp.EmbeddedFiles; @@ -43,7 +44,8 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap { "/libs/jquery/jquery-3.1.1.min.js", "/libs/tether/js/tether.min.js", - "/libs/bootstrap/js/bootstrap.min.js" + "/libs/bootstrap/js/bootstrap.min.js", + "/abp/abp.jquery.js?_v" + DateTime.Now.Ticks }); }); } diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/AbpAspNetCoreMvcUiModule.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/AbpAspNetCoreMvcUiModule.cs index 44103429fd..41d9d1d0af 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI/AbpAspNetCoreMvcUiModule.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI/AbpAspNetCoreMvcUiModule.cs @@ -1,5 +1,7 @@ -using System.Reflection; +using System; +using System.Reflection; using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.AspNetCore.Mvc.Bundling; using Volo.Abp.EmbeddedFiles; using Volo.Abp.Modularity; using Volo.Abp.Ui.Navigation; @@ -27,6 +29,22 @@ namespace Volo.Abp.AspNetCore.Mvc "Volo.Abp.AspNetCore.Mvc.Views" ) ); + + options.Sources.Add( + new EmbeddedFileSet( + "/abp/", + GetType().GetTypeInfo().Assembly, + "Volo.Abp.AspNetCore.Mvc.wwwroot.abp" + ) + ); + }); + + services.Configure(options => + { + options.ScriptBundles.Add("GlobalScripts", new[] + { + "/abp/abp.js?_v" + DateTime.Now.Ticks + }); }); } } diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/Volo.Abp.AspNetCore.Mvc.UI.csproj b/src/Volo.Abp.AspNetCore.Mvc.UI/Volo.Abp.AspNetCore.Mvc.UI.csproj index d23daf5e80..fc231c8dbd 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI/Volo.Abp.AspNetCore.Mvc.UI.csproj +++ b/src/Volo.Abp.AspNetCore.Mvc.UI/Volo.Abp.AspNetCore.Mvc.UI.csproj @@ -12,6 +12,16 @@ + + + + + + + + + + diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/wwwroot/abp/abp.jquery.js b/src/Volo.Abp.AspNetCore.Mvc.UI/wwwroot/abp/abp.jquery.js new file mode 100644 index 0000000000..1b74c060ae --- /dev/null +++ b/src/Volo.Abp.AspNetCore.Mvc.UI/wwwroot/abp/abp.jquery.js @@ -0,0 +1,246 @@ +var abp = abp || {}; +(function ($) { + + if (!$) { + return; + } + + /* JQUERY ENHANCEMENTS ***************************************************/ + + // abp.ajax -> uses $.ajax ------------------------------------------------ + + abp.ajax = function (userOptions) { + userOptions = userOptions || {}; + + var options = $.extend(true, {}, abp.ajax.defaultOpts, userOptions); + options.success = undefined; + options.error = undefined; + + return $.Deferred(function ($dfd) { + $.ajax(options) + .done(function (data, textStatus, jqXHR) { + if (data.__abp) { + abp.ajax.handleResponse(data, userOptions, $dfd, jqXHR); + } else { + $dfd.resolve(data); + userOptions.success && userOptions.success(data); + } + }).fail(function (jqXHR) { + if (jqXHR.responseJSON && jqXHR.responseJSON.__abp) { + abp.ajax.handleResponse(jqXHR.responseJSON, userOptions, $dfd, jqXHR); + } else { + abp.ajax.handleNonAbpErrorResponse(jqXHR, userOptions, $dfd); + } + }); + }); + }; + + $.extend(abp.ajax, { + defaultOpts: { + dataType: 'json', + type: 'POST', + contentType: 'application/json', + headers: { + 'X-Requested-With': 'XMLHttpRequest' + } + }, + + defaultError: { + message: 'An error has occurred!', + details: 'Error detail not sent by server.' + }, + + defaultError401: { + message: 'You are not authenticated!', + details: 'You should be authenticated (sign in) in order to perform this operation.' + }, + + defaultError403: { + message: 'You are not authorized!', + details: 'You are not allowed to perform this operation.' + }, + + defaultError404: { + message: 'Resource not found!', + details: 'The resource requested could not found on the server.' + }, + + logError: function (error) { + abp.log.error(error); + }, + + showError: function (error) { + if (error.details) { + return abp.message.error(error.details, error.message); + } else { + return abp.message.error(error.message || abp.ajax.defaultError.message); + } + }, + + handleTargetUrl: function (targetUrl) { + if (!targetUrl) { + location.href = abp.appPath; + } else { + location.href = targetUrl; + } + }, + + handleNonAbpErrorResponse: function (jqXHR, userOptions, $dfd) { + if (userOptions.abpHandleError !== false) { + switch (jqXHR.status) { + case 401: + abp.ajax.handleUnAuthorizedRequest( + abp.ajax.showError(abp.ajax.defaultError401), + abp.appPath + ); + break; + case 403: + abp.ajax.showError(abp.ajax.defaultError403); + break; + case 404: + abp.ajax.showError(abp.ajax.defaultError404); + break; + default: + abp.ajax.showError(abp.ajax.defaultError); + break; + } + } + + $dfd.reject.apply(this, arguments); + userOptions.error && userOptions.error.apply(this, arguments); + }, + + handleUnAuthorizedRequest: function (messagePromise, targetUrl) { + if (messagePromise) { + messagePromise.done(function () { + abp.ajax.handleTargetUrl(targetUrl); + }); + } else { + abp.ajax.handleTargetUrl(targetUrl); + } + }, + + handleResponse: function (data, userOptions, $dfd, jqXHR) { + if (data) { + if (data.success === true) { + $dfd && $dfd.resolve(data.result, data, jqXHR); + userOptions.success && userOptions.success(data.result, data, jqXHR); + + if (data.targetUrl) { + abp.ajax.handleTargetUrl(data.targetUrl); + } + } else if (data.success === false) { + var messagePromise = null; + + if (data.error) { + if (userOptions.abpHandleError !== false) { + messagePromise = abp.ajax.showError(data.error); + } + } else { + data.error = abp.ajax.defaultError; + } + + abp.ajax.logError(data.error); + + $dfd && $dfd.reject(data.error, jqXHR); + userOptions.error && userOptions.error(data.error, jqXHR); + + if (jqXHR.status === 401 && userOptions.abpHandleError !== false) { + abp.ajax.handleUnAuthorizedRequest(messagePromise, data.targetUrl); + } + } else { //not wrapped result + $dfd && $dfd.resolve(data, null, jqXHR); + userOptions.success && userOptions.success(data, null, jqXHR); + } + } else { //no data sent to back + $dfd && $dfd.resolve(jqXHR); + userOptions.success && userOptions.success(jqXHR); + } + }, + + blockUI: function (options) { + if (options.blockUI) { + if (options.blockUI === true) { //block whole page + abp.ui.setBusy(); + } else { //block an element + abp.ui.setBusy(options.blockUI); + } + } + }, + + unblockUI: function (options) { + if (options.blockUI) { + if (options.blockUI === true) { //unblock whole page + abp.ui.clearBusy(); + } else { //unblock an element + abp.ui.clearBusy(options.blockUI); + } + } + }, + + ajaxSendHandler: function (event, request, settings) { + var token = abp.security.antiForgery.getToken(); + if (!token) { + return; + } + + if (!settings.headers || settings.headers[abp.security.antiForgery.tokenHeaderName] === undefined) { + request.setRequestHeader(abp.security.antiForgery.tokenHeaderName, token); + } + } + }); + + $(document).ajaxSend(function (event, request, settings) { + return abp.ajax.ajaxSendHandler(event, request, settings); + }); + + /* JQUERY PLUGIN ENHANCEMENTS ********************************************/ + + /* jQuery Form Plugin + * http://www.malsup.com/jquery/form/ + */ + + // abpAjaxForm -> uses ajaxForm ------------------------------------------ + + if ($.fn.ajaxForm) { + $.fn.abpAjaxForm = function (userOptions) { + userOptions = userOptions || {}; + + var options = $.extend({}, $.fn.abpAjaxForm.defaults, userOptions); + + options.beforeSubmit = function () { + abp.ajax.blockUI(options); + userOptions.beforeSubmit && userOptions.beforeSubmit.apply(this, arguments); + }; + + options.success = function (data) { + abp.ajax.handleResponse(data, userOptions); + }; + + //TODO: Error? + + options.complete = function () { + abp.ajax.unblockUI(options); + userOptions.complete && userOptions.complete.apply(this, arguments); + }; + + return this.ajaxForm(options); + }; + + $.fn.abpAjaxForm.defaults = { + method: 'POST' + }; + } + + abp.event.on('abp.dynamicScriptsInitialized', function () { + abp.ajax.defaultError.message = abp.localization.abpWeb('DefaultError'); + abp.ajax.defaultError.details = abp.localization.abpWeb('DefaultErrorDetail'); + abp.ajax.defaultError401.message = abp.localization.abpWeb('DefaultError401'); + abp.ajax.defaultError401.details = abp.localization.abpWeb('DefaultErrorDetail401'); + abp.ajax.defaultError403.message = abp.localization.abpWeb('DefaultError403'); + abp.ajax.defaultError403.details = abp.localization.abpWeb('DefaultErrorDetail403'); + abp.ajax.defaultError404.message = abp.localization.abpWeb('DefaultError404'); + abp.ajax.defaultError404.details = abp.localization.abpWeb('DefaultErrorDetail404'); + }); + +})(jQuery); \ No newline at end of file diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/wwwroot/abp/abp.js b/src/Volo.Abp.AspNetCore.Mvc.UI/wwwroot/abp/abp.js new file mode 100644 index 0000000000..aec598b609 --- /dev/null +++ b/src/Volo.Abp.AspNetCore.Mvc.UI/wwwroot/abp/abp.js @@ -0,0 +1,478 @@ +var abp = abp || {}; +(function ($) { + + /* Application paths *****************************************/ + + //Current application root path (including virtual directory if exists). + abp.appPath = abp.appPath || '/'; + + abp.pageLoadTime = new Date(); + + //Converts given path to absolute path using abp.appPath variable. + abp.toAbsAppPath = function (path) { + if (path.indexOf('/') == 0) { + path = path.substring(1); + } + + return abp.appPath + path; + }; + + /* LOGGING ***************************************************/ + //Implements Logging API that provides secure & controlled usage of console.log + + abp.log = abp.log || {}; + + abp.log.levels = { + DEBUG: 1, + INFO: 2, + WARN: 3, + ERROR: 4, + FATAL: 5 + }; + + abp.log.level = abp.log.levels.DEBUG; + + abp.log.log = function (logObject, logLevel) { + if (!window.console || !window.console.log) { + return; + } + + if (logLevel != undefined && logLevel < abp.log.level) { + return; + } + + console.log(logObject); + }; + + abp.log.debug = function (logObject) { + abp.log.log("DEBUG: ", abp.log.levels.DEBUG); + abp.log.log(logObject, abp.log.levels.DEBUG); + }; + + abp.log.info = function (logObject) { + abp.log.log("INFO: ", abp.log.levels.INFO); + abp.log.log(logObject, abp.log.levels.INFO); + }; + + abp.log.warn = function (logObject) { + abp.log.log("WARN: ", abp.log.levels.WARN); + abp.log.log(logObject, abp.log.levels.WARN); + }; + + abp.log.error = function (logObject) { + abp.log.log("ERROR: ", abp.log.levels.ERROR); + abp.log.log(logObject, abp.log.levels.ERROR); + }; + + abp.log.fatal = function (logObject) { + abp.log.log("FATAL: ", abp.log.levels.FATAL); + abp.log.log(logObject, abp.log.levels.FATAL); + }; + + /* NOTIFICATION *********************************************/ + //Defines Notification API, not implements it + + abp.notify = abp.notify || {}; + + abp.notify.success = function (message, title, options) { + abp.log.warn('abp.notify.success is not implemented!'); + }; + + abp.notify.info = function (message, title, options) { + abp.log.warn('abp.notify.info is not implemented!'); + }; + + abp.notify.warn = function (message, title, options) { + abp.log.warn('abp.notify.warn is not implemented!'); + }; + + abp.notify.error = function (message, title, options) { + abp.log.warn('abp.notify.error is not implemented!'); + }; + + /* MESSAGE **************************************************/ + //Defines Message API, not implements it + + abp.message = abp.message || {}; + + var showMessage = function (message, title) { + alert((title || '') + ' ' + message); + + if (!$) { + abp.log.warn('abp.message can not return promise since jQuery is not defined!'); + return null; + } + + return $.Deferred(function ($dfd) { + $dfd.resolve(); + }); + }; + + abp.message.info = function (message, title) { + abp.log.warn('abp.message.info is not implemented!'); + return showMessage(message, title); + }; + + abp.message.success = function (message, title) { + abp.log.warn('abp.message.success is not implemented!'); + return showMessage(message, title); + }; + + abp.message.warn = function (message, title) { + abp.log.warn('abp.message.warn is not implemented!'); + return showMessage(message, title); + }; + + abp.message.error = function (message, title) { + abp.log.warn('abp.message.error is not implemented!'); + return showMessage(message, title); + }; + + abp.message.confirm = function (message, titleOrCallback, callback) { + abp.log.warn('abp.message.confirm is not implemented!'); + + if (titleOrCallback && !(typeof titleOrCallback == 'string')) { + callback = titleOrCallback; + } + + var result = confirm(message); + callback && callback(result); + + if (!$) { + abp.log.warn('abp.message can not return promise since jQuery is not defined!'); + return null; + } + + return $.Deferred(function ($dfd) { + $dfd.resolve(); + }); + }; + + /* UI *******************************************************/ + + abp.ui = abp.ui || {}; + + /* UI BLOCK */ + //Defines UI Block API, not implements it + + abp.ui.block = function (elm) { + abp.log.warn('abp.ui.block is not implemented!'); + }; + + abp.ui.unblock = function (elm) { + abp.log.warn('abp.ui.unblock is not implemented!'); + }; + + /* UI BUSY */ + //Defines UI Busy API, not implements it + + abp.ui.setBusy = function (elm, optionsOrPromise) { + abp.log.warn('abp.ui.setBusy is not implemented!'); + }; + + abp.ui.clearBusy = function (elm) { + abp.log.warn('abp.ui.clearBusy is not implemented!'); + }; + + /* SIMPLE EVENT BUS *****************************************/ + + abp.event = (function () { + + var _callbacks = {}; + + var on = function (eventName, callback) { + if (!_callbacks[eventName]) { + _callbacks[eventName] = []; + } + + _callbacks[eventName].push(callback); + }; + + var off = function (eventName, callback) { + var callbacks = _callbacks[eventName]; + if (!callbacks) { + return; + } + + var index = -1; + for (var i = 0; i < callbacks.length; i++) { + if (callbacks[i] === callback) { + index = i; + break; + } + } + + if (index < 0) { + return; + } + + _callbacks[eventName].splice(index, 1); + }; + + var trigger = function (eventName) { + var callbacks = _callbacks[eventName]; + if (!callbacks || !callbacks.length) { + return; + } + + var args = Array.prototype.slice.call(arguments, 1); + for (var i = 0; i < callbacks.length; i++) { + callbacks[i].apply(this, args); + } + }; + + // Public interface /////////////////////////////////////////////////// + + return { + on: on, + off: off, + trigger: trigger + }; + })(); + + + /* UTILS ***************************************************/ + + abp.utils = abp.utils || {}; + + /* Creates a name namespace. + * Example: + * var taskService = abp.utils.createNamespace(abp, 'services.task'); + * taskService will be equal to abp.services.task + * first argument (root) must be defined first + ************************************************************/ + abp.utils.createNamespace = function (root, ns) { + var parts = ns.split('.'); + for (var i = 0; i < parts.length; i++) { + if (typeof root[parts[i]] == 'undefined') { + root[parts[i]] = {}; + } + + root = root[parts[i]]; + } + + return root; + }; + + /* Find and replaces a string (search) to another string (replacement) in + * given string (str). + * Example: + * abp.utils.replaceAll('This is a test string', 'is', 'X') = 'ThX X a test string' + ************************************************************/ + abp.utils.replaceAll = function (str, search, replacement) { + var fix = search.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); + return str.replace(new RegExp(fix, 'g'), replacement); + }; + + /* Formats a string just like string.format in C#. + * Example: + * abp.utils.formatString('Hello {0}','Tuana') = 'Hello Tuana' + ************************************************************/ + abp.utils.formatString = function () { + if (arguments.length < 1) { + return null; + } + + var str = arguments[0]; + + for (var i = 1; i < arguments.length; i++) { + var placeHolder = '{' + (i - 1) + '}'; + str = abp.utils.replaceAll(str, placeHolder, arguments[i]); + } + + return str; + }; + + abp.utils.toPascalCase = function (str) { + if (!str || !str.length) { + return str; + } + + if (str.length === 1) { + return str.charAt(0).toUpperCase(); + } + + return str.charAt(0).toUpperCase() + str.substr(1); + } + + abp.utils.toCamelCase = function (str) { + if (!str || !str.length) { + return str; + } + + if (str.length === 1) { + return str.charAt(0).toLowerCase(); + } + + return str.charAt(0).toLowerCase() + str.substr(1); + } + + abp.utils.truncateString = function (str, maxLength) { + if (!str || !str.length || str.length <= maxLength) { + return str; + } + + return str.substr(0, maxLength); + }; + + abp.utils.truncateStringWithPostfix = function (str, maxLength, postfix) { + postfix = postfix || '...'; + + if (!str || !str.length || str.length <= maxLength) { + return str; + } + + if (maxLength <= postfix.length) { + return postfix.substr(0, maxLength); + } + + return str.substr(0, maxLength - postfix.length) + postfix; + }; + + abp.utils.isFunction = function (obj) { + if ($) { + //Prefer to use jQuery if possible + return $.isFunction(obj); + } + + //alternative for $.isFunction + return !!(obj && obj.constructor && obj.call && obj.apply); + }; + + /** + * parameterInfos should be an array of { name, value } objects + * where name is query string parameter name and value is it's value. + * includeQuestionMark is true by default. + */ + abp.utils.buildQueryString = function (parameterInfos, includeQuestionMark) { + if (includeQuestionMark === undefined) { + includeQuestionMark = true; + } + + var qs = ''; + + function addSeperator() { + if (!qs.length) { + if (includeQuestionMark) { + qs = qs + '?'; + } + } else { + qs = qs + '&'; + } + } + + for (var i = 0; i < parameterInfos.length; ++i) { + var parameterInfo = parameterInfos[i]; + if (parameterInfo.value === undefined) { + continue; + } + + if (parameterInfo.value === null) { + parameterInfo.value = ''; + } + + addSeperator(); + + if (parameterInfo.value.toJSON && typeof parameterInfo.value.toJSON === "function") { + qs = qs + parameterInfo.name + '=' + encodeURIComponent(parameterInfo.value.toJSON()); + } else if (Array.isArray(parameterInfo.value) && parameterInfo.value.length) { + for (var j = 0; j < parameterInfo.value.length; j++) { + if (j > 0) { + addSeperator(); + } + + qs = qs + parameterInfo.name + '[' + j + ']=' + encodeURIComponent(parameterInfo.value[j]); + } + } else { + qs = qs + parameterInfo.name + '=' + encodeURIComponent(parameterInfo.value); + } + } + + return qs; + } + + /** + * Sets a cookie value for given key. + * This is a simple implementation created to be used by ABP. + * Please use a complete cookie library if you need. + * @param {string} key + * @param {string} value + * @param {Date} expireDate (optional). If not specified the cookie will expire at the end of session. + * @param {string} path (optional) + */ + abp.utils.setCookieValue = function (key, value, expireDate, path) { + var cookieValue = encodeURIComponent(key) + '='; + + if (value) { + cookieValue = cookieValue + encodeURIComponent(value); + } + + if (expireDate) { + cookieValue = cookieValue + "; expires=" + expireDate.toUTCString(); + } + + if (path) { + cookieValue = cookieValue + "; path=" + path; + } + + document.cookie = cookieValue; + }; + + /** + * Gets a cookie with given key. + * This is a simple implementation created to be used by ABP. + * Please use a complete cookie library if you need. + * @param {string} key + * @returns {string} Cookie value or null + */ + abp.utils.getCookieValue = function (key) { + var equalities = document.cookie.split('; '); + for (var i = 0; i < equalities.length; i++) { + if (!equalities[i]) { + continue; + } + + var splitted = equalities[i].split('='); + if (splitted.length != 2) { + continue; + } + + if (decodeURIComponent(splitted[0]) === key) { + return decodeURIComponent(splitted[1] || ''); + } + } + + return null; + }; + + /** + * Deletes cookie for given key. + * This is a simple implementation created to be used by ABP. + * Please use a complete cookie library if you need. + * @param {string} key + * @param {string} path (optional) + */ + abp.utils.deleteCookie = function (key, path) { + var cookieValue = encodeURIComponent(key) + '='; + + cookieValue = cookieValue + "; expires=" + (new Date(new Date().getTime() - 86400000)).toUTCString(); + + if (path) { + cookieValue = cookieValue + "; path=" + path; + } + + document.cookie = cookieValue; + } + + /* SECURITY ***************************************/ + abp.security = abp.security || {}; + abp.security.antiForgery = abp.security.antiForgery || {}; + + abp.security.antiForgery.tokenCookieName = 'XSRF-TOKEN'; + abp.security.antiForgery.tokenHeaderName = 'X-XSRF-TOKEN'; + + abp.security.antiForgery.getToken = function () { + return abp.utils.getCookieValue(abp.security.antiForgery.tokenCookieName); + }; + +})(); \ No newline at end of file diff --git a/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/JQuery/JQueryProxyScriptGenerator.cs b/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/JQuery/JQueryProxyScriptGenerator.cs index 7e0e2431d3..6f6e77c0f4 100644 --- a/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/JQuery/JQueryProxyScriptGenerator.cs +++ b/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/JQuery/JQueryProxyScriptGenerator.cs @@ -5,6 +5,8 @@ using Volo.Abp.Http.Modeling; namespace Volo.Abp.Http.ProxyScripting.Generators.JQuery { + //TODO: Add abp.ajax, abp.utils... etc. + public class JQueryProxyScriptGenerator : IProxyScriptGenerator, ITransientDependency { ///