Skip to content

Commit ffeed58

Browse files
committed
Fixes: U4-3576 When editing file based items and changing the file name - we need to change the route location
1 parent 6fd5eee commit ffeed58

File tree

4 files changed

+95
-27
lines changed

4 files changed

+95
-27
lines changed

src/Umbraco.Web.UI/umbraco_client/Editors/EditMacroScripts.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,30 @@
4848
submitSucces: function(t) {
4949
if (t != 'true') {
5050
top.UmbSpeechBubble.ShowMessage('error', 'Saving scripting file failed', t);
51+
}
52+
53+
var newFilePath = this._opts.nameTxtBox.val();
54+
55+
//if the filename changes, we need to redirect since the file name is used in the url
56+
if (this._opts.originalFileName != newFilePath) {
57+
var newLocation = window.location.pathname + "?" + "&file=" + newFilePath;
58+
59+
UmbClientMgr.contentFrame(newLocation);
60+
61+
//we need to do this after we navigate otherwise the navigation will wait unti lthe message timeout is done!
62+
top.UmbSpeechBubble.ShowMessage('save', 'Scripting file saved', '');
5163
}
5264
else {
65+
5366
top.UmbSpeechBubble.ShowMessage('save', 'Scripting file saved', '');
67+
UmbClientMgr.mainTree().setActiveTreeType('python');
68+
//we need to pass in the newId parameter so it knows which node to resync after retreival from the server
69+
UmbClientMgr.mainTree().syncTree("-1,init," + this._opts.originalFileName, true, null, newFilePath);
70+
//set the original file path to the new one
71+
this._opts.originalFileName = newFilePath;
5472
}
5573

56-
57-
var newFilePath = this._opts.nameTxtBox.val();
58-
UmbClientMgr.mainTree().setActiveTreeType('python');
59-
//we need to pass in the newId parameter so it knows which node to resync after retreival from the server
60-
UmbClientMgr.mainTree().syncTree("-1,init," + this._opts.originalFileName, true, null, newFilePath);
61-
//set the original file path to the new one
62-
this._opts.originalFileName = newFilePath;
74+
6375
},
6476

6577
submitFailure: function(t) {

src/Umbraco.Web.UI/umbraco_client/Editors/EditScript.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,32 @@
4444
},
4545

