Fixes up script editor and tree syncing.

This commit is contained in:
Shannon Deminick
2013-05-08 16:13:18 -10:00
parent baed852767
commit 28b6c5897f
5 changed files with 103 additions and 117 deletions

View File

@@ -2029,7 +2029,9 @@
<Content Include="Config\feedProxy.config" />
<Content Include="Umbraco_Client\ui\ui-lightness\jquery-ui.custom.css" />
<Content Include="Config\applications.config" />
<Content Include="Config\trees.config" />
<Content Include="Config\trees.config">
<SubType>Designer</SubType>
</Content>
<None Include="Config\applications.Release.config">
<DependentUpon>applications.config</DependentUpon>
<SubType>Designer</SubType>

View File

@@ -15,30 +15,26 @@
<script language="javascript" type="text/javascript">
function doSubmit() {
var codeVal = jQuery('#<%= editorSource.ClientID %>').val();
//if CodeMirror is not defined, then the code editor is disabled.
if (typeof (CodeMirror) != "undefined") {
codeVal = UmbEditor.GetCode();
}
umbraco.presentation.webservices.codeEditorSave.SaveScript(jQuery('#<%= NameTxt.ClientID %>').val(), '<%= NameTxt.Text %>', codeVal, submitSucces, submitFailure);
}
function submitSucces(t) {
if (t != 'true') {
top.UmbSpeechBubble.ShowMessage('error', '<%= umbraco.ui.Text("speechBubbles", "fileErrorHeader") %>', '<%= umbraco.ui.Text("speechBubbles", "fileErrorText") %>');
}
else {
top.UmbSpeechBubble.ShowMessage('save', '<%= umbraco.ui.Text("speechBubbles", "fileSavedHeader") %>', '')
}
}
function submitFailure(t) {
top.UmbSpeechBubble.ShowMessage('error', '<%= umbraco.ui.Text("speechBubbles", "fileErrorHeader") %>', '<%= umbraco.ui.Text("speechBubbles", "fileErrorText") %>')
}
jQuery(document).ready(function () {
UmbClientMgr.appActions().bindSaveShortCut();
});
(function ($) {
$(document).ready(function () {
var editor = new Umbraco.Editors.EditScript({
nameTxtBox: $('#<%= NameTxt.ClientID %>'),
originalFileName: '<%= NameTxt.Text %>',
saveButton: $("#<%= ((Control)SaveButton).ClientID %>"),
editorSourceElement: $('#<%= editorSource.ClientID %>'),
text: {
fileErrorHeader: '<%= umbraco.ui.Text("speechBubbles", "fileErrorHeader") %>',
fileSavedHeader: '<%= umbraco.ui.Text("speechBubbles", "fileSavedHeader") %>',
fileSavedText: '',
fileErrorText: '<%= umbraco.ui.Text("speechBubbles", "fileErrorText") %>',
}
});
editor.init();
//bind save shortcut
UmbClientMgr.appActions().bindSaveShortCut();
});
})(jQuery);
</script>
</asp:Content>

View File

@@ -25,10 +25,11 @@
}
});
editor.init();
//bind save shortcut
UmbClientMgr.appActions().bindSaveShortCut();
});
})(jQuery);
</script>
</asp:Content>

View File

@@ -3,61 +3,64 @@
(function ($) {
Umbraco.Editors.EditScript = base2.Base.extend({
//private methods/variables
_opts: null,
//private methods/variables
_opts: null,
// Constructor
constructor: function(opts) {
// Merge options with default
this._opts = $.extend({
// Default options go here
}, opts);
},
save: function() {
var self = this;
umbraco.presentation.webservices.codeEditorSave.SaveCss(
self._opts.fileName, self._opts.oldName, self._opts.codeVal, self._opts.cssId,
function(t) { self.submitSucces(t); },
function(t) { self.submitFailure(t); });
},
submitSucces: function(t) {
if (t != 'true') {
top.UmbSpeechBubble.ShowMessage('error', this._opts.text.cssErrorHeader, this._opts.text.cssErrorText);
}
else {
top.UmbSpeechBubble.ShowMessage('save', this._opts.text.cssSavedHeader, this._opts.text.cssSavedText);
}
// Constructor
constructor: function(opts) {
// Merge options with default
this._opts = $.extend({
UmbClientMgr.mainTree().setActiveTreeType('stylesheets');
UmbClientMgr.mainTree().syncTree("-1,init," + this._opts.cssId, true);
},
submitFailure: function(t) {
top.UmbSpeechBubble.ShowMessage('error', this._opts.text.cssErrorHeader, this._opts.text.cssErrorText);
}
// Default options go here
}, opts);
},
{
saveScript: function(codeVal, fileName, oldName, cssId) {
//<summary>Static method to do the saving</summary>
var codeVal = $('#' + editorSourceClientId).val();
//if CodeMirror is not defined, then the code editor is disabled.
if (typeof(CodeMirror) != "undefined") {
codeVal = UmbEditor.GetCode();
}
init: function () {
//setup UI elements
var self = this;
var processor = new Umbraco.Editors.EditStyleSheet({
codeVal: codeVal,
fileName: $('#' + nameTxtClientId).val(),
oldname: nameTxtValue,
cssId: cssId
});
processor.save();
//bind to the save event
this._opts.saveButton.click(function () {
self.doSubmit();
});
},
doSubmit: function () {
var self = this;
var fileName = this._opts.nameTxtBox.val();
var codeVal = this._opts.editorSourceElement.val();
//if CodeMirror is not defined, then the code editor is disabled.
if (typeof (CodeMirror) != "undefined") {
codeVal = UmbEditor.GetCode();
}
});
umbraco.presentation.webservices.codeEditorSave.SaveScript(
fileName, self._opts.originalFileName, codeVal,
function (t) { self.submitSucces(t); },
function (t) { self.submitFailure(t); });
},
submitSucces: function(t) {
if (t != 'true') {
top.UmbSpeechBubble.ShowMessage('error', this._opts.text.fileErrorHeader, this._opts.text.fileErrorText);
}
else {
top.UmbSpeechBubble.ShowMessage('save', this._opts.text.fileSavedHeader, this._opts.text.fileSavedText);
}
var newFilePath = this._opts.nameTxtBox.val();
UmbClientMgr.mainTree().setActiveTreeType('scripts');
//we need to pass in the newId parameter so it knows which node to resync after retreival from the server
UmbClientMgr.mainTree().syncTree("-1,init," + this._opts.originalFileName, true, null, newFilePath);
//set the original file path to the new one
this._opts.originalFileName = newFilePath;
},
submitFailure: function(t) {
top.UmbSpeechBubble.ShowMessage('error', this._opts.text.fileErrorHeader, this._opts.text.fileErrorText);
}
});
})(jQuery);