diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index ad49af2196..c552f1b5af 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -697,6 +697,7 @@ + diff --git a/src/Umbraco.Web.UI/umbraco/settings/EditTemplate.aspx.designer.cs b/src/Umbraco.Web.UI/umbraco/settings/EditTemplate.aspx.designer.cs index d77c3b0cfa..956466eac9 100644 --- a/src/Umbraco.Web.UI/umbraco/settings/EditTemplate.aspx.designer.cs +++ b/src/Umbraco.Web.UI/umbraco/settings/EditTemplate.aspx.designer.cs @@ -11,5 +11,14 @@ namespace Umbraco.Web.UI.Umbraco.Settings { public partial class EditTemplate { + + /// + /// JsInclude1 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::ClientDependency.Core.Controls.JsInclude JsInclude1; } } diff --git a/src/Umbraco.Web.UI/umbraco/settings/editTemplate.aspx b/src/Umbraco.Web.UI/umbraco/settings/editTemplate.aspx index be119d814f..5669c799e4 100644 --- a/src/Umbraco.Web.UI/umbraco/settings/editTemplate.aspx +++ b/src/Umbraco.Web.UI/umbraco/settings/editTemplate.aspx @@ -11,162 +11,91 @@ - + @@ -190,7 +119,7 @@ function insertMacro(alias)
- + Insert Inline Razor Macro @@ -205,7 +134,7 @@ function insertMacro(alias)
- + Insert Macro diff --git a/src/Umbraco.Web.UI/umbraco_client/Editors/EditTemplate.js b/src/Umbraco.Web.UI/umbraco_client/Editors/EditTemplate.js new file mode 100644 index 0000000000..f2b3de1ab8 --- /dev/null +++ b/src/Umbraco.Web.UI/umbraco_client/Editors/EditTemplate.js @@ -0,0 +1,130 @@ +Umbraco.Sys.registerNamespace("Umbraco.Editors"); + +(function ($) { + + Umbraco.Editors.EditTemplate = base2.Base.extend({ + //private methods/variables + _opts: null, + + _openMacroModal: function(alias) { + var t = ""; + if (alias != null && alias != "") { + t = "&alias=" + alias; + } + UmbClientMgr.openModalWindow(this._opts.umbracoPath + '/dialogs/editMacro.aspx?renderingEngine=Webforms&objectId=' + this._opts.editorClientId + t, 'Insert Macro', true, 470, 530, 0, 0, '', ''); + }, + + _insertMacro: function(alias) { + var macroElement = "umbraco:Macro"; + if (!this._opts.useMasterPages) { + macroElement = "?UMBRACO_MACRO"; + } + var cp = macroElement + ' Alias="' + alias + '" runat="server"'; + UmbEditor.Insert('<' + cp + ' />', '', this._opts.editorClientId); + }, + + _insertCodeBlockFromTemplate: function(templateId) { + var self = this; + $.ajax({ + type: "POST", + url: this._opts.umbracoPath + "/webservices/templates.asmx/GetCodeSnippet", + data: "{templateId: '" + templateId + "'}", + contentType: "application/json; charset=utf-8", + dataType: "json", + success: function(msg) { + + var cp = 'umbraco:Macro runat="server" language="cshtml"'; + UmbEditor.Insert('\n<' + cp + '>\n' + msg.d, '\n\n', self._opts.editorClientId); + + } + }); + }, + + _insertCodeBlock: function() { + var snip = this._umbracoInsertSnippet(); + UmbEditor.Insert(snip.BeginTag, snip.EndTag, this._opts.editorClientId); + }, + + _umbracoInsertSnippet: function() { + var snip = new UmbracoCodeSnippet(); + var cp = 'umbraco:Macro runat="server" language="cshtml"'; + snip.BeginTag = '\n<' + cp + '>\n'; + snip.EndTag = '\n<' + '/umbraco:Macro' + '>\n'; + snip.TargetId = this._opts.editorClientId; + return snip; + }, + + // Constructor + constructor: function(opts) { + // Merge options with default + this._opts = $.extend({ + + + // Default options go here + }, opts); + }, + + init: function() { + //Sets up the UI and binds events + + var self = this; + + $("#sb").click(function() { + self._insertCodeBlock(); + }); + $("#sbMacro").click(function() { + self._openMacroModal(); + }); + //macro split button + $('#sbMacro').splitbutton({ menu: '#macroMenu' }); + $("#splitButtonMacro").appendTo("#splitButtonMacroPlaceHolder"); + + ////razor macro split button + $('#sb').splitbutton({ menu: '#codeTemplateMenu' }); + $("#splitButton").appendTo("#splitButtonPlaceHolder"); + + $(".macro").click(function() { + var alias = $(this).attr("rel"); + if ($(this).attr("params") == "1") { + self._openMacroModal(alias); + } + else { + self._insertMacro(alias); + } + }); + + $(".codeTemplate").click(function() { + self._insertCodeBlockFromTemplate($(this).attr("rel")); + }); + }, + + save: function(templateName, templateAlias, codeVal) { + var self = this; + + umbraco.presentation.webservices.codeEditorSave.SaveTemplate( + templateName, templateAlias, codeVal, self._opts.templateId, self._opts.masterTemplateId, + function(t) { self.submitSucces(t); }, + function(t) { self.submitFailure(t); }); + + }, + + submitSucces: function(t) { + if (t != 'true') { + top.UmbSpeechBubble.ShowMessage('error', this._opts.text.templateErrorHeader, this._opts.text.templateErrorText); + } + else { + top.UmbSpeechBubble.ShowMessage('save', this._opts.text.templateSavedHeader, this._opts.text.templateSavedText); + } + + 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); + + UmbClientMgr.mainTree().setActiveTreeType('templates'); + UmbClientMgr.mainTree().syncTree(this._opts.treeSyncPath, true); + } + }); +})(jQuery); \ No newline at end of file diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/settings/editTemplate.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/settings/editTemplate.aspx.cs index 8e24df4b19..acc060ee4f 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/settings/editTemplate.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/settings/editTemplate.aspx.cs @@ -37,11 +37,14 @@ namespace umbraco.cms.presentation.settings new ServiceReference(IOHelper.ResolveUrl(SystemDirectories.Webservices + "/legacyAjaxCalls.asmx"))); } + protected string TemplateTreeSyncPath { get; private set; } protected void Page_Load(object sender, EventArgs e) { MasterTemplate.Attributes.Add("onchange", "changeMasterPageFile()"); + TemplateTreeSyncPath = "-1,init," + _template.Path.Replace("-1,", ""); + if (!IsPostBack) { MasterTemplate.Items.Add(new ListItem(ui.Text("none"), "0")); @@ -70,7 +73,7 @@ namespace umbraco.cms.presentation.settings ClientTools .SetActiveTreeType(TreeDefinitionCollection.Instance.FindTree().Tree.Alias) - .SyncTree("-1,init," + _template.Path.Replace("-1,", ""), false); + .SyncTree(TemplateTreeSyncPath, false); LoadScriptingTemplates(); LoadMacros();