diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/macro.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/macro.resource.js index 43ba045230..5a489f0651 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/macro.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/macro.resource.js @@ -62,14 +62,14 @@ function macroResource($q, $http, umbRequestHelper) { * @param {} filename * @returns {} */ - createPartialViewMacroWithFile: function(parent, filename) { + createPartialViewMacroWithFile: function(virtualPath, filename) { return umbRequestHelper.resourcePromise( $http.post( umbRequestHelper.getApiUrl( "macroApiBaseUrl", "CreatePartialViewMacroWithFile"), { - parent: parent, + virtualPath: virtualPath, filename: filename } ), diff --git a/src/Umbraco.Web.UI.Client/src/views/partialviewmacros/edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/partialviewmacros/edit.controller.js index a7896755b8..f260d5f0c0 100644 --- a/src/Umbraco.Web.UI.Client/src/views/partialviewmacros/edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/partialviewmacros/edit.controller.js @@ -41,10 +41,9 @@ redirectOnFailure: false, rebindCallback: function (orignal, saved) {} }).then(function (saved) { - // create macro if needed if($routeParams.create && $routeParams.nomacro !== "true") { - macroResource.createPartialViewMacroWithFile(saved.path, saved.name).then(function(created) { + macroResource.createPartialViewMacroWithFile(saved.virtualPath, saved.name).then(function(created) { completeSave(saved); }, function(err) { //show any notifications diff --git a/src/Umbraco.Web/Editors/MacroController.cs b/src/Umbraco.Web/Editors/MacroController.cs index 7b09287ea9..129c78cbcd 100644 --- a/src/Umbraco.Web/Editors/MacroController.cs +++ b/src/Umbraco.Web/Editors/MacroController.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using System.Net; @@ -134,12 +135,17 @@ namespace Umbraco.Web.Editors [HttpPost] public HttpResponseMessage CreatePartialViewMacroWithFile(CreatePartialViewMacroWithFileModel model) { + if (model == null) throw new ArgumentNullException("model"); + if (string.IsNullOrWhiteSpace(model.Filename)) throw new ArgumentException("Filename cannot be null or whitespace", "model.Filename"); + if (string.IsNullOrWhiteSpace(model.VirtualPath)) throw new ArgumentException("VirtualPath cannot be null or whitespace", "model.VirtualPath"); + + var macroName = model.Filename.TrimEnd(".cshtml"); + var macro = new Macro { - - Alias = model.Filename, - Name = model.Filename, // will be "aliased" - ScriptPath = "~/Views/MacroPartials/" + model.Parent + "/" + model.Filename + ".cshtml" + Alias = macroName.ToSafeAlias(), + Name = macroName, + ScriptPath = model.VirtualPath.EnsureStartsWith("~") }; Services.MacroService.Save(macro); // may throw @@ -148,8 +154,8 @@ namespace Umbraco.Web.Editors public class CreatePartialViewMacroWithFileModel { - public string Parent { get; set; } public string Filename { get; set; } + public string VirtualPath { get; set; } } } } \ No newline at end of file