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);

View File

@@ -11,10 +11,11 @@ using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using Umbraco.Core;
using Umbraco.Core.IO;
using umbraco.cms.presentation.Trees;
using umbraco.IO;
using System.Linq;
using umbraco.cms.helpers;
using umbraco.uicontrols;
namespace umbraco.cms.presentation.settings.scripts
{
@@ -36,18 +37,20 @@ namespace umbraco.cms.presentation.settings.scripts
protected umbraco.uicontrols.PropertyPanel pp_name;
protected umbraco.uicontrols.PropertyPanel pp_path;
protected MenuIconI SaveButton;
private string file;
protected void Page_Load(object sender, System.EventArgs e)
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
NameTxt.Text = file;
string path = "";
if (file.StartsWith("~/"))
path = Umbraco.Core.IO.IOHelper.ResolveUrl(file);
path = Umbraco.Core.IO.IOHelper.ResolveUrl(file);
else
path = Umbraco.Core.IO.IOHelper.ResolveUrl(Umbraco.Core.IO.SystemDirectories.Scripts + "/" + file);
path = Umbraco.Core.IO.IOHelper.ResolveUrl(Umbraco.Core.IO.SystemDirectories.Scripts + "/" + file);
lttPath.Text = "<a target='_blank' href='" + path + "'>" + path + "</a>";
@@ -60,19 +63,19 @@ namespace umbraco.cms.presentation.settings.scripts
}
var dirs = Umbraco.Core.IO.SystemDirectories.Scripts;
if (Umbraco.Core.Configuration.UmbracoSettings.DefaultRenderingEngine == RenderingEngine.Mvc)
if (Umbraco.Core.Configuration.UmbracoSettings.DefaultRenderingEngine == RenderingEngine.Mvc)
dirs += "," + Umbraco.Core.IO.SystemDirectories.MvcViews;
// validate file
Umbraco.Core.IO.IOHelper.ValidateEditPath(Umbraco.Core.IO.IOHelper.MapPath(path), dirs.Split(','));
Umbraco.Core.IO.IOHelper.ValidateEditPath(Umbraco.Core.IO.IOHelper.MapPath(path), dirs.Split(','));
// validate extension
Umbraco.Core.IO.IOHelper.ValidateFileExtension(Umbraco.Core.IO.IOHelper.MapPath(path), exts);
Umbraco.Core.IO.IOHelper.ValidateFileExtension(Umbraco.Core.IO.IOHelper.MapPath(path), exts);
StreamReader SR;
string S;
SR = File.OpenText(Umbraco.Core.IO.IOHelper.MapPath(path));
SR = File.OpenText(Umbraco.Core.IO.IOHelper.MapPath(path));
S = SR.ReadToEnd();
SR.Close();
@@ -91,25 +94,22 @@ namespace umbraco.cms.presentation.settings.scripts
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
base.OnInit(e);
file = Request.QueryString["file"].TrimStart('/');
//need to change the editor type if it is XML
if (file.EndsWith("xml"))
editorSource.CodeBase = umbraco.uicontrols.CodeArea.EditorType.XML;
editorSource.CodeBase = uicontrols.CodeArea.EditorType.XML;
else if (file.EndsWith("master"))
editorSource.CodeBase = umbraco.uicontrols.CodeArea.EditorType.HTML;
editorSource.CodeBase = uicontrols.CodeArea.EditorType.HTML;
uicontrols.MenuIconI save = Panel1.Menu.NewIcon();
save.ImageURL = SystemDirectories.Umbraco + "/images/editor/save.gif";
save.OnClickCommand = "doSubmit()";
save.AltText = "Save File";
save.ID = "save";
SaveButton = Panel1.Menu.NewIcon();
SaveButton.ImageURL = SystemDirectories.Umbraco + "/images/editor/save.gif";
SaveButton.AltText = "Save File";
SaveButton.ID = "save";
if (editorSource.CodeBase == uicontrols.CodeArea.EditorType.HTML)
{
@@ -117,19 +117,19 @@ namespace umbraco.cms.presentation.settings.scripts
Panel1.Menu.InsertSplitter();
uicontrols.MenuIconI umbField = Panel1.Menu.NewIcon();
umbField.ImageURL = UmbracoPath + "/images/editor/insField.gif";
umbField.OnClickCommand = umbraco.BasePages.ClientTools.Scripts.OpenModalWindow(umbraco.IO.IOHelper.ResolveUrl(umbraco.IO.SystemDirectories.Umbraco) + "/dialogs/umbracoField.aspx?objectId=" + editorSource.ClientID + "&tagName=UMBRACOGETDATA", ui.Text("template", "insertPageField"), 640, 550);
umbField.OnClickCommand = BasePages.ClientTools.Scripts.OpenModalWindow(IOHelper.ResolveUrl(SystemDirectories.Umbraco) + "/dialogs/umbracoField.aspx?objectId=" + editorSource.ClientID + "&tagName=UMBRACOGETDATA", ui.Text("template", "insertPageField"), 640, 550);
umbField.AltText = ui.Text("template", "insertPageField");
// TODO: Update icon
uicontrols.MenuIconI umbDictionary = Panel1.Menu.NewIcon();
umbDictionary.ImageURL = GlobalSettings.Path + "/images/editor/dictionaryItem.gif";
umbDictionary.OnClickCommand = umbraco.BasePages.ClientTools.Scripts.OpenModalWindow(umbraco.IO.IOHelper.ResolveUrl(umbraco.IO.SystemDirectories.Umbraco) + "/dialogs/umbracoField.aspx?objectId=" + editorSource.ClientID + "&tagName=UMBRACOGETDICTIONARY", ui.Text("template", "insertDictionaryItem"), 640, 550);
umbDictionary.OnClickCommand = BasePages.ClientTools.Scripts.OpenModalWindow(IOHelper.ResolveUrl(SystemDirectories.Umbraco) + "/dialogs/umbracoField.aspx?objectId=" + editorSource.ClientID + "&tagName=UMBRACOGETDICTIONARY", ui.Text("template", "insertDictionaryItem"), 640, 550);
umbDictionary.AltText = "Insert umbraco dictionary item";
uicontrols.MenuIconI umbMacro = Panel1.Menu.NewIcon();
umbMacro.ImageURL = UmbracoPath + "/images/editor/insMacro.gif";
umbMacro.AltText = ui.Text("template", "insertMacro");
umbMacro.OnClickCommand = umbraco.BasePages.ClientTools.Scripts.OpenModalWindow(umbraco.IO.IOHelper.ResolveUrl(umbraco.IO.SystemDirectories.Umbraco) + "/dialogs/editMacro.aspx?objectId=" + editorSource.ClientID, ui.Text("template", "insertMacro"), 470, 530);
umbMacro.OnClickCommand = BasePages.ClientTools.Scripts.OpenModalWindow(IOHelper.ResolveUrl(SystemDirectories.Umbraco) + "/dialogs/editMacro.aspx?objectId=" + editorSource.ClientID, ui.Text("template", "insertMacro"), 470, 530);
// Help
Panel1.Menu.InsertSplitter();
@@ -141,23 +141,8 @@ namespace umbraco.cms.presentation.settings.scripts
}
this.Load += new System.EventHandler(Page_Load);
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
protected override void OnPreRender(EventArgs e)
{
@@ -165,7 +150,6 @@ namespace umbraco.cms.presentation.settings.scripts
ScriptManager.GetCurrent(Page).Services.Add(new ServiceReference("../webservices/codeEditorSave.asmx"));
ScriptManager.GetCurrent(Page).Services.Add(new ServiceReference("../webservices/legacyAjaxCalls.asmx"));
}
#endregion
}
}