From 0f4de0a1c3653c0f96616f871517234036e9bce8 Mon Sep 17 00:00:00 2001 From: starfighter83 Date: Tue, 15 Sep 2009 16:09:50 +0000 Subject: [PATCH] Initial checkin Macro Container Datatype [TFS Changeset #59190] --- .../editorControls/macrocontainer/DataType.cs | 64 ++++ .../editorControls/macrocontainer/Editor.cs | 272 ++++++++++++++ .../macrocontainer/MacroContainerEvent.cs | 25 ++ .../macrocontainer/MacroControlFactory.cs | 97 +++++ .../macrocontainer/MacroEditor.cs | 334 ++++++++++++++++++ .../PersistableMacroProperty.cs | 67 ++++ .../macrocontainer/PrevalueEditor.cs | 303 ++++++++++++++++ .../umbraco.editorControls.csproj | 7 + .../presentation/umbraco.presentation.csproj | 6 + .../js/sortable/jquery-ui-1.7.2.custom.min.js | 34 ++ .../webservices/MacroContainerService.asmx | 1 + .../webservices/MacroContainerService.asmx.cs | 28 ++ 12 files changed, 1238 insertions(+) create mode 100644 components/editorControls/macrocontainer/DataType.cs create mode 100644 components/editorControls/macrocontainer/Editor.cs create mode 100644 components/editorControls/macrocontainer/MacroContainerEvent.cs create mode 100644 components/editorControls/macrocontainer/MacroControlFactory.cs create mode 100644 components/editorControls/macrocontainer/MacroEditor.cs create mode 100644 components/editorControls/macrocontainer/PersistableMacroProperty.cs create mode 100644 components/editorControls/macrocontainer/PrevalueEditor.cs create mode 100644 umbraco/presentation/umbraco/js/sortable/jquery-ui-1.7.2.custom.min.js create mode 100644 umbraco/presentation/umbraco/webservices/MacroContainerService.asmx create mode 100644 umbraco/presentation/umbraco/webservices/MacroContainerService.asmx.cs diff --git a/components/editorControls/macrocontainer/DataType.cs b/components/editorControls/macrocontainer/DataType.cs new file mode 100644 index 0000000000..55aa799482 --- /dev/null +++ b/components/editorControls/macrocontainer/DataType.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace umbraco.editorControls.macrocontainer +{ + public class DataType : cms.businesslogic.datatype.BaseDataType, interfaces.IDataType + { + + private interfaces.IDataEditor _Editor; + private interfaces.IData _baseData; + private interfaces.IDataPrevalue _prevalueeditor; + + public override interfaces.IDataEditor DataEditor + { + get + { + if (_Editor == null) + _Editor = new Editor(Data, ((PrevalueEditor)PrevalueEditor).AllowedMacros, + (int)((PrevalueEditor)PrevalueEditor).MaxNumber, + (int)((PrevalueEditor)PrevalueEditor).PreferedHeight, + (int)((PrevalueEditor)PrevalueEditor).PreferedWidth); + return _Editor; + } + } + + public override interfaces.IData Data + { + get + { + if (_baseData == null) + _baseData = new cms.businesslogic.datatype.DefaultData(this); + return _baseData; + } + } + + + public override Guid Id + { + get + { + return new Guid("474FCFF8-9D2D-11DE-ABC6-AD7A56D89593"); + } + } + public override string DataTypeName + { + get + { + return "Macro Container"; + } + } + public override interfaces.IDataPrevalue PrevalueEditor + { + get + { + if (_prevalueeditor == null) + _prevalueeditor = new PrevalueEditor(this); + return _prevalueeditor; + } + } + + } +} diff --git a/components/editorControls/macrocontainer/Editor.cs b/components/editorControls/macrocontainer/Editor.cs new file mode 100644 index 0000000000..ef86d6bce9 --- /dev/null +++ b/components/editorControls/macrocontainer/Editor.cs @@ -0,0 +1,272 @@ +using System; +using System.Collections.Generic; +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; +using System.Text.RegularExpressions; +using ClientDependency.Core; +using System.Web; +using ClientDependency.Core.Controls; + +namespace umbraco.editorControls.macrocontainer +{ + //[ClientDependency(100, ClientDependencyType.Javascript, "webservices/MacroContainerService.asmx/js", "UmbracoRoot")] + public class Editor : UpdatePanel, IDataEditor + { + private IData _data; + private List _allowedMacros; + private int _maxNumber, _preferedHeight, _preferedWidth; + + private LinkButton _addMacro; + private Literal _limit; + + + + public Editor(IData data, List allowedMacros, int maxNumber, int preferedHeight, int preferedWidth) + { + _data = data; + _allowedMacros = allowedMacros; + _maxNumber = maxNumber; + _preferedHeight = preferedHeight; + _preferedWidth = preferedWidth; + + } + + protected override void OnInit(EventArgs e) + { + base.OnInit(e); + + + base.Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "subModal", ""); + ajaxHelpers.EnsureLegacyCalls(base.Page); + + + + + _addMacro = new LinkButton(); + _addMacro.ID = ID + "_btnaddmacro"; + + + _addMacro.Click += new EventHandler(_addMacro_Click); + _addMacro.Text = "Add"; + + 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; + + this.ContentTemplateContainer.Controls.Add(_limit); + + this.ContentTemplateContainer.Controls.Add(new LiteralControl("
")); + + 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; + + + for (int i = 0; i < _maxNumber; i++) + { + if (!editornumbers.Contains(i)) + { + string data = string.Empty; + + if (tags.Count > i) + data = tags[i].Value; + + MacroEditor macroEditor = new MacroEditor(data, _allowedMacros); + macroEditor.ID = ID + "macroeditor_" + i; + + this.ContentTemplateContainer.Controls.Add(macroEditor); + } + + + } + + this.ContentTemplateContainer.Controls.Add(new LiteralControl("
")); + + 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())); + + if (!current.Visible) + { + allowadd = true; + break; + }; + } + + if (!allowadd) + { + _addMacro.Enabled = false; + _limit.Visible = true; + } + else + { + _addMacro.Enabled = true; + _limit.Visible = false; + } + } + + private void MacroContainerEvent_Execute() + { + CheckLimit(); + + } + + 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); + + // And a reference to the macro container calls + ScriptManager sm = ScriptManager.GetCurrent(base.Page); + ServiceReference webservicePath = new ServiceReference(GlobalSettings.Path + "/webservices/MacroContainerService.asmx"); + + if (!sm.Services.Contains(webservicePath)) + sm.Services.Add(webservicePath); + + + + ClientDependencyLoader.Instance.RegisterDependency("js/sortable/jquery-ui-1.7.2.custom.min.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); + + if (!Page.IsPostBack) + HttpContext.Current.Session[ID + "sortorder"] = null; + + ScriptManager.RegisterStartupScript(this, this.GetType(), ID + "initsort", ID + "makesortable();", true); + + string sortscript = string.Empty; + + 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); + + EnsureChildControls(); + + } + + + + + + #region IDataEditor Members + + public void Save() + { + + + + string value = string.Empty; + + if (HttpContext.Current.Session[ID + "sortorder"] != null) + { + string sortorder = HttpContext.Current.Session[ID + "sortorder"].ToString(); + + foreach (string temp in sortorder.Split('&')) + { + string number = temp.Substring(temp.LastIndexOf('=') + 1); + + MacroEditor current = ((MacroEditor)this.ContentTemplateContainer.FindControl(ID + "macroeditor_" + number)); + if (current.Visible) + value += current.MacroTag; + } + } + else + { + for(int i = 0; i< _maxNumber; i++) + { + MacroEditor current = ((MacroEditor)this.ContentTemplateContainer.FindControl(ID + "macroeditor_" + i.ToString())); + if(current.Visible) + value += current.MacroTag; + } + } + _data.Value = value; + + } + + public bool ShowLabel + { + get { return true; } + } + + public bool TreatAsRichTextEditor + { + get { return false; } + } + + Control IDataEditor.Editor + { + get { return this; } + } + + #endregion + } +} diff --git a/components/editorControls/macrocontainer/MacroContainerEvent.cs b/components/editorControls/macrocontainer/MacroContainerEvent.cs new file mode 100644 index 0000000000..5ceb848cdb --- /dev/null +++ b/components/editorControls/macrocontainer/MacroContainerEvent.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace umbraco.editorControls.macrocontainer +{ + public static class MacroContainerEvent + { + public delegate void ExecuteHandler(); + public static event ExecuteHandler Execute; + + public static void Add() + { + if (Execute != null) + Execute(); + } + + public static void Delete() + { + if (Execute != null) + Execute(); + } + } +} diff --git a/components/editorControls/macrocontainer/MacroControlFactory.cs b/components/editorControls/macrocontainer/MacroControlFactory.cs new file mode 100644 index 0000000000..e533293793 --- /dev/null +++ b/components/editorControls/macrocontainer/MacroControlFactory.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using System.Web.UI; +using umbraco.BusinessLogic.Utils; +using umbraco.interfaces; +using umbraco.editorControls; + + + +namespace umbraco.editorControls.macrocontainer +{ + internal class MacroControlFactory + { + #region Private Fields + /// + /// All Possible Macro types + /// + private static List _macroControlTypes = null; + #endregion + + #region Methods + /// + /// Create an instance of a Macro control and return it. + /// Because the macro control uses inline client script whichs is not generated after postback + /// That's why we use the Page Picker instead of the content picker of the macro. + /// + internal static Control GetMacroRenderControlByType(PersistableMacroProperty prop, string uniqueID) + { + Control macroControl; + //Determine the property type + switch (prop.TypeName.ToLower()) + { + //Use a pagepicker instead of a IMacroGuiRendering control + case "content": + macroControl = new pagePicker(null); + ((pagePicker)macroControl).Value = prop.Value; + break; + ///Default behaviour + default: + Type m = MacroControlTypes.FindLast(delegate(Type macroGuiCcontrol) { return macroGuiCcontrol.ToString() == string.Format("{0}.{1}", prop.AssemblyName, prop.TypeName); }); + IMacroGuiRendering typeInstance; + typeInstance = Activator.CreateInstance(m) as IMacroGuiRendering; + if (!string.IsNullOrEmpty(prop.Value)) + { + ((IMacroGuiRendering)typeInstance).Value = prop.Value; + } + macroControl = (Control)typeInstance; + break; + } + + macroControl.ID = uniqueID; + return macroControl; + } + + /// + /// Gets the value based on the type of control + /// + /// + /// + internal static string GetValueFromMacroControl(Control macroControl) + { + if (macroControl is pagePicker) + { + //pagePicker Control + return ((pagePicker)macroControl).Value; + } + else + { + ///Macro control + return ((IMacroGuiRendering)macroControl).Value; + } + + } + #endregion + + #region Properties + /// + /// All Possible Macro types + /// + private static List MacroControlTypes + { + get + { + if (_macroControlTypes == null || _macroControlTypes.Count == 0) + { + //Populate the list with all the types of IMacroGuiRendering + _macroControlTypes = new List(); + _macroControlTypes = TypeFinder.FindClassesOfType(true); + } + + return _macroControlTypes; + } + } + #endregion + + } +} diff --git a/components/editorControls/macrocontainer/MacroEditor.cs b/components/editorControls/macrocontainer/MacroEditor.cs new file mode 100644 index 0000000000..c24c028fdd --- /dev/null +++ b/components/editorControls/macrocontainer/MacroEditor.cs @@ -0,0 +1,334 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Web.UI.WebControls; +using System.Web.UI; +using umbraco.cms.businesslogic.macro; +using System.Collections; +using umbraco.presentation; +using System.Web; + +namespace umbraco.editorControls.macrocontainer +{ + public class MacroEditor: System.Web.UI.Control + { + private List _allowedMacros; + private DropDownList _macroSelectDropdown; + private LinkButton _delete; + private Table _formTable; + private Hashtable _dataValues; + private string _data; + + public MacroEditor(string Data, List allowedMacros) + { + _data = Data; + _allowedMacros = allowedMacros; + } + + protected override void OnInit(EventArgs e) + { + base.OnInit(e); + + _macroSelectDropdown = new DropDownList(); + _macroSelectDropdown.ID = ID + "_ddselectmacro"; + _macroSelectDropdown.SelectedIndexChanged += new EventHandler(_macroSelectDropdown_SelectedIndexChanged); + _macroSelectDropdown.Items.Add(new ListItem(umbraco.ui.Text("choose"), "")); + foreach (string item in _allowedMacros) + { + _macroSelectDropdown.Items.Add(new ListItem(Macro.GetByAlias(item).Name, item)); + } + _macroSelectDropdown.AutoPostBack = true; + + _delete = new LinkButton(); + _delete.ID = ID + "_btndelete"; + _delete.Text = "Delete"; + _delete.Attributes.Add("style", "color:red;"); + _delete.Click += new EventHandler(_delete_Click); + _formTable = new Table(); + _formTable.ID = ID + "_tblform"; + + this.Controls.Add(_macroSelectDropdown); + this.Controls.Add(_delete); + this.Controls.Add(_formTable); + } + + void _delete_Click(object sender, EventArgs e) + { + _macroSelectDropdown.SelectedIndex = 0; + InitializeForm(""); + this.Visible = false; + MacroContainerEvent.Delete(); + } + + + + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + + + if (!GlobalSettings.RequestIsInUmbracoApplication(HttpContext.Current) && umbraco.presentation.UmbracoContext.Current.LiveEditingContext.Enabled) + { + if (ViewState[ID + "init"] == null) + { + if (DataValues["macroalias"] != null) + { + //Data is available from the database, initialize the form with the data + string alias = DataValues["macroalias"].ToString(); + + //Set Pulldown selected value based on the macro alias + _macroSelectDropdown.SelectedValue = alias; + + //Create from with values based on the alias + InitializeForm(alias); + } + else + { + this.Visible = false; + } + + ViewState[ID + "init"] = "ok"; + } + else + { + //Render form if properties are in the viewstate + if (SelectedProperties.Count > 0) + { + RendeFormControls(); + } + } + } + else + { + + if (!Page.IsPostBack) + { + + //Handle Initial Request + if (DataValues["macroalias"] != null) + { + //Data is available from the database, initialize the form with the data + string alias = DataValues["macroalias"].ToString(); + + //Set Pulldown selected value based on the macro alias + _macroSelectDropdown.SelectedValue = alias; + + //Create from with values based on the alias + InitializeForm(alias); + } + else + { + this.Visible = false; + } + + } + else + { + //Render form if properties are in the viewstate + if (SelectedProperties.Count > 0) + { + RendeFormControls(); + } + } + } + //Make sure child controls get rendered + EnsureChildControls(); + + } + + protected override void Render(HtmlTextWriter writer) + { + + writer.Write("
"); + _macroSelectDropdown.RenderControl(writer); + writer.Write(" ");//Delete"); + _delete.RenderControl(writer); + _formTable.RenderControl(writer); + writer.Write("
"); + } + + private void _macroSelectDropdown_SelectedIndexChanged(object sender, EventArgs e) + { + InitializeForm(_macroSelectDropdown.SelectedValue); + + } + + private void InitializeForm(string macroAlias) + { + + //Hold selected Alias in Viewstate + SelectedMacroAlias = macroAlias; + + //Create new property collection + List props = new List(); + + //Clear Old Control Collection + _formTable.Controls.Clear(); + + //Is a Macro selected + if (!string.IsNullOrEmpty(macroAlias)) + { + Macro formMacro = Macro.GetByAlias(macroAlias); + + ///Only render form when macro is found + if (formMacro != null) + { + foreach (MacroProperty macroProperty in formMacro.Properties) + { + //Only add properties that people may see. + if (macroProperty.Public) + { + PersistableMacroProperty prop = new PersistableMacroProperty(); + prop.Alias = macroProperty.Alias; + prop.Name = macroProperty.Name; + prop.AssemblyName = macroProperty.Type.Assembly; + prop.TypeName = macroProperty.Type.Type; + + //Assign value if specified + if (DataValues[macroProperty.Alias.ToLower()] != null) + { + prop.Value = DataValues[macroProperty.Alias.ToLower()].ToString(); + } + + props.Add(prop); + } + } + } + } + //Hold selected properties in ViewState + SelectedProperties = props; + + //Render the form + RendeFormControls(); + } + + /// + /// Renders a from based on the properties of the macro + /// + private void RendeFormControls() + { + foreach (PersistableMacroProperty prop in SelectedProperties) + { + //Create Literal + Literal caption = new Literal(); + caption.ID = ID + "_" + string.Format("{0}Label", prop.Alias); + caption.Text = prop.Name; + + //Get the MacroControl + Control macroControl = MacroControlFactory.GetMacroRenderControlByType(prop,ID + "_" + prop.Alias); + + AddFormRow(caption, macroControl); + + } + } + + /// + /// Add a new TableRow to the table. with two cells that holds the Caption and the form element + /// + /// + /// + private void AddFormRow(Control name, Control formElement) + { + string aliasPrefix = formElement.ID; + + TableRow tr = new TableRow(); + tr.ID = ID + "_" + string.Format("{0}tr", aliasPrefix); + + TableCell tcLeft = new TableCell(); + tcLeft.ID = ID + "_" + string.Format("{0}tcleft", aliasPrefix); + tcLeft.Width = 120; + + TableCell tcRight = new TableCell(); + tcRight.ID = ID + "_" + string.Format("{0}tcright", aliasPrefix); + tcRight.Width = 300; + + tcLeft.Controls.Add(name); + tcRight.Controls.Add(formElement); + + tr.Controls.Add(tcLeft); + tr.Controls.Add(tcRight); + + _formTable.Controls.Add(tr); + + } + + /// + /// Builds an Umbraco Macro tag if a user selected a macro + /// + /// + private string CreateUmbracoMacroTag() + { + string result = string.Empty; + + if (!string.IsNullOrEmpty(SelectedMacroAlias)) + { + //Only create Macro Tag if we have something to store. + StringBuilder sb = new StringBuilder(); + //Start + sb.Append(""); + result = sb.ToString(); + } + return result; + } + + private string SelectedMacroAlias + { + + get { return string.Format("{0}", ViewState[ID + "SelectedMacroAlias"]); } + set { ViewState[ID + "SelectedMacroAlias"] = value; } + } + + private List SelectedProperties + { + get + { + if (ViewState[ID + "controls"] == null) + { + return new List(); + } + else + { + return (List)ViewState[ID + "controls"]; + } + } + set + { + ViewState[ID + "controls"] = value; + } + } + + public Hashtable DataValues + { + get + { + if (_dataValues == null) + { + _dataValues = umbraco.helper.ReturnAttributes(_data); + } + return _dataValues; + } + } + + + public string MacroTag + { + get + { + return CreateUmbracoMacroTag(); + } + } + } +} diff --git a/components/editorControls/macrocontainer/PersistableMacroProperty.cs b/components/editorControls/macrocontainer/PersistableMacroProperty.cs new file mode 100644 index 0000000000..cad09362f2 --- /dev/null +++ b/components/editorControls/macrocontainer/PersistableMacroProperty.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace umbraco.editorControls.macrocontainer +{ + [Serializable] + internal class PersistableMacroProperty + { + #region Private Fields + private string _name; + private string _alias; + private string _value; + private string _assemblyName; + private string _typeName; + #endregion + + #region Properties + /// + /// Macro Caption + /// + public string Name + { + get { return _name; } + set { _name = value; } + } + + /// + /// Macro Alias + /// + public string Alias + { + get { return _alias; } + set { _alias = value; } + } + + /// + /// Macro Value + /// + public string Value + { + get { return _value; } + set { _value = value; } + } + + /// + /// AssemblyName of the Property of teh Macro + /// + public string AssemblyName + { + get { return _assemblyName; } + set { _assemblyName = value; } + } + + /// + /// TypeName of the property of the macro + /// + public string TypeName + { + get { return _typeName; } + set { _typeName = value; } + } + #endregion + + } +} diff --git a/components/editorControls/macrocontainer/PrevalueEditor.cs b/components/editorControls/macrocontainer/PrevalueEditor.cs new file mode 100644 index 0000000000..f80f9e9e29 --- /dev/null +++ b/components/editorControls/macrocontainer/PrevalueEditor.cs @@ -0,0 +1,303 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Web.UI.WebControls; +using umbraco.uicontrols; +using umbraco.cms.businesslogic.macro; +using umbraco.BusinessLogic; +using System.Web.UI; + + +namespace umbraco.editorControls.macrocontainer +{ + public class PrevalueEditor : System.Web.UI.WebControls.PlaceHolder, umbraco.interfaces.IDataPrevalue + { + + #region Private fields + private umbraco.cms.businesslogic.datatype.BaseDataType _datatype; + + private string _configuration; + private List _allowedMacros; + private int? _maxNumber; + private int? _preferedWidth; + private int? _preferedHeight; + + private CheckBoxList _macroList = new CheckBoxList(); + private TextBox _txtMaxNumber; + private TextBox _txtPreferedHeight; + private TextBox _txtPreferedWidth; + + #endregion + + #region Constructor + /// + /// Constructor + /// + /// + public PrevalueEditor(umbraco.cms.businesslogic.datatype.BaseDataType dataType) + { + Datatype = dataType; + } + #endregion + + #region Overrides + /// + /// Initializes controls + /// + /// + protected override void OnInit(EventArgs e) + { + base.OnLoad(e); + PropertyPanel allowedPropertyPanel = new PropertyPanel(); + allowedPropertyPanel.Text = "Allowed Macros"; + allowedPropertyPanel.Controls.Add(_macroList); + Controls.Add(allowedPropertyPanel); + + PropertyPanel numberPropertyPanel = new PropertyPanel(); + numberPropertyPanel.Text = "Max Number"; + _txtMaxNumber = new TextBox(); + _txtMaxNumber.ID = "maxnumber"; + numberPropertyPanel.Controls.Add(_txtMaxNumber); + Controls.Add(numberPropertyPanel); + + PropertyPanel heightPropertyPanel = new PropertyPanel(); + heightPropertyPanel.Text = "Prefered height"; + _txtPreferedHeight= new TextBox(); + _txtPreferedHeight.ID = "prefheight"; + heightPropertyPanel.Controls.Add(_txtPreferedHeight); + Controls.Add(heightPropertyPanel); + + PropertyPanel widthPropertyPanel = new PropertyPanel(); + widthPropertyPanel.Text = "Prefered width"; + _txtPreferedWidth = new TextBox(); + _txtPreferedWidth.ID = "prefwidth"; + widthPropertyPanel.Controls.Add(_txtPreferedWidth); + Controls.Add(widthPropertyPanel); + } + + /// + /// Initialize the form + /// + /// + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + + if (!Page.IsPostBack) + { + _macroList.DataValueField = "Alias"; + _macroList.DataTextField = "Name"; + _macroList.DataSource = Macro.GetAll(); + _macroList.DataBound += new EventHandler(MacroList_DataBound); + + if(MaxNumber != 0) + _txtMaxNumber.Text = MaxNumber.ToString(); + if (PreferedHeight != 0) + _txtPreferedHeight.Text = PreferedHeight.ToString(); + if(PreferedWidth != 0) + _txtPreferedWidth.Text = PreferedWidth.ToString(); + } + + _macroList.DataBind(); + } + + #endregion + + #region EventHandlers + private void MacroList_DataBound(object sender, EventArgs e) + { + CheckBoxList cbl = (CheckBoxList)sender; + foreach (ListItem item in cbl.Items) + { + item.Selected = AllowedMacros.Contains(item.Value); + } + } + #endregion + + #region Methods + /// + /// Returns the selected Macro's in a comma seperated string + /// + private string GetSelectedMacosFromCheckList() + { + StringBuilder result = new StringBuilder(); + foreach (ListItem lst in _macroList.Items) + { + if (lst.Selected) + { + //User Selected the Macro, add to the string builder + if (result.Length > 0) + { + //Allready item on the list add a comma first + result.Append(","); + } + result.Append(lst.Value); + } + } + return result.ToString(); + } + + + #endregion + + #region Properties + + public string Configuration + { + get + { + if (_configuration == null) + { + return Application.SqlHelper.ExecuteScalar( + "select value from cmsDataTypePreValues where datatypenodeid = @datatypenodeid", + Application.SqlHelper.CreateParameter("@datatypenodeid", Datatype.DataTypeDefinitionId)); + } + else + { + return _configuration; + } + } + } + + public List AllowedMacros + { + get + { + if (_allowedMacros == null) + { + List result = new List(); + string values = Configuration.Split('|')[0]; + + result.AddRange(values.Split(',')); + + _allowedMacros = result; + + return _allowedMacros; + + } + return _allowedMacros; + } + } + + public int? MaxNumber + { + get + { + if (_maxNumber == null) + { + int output = 0; + if (Configuration.Split('|').Length > 1) + { + int.TryParse(Configuration.Split('|')[1], out output); + return output; + } + return output; + } + else + { + return _maxNumber; + } + + } + } + + + public int? PreferedHeight + { + get + { + if (_preferedHeight == null) + { + int output = 0; + if (Configuration.Split('|').Length > 2) + { + int.TryParse(Configuration.Split('|')[2], out output); + return output; + } + return output; + } + else + { + return _preferedHeight; + } + + } + } + + public int? PreferedWidth + { + get + { + if (_preferedWidth == null) + { + int output = 0; + if (Configuration.Split('|').Length > 3) + { + int.TryParse(Configuration.Split('|')[3], out output); + return output; + } + return output; + } + else + { + return _preferedWidth; + } + + } + } + + #endregion + + #region IDataPrevalue Members + /// + /// Reference to the datatype + /// + public umbraco.cms.businesslogic.datatype.BaseDataType Datatype + { + get { return _datatype; } + set { _datatype = value; } + } + + /// + /// Reference to the editor + /// + public Control Editor + { + get { return this; } + } + + /// + /// Save settings + /// + public void Save() + { + + Application.SqlHelper.ExecuteNonQuery( + "delete from cmsDataTypePreValues where datatypenodeid = @dtdefid", + Application.SqlHelper.CreateParameter("@dtdefid", Datatype.DataTypeDefinitionId)); + + StringBuilder config = new StringBuilder(); + config.Append(GetSelectedMacosFromCheckList()); + config.Append("|"); + int maxnumber = 0; + int.TryParse(_txtMaxNumber.Text, out maxnumber); + config.Append(maxnumber); + config.Append("|"); + int prefheight = 0; + int.TryParse(_txtPreferedHeight.Text, out prefheight); + config.Append(prefheight); + config.Append("|"); + int prefwidth = 0; + int.TryParse(_txtPreferedWidth.Text, out prefwidth); + config.Append(prefwidth); + + Application.SqlHelper.ExecuteNonQuery( + "insert into cmsDataTypePreValues (datatypenodeid,[value],sortorder,alias) values (@dtdefid,@value,0,'')", + Application.SqlHelper.CreateParameter("@dtdefid", Datatype.DataTypeDefinitionId), Application.SqlHelper.CreateParameter("@value", config.ToString())); + + } + #endregion + + } +} diff --git a/components/editorControls/umbraco.editorControls.csproj b/components/editorControls/umbraco.editorControls.csproj index 0abdb46015..4e41212496 100644 --- a/components/editorControls/umbraco.editorControls.csproj +++ b/components/editorControls/umbraco.editorControls.csproj @@ -252,6 +252,13 @@ Code + + + + + + + Code diff --git a/umbraco/presentation/umbraco.presentation.csproj b/umbraco/presentation/umbraco.presentation.csproj index 8488049a2c..d750947f13 100644 --- a/umbraco/presentation/umbraco.presentation.csproj +++ b/umbraco/presentation/umbraco.presentation.csproj @@ -1192,6 +1192,10 @@ + + MacroContainerService.asmx + Component + MediaPickerService.asmx Component @@ -1488,6 +1492,8 @@ + + diff --git a/umbraco/presentation/umbraco/js/sortable/jquery-ui-1.7.2.custom.min.js b/umbraco/presentation/umbraco/js/sortable/jquery-ui-1.7.2.custom.min.js new file mode 100644 index 0000000000..8f9db8c622 --- /dev/null +++ b/umbraco/presentation/umbraco/js/sortable/jquery-ui-1.7.2.custom.min.js @@ -0,0 +1,34 @@ +/* + * jQuery UI 1.7.2 + * + * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT (MIT-LICENSE.txt) + * and GPL (GPL-LICENSE.txt) licenses. + * + * http://docs.jquery.com/UI + */ +jQuery.ui||(function(c){var i=c.fn.remove,d=c.browser.mozilla&&(parseFloat(c.browser.version)<1.9);c.ui={version:"1.7.2",plugin:{add:function(k,l,n){var m=c.ui[k].prototype;for(var j in n){m.plugins[j]=m.plugins[j]||[];m.plugins[j].push([l,n[j]])}},call:function(j,l,k){var n=j.plugins[l];if(!n||!j.element[0].parentNode){return}for(var m=0;m0){return true}m[j]=1;l=(m[j]>0);m[j]=0;return l},isOverAxis:function(k,j,l){return(k>j)&&(k<(j+l))},isOver:function(o,k,n,m,j,l){return c.ui.isOverAxis(o,n,j)&&c.ui.isOverAxis(k,m,l)},keyCode:{BACKSPACE:8,CAPS_LOCK:20,COMMA:188,CONTROL:17,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,INSERT:45,LEFT:37,NUMPAD_ADD:107,NUMPAD_DECIMAL:110,NUMPAD_DIVIDE:111,NUMPAD_ENTER:108,NUMPAD_MULTIPLY:106,NUMPAD_SUBTRACT:109,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SHIFT:16,SPACE:32,TAB:9,UP:38}};if(d){var f=c.attr,e=c.fn.removeAttr,h="http://www.w3.org/2005/07/aaa",a=/^aria-/,b=/^wairole:/;c.attr=function(k,j,l){var m=l!==undefined;return(j=="role"?(m?f.call(this,k,j,"wairole:"+l):(f.apply(this,arguments)||"").replace(b,"")):(a.test(j)?(m?k.setAttributeNS(h,j.replace(a,"aaa:"),l):f.call(this,k,j.replace(a,"aaa:"))):f.apply(this,arguments)))};c.fn.removeAttr=function(j){return(a.test(j)?this.each(function(){this.removeAttributeNS(h,j.replace(a,""))}):e.call(this,j))}}c.fn.extend({remove:function(){c("*",this).add(this).each(function(){c(this).triggerHandler("remove")});return i.apply(this,arguments)},enableSelection:function(){return this.attr("unselectable","off").css("MozUserSelect","").unbind("selectstart.ui")},disableSelection:function(){return this.attr("unselectable","on").css("MozUserSelect","none").bind("selectstart.ui",function(){return false})},scrollParent:function(){var j;if((c.browser.msie&&(/(static|relative)/).test(this.css("position")))||(/absolute/).test(this.css("position"))){j=this.parents().filter(function(){return(/(relative|absolute|fixed)/).test(c.curCSS(this,"position",1))&&(/(auto|scroll)/).test(c.curCSS(this,"overflow",1)+c.curCSS(this,"overflow-y",1)+c.curCSS(this,"overflow-x",1))}).eq(0)}else{j=this.parents().filter(function(){return(/(auto|scroll)/).test(c.curCSS(this,"overflow",1)+c.curCSS(this,"overflow-y",1)+c.curCSS(this,"overflow-x",1))}).eq(0)}return(/fixed/).test(this.css("position"))||!j.length?c(document):j}});c.extend(c.expr[":"],{data:function(l,k,j){return !!c.data(l,j[3])},focusable:function(k){var l=k.nodeName.toLowerCase(),j=c.attr(k,"tabindex");return(/input|select|textarea|button|object/.test(l)?!k.disabled:"a"==l||"area"==l?k.href||!isNaN(j):!isNaN(j))&&!c(k)["area"==l?"parents":"closest"](":hidden").length},tabbable:function(k){var j=c.attr(k,"tabindex");return(isNaN(j)||j>=0)&&c(k).is(":focusable")}});function g(m,n,o,l){function k(q){var p=c[m][n][q]||[];return(typeof p=="string"?p.split(/,?\s+/):p)}var j=k("getter");if(l.length==1&&typeof l[0]=="string"){j=j.concat(k("getterSetter"))}return(c.inArray(o,j)!=-1)}c.widget=function(k,j){var l=k.split(".")[0];k=k.split(".")[1];c.fn[k]=function(p){var n=(typeof p=="string"),o=Array.prototype.slice.call(arguments,1);if(n&&p.substring(0,1)=="_"){return this}if(n&&g(l,k,p,o)){var m=c.data(this[0],k);return(m?m[p].apply(m,o):undefined)}return this.each(function(){var q=c.data(this,k);(!q&&!n&&c.data(this,k,new c[l][k](this,p))._init());(q&&n&&c.isFunction(q[p])&&q[p].apply(q,o))})};c[l]=c[l]||{};c[l][k]=function(o,n){var m=this;this.namespace=l;this.widgetName=k;this.widgetEventPrefix=c[l][k].eventPrefix||k;this.widgetBaseClass=l+"-"+k;this.options=c.extend({},c.widget.defaults,c[l][k].defaults,c.metadata&&c.metadata.get(o)[k],n);this.element=c(o).bind("setData."+k,function(q,p,r){if(q.target==o){return m._setData(p,r)}}).bind("getData."+k,function(q,p){if(q.target==o){return m._getData(p)}}).bind("remove",function(){return m.destroy()})};c[l][k].prototype=c.extend({},c.widget.prototype,j);c[l][k].getterSetter="option"};c.widget.prototype={_init:function(){},destroy:function(){this.element.removeData(this.widgetName).removeClass(this.widgetBaseClass+"-disabled "+this.namespace+"-state-disabled").removeAttr("aria-disabled")},option:function(l,m){var k=l,j=this;if(typeof l=="string"){if(m===undefined){return this._getData(l)}k={};k[l]=m}c.each(k,function(n,o){j._setData(n,o)})},_getData:function(j){return this.options[j]},_setData:function(j,k){this.options[j]=k;if(j=="disabled"){this.element[k?"addClass":"removeClass"](this.widgetBaseClass+"-disabled "+this.namespace+"-state-disabled").attr("aria-disabled",k)}},enable:function(){this._setData("disabled",false)},disable:function(){this._setData("disabled",true)},_trigger:function(l,m,n){var p=this.options[l],j=(l==this.widgetEventPrefix?l:this.widgetEventPrefix+l);m=c.Event(m);m.type=j;if(m.originalEvent){for(var k=c.event.props.length,o;k;){o=c.event.props[--k];m[o]=m.originalEvent[o]}}this.element.trigger(m,n);return !(c.isFunction(p)&&p.call(this.element[0],m,n)===false||m.isDefaultPrevented())}};c.widget.defaults={disabled:false};c.ui.mouse={_mouseInit:function(){var j=this;this.element.bind("mousedown."+this.widgetName,function(k){return j._mouseDown(k)}).bind("click."+this.widgetName,function(k){if(j._preventClickEvent){j._preventClickEvent=false;k.stopImmediatePropagation();return false}});if(c.browser.msie){this._mouseUnselectable=this.element.attr("unselectable");this.element.attr("unselectable","on")}this.started=false},_mouseDestroy:function(){this.element.unbind("."+this.widgetName);(c.browser.msie&&this.element.attr("unselectable",this._mouseUnselectable))},_mouseDown:function(l){l.originalEvent=l.originalEvent||{};if(l.originalEvent.mouseHandled){return}(this._mouseStarted&&this._mouseUp(l));this._mouseDownEvent=l;var k=this,m=(l.which==1),j=(typeof this.options.cancel=="string"?c(l.target).parents().add(l.target).filter(this.options.cancel).length:false);if(!m||j||!this._mouseCapture(l)){return true}this.mouseDelayMet=!this.options.delay;if(!this.mouseDelayMet){this._mouseDelayTimer=setTimeout(function(){k.mouseDelayMet=true},this.options.delay)}if(this._mouseDistanceMet(l)&&this._mouseDelayMet(l)){this._mouseStarted=(this._mouseStart(l)!==false);if(!this._mouseStarted){l.preventDefault();return true}}this._mouseMoveDelegate=function(n){return k._mouseMove(n)};this._mouseUpDelegate=function(n){return k._mouseUp(n)};c(document).bind("mousemove."+this.widgetName,this._mouseMoveDelegate).bind("mouseup."+this.widgetName,this._mouseUpDelegate);(c.browser.safari||l.preventDefault());l.originalEvent.mouseHandled=true;return true},_mouseMove:function(j){if(c.browser.msie&&!j.button){return this._mouseUp(j)}if(this._mouseStarted){this._mouseDrag(j);return j.preventDefault()}if(this._mouseDistanceMet(j)&&this._mouseDelayMet(j)){this._mouseStarted=(this._mouseStart(this._mouseDownEvent,j)!==false);(this._mouseStarted?this._mouseDrag(j):this._mouseUp(j))}return !this._mouseStarted},_mouseUp:function(j){c(document).unbind("mousemove."+this.widgetName,this._mouseMoveDelegate).unbind("mouseup."+this.widgetName,this._mouseUpDelegate);if(this._mouseStarted){this._mouseStarted=false;this._preventClickEvent=(j.target==this._mouseDownEvent.target);this._mouseStop(j)}return false},_mouseDistanceMet:function(j){return(Math.max(Math.abs(this._mouseDownEvent.pageX-j.pageX),Math.abs(this._mouseDownEvent.pageY-j.pageY))>=this.options.distance)},_mouseDelayMet:function(j){return this.mouseDelayMet},_mouseStart:function(j){},_mouseDrag:function(j){},_mouseStop:function(j){},_mouseCapture:function(j){return true}};c.ui.mouse.defaults={cancel:null,distance:1,delay:0}})(jQuery);;/* + * jQuery UI Draggable 1.7.2 + * + * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT (MIT-LICENSE.txt) + * and GPL (GPL-LICENSE.txt) licenses. + * + * http://docs.jquery.com/UI/Draggables + * + * Depends: + * ui.core.js + */ +(function(a){a.widget("ui.draggable",a.extend({},a.ui.mouse,{_init:function(){if(this.options.helper=="original"&&!(/^(?:r|a|f)/).test(this.element.css("position"))){this.element[0].style.position="relative"}(this.options.addClasses&&this.element.addClass("ui-draggable"));(this.options.disabled&&this.element.addClass("ui-draggable-disabled"));this._mouseInit()},destroy:function(){if(!this.element.data("draggable")){return}this.element.removeData("draggable").unbind(".draggable").removeClass("ui-draggable ui-draggable-dragging ui-draggable-disabled");this._mouseDestroy()},_mouseCapture:function(b){var c=this.options;if(this.helper||c.disabled||a(b.target).is(".ui-resizable-handle")){return false}this.handle=this._getHandle(b);if(!this.handle){return false}return true},_mouseStart:function(b){var c=this.options;this.helper=this._createHelper(b);this._cacheHelperProportions();if(a.ui.ddmanager){a.ui.ddmanager.current=this}this._cacheMargins();this.cssPosition=this.helper.css("position");this.scrollParent=this.helper.scrollParent();this.offset=this.element.offset();this.offset={top:this.offset.top-this.margins.top,left:this.offset.left-this.margins.left};a.extend(this.offset,{click:{left:b.pageX-this.offset.left,top:b.pageY-this.offset.top},parent:this._getParentOffset(),relative:this._getRelativeOffset()});this.originalPosition=this._generatePosition(b);this.originalPageX=b.pageX;this.originalPageY=b.pageY;if(c.cursorAt){this._adjustOffsetFromHelper(c.cursorAt)}if(c.containment){this._setContainment()}this._trigger("start",b);this._cacheHelperProportions();if(a.ui.ddmanager&&!c.dropBehaviour){a.ui.ddmanager.prepareOffsets(this,b)}this.helper.addClass("ui-draggable-dragging");this._mouseDrag(b,true);return true},_mouseDrag:function(b,d){this.position=this._generatePosition(b);this.positionAbs=this._convertPositionTo("absolute");if(!d){var c=this._uiHash();this._trigger("drag",b,c);this.position=c.position}if(!this.options.axis||this.options.axis!="y"){this.helper[0].style.left=this.position.left+"px"}if(!this.options.axis||this.options.axis!="x"){this.helper[0].style.top=this.position.top+"px"}if(a.ui.ddmanager){a.ui.ddmanager.drag(this,b)}return false},_mouseStop:function(c){var d=false;if(a.ui.ddmanager&&!this.options.dropBehaviour){d=a.ui.ddmanager.drop(this,c)}if(this.dropped){d=this.dropped;this.dropped=false}if((this.options.revert=="invalid"&&!d)||(this.options.revert=="valid"&&d)||this.options.revert===true||(a.isFunction(this.options.revert)&&this.options.revert.call(this.element,d))){var b=this;a(this.helper).animate(this.originalPosition,parseInt(this.options.revertDuration,10),function(){b._trigger("stop",c);b._clear()})}else{this._trigger("stop",c);this._clear()}return false},_getHandle:function(b){var c=!this.options.handle||!a(this.options.handle,this.element).length?true:false;a(this.options.handle,this.element).find("*").andSelf().each(function(){if(this==b.target){c=true}});return c},_createHelper:function(c){var d=this.options;var b=a.isFunction(d.helper)?a(d.helper.apply(this.element[0],[c])):(d.helper=="clone"?this.element.clone():this.element);if(!b.parents("body").length){b.appendTo((d.appendTo=="parent"?this.element[0].parentNode:d.appendTo))}if(b[0]!=this.element[0]&&!(/(fixed|absolute)/).test(b.css("position"))){b.css("position","absolute")}return b},_adjustOffsetFromHelper:function(b){if(b.left!=undefined){this.offset.click.left=b.left+this.margins.left}if(b.right!=undefined){this.offset.click.left=this.helperProportions.width-b.right+this.margins.left}if(b.top!=undefined){this.offset.click.top=b.top+this.margins.top}if(b.bottom!=undefined){this.offset.click.top=this.helperProportions.height-b.bottom+this.margins.top}},_getParentOffset:function(){this.offsetParent=this.helper.offsetParent();var b=this.offsetParent.offset();if(this.cssPosition=="absolute"&&this.scrollParent[0]!=document&&a.ui.contains(this.scrollParent[0],this.offsetParent[0])){b.left+=this.scrollParent.scrollLeft();b.top+=this.scrollParent.scrollTop()}if((this.offsetParent[0]==document.body)||(this.offsetParent[0].tagName&&this.offsetParent[0].tagName.toLowerCase()=="html"&&a.browser.msie)){b={top:0,left:0}}return{top:b.top+(parseInt(this.offsetParent.css("borderTopWidth"),10)||0),left:b.left+(parseInt(this.offsetParent.css("borderLeftWidth"),10)||0)}},_getRelativeOffset:function(){if(this.cssPosition=="relative"){var b=this.element.position();return{top:b.top-(parseInt(this.helper.css("top"),10)||0)+this.scrollParent.scrollTop(),left:b.left-(parseInt(this.helper.css("left"),10)||0)+this.scrollParent.scrollLeft()}}else{return{top:0,left:0}}},_cacheMargins:function(){this.margins={left:(parseInt(this.element.css("marginLeft"),10)||0),top:(parseInt(this.element.css("marginTop"),10)||0)}},_cacheHelperProportions:function(){this.helperProportions={width:this.helper.outerWidth(),height:this.helper.outerHeight()}},_setContainment:function(){var e=this.options;if(e.containment=="parent"){e.containment=this.helper[0].parentNode}if(e.containment=="document"||e.containment=="window"){this.containment=[0-this.offset.relative.left-this.offset.parent.left,0-this.offset.relative.top-this.offset.parent.top,a(e.containment=="document"?document:window).width()-this.helperProportions.width-this.margins.left,(a(e.containment=="document"?document:window).height()||document.body.parentNode.scrollHeight)-this.helperProportions.height-this.margins.top]}if(!(/^(document|window|parent)$/).test(e.containment)&&e.containment.constructor!=Array){var c=a(e.containment)[0];if(!c){return}var d=a(e.containment).offset();var b=(a(c).css("overflow")!="hidden");this.containment=[d.left+(parseInt(a(c).css("borderLeftWidth"),10)||0)+(parseInt(a(c).css("paddingLeft"),10)||0)-this.margins.left,d.top+(parseInt(a(c).css("borderTopWidth"),10)||0)+(parseInt(a(c).css("paddingTop"),10)||0)-this.margins.top,d.left+(b?Math.max(c.scrollWidth,c.offsetWidth):c.offsetWidth)-(parseInt(a(c).css("borderLeftWidth"),10)||0)-(parseInt(a(c).css("paddingRight"),10)||0)-this.helperProportions.width-this.margins.left,d.top+(b?Math.max(c.scrollHeight,c.offsetHeight):c.offsetHeight)-(parseInt(a(c).css("borderTopWidth"),10)||0)-(parseInt(a(c).css("paddingBottom"),10)||0)-this.helperProportions.height-this.margins.top]}else{if(e.containment.constructor==Array){this.containment=e.containment}}},_convertPositionTo:function(f,h){if(!h){h=this.position}var c=f=="absolute"?1:-1;var e=this.options,b=this.cssPosition=="absolute"&&!(this.scrollParent[0]!=document&&a.ui.contains(this.scrollParent[0],this.offsetParent[0]))?this.offsetParent:this.scrollParent,g=(/(html|body)/i).test(b[0].tagName);return{top:(h.top+this.offset.relative.top*c+this.offset.parent.top*c-(a.browser.safari&&this.cssPosition=="fixed"?0:(this.cssPosition=="fixed"?-this.scrollParent.scrollTop():(g?0:b.scrollTop()))*c)),left:(h.left+this.offset.relative.left*c+this.offset.parent.left*c-(a.browser.safari&&this.cssPosition=="fixed"?0:(this.cssPosition=="fixed"?-this.scrollParent.scrollLeft():g?0:b.scrollLeft())*c))}},_generatePosition:function(e){var h=this.options,b=this.cssPosition=="absolute"&&!(this.scrollParent[0]!=document&&a.ui.contains(this.scrollParent[0],this.offsetParent[0]))?this.offsetParent:this.scrollParent,i=(/(html|body)/i).test(b[0].tagName);if(this.cssPosition=="relative"&&!(this.scrollParent[0]!=document&&this.scrollParent[0]!=this.offsetParent[0])){this.offset.relative=this._getRelativeOffset()}var d=e.pageX;var c=e.pageY;if(this.originalPosition){if(this.containment){if(e.pageX-this.offset.click.leftthis.containment[2]){d=this.containment[2]+this.offset.click.left}if(e.pageY-this.offset.click.top>this.containment[3]){c=this.containment[3]+this.offset.click.top}}if(h.grid){var g=this.originalPageY+Math.round((c-this.originalPageY)/h.grid[1])*h.grid[1];c=this.containment?(!(g-this.offset.click.topthis.containment[3])?g:(!(g-this.offset.click.topthis.containment[2])?f:(!(f-this.offset.click.left').css({width:this.offsetWidth+"px",height:this.offsetHeight+"px",position:"absolute",opacity:"0.001",zIndex:1000}).css(a(this).offset()).appendTo("body")})},stop:function(b,c){a("div.ui-draggable-iframeFix").each(function(){this.parentNode.removeChild(this)})}});a.ui.plugin.add("draggable","opacity",{start:function(c,d){var b=a(d.helper),e=a(this).data("draggable").options;if(b.css("opacity")){e._opacity=b.css("opacity")}b.css("opacity",e.opacity)},stop:function(b,c){var d=a(this).data("draggable").options;if(d._opacity){a(c.helper).css("opacity",d._opacity)}}});a.ui.plugin.add("draggable","scroll",{start:function(c,d){var b=a(this).data("draggable");if(b.scrollParent[0]!=document&&b.scrollParent[0].tagName!="HTML"){b.overflowOffset=b.scrollParent.offset()}},drag:function(d,e){var c=a(this).data("draggable"),f=c.options,b=false;if(c.scrollParent[0]!=document&&c.scrollParent[0].tagName!="HTML"){if(!f.axis||f.axis!="x"){if((c.overflowOffset.top+c.scrollParent[0].offsetHeight)-d.pageY=0;v--){var s=g.snapElements[v].left,n=s+g.snapElements[v].width,m=g.snapElements[v].top,A=m+g.snapElements[v].height;if(!((s-y=0;b--){this.items[b].item.removeData("sortable-item")}},_mouseCapture:function(e,f){if(this.reverting){return false}if(this.options.disabled||this.options.type=="static"){return false}this._refreshItems(e);var d=null,c=this,b=a(e.target).parents().each(function(){if(a.data(this,"sortable-item")==c){d=a(this);return false}});if(a.data(e.target,"sortable-item")==c){d=a(e.target)}if(!d){return false}if(this.options.handle&&!f){var g=false;a(this.options.handle,d).find("*").andSelf().each(function(){if(this==e.target){g=true}});if(!g){return false}}this.currentItem=d;this._removeCurrentsFromItems();return true},_mouseStart:function(e,f,b){var g=this.options,c=this;this.currentContainer=this;this.refreshPositions();this.helper=this._createHelper(e);this._cacheHelperProportions();this._cacheMargins();this.scrollParent=this.helper.scrollParent();this.offset=this.currentItem.offset();this.offset={top:this.offset.top-this.margins.top,left:this.offset.left-this.margins.left};this.helper.css("position","absolute");this.cssPosition=this.helper.css("position");a.extend(this.offset,{click:{left:e.pageX-this.offset.left,top:e.pageY-this.offset.top},parent:this._getParentOffset(),relative:this._getRelativeOffset()});this.originalPosition=this._generatePosition(e);this.originalPageX=e.pageX;this.originalPageY=e.pageY;if(g.cursorAt){this._adjustOffsetFromHelper(g.cursorAt)}this.domPosition={prev:this.currentItem.prev()[0],parent:this.currentItem.parent()[0]};if(this.helper[0]!=this.currentItem[0]){this.currentItem.hide()}this._createPlaceholder();if(g.containment){this._setContainment()}if(g.cursor){if(a("body").css("cursor")){this._storedCursor=a("body").css("cursor")}a("body").css("cursor",g.cursor)}if(g.opacity){if(this.helper.css("opacity")){this._storedOpacity=this.helper.css("opacity")}this.helper.css("opacity",g.opacity)}if(g.zIndex){if(this.helper.css("zIndex")){this._storedZIndex=this.helper.css("zIndex")}this.helper.css("zIndex",g.zIndex)}if(this.scrollParent[0]!=document&&this.scrollParent[0].tagName!="HTML"){this.overflowOffset=this.scrollParent.offset()}this._trigger("start",e,this._uiHash());if(!this._preserveHelperProportions){this._cacheHelperProportions()}if(!b){for(var d=this.containers.length-1;d>=0;d--){this.containers[d]._trigger("activate",e,c._uiHash(this))}}if(a.ui.ddmanager){a.ui.ddmanager.current=this}if(a.ui.ddmanager&&!g.dropBehaviour){a.ui.ddmanager.prepareOffsets(this,e)}this.dragging=true;this.helper.addClass("ui-sortable-helper");this._mouseDrag(e);return true},_mouseDrag:function(f){this.position=this._generatePosition(f);this.positionAbs=this._convertPositionTo("absolute");if(!this.lastPositionAbs){this.lastPositionAbs=this.positionAbs}if(this.options.scroll){var g=this.options,b=false;if(this.scrollParent[0]!=document&&this.scrollParent[0].tagName!="HTML"){if((this.overflowOffset.top+this.scrollParent[0].offsetHeight)-f.pageY=0;d--){var e=this.items[d],c=e.item[0],h=this._intersectsWithPointer(e);if(!h){continue}if(c!=this.currentItem[0]&&this.placeholder[h==1?"next":"prev"]()[0]!=c&&!a.ui.contains(this.placeholder[0],c)&&(this.options.type=="semi-dynamic"?!a.ui.contains(this.element[0],c):true)){this.direction=h==1?"down":"up";if(this.options.tolerance=="pointer"||this._intersectsWithSides(e)){this._rearrange(f,e)}else{break}this._trigger("change",f,this._uiHash());break}}this._contactContainers(f);if(a.ui.ddmanager){a.ui.ddmanager.drag(this,f)}this._trigger("sort",f,this._uiHash());this.lastPositionAbs=this.positionAbs;return false},_mouseStop:function(c,d){if(!c){return}if(a.ui.ddmanager&&!this.options.dropBehaviour){a.ui.ddmanager.drop(this,c)}if(this.options.revert){var b=this;var e=b.placeholder.offset();b.reverting=true;a(this.helper).animate({left:e.left-this.offset.parent.left-b.margins.left+(this.offsetParent[0]==document.body?0:this.offsetParent[0].scrollLeft),top:e.top-this.offset.parent.top-b.margins.top+(this.offsetParent[0]==document.body?0:this.offsetParent[0].scrollTop)},parseInt(this.options.revert,10)||500,function(){b._clear(c)})}else{this._clear(c,d)}return false},cancel:function(){var b=this;if(this.dragging){this._mouseUp();if(this.options.helper=="original"){this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper")}else{this.currentItem.show()}for(var c=this.containers.length-1;c>=0;c--){this.containers[c]._trigger("deactivate",null,b._uiHash(this));if(this.containers[c].containerCache.over){this.containers[c]._trigger("out",null,b._uiHash(this));this.containers[c].containerCache.over=0}}}if(this.placeholder[0].parentNode){this.placeholder[0].parentNode.removeChild(this.placeholder[0])}if(this.options.helper!="original"&&this.helper&&this.helper[0].parentNode){this.helper.remove()}a.extend(this,{helper:null,dragging:false,reverting:false,_noFinalSort:null});if(this.domPosition.prev){a(this.domPosition.prev).after(this.currentItem)}else{a(this.domPosition.parent).prepend(this.currentItem)}return true},serialize:function(d){var b=this._getItemsAsjQuery(d&&d.connected);var c=[];d=d||{};a(b).each(function(){var e=(a(d.item||this).attr(d.attribute||"id")||"").match(d.expression||(/(.+)[-=_](.+)/));if(e){c.push((d.key||e[1]+"[]")+"="+(d.key&&d.expression?e[1]:e[2]))}});return c.join("&")},toArray:function(d){var b=this._getItemsAsjQuery(d&&d.connected);var c=[];d=d||{};b.each(function(){c.push(a(d.item||this).attr(d.attribute||"id")||"")});return c},_intersectsWith:function(m){var e=this.positionAbs.left,d=e+this.helperProportions.width,k=this.positionAbs.top,j=k+this.helperProportions.height;var f=m.left,c=f+m.width,n=m.top,i=n+m.height;var o=this.offset.click.top,h=this.offset.click.left;var g=(k+o)>n&&(k+o)f&&(e+h)m[this.floating?"width":"height"])){return g}else{return(f0?"down":"up")},_getDragHorizontalDirection:function(){var b=this.positionAbs.left-this.lastPositionAbs.left;return b!=0&&(b>0?"right":"left")},refresh:function(b){this._refreshItems(b);this.refreshPositions()},_connectWith:function(){var b=this.options;return b.connectWith.constructor==String?[b.connectWith]:b.connectWith},_getItemsAsjQuery:function(b){var l=this;var g=[];var e=[];var h=this._connectWith();if(h&&b){for(var d=h.length-1;d>=0;d--){var k=a(h[d]);for(var c=k.length-1;c>=0;c--){var f=a.data(k[c],"sortable");if(f&&f!=this&&!f.options.disabled){e.push([a.isFunction(f.options.items)?f.options.items.call(f.element):a(f.options.items,f.element).not(".ui-sortable-helper"),f])}}}}e.push([a.isFunction(this.options.items)?this.options.items.call(this.element,null,{options:this.options,item:this.currentItem}):a(this.options.items,this.element).not(".ui-sortable-helper"),this]);for(var d=e.length-1;d>=0;d--){e[d][0].each(function(){g.push(this)})}return a(g)},_removeCurrentsFromItems:function(){var d=this.currentItem.find(":data(sortable-item)");for(var c=0;c=0;e--){var m=a(l[e]);for(var d=m.length-1;d>=0;d--){var g=a.data(m[d],"sortable");if(g&&g!=this&&!g.options.disabled){f.push([a.isFunction(g.options.items)?g.options.items.call(g.element[0],b,{item:this.currentItem}):a(g.options.items,g.element),g]);this.containers.push(g)}}}}for(var e=f.length-1;e>=0;e--){var k=f[e][1];var c=f[e][0];for(var d=0,n=c.length;d=0;d--){var e=this.items[d];if(e.instance!=this.currentContainer&&this.currentContainer&&e.item[0]!=this.currentItem[0]){continue}var c=this.options.toleranceElement?a(this.options.toleranceElement,e.item):e.item;if(!b){e.width=c.outerWidth();e.height=c.outerHeight()}var f=c.offset();e.left=f.left;e.top=f.top}if(this.options.custom&&this.options.custom.refreshContainers){this.options.custom.refreshContainers.call(this)}else{for(var d=this.containers.length-1;d>=0;d--){var f=this.containers[d].element.offset();this.containers[d].containerCache.left=f.left;this.containers[d].containerCache.top=f.top;this.containers[d].containerCache.width=this.containers[d].element.outerWidth();this.containers[d].containerCache.height=this.containers[d].element.outerHeight()}}},_createPlaceholder:function(d){var b=d||this,e=b.options;if(!e.placeholder||e.placeholder.constructor==String){var c=e.placeholder;e.placeholder={element:function(){var f=a(document.createElement(b.currentItem[0].nodeName)).addClass(c||b.currentItem[0].className+" ui-sortable-placeholder").removeClass("ui-sortable-helper")[0];if(!c){f.style.visibility="hidden"}return f},update:function(f,g){if(c&&!e.forcePlaceholderSize){return}if(!g.height()){g.height(b.currentItem.innerHeight()-parseInt(b.currentItem.css("paddingTop")||0,10)-parseInt(b.currentItem.css("paddingBottom")||0,10))}if(!g.width()){g.width(b.currentItem.innerWidth()-parseInt(b.currentItem.css("paddingLeft")||0,10)-parseInt(b.currentItem.css("paddingRight")||0,10))}}}}b.placeholder=a(e.placeholder.element.call(b.element,b.currentItem));b.currentItem.after(b.placeholder);e.placeholder.update(b,b.placeholder)},_contactContainers:function(d){for(var c=this.containers.length-1;c>=0;c--){if(this._intersectsWith(this.containers[c].containerCache)){if(!this.containers[c].containerCache.over){if(this.currentContainer!=this.containers[c]){var h=10000;var g=null;var e=this.positionAbs[this.containers[c].floating?"left":"top"];for(var b=this.items.length-1;b>=0;b--){if(!a.ui.contains(this.containers[c].element[0],this.items[b].item[0])){continue}var f=this.items[b][this.containers[c].floating?"left":"top"];if(Math.abs(f-e)this.containment[2]){d=this.containment[2]+this.offset.click.left}if(e.pageY-this.offset.click.top>this.containment[3]){c=this.containment[3]+this.offset.click.top}}if(h.grid){var g=this.originalPageY+Math.round((c-this.originalPageY)/h.grid[1])*h.grid[1];c=this.containment?(!(g-this.offset.click.topthis.containment[3])?g:(!(g-this.offset.click.topthis.containment[2])?f:(!(f-this.offset.click.left=0;c--){if(a.ui.contains(this.containers[c].element[0],this.currentItem[0])&&!e){f.push((function(g){return function(h){g._trigger("receive",h,this._uiHash(this))}}).call(this,this.containers[c]));f.push((function(g){return function(h){g._trigger("update",h,this._uiHash(this))}}).call(this,this.containers[c]))}}}for(var c=this.containers.length-1;c>=0;c--){if(!e){f.push((function(g){return function(h){g._trigger("deactivate",h,this._uiHash(this))}}).call(this,this.containers[c]))}if(this.containers[c].containerCache.over){f.push((function(g){return function(h){g._trigger("out",h,this._uiHash(this))}}).call(this,this.containers[c]));this.containers[c].containerCache.over=0}}if(this._storedCursor){a("body").css("cursor",this._storedCursor)}if(this._storedOpacity){this.helper.css("opacity",this._storedOpacity)}if(this._storedZIndex){this.helper.css("zIndex",this._storedZIndex=="auto"?"":this._storedZIndex)}this.dragging=false;if(this.cancelHelperRemoval){if(!e){this._trigger("beforeStop",d,this._uiHash());for(var c=0;c *",opacity:false,placeholder:false,revert:false,scroll:true,scrollSensitivity:20,scrollSpeed:20,scope:"default",tolerance:"intersect",zIndex:1000}})})(jQuery);; \ No newline at end of file diff --git a/umbraco/presentation/umbraco/webservices/MacroContainerService.asmx b/umbraco/presentation/umbraco/webservices/MacroContainerService.asmx new file mode 100644 index 0000000000..593d4f5037 --- /dev/null +++ b/umbraco/presentation/umbraco/webservices/MacroContainerService.asmx @@ -0,0 +1 @@ +<%@ WebService Language="C#" CodeBehind="MacroContainerService.asmx.cs" Class="umbraco.presentation.webservices.MacroContainerService" %> diff --git a/umbraco/presentation/umbraco/webservices/MacroContainerService.asmx.cs b/umbraco/presentation/umbraco/webservices/MacroContainerService.asmx.cs new file mode 100644 index 0000000000..76cb25d994 --- /dev/null +++ b/umbraco/presentation/umbraco/webservices/MacroContainerService.asmx.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Services; +using System.Web.Script.Services; + +namespace umbraco.presentation.webservices +{ + /// + /// Summary description for MacroContainerService + /// + [WebService(Namespace = "http://umbraco.org/webservices")] + [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] + [System.ComponentModel.ToolboxItem(false)] + [ScriptService] + public class MacroContainerService : System.Web.Services.WebService + { + + [WebMethod(EnableSession = true)] + [ScriptMethod] + public void SetSortOrder(string id, string sortorder) + { + HttpContext.Current.Session[id + "sortorder"] = sortorder; + + } + } +}