From 1f87470f896627fc96ac9cda78563bdca17ad90c Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Wed, 8 May 2013 14:18:18 -1000 Subject: [PATCH] Fixes up tree syncing for views, stylesheets and partial views. Now ensures we can actually sync a tree for a file based node that doesn't have a static id. Also ensures that when we change a Partial view name that we don't end up duplicating some files when we change it twice in the same session. --- .../config/umbracoSettings.config | 2 +- .../umbraco/settings/views/EditView.aspx | 2 ++ .../umbraco/settings/views/EditView.aspx.cs | 34 ++++++++++++++----- .../umbraco_client/Editors/EditStyleSheet.js | 3 -- .../umbraco_client/Editors/EditTemplate.js | 3 -- .../umbraco_client/Editors/EditView.js | 27 ++++++++++++++- .../umbraco_client/Tree/UmbracoTree.js | 22 +++++++----- .../Trees/PartialViewMacrosTree.cs | 4 +-- src/Umbraco.Web/Trees/PartialViewsTree.cs | 4 +-- .../umbraco/Trees/BaseTree.cs | 7 ++-- .../umbraco/Trees/FileSystemTree.cs | 2 +- .../umbraco/Trees/loadTemplates.cs | 2 +- 12 files changed, 79 insertions(+), 33 deletions(-) diff --git a/src/Umbraco.Web.UI/config/umbracoSettings.config b/src/Umbraco.Web.UI/config/umbracoSettings.config index b1f3bd7d3b..e5e88a781a 100644 --- a/src/Umbraco.Web.UI/config/umbracoSettings.config +++ b/src/Umbraco.Web.UI/config/umbracoSettings.config @@ -140,7 +140,7 @@ true true - Webforms + Mvc diff --git a/src/Umbraco.Web.UI/umbraco/settings/views/EditView.aspx b/src/Umbraco.Web.UI/umbraco/settings/views/EditView.aspx index 54fc190717..2253dae9cc 100644 --- a/src/Umbraco.Web.UI/umbraco/settings/views/EditView.aspx +++ b/src/Umbraco.Web.UI/umbraco/settings/views/EditView.aspx @@ -24,6 +24,8 @@ $(document).ready(function () { //create and assign a new EditView object editViewEditor = new Umbraco.Editors.EditView({ + treeSyncPath: "<%=TemplateTreeSyncPath%>", + currentTreeType: "<%=CurrentTreeType%>", editorType: "<%= EditorType.ToString() %>", originalFileName: "<%=OriginalFileName %>", restServiceLocation: "<%= Url.GetSaveFileServicePath() %>", diff --git a/src/Umbraco.Web.UI/umbraco/settings/views/EditView.aspx.cs b/src/Umbraco.Web.UI/umbraco/settings/views/EditView.aspx.cs index 9d6db3c41a..b0f9b57c7e 100644 --- a/src/Umbraco.Web.UI/umbraco/settings/views/EditView.aspx.cs +++ b/src/Umbraco.Web.UI/umbraco/settings/views/EditView.aspx.cs @@ -45,6 +45,23 @@ namespace Umbraco.Web.UI.Umbraco.Settings.Views get { return _template == null ? ViewEditorType.PartialView : ViewEditorType.Template; } } + protected string TemplateTreeSyncPath { get; private set; } + + /// + /// This view is shared between different trees so we'll look for the query string + /// + protected string CurrentTreeType + { + get + { + if (Request.QueryString["treeType"].IsNullOrWhiteSpace()) + { + return TreeDefinitionCollection.Instance.FindTree().Tree.Alias; + } + return Request.QueryString["treeType"]; + } + } + /// /// Returns the original file name that the editor was loaded with /// @@ -89,9 +106,6 @@ namespace Umbraco.Web.UI.Umbraco.Settings.Views AliasTxt.Text = _template.Alias; editorSource.Text = _template.Design; - ClientTools - .SetActiveTreeType(TreeDefinitionCollection.Instance.FindTree().Tree.Alias) - .SyncTree("-1,init," + _template.Path.Replace("-1,", ""), false); } else { @@ -105,13 +119,13 @@ namespace Umbraco.Web.UI.Umbraco.Settings.Views var s = sr.ReadToEnd(); editorSource.Text = s; } - - //string path = DeepLink.GetTreePathFromFilePath(file); - //ClientTools - // .SetActiveTreeType(TreeDefinitionCollection.Instance.FindTree().Tree.Alias) - // .SyncTree(path, false); + } } + + ClientTools + .SetActiveTreeType(CurrentTreeType) + .SyncTree(TemplateTreeSyncPath, false); } @@ -122,12 +136,14 @@ namespace Umbraco.Web.UI.Umbraco.Settings.Views //check if a templateId is assigned, meaning we are editing a template if (!Request.QueryString["templateID"].IsNullOrWhiteSpace()) { - _template = new Template(int.Parse(Request.QueryString["templateID"])); + _template = new Template(int.Parse(Request.QueryString["templateID"])); + TemplateTreeSyncPath = "-1,init," + _template.Path.Replace("-1,", ""); } else if (!Request.QueryString["file"].IsNullOrWhiteSpace()) { //we are editing a view (i.e. partial view) OriginalFileName = HttpUtility.UrlDecode(Request.QueryString["file"]); + TemplateTreeSyncPath = "-1,init," + Path.GetFileName(OriginalFileName); } else { diff --git a/src/Umbraco.Web.UI/umbraco_client/Editors/EditStyleSheet.js b/src/Umbraco.Web.UI/umbraco_client/Editors/EditStyleSheet.js index 1357fa6e0b..78817f3328 100644 --- a/src/Umbraco.Web.UI/umbraco_client/Editors/EditStyleSheet.js +++ b/src/Umbraco.Web.UI/umbraco_client/Editors/EditStyleSheet.js @@ -39,9 +39,6 @@ submitFailure: function(t) { top.UmbSpeechBubble.ShowMessage('error', this._opts.text.cssErrorHeader, this._opts.text.cssErrorText); - - UmbClientMgr.mainTree().setActiveTreeType('stylesheets'); - UmbClientMgr.mainTree().syncTree("-1,init," + this._opts.cssId, true); } }, { diff --git a/src/Umbraco.Web.UI/umbraco_client/Editors/EditTemplate.js b/src/Umbraco.Web.UI/umbraco_client/Editors/EditTemplate.js index f2b3de1ab8..d67cd2aae5 100644 --- a/src/Umbraco.Web.UI/umbraco_client/Editors/EditTemplate.js +++ b/src/Umbraco.Web.UI/umbraco_client/Editors/EditTemplate.js @@ -122,9 +122,6 @@ submitFailure: function(t) { top.UmbSpeechBubble.ShowMessage('error', this._opts.text.templateErrorHeader, this._opts.text.templateErrorText); - - UmbClientMgr.mainTree().setActiveTreeType('templates'); - UmbClientMgr.mainTree().syncTree(this._opts.treeSyncPath, true); } }); })(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 382b70b53a..72a4d87809 100644 --- a/src/Umbraco.Web.UI/umbraco_client/Editors/EditView.js +++ b/src/Umbraco.Web.UI/umbraco_client/Editors/EditView.js @@ -8,6 +8,21 @@ //private methods/variables _opts: null, + _updateNewProperties: function(filePath) { + /// Updates the current treeSyncPath and original file name to have the new file name + + //update the originalFileName prop + this._opts.originalFileName = filePath; + + //re-create the new path + var subPath = this._opts.treeSyncPath.split(","); + //remove the last element + subPath.pop(); + //add the new element + subPath.push(filePath.split("/")[1]); + this._opts.treeSyncPath = subPath.join(); + }, + // Constructor constructor: function (opts) { // Merge options with default @@ -92,10 +107,20 @@ submitSuccess: function (err, header) { top.UmbSpeechBubble.ShowMessage('save', header, err); + + UmbClientMgr.mainTree().setActiveTreeType(this._opts.currentTreeType); + + var newFilePath = this._opts.nameTxtBox.val(); + //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]); + + //then we need to update our current tree sync path to represent the new one + this._updateNewProperties(newFilePath); + }, submitFailure: function (err, header) { - top.UmbSpeechBubble.ShowMessage('error', header, err); + top.UmbSpeechBubble.ShowMessage('error', header, err); }, changeMasterPageFile: function ( ) { diff --git a/src/Umbraco.Web.UI/umbraco_client/Tree/UmbracoTree.js b/src/Umbraco.Web.UI/umbraco_client/Tree/UmbracoTree.js index 71c419337a..cc6e3e5d00 100644 --- a/src/Umbraco.Web.UI/umbraco_client/Tree/UmbracoTree.js +++ b/src/Umbraco.Web.UI/umbraco_client/Tree/UmbracoTree.js @@ -51,7 +51,7 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls"); functionToCall: "", nodeKey: "" }; - } + }; Umbraco.Controls.UmbracoTree = function() { /// @@ -100,10 +100,10 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls"); if (this._opts.appActions != null) { var _this = this; //wrapped functions maintain scope - this._opts.appActions.addEventHandler("nodeDeleting", function(E) { _this.onNodeDeleting(E) }); - this._opts.appActions.addEventHandler("nodeDeleted", function(E) { _this.onNodeDeleted(E) }); - this._opts.appActions.addEventHandler("nodeRefresh", function(E) { _this.onNodeRefresh(E) }); - this._opts.appActions.addEventHandler("publicError", function(E, err) { _this.onPublicError(E, err) }); + this._opts.appActions.addEventHandler("nodeDeleting", function (E) { _this.onNodeDeleting(E); }); + this._opts.appActions.addEventHandler("nodeDeleted", function (E) { _this.onNodeDeleted(E); }); + this._opts.appActions.addEventHandler("nodeRefresh", function (E) { _this.onNodeRefresh(E); }); + this._opts.appActions.addEventHandler("publicError", function (E, err) { _this.onPublicError(E, err); }); } this._containerId = jItem.attr("id"); @@ -309,19 +309,20 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls"); } }, - syncTree: function(path, forceReload, supressChildReload) { + syncTree: function(path, forceReload, supressChildReload, newId) { /// /// Syncronizes the tree with the path supplied and makes that node visible/selected. /// /// The path of the node /// If true, will ensure that the node to be synced is synced with data from the server + /// This parameter is only used when we don't have a real unique ID for a node, for example for a file. If a filename changes we don't know what the new one is since we are syncing the tree to the old original path. Once we retreive the results the sync the tree we need to find the result by it's new id and update the node. this._debug("syncTree: " + path + ", " + forceReload); //set the flag so that multiple synces aren't attempted this._isSyncing = true; - this._syncTree.call(this, path, forceReload, null, null, supressChildReload); + this._syncTree.call(this, path, forceReload, null, null, supressChildReload, newId); }, @@ -864,7 +865,7 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls"); this._tree.open_branch(liNode, false, callback); }, - _syncTree: function(path, forceReload, numPaths, numAsync, supressChildReload) { + _syncTree: function(path, forceReload, numPaths, numAsync, supressChildReload, newId) { /// /// This is the internal method that will recursively search for the nodes to sync. If an invalid path is /// passed to this method, it will raise an event which can be handled. @@ -873,6 +874,7 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls"); /// If true, will ensure that the node to be synced is synced with data from the server /// the number of id's deep to search starting from the end of the path. Used in recursion. /// the number of async calls made so far to sync. Used in recursion and used to determine if the found node has been loaded by ajax. + /// This parameter is only used when we don't have a real unique ID for a node, for example for a file. If a filename changes we don't know what the new one is since we are syncing the tree to the old original path. Once we retreive the results the sync the tree we need to find the result by it's new id and update the node. this._debug("_syncTree"); @@ -917,6 +919,10 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls"); this._debug("_syncTree: found! numAsync: " + numAsync + ", forceReload: " + forceReload + ", doReload: " + doReload); if (doReload) { this._actionNode = this.getNodeDef(found); + //we need to change the id if the newId parameter is set + if (newId) { + this._actionNode.nodeId = newId; + } if (supressChildReload === undefined) { this.reloadActionNode(false, true, null); } else { diff --git a/src/Umbraco.Web/Trees/PartialViewMacrosTree.cs b/src/Umbraco.Web/Trees/PartialViewMacrosTree.cs index 777b4cb5db..1278648de5 100644 --- a/src/Umbraco.Web/Trees/PartialViewMacrosTree.cs +++ b/src/Umbraco.Web/Trees/PartialViewMacrosTree.cs @@ -26,9 +26,9 @@ namespace Umbraco.Web.Trees //NOTE: Notice the MacroPartials%2f string below, this is a URLEncoded string of "MacroPartials/" so that the editor knows // to load the file from the correct location javascript.Append( - @" + @" function openMacroPartialView(id) { - UmbClientMgr.contentFrame('Settings/Views/EditView.aspx?file=MacroPartials%2f' + id); + UmbClientMgr.contentFrame('Settings/Views/EditView.aspx?treeType=partialViewMacros&file=MacroPartials%2f' + id); } "); } diff --git a/src/Umbraco.Web/Trees/PartialViewsTree.cs b/src/Umbraco.Web/Trees/PartialViewsTree.cs index dba21b129a..341a906d25 100644 --- a/src/Umbraco.Web/Trees/PartialViewsTree.cs +++ b/src/Umbraco.Web/Trees/PartialViewsTree.cs @@ -28,9 +28,9 @@ namespace Umbraco.Web.Trees //NOTE: Notice the Partials%2f string below, this is a URLEncoded string of "Partials/" so that the editor knows // to load the file from the correct location javascript.Append( - @" + @" function openPartialView(id) { - UmbClientMgr.contentFrame('Settings/Views/EditView.aspx?file=Partials%2f' + id); + UmbClientMgr.contentFrame('Settings/Views/EditView.aspx?treeType=partialViews&file=Partials%2f' + id); } "); } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/BaseTree.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/BaseTree.cs index caadca5caa..3ea88f38b8 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/BaseTree.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/BaseTree.cs @@ -494,8 +494,11 @@ namespace umbraco.cms.presentation.Trees /// The instance containing the event data. protected virtual void OnBeforeNodeRender(ref XmlTree sender, ref XmlTreeNode node, EventArgs e) { - if (BeforeNodeRender != null) - BeforeNodeRender(ref sender, ref node, e); + if (node != null && node != null) + { + if (BeforeNodeRender != null) + BeforeNodeRender(ref sender, ref node, e); + } } /// diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/FileSystemTree.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/FileSystemTree.cs index 84514d3a39..a78ad6d0fc 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/FileSystemTree.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/FileSystemTree.cs @@ -8,7 +8,7 @@ using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.IO; -using umbraco.IO; +using Umbraco.Core.IO; namespace umbraco.cms.presentation.Trees { diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadTemplates.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadTemplates.cs index ad1feb1c69..aaa75f750d 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadTemplates.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadTemplates.cs @@ -52,7 +52,7 @@ namespace umbraco } function openView(id) { - UmbClientMgr.contentFrame('settings/views/editView.aspx?templateID=' + id); + UmbClientMgr.contentFrame('settings/views/editView.aspx?treeType=templates&templateID=' + id); } function openSkin(id) {