4646
submitSucces: function(t) {
47+
4748
if (t != 'true') {
4849
top.UmbSpeechBubble.ShowMessage('error', this._opts.text.fileErrorHeader, this._opts.text.fileErrorText);
4950
}
50-
else {
51+
52+
var newFilePath = this._opts.nameTxtBox.val();
53+
54+
//if the filename changes, we need to redirect since the file name is used in the url
55+
if (this._opts.originalFileName != newFilePath) {
56+
var newLocation = window.location.pathname + "?" + "&file=" + newFilePath;
57+
58+
UmbClientMgr.contentFrame(newLocation);
59+
60+
//we need to do this after we navigate otherwise the navigation will wait unti lthe message timeout is done!
5161
top.UmbSpeechBubble.ShowMessage('save', this._opts.text.fileSavedHeader, this._opts.text.fileSavedText);
5262
}
63+
else {
5364

54-
55-
var newFilePath = this._opts.nameTxtBox.val();
56-
UmbClientMgr.mainTree().setActiveTreeType('scripts');
57-
//we need to pass in the newId parameter so it knows which node to resync after retreival from the server
58-
UmbClientMgr.mainTree().syncTree("-1,init," + this._opts.originalFileName, true, null, newFilePath);
59-
//set the original file path to the new one
60-
this._opts.originalFileName = newFilePath;
65+
top.UmbSpeechBubble.ShowMessage('save', this._opts.text.fileSavedHeader, this._opts.text.fileSavedText);
66+
UmbClientMgr.mainTree().setActiveTreeType('scripts');
67+
//we need to pass in the newId parameter so it knows which node to resync after retreival from the server
68+
UmbClientMgr.mainTree().syncTree("-1,init," + this._opts.originalFileName, true, null, newFilePath);
69+
//set the original file path to the new one
70+
this._opts.originalFileName = newFilePath;
71+
}
72+
6173
},
6274

6375
submitFailure: function(t) {

src/Umbraco.Web.UI/umbraco_client/Editors/EditView.js

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,12 @@
125125
path = args.path;
126126
}
127127

128-
top.UmbSpeechBubble.ShowMessage('save', header, msg);
129-
130128
UmbClientMgr.mainTree().setActiveTreeType(this._opts.currentTreeType);
131129

132130
if (this._opts.editorType == "Template") {
131+
132+
top.UmbSpeechBubble.ShowMessage('save', header, msg);
133+
133134
//templates are different because they are ID based, whereas view files are file based without a static id
134135

135136
if (pathChanged) {
@@ -143,10 +144,40 @@
143144
}
144145
else {
145146
var newFilePath = this._opts.nameTxtBox.val();
146-
//then we need to update our current tree sync path to represent the new one
147-
this._updateNewFileProperties(newFilePath);
148-
149-
UmbClientMgr.mainTree().syncTree(path, true, null, newFilePath.split("/")[1]);
147+
148+
149+
function trimStart(str, trim) {
150+
if (str.startsWith(trim)) {
151+
return str.substring(trim.length);
152+
}
153+
return str;
154+
}
155+
156+
//if the filename changes, we need to redirect since the file name is used in the url
157+
if (this._opts.originalFileName != newFilePath) {
158+
var queryParts = trimStart(window.location.search, "?").split('&');
159+
var notFileParts = [];
160+
for (var i = 0; i < queryParts.length; i++) {
161+
if (queryParts[i].substr(0, "file=".length) != "file=") {
162+
notFileParts.push(queryParts[i]);
163+
}
164+
}
165+
var newLocation = window.location.pathname + "?" + notFileParts.join("&") + "&file=" + newFilePath;
166+
167+
UmbClientMgr.contentFrame(newLocation);
168+
169+
//we need to do this after we navigate otherwise the navigation will wait unti lthe message timeout is done!
170+
top.UmbSpeechBubble.ShowMessage('save', header, msg);
171+
}
172+
else {
173+
174+
top.UmbSpeechBubble.ShowMessage('save', header, msg);
175+
176+
//then we need to update our current tree sync path to represent the new one
177+
this._updateNewFileProperties(newFilePath);
178+
179+
UmbClientMgr.mainTree().syncTree(path, true, null, newFilePath.split("/")[1]);
180+
}
150181
}
151182

152183
},

src/Umbraco.Web.UI/umbraco_client/Editors/EditXslt.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,29 @@
4747
if (t != 'true') {
4848
top.UmbSpeechBubble.ShowMessage('error', 'Saving Xslt file failed',"<pre>" + t + "</pre>");
4949
}
50+
51+
var newFilePath = this._opts.nameTxtBox.val();
52+
53+
//if the filename changes, we need to redirect since the file name is used in the url
54+
if (this._opts.originalFileName != newFilePath) {
55+
var newLocation = window.location.pathname + "?" + "&file=" + newFilePath;
56+
57+
UmbClientMgr.contentFrame(newLocation);
58+
59+
//we need to do this after we navigate otherwise the navigation will wait unti lthe message timeout is done!
60+
top.UmbSpeechBubble.ShowMessage('save', 'Xslt file saved', '');
61+
}
5062
else {
63+
5164
top.UmbSpeechBubble.ShowMessage('save', 'Xslt file saved', '');
65+
UmbClientMgr.mainTree().setActiveTreeType('xslt');
66+
//we need to pass in the newId parameter so it knows which node to resync after retreival from the server
67+
UmbClientMgr.mainTree().syncTree("-1,init," + this._opts.originalFileName, true, null, newFilePath);
68+
//set the original file path to the new one
69+
this._opts.originalFileName = newFilePath;
5270
}
71+
5372

54-
var newFilePath = this._opts.nameTxtBox.val();
55-
UmbClientMgr.mainTree().setActiveTreeType('xslt');
56-
//we need to pass in the newId parameter so it knows which node to resync after retreival from the server
57-
UmbClientMgr.mainTree().syncTree("-1,init," + this._opts.originalFileName, true, null, newFilePath);
58-
//set the original file path to the new one
59-
this._opts.originalFileName = newFilePath;
6073
},
6174

6275
submitFailure: function (t) {

0 commit comments

Comments
 (0)