diff --git a/src/Umbraco.Web.UI/umbraco/settings/editTemplate.aspx b/src/Umbraco.Web.UI/umbraco/settings/editTemplate.aspx
index 1308d96298..84a2579687 100644
--- a/src/Umbraco.Web.UI/umbraco/settings/editTemplate.aspx
+++ b/src/Umbraco.Web.UI/umbraco/settings/editTemplate.aspx
@@ -1,5 +1,6 @@
<%@ Page MasterPageFile="../masterpages/umbracoPage.Master" Language="c#" CodeBehind="EditTemplate.aspx.cs"
ValidateRequest="false" AutoEventWireup="True" Inherits="Umbraco.Web.UI.Umbraco.Settings.EditTemplate" %>
+<%@ Import Namespace="Umbraco.Core" %>
<%@ Import Namespace="Umbraco.Core.IO" %>
<%@ Register TagPrefix="cc1" Namespace="umbraco.uicontrols" Assembly="controls" %>
<%@ Register TagPrefix="umb" Namespace="ClientDependency.Core.Controls" Assembly="ClientDependency.Core" %>
@@ -19,6 +20,7 @@
jQuery(document).ready(function() {
//create the editor
editor = new Umbraco.Editors.EditTemplate({
+ restServiceLocation: "<%= Url.GetSaveFileServicePath() %>",
umbracoPath: '<%= IOHelper.ResolveUrl(SystemDirectories.Umbraco) %>',
editorClientId: '<%= editorSource.ClientID %>',
useMasterPages: <%=umbraco.UmbracoSettings.UseAspNetMasterPages.ToString().ToLower()%>,
diff --git a/src/Umbraco.Web.UI/umbraco_client/Editors/EditTemplate.js b/src/Umbraco.Web.UI/umbraco_client/Editors/EditTemplate.js
index c3d142e314..adcf8de50c 100644
--- a/src/Umbraco.Web.UI/umbraco_client/Editors/EditTemplate.js
+++ b/src/Umbraco.Web.UI/umbraco_client/Editors/EditTemplate.js
@@ -101,27 +101,57 @@
save: function(templateName, templateAlias, codeVal) {
var self = this;
- umbraco.presentation.webservices.codeEditorSave.SaveTemplate(
- templateName, templateAlias, codeVal, self._opts.templateId, this._opts.masterPageDropDown.val(),
- function(t) { self.submitSucces(t); },
- function(t) { self.submitFailure(t); });
-
+ $.post(self._opts.restServiceLocation + "SaveTemplate",
+ JSON.stringify({
+ templateName: templateName,
+ templateAlias: templateAlias,
+ templateContents: codeVal,
+ templateId: self._opts.templateId,
+ masterTemplateId: this._opts.masterPageDropDown.val()
+ }),
+ function (e) {
+ if (e.success) {
+ self.submitSuccess(e);
+ } else {
+ self.submitFailure(e.message, e.header);
+ }
+ });
+
},
- submitSucces: function(t) {
- if (t != 'true') {
- top.UmbSpeechBubble.ShowMessage('error', this._opts.text.templateErrorHeader, this._opts.text.templateErrorText);
+ submitSuccess: function (args) {
+ var msg = args.message;
+ var header = args.header;
+ var path = this._opts.treeSyncPath;
+ var pathChanged = false;
+ if (args.path) {
+ if (path != args.path) {
+ pathChanged = true;
+ }
+ path = args.path;
+ }
+
+ top.UmbSpeechBubble.ShowMessage('save', header, msg);
+ UmbClientMgr.mainTree().setActiveTreeType('templates');
+ if (pathChanged) {
+ UmbClientMgr.mainTree().moveNode(this._opts.templateId, path);
}
else {
- top.UmbSpeechBubble.ShowMessage('save', this._opts.text.templateSavedHeader, this._opts.text.templateSavedText);
+ UmbClientMgr.mainTree().syncTree(path, true);
}
- UmbClientMgr.mainTree().setActiveTreeType('templates');
- UmbClientMgr.mainTree().syncTree(this._opts.treeSyncPath, true);
},
- submitFailure: function(t) {
- top.UmbSpeechBubble.ShowMessage('error', this._opts.text.templateErrorHeader, this._opts.text.templateErrorText);
+ submitFailure: function (err, header) {
+ top.UmbSpeechBubble.ShowMessage('error', header, err);
}
});
+
+ //Set defaults for jQuery ajax calls.
+ $.ajaxSetup({
+ dataType: 'json',
+ cache: false,
+ contentType: 'application/json; charset=utf-8'
+ });
+
})(jQuery);
\ No newline at end of file
diff --git a/src/Umbraco.Web.UI/umbraco_client/Editors/EditView.js b/src/Umbraco.Web.UI/umbraco_client/Editors/EditView.js
index 646890a042..655a7b1609 100644
--- a/src/Umbraco.Web.UI/umbraco_client/Editors/EditView.js
+++ b/src/Umbraco.Web.UI/umbraco_client/Editors/EditView.js
@@ -80,7 +80,7 @@
}),
function(e) {
if (e.success) {
- self.submitSuccess(e.message, e.header);
+ self.submitSuccess(e);
} else {
self.submitFailure(e.message, e.header);
}
@@ -97,7 +97,7 @@
}),
function(e) {
if (e.success) {
- self.submitSuccess(e.message, e.header);
+ self.submitSuccess(e);
} else {
self.submitFailure(e.message, e.header);
}
@@ -105,8 +105,20 @@
}
},
- submitSuccess: function (err, header) {
- top.UmbSpeechBubble.ShowMessage('save', header, err);
+ submitSuccess: function (args) {
+
+ var msg = args.message;
+ var header = args.header;
+ var path = this._opts.treeSyncPath;
+ var pathChanged = false;
+ if (args.path) {
+ if (path != args.path) {
+ pathChanged = true;
+ }
+ path = args.path;
+ }
+
+ top.UmbSpeechBubble.ShowMessage('save', header, msg);
UmbClientMgr.mainTree().setActiveTreeType(this._opts.currentTreeType);
@@ -114,11 +126,19 @@
if (this._opts.editorType == "Template") {
//templates are different because they are ID based, whereas view files are file based without a static id
- UmbClientMgr.mainTree().syncTree(this._opts.treeSyncPath, true);
+
+ if (pathChanged) {
+ UmbClientMgr.mainTree().moveNode(this._opts.templateId, path);
+ }
+ else {
+ UmbClientMgr.mainTree().syncTree(path, true);
+ }
+
+
}
else {
//we need to pass in the newId parameter so it knows which node to resync after retreival from the server
- UmbClientMgr.mainTree().syncTree(this._opts.treeSyncPath, true, null, newFilePath.split("/")[1]);
+ UmbClientMgr.mainTree().syncTree(path, true, null, newFilePath.split("/")[1]);
}
//then we need to update our current tree sync path to represent the new one
diff --git a/src/Umbraco.Web/WebServices/SaveFileController.cs b/src/Umbraco.Web/WebServices/SaveFileController.cs
index 39c7baa4e6..7b90da05c1 100644
--- a/src/Umbraco.Web/WebServices/SaveFileController.cs
+++ b/src/Umbraco.Web/WebServices/SaveFileController.cs
@@ -8,7 +8,9 @@ using Umbraco.Web.Macros;
using Umbraco.Web.Mvc;
using umbraco;
using umbraco.cms.businesslogic.macro;
+using System.Collections.Generic;
using Umbraco.Core;
+
using Template = umbraco.cms.businesslogic.template.Template;
namespace Umbraco.Web.WebServices
@@ -90,15 +92,22 @@ namespace Umbraco.Web.WebServices
public JsonResult SaveTemplate(string templateName, string templateAlias, string templateContents, int templateId, int masterTemplateId)
{
Template t;
+ bool pathChanged = false;
try
{
t = new Template(templateId)
{
Text = templateName,
- Alias = templateAlias,
- MasterTemplate = masterTemplateId,
+ Alias = templateAlias,
Design = templateContents
};
+
+ //check if the master page has changed
+ if (t.MasterTemplate != masterTemplateId)
+ {
+ pathChanged = true;
+ t.MasterTemplate = masterTemplateId;
+ }
}
catch (ArgumentException ex)
{
@@ -110,7 +119,17 @@ namespace Umbraco.Web.WebServices
{
t.Save();
- return Success(ui.Text("speechBubbles", "templateSavedText"), ui.Text("speechBubbles", "templateSavedHeader"));
+ //ensure the correct path is synced as the parent might have been changed
+ // http://issues.umbraco.org/issue/U4-2300
+ if (pathChanged)
+ {
+ //need to re-look it up
+ t = new Template(templateId);
+ }
+ var syncPath = "-1,init," + t.Path.Replace("-1,", "");
+
+ return Success(ui.Text("speechBubbles", "templateSavedText"), ui.Text("speechBubbles", "templateSavedHeader"),
+ new {path = syncPath});
}
catch (Exception ex)
{
@@ -118,20 +137,21 @@ namespace Umbraco.Web.WebServices
}
}
- ///
- /// Returns a successful message
- ///
- /// The message to display in the speach bubble
- /// The header to display in the speach bubble
- ///
- private JsonResult Success(string message, string header)
- {
- return Json(new
- {
- success = true,
- message = message,
- header = header
- });
+ ///
+ /// Returns a successful message
+ ///
+ /// The message to display in the speach bubble
+ /// The header to display in the speach bubble
+ ///
+ ///
+ private JsonResult Success(string message, string header, object additionalVals = null)
+ {
+ var d = additionalVals == null ? new Dictionary() : additionalVals.ToDictionary