From 33b7ade10db4d0655b271e0161c360e3defc0030 Mon Sep 17 00:00:00 2001 From: Shandem Date: Tue, 26 Oct 2010 09:13:47 +0000 Subject: [PATCH] Fixes: 28681 [TFS Changeset #78958] --- .../editorControls/macrocontainer/Editor.cs | 325 +++++++++--------- 1 file changed, 162 insertions(+), 163 deletions(-) diff --git a/components/editorControls/macrocontainer/Editor.cs b/components/editorControls/macrocontainer/Editor.cs index 9204277a28..a206c2faeb 100644 --- a/components/editorControls/macrocontainer/Editor.cs +++ b/components/editorControls/macrocontainer/Editor.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Text; using System.Web.UI; using System.Web.UI.WebControls; - using umbraco.interfaces; using umbraco.cms.businesslogic.macro; using umbraco.presentation.webservices; @@ -22,231 +21,231 @@ namespace umbraco.editorControls.macrocontainer [ClientDependency(ClientDependencyType.Css, "/macroContainer/macroContainer.css", "UmbracoClient")] public class Editor : UpdatePanel, IDataEditor { - private IData _data; - private List _allowedMacros; - private int _maxNumber, _preferedHeight, _preferedWidth; + private IData _data; + private List _allowedMacros; + private int _maxNumber, _preferedHeight, _preferedWidth; - private LinkButton _addMacro; - private Literal _limit; + private LinkButton _addMacro; + private Literal _limit; - public Editor(IData data, List allowedMacros, int maxNumber, int preferedHeight, int preferedWidth) + public Editor(IData data, List allowedMacros, int maxNumber, int preferedHeight, int preferedWidth) { - _data = data; - _allowedMacros = allowedMacros; - _maxNumber = maxNumber; - _preferedHeight = preferedHeight; - _preferedWidth = preferedWidth; + _data = data; + _allowedMacros = allowedMacros; + _maxNumber = maxNumber; + _preferedHeight = preferedHeight; + _preferedWidth = preferedWidth; } - protected override void OnInit(EventArgs e) - { - base.OnInit(e); - - //SD: This is useless as it won't work in live editing anyways whilst using MS Ajax/ScriptManager for ajax calls - if (!UmbracoContext.Current.LiveEditingContext.Enabled) - { - presentation.webservices.ajaxHelpers.EnsureLegacyCalls(base.Page); - ScriptManager sm = ScriptManager.GetCurrent(base.Page); - ServiceReference webservicePath = new ServiceReference(umbraco.IO.IOHelper.ResolveUrl(umbraco.IO.SystemDirectories.Umbraco) + "/webservices/MacroContainerService.asmx"); + protected override void OnInit(EventArgs e) + { + base.OnInit(e); - if (!sm.Services.Contains(webservicePath)) - sm.Services.Add(webservicePath); - } - else - { - ClientDependencyLoader.Instance.RegisterDependency("webservices/legacyAjaxCalls.asmx/js", "UmbracoRoot", ClientDependencyType.Javascript); - ClientDependencyLoader.Instance.RegisterDependency("webservices/MacroContainerService.asmx/js", "UmbracoRoot", ClientDependencyType.Javascript); - } + //SD: This is useless as it won't work in live editing anyways whilst using MS Ajax/ScriptManager for ajax calls + if (!UmbracoContext.Current.LiveEditingContext.Enabled) + { + presentation.webservices.ajaxHelpers.EnsureLegacyCalls(base.Page); + ScriptManager sm = ScriptManager.GetCurrent(base.Page); + ServiceReference webservicePath = new ServiceReference(umbraco.IO.IOHelper.ResolveUrl(umbraco.IO.SystemDirectories.Umbraco) + "/webservices/MacroContainerService.asmx"); - _addMacro = new LinkButton(); - _addMacro.ID = ID + "_btnaddmacro"; + if (!sm.Services.Contains(webservicePath)) + sm.Services.Add(webservicePath); + } + else + { + ClientDependencyLoader.Instance.RegisterDependency("webservices/legacyAjaxCalls.asmx/js", "UmbracoRoot", ClientDependencyType.Javascript); + ClientDependencyLoader.Instance.RegisterDependency("webservices/MacroContainerService.asmx/js", "UmbracoRoot", ClientDependencyType.Javascript); + } + + _addMacro = new LinkButton(); + _addMacro.ID = ID + "_btnaddmacro"; - _addMacro.Click += new EventHandler(_addMacro_Click); - _addMacro.Text = ui.Text("insertMacro"); - _addMacro.CssClass = "macroContainerAdd"; + _addMacro.Click += new EventHandler(_addMacro_Click); + _addMacro.Text = ui.Text("insertMacro"); + _addMacro.CssClass = "macroContainerAdd"; - this.ContentTemplateContainer.Controls.Add(_addMacro); + this.ContentTemplateContainer.Controls.Add(_addMacro); - _limit = new Literal(); - _limit.Text = string.Format(" Only {0} macros are allowed", _maxNumber); - _limit.ID = ID + "_litlimit"; - _limit.Visible = false; + _limit = new Literal(); + _limit.Text = string.Format(" Only {0} macros are allowed", _maxNumber); + _limit.ID = ID + "_litlimit"; + _limit.Visible = false; - this.ContentTemplateContainer.Controls.Add(_limit); + this.ContentTemplateContainer.Controls.Add(_limit); - string widthHeight = ""; - if (_preferedHeight > 0 && _preferedWidth > 0) - { - widthHeight = String.Format(" style=\"min-width: {0}px; min-height: {1}px;\"", _preferedWidth, _preferedHeight); - } + string widthHeight = ""; + if (_preferedHeight > 0 && _preferedWidth > 0) + { + widthHeight = String.Format(" style=\"min-width: {0}px; min-height: {1}px;\"", _preferedWidth, _preferedHeight); + } - this.ContentTemplateContainer.Controls.Add(new LiteralControl(String.Format("
", widthHeight))); + this.ContentTemplateContainer.Controls.Add(new LiteralControl(String.Format("
", widthHeight))); - Regex tagregex = new Regex("<[^>]*(>|$)", RegexOptions.Singleline | RegexOptions.ExplicitCapture | RegexOptions.Compiled); - MatchCollection tags = tagregex.Matches(_data.Value.ToString()); + Regex tagregex = new Regex("<[^>]*(>|$)", RegexOptions.Singleline | RegexOptions.ExplicitCapture | RegexOptions.Compiled); + MatchCollection tags = tagregex.Matches(_data.Value.ToString()); - List editornumbers = new List(); - string sortorder = string.Empty; + List editornumbers = new List(); + string sortorder = string.Empty; - for (int i = 0; i < _maxNumber; i++) - { - if (!editornumbers.Contains(i)) - { - string data = string.Empty; + for (int i = 0; i < _maxNumber; i++) + { + if (!editornumbers.Contains(i)) + { + string data = string.Empty; - if (tags.Count > i) - data = tags[i].Value; + if (tags.Count > i) + data = tags[i].Value; - MacroEditor macroEditor = new MacroEditor(data, _allowedMacros); - macroEditor.ID = ID + "macroeditor_" + i; + MacroEditor macroEditor = new MacroEditor(data, _allowedMacros); + macroEditor.ID = ID + "macroeditor_" + i; - this.ContentTemplateContainer.Controls.Add(macroEditor); - } + this.ContentTemplateContainer.Controls.Add(macroEditor); + } - } + } - this.ContentTemplateContainer.Controls.Add(new LiteralControl("
")); + this.ContentTemplateContainer.Controls.Add(new LiteralControl("
")); - if (tags.Count == _maxNumber) - { - _addMacro.Enabled = false; - _limit.Visible = true; - } + if (tags.Count == _maxNumber) + { + _addMacro.Enabled = false; + _limit.Visible = true; + } - MacroContainerEvent.Execute += new MacroContainerEvent.ExecuteHandler(MacroContainerEvent_Execute); - - } - private void CheckLimit() - { - bool allowadd = false; - for (int i = 0; i < _maxNumber; i++) - { - MacroEditor current = ((MacroEditor)this.ContentTemplateContainer.FindControl(ID + "macroeditor_" + i.ToString())); + MacroContainerEvent.Execute += new MacroContainerEvent.ExecuteHandler(MacroContainerEvent_Execute); - if (!current.Visible) - { - allowadd = true; - break; - }; - } + } + private void CheckLimit() + { + bool allowadd = false; + for (int i = 0; i < _maxNumber; i++) + { + MacroEditor current = ((MacroEditor)this.ContentTemplateContainer.FindControl(ID + "macroeditor_" + i.ToString())); - if (!allowadd) - { - _addMacro.Enabled = false; - _limit.Visible = true; - } - else - { - _addMacro.Enabled = true; - _limit.Visible = false; - } - } + if (!current.Visible) + { + allowadd = true; + break; + }; + } - private void MacroContainerEvent_Execute() - { - CheckLimit(); - - } + if (!allowadd) + { + _addMacro.Enabled = false; + _limit.Visible = true; + } + else + { + _addMacro.Enabled = true; + _limit.Visible = false; + } + } - private void _addMacro_Click(object sender, EventArgs e) - { + private void MacroContainerEvent_Execute() + { + CheckLimit(); - for (int i = 0; i < _maxNumber; i++) - { - MacroEditor current = ((MacroEditor)this.ContentTemplateContainer.FindControl(ID + "macroeditor_" + i.ToString())); + } - if (!current.Visible) - { - current.Visible = true; - MacroContainerEvent.Add(); - break; - }; - } - } + private void _addMacro_Click(object sender, EventArgs e) + { + + for (int i = 0; i < _maxNumber; i++) + { + MacroEditor current = ((MacroEditor)this.ContentTemplateContainer.FindControl(ID + "macroeditor_" + i.ToString())); + + if (!current.Visible) + { + current.Visible = true; + MacroContainerEvent.Add(); + break; + }; + } + } - protected override void OnLoad(EventArgs e) - { - base.OnLoad(e); + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); - // And a reference to the macro container calls - //if (!UmbracoContext.Current.LiveEditingContext.Enabled) - //{ - // ScriptManager sm = ScriptManager.GetCurrent(base.Page); - // ServiceReference webservicePath = new ServiceReference(SystemDirectories.Webservices + "/MacroContainerService.asmx"); + // And a reference to the macro container calls + //if (!UmbracoContext.Current.LiveEditingContext.Enabled) + //{ + // ScriptManager sm = ScriptManager.GetCurrent(base.Page); + // ServiceReference webservicePath = new ServiceReference(SystemDirectories.Webservices + "/MacroContainerService.asmx"); - // if (!sm.Services.Contains(webservicePath)) - // sm.Services.Add(webservicePath); - //} - //else - //{ - // ClientDependencyLoader.Instance.RegisterDependency("webservices/MacroContainerService.asmx/js", "UmbracoRoot", ClientDependencyType.Javascript); - //} + // if (!sm.Services.Contains(webservicePath)) + // sm.Services.Add(webservicePath); + //} + //else + //{ + // ClientDependencyLoader.Instance.RegisterDependency("webservices/MacroContainerService.asmx/js", "UmbracoRoot", ClientDependencyType.Javascript); + //} - - string script = "function "+ ID +"makesortable(){ "; - script += " jQuery('.macrocontainer').sortable({ update : function () { "; - script += " umbraco.presentation.webservices.MacroContainerService.SetSortOrder('" + ID + "',jQuery('.macrocontainer').sortable('serialize'));"; - script +=" }}); "; - script += " "; - script += "}"; - ScriptManager.RegisterClientScriptBlock(this, this.GetType(), ID + "macrocontainersortable", - script, true); + string script = "function " + ID + "makesortable(){ "; + script += " jQuery('#" + ID + "container').sortable({ update : function () { "; + script += " umbraco.presentation.webservices.MacroContainerService.SetSortOrder('" + ID + "', jQuery('#" + ID + "container').sortable('serialize'));"; + script += " }}); "; + script += " "; + script += "}"; - if (!Page.IsPostBack) - HttpContext.Current.Session[ID + "sortorder"] = null; + ScriptManager.RegisterClientScriptBlock(this, this.GetType(), ID + "macrocontainersortable", + script, true); - ScriptManager.RegisterStartupScript(this, this.GetType(), ID + "initsort", ID + "makesortable();", true); + if (!Page.IsPostBack) + HttpContext.Current.Session[ID + "sortorder"] = null; - string sortscript = string.Empty; + ScriptManager.RegisterStartupScript(this, this.GetType(), ID + "initsort", ID + "makesortable();", true); - string sortorder = string.Empty; - if (HttpContext.Current.Session[ID + "sortorder"] != null) - { - sortorder = HttpContext.Current.Session[ID + "sortorder"].ToString(); - } - if (sortorder != string.Empty) - { + string sortscript = string.Empty; - foreach (string temp in sortorder.Split('&')) - { - string number = temp.Substring(temp.LastIndexOf('=') + 1); + string sortorder = string.Empty; + if (HttpContext.Current.Session[ID + "sortorder"] != null) + { + sortorder = HttpContext.Current.Session[ID + "sortorder"].ToString(); + } + if (sortorder != string.Empty) + { + + foreach (string temp in sortorder.Split('&')) + { + string number = temp.Substring(temp.LastIndexOf('=') + 1); - sortscript += "jQuery('#container"+ID+"macroeditor_" + number + "').appendTo('#"+ID+"container');"; - } - } - if(sortscript != string.Empty) - ScriptManager.RegisterStartupScript(this, this.GetType(), ID + "resort", sortscript, true); + sortscript += "jQuery('#container" + ID + "macroeditor_" + number + "').appendTo('#" + ID + "container');"; + } + } + if (sortscript != string.Empty) + ScriptManager.RegisterStartupScript(this, this.GetType(), ID + "resort", sortscript, true); - EnsureChildControls(); + EnsureChildControls(); + + } - } - #region IDataEditor Members public void Save() { - - + + string value = string.Empty; @@ -265,10 +264,10 @@ namespace umbraco.editorControls.macrocontainer } else { - for(int i = 0; i< _maxNumber; i++) + for (int i = 0; i < _maxNumber; i++) { MacroEditor current = ((MacroEditor)this.ContentTemplateContainer.FindControl(ID + "macroeditor_" + i.ToString())); - if(current.Visible) + if (current.Visible) value += current.MacroTag; } }