diff --git a/src/Umbraco.Web.UI.Client/src/common/services/umbrequesthelper.service.js b/src/Umbraco.Web.UI.Client/src/common/services/umbrequesthelper.service.js index a494a0220a..963e2af06e 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/umbrequesthelper.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/umbrequesthelper.service.js @@ -6,6 +6,30 @@ function umbRequestHelper($http, $q, umbDataFormatter, angularHelper, dialogService, notificationsService) { return { + /** + * @ngdoc method + * @name umbraco.services.umbRequestHelper#convertVirtualToAbsolutePath + * @methodOf umbraco.services.umbRequestHelper + * @function + * + * @description + * This will convert a virtual path (i.e. ~/App_Plugins/Blah/Test.html ) to an absolute path + * + * @param {string} a virtual path, if this is already an absolute path it will just be returned, if this is a relative path an exception will be thrown + */ + convertVirtualToAbsolutePath: function(virtualPath) { + if (virtualPath.startsWith("/")) { + return virtualPath; + } + if (!virtualPath.startsWith("~/")) { + throw "The path " + virtualPath + " is not a virtual path"; + } + if (!Umbraco.Sys.ServerVariables.application.applicationPath) { + throw "No applicationPath defined in Umbraco.ServerVariables.application.applicationPath"; + } + return Umbraco.Sys.ServerVariables.application.applicationPath + virtualPath.trimStart("~/"); + }, + /** * @ngdoc method * @name umbraco.services.umbRequestHelper#dictionaryToQueryString diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/grid/grid.controller.js b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/grid/grid.controller.js index f802173a25..8851f74b34 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/grid/grid.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/grid/grid.controller.js @@ -1,6 +1,6 @@ angular.module("umbraco") .controller("Umbraco.PropertyEditors.GridController", - function ($scope, $http, assetsService, $rootScope, dialogService, gridService, mediaResource, imageHelper, $timeout) { + function ($scope, $http, assetsService, $rootScope, dialogService, gridService, mediaResource, imageHelper, $timeout, umbRequestHelper) { // Grid status variables $scope.currentRow = null; @@ -576,10 +576,11 @@ angular.module("umbraco") var editorConfig = $scope.getEditor(control.editor.alias); control.editor = editorConfig; - //if its a path - if(_.indexOf(control.editor.view, "/") >= 0){ - control.$editorPath = control.editor.view; - }else{ + //if its an absolute path + if (control.editor.view.startsWith("/") || control.editor.view.startsWith("~/")) { + control.$editorPath = umbRequestHelper.convertVirtualToAbsolutePath(control.editor.view); + } + else { //use convention control.$editorPath = "views/propertyeditors/grid/editors/" + control.editor.view + ".html"; } diff --git a/src/Umbraco.Web.UI/umbraco/Views/Default.cshtml b/src/Umbraco.Web.UI/umbraco/Views/Default.cshtml index bef809a593..308f483af2 100644 --- a/src/Umbraco.Web.UI/umbraco/Views/Default.cshtml +++ b/src/Umbraco.Web.UI/umbraco/Views/Default.cshtml @@ -58,6 +58,9 @@ "umbracoUrls": { "authenticationApiBaseUrl": "@(Url.GetUmbracoApiServiceBaseUrl(controller => controller.PostLogin(null)))", "serverVarsJs": '@Url.GetUrlWithCacheBust("ServerVariables", "BackOffice")' + }, + "application": { + "applicationPath" : "@Context.Request.ApplicationPath" } }; diff --git a/src/Umbraco.Web/Editors/BackOfficeController.cs b/src/Umbraco.Web/Editors/BackOfficeController.cs index b353b3ce27..003104de63 100644 --- a/src/Umbraco.Web/Editors/BackOfficeController.cs +++ b/src/Umbraco.Web/Editors/BackOfficeController.cs @@ -281,15 +281,17 @@ namespace Umbraco.Web.Editors } }, {"isDebuggingEnabled", HttpContext.IsDebuggingEnabled}, - { - "application", GetApplicationState() - } + {"application", GetApplicationState()} }; return JavaScript(ServerVariablesParser.Parse(d)); } + /// + /// Returns the server variables regarding the application state + /// + /// private Dictionary GetApplicationState() { if (ApplicationContext.IsConfigured == false) @@ -306,6 +308,8 @@ namespace Umbraco.Web.Editors app.Add("version", version); app.Add("cdf", ClientDependency.Core.Config.ClientDependencySettings.Instance.Version); + //useful for dealing with virtual paths on the client side when hosted in virtual directories especially + app.Add("applicationPath", HttpContext.Request.ApplicationPath.EnsureEndsWith('/')); return app; }