64
components/editorControls/macrocontainer/DataType.cs
Normal file
64
components/editorControls/macrocontainer/DataType.cs
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
272
components/editorControls/macrocontainer/Editor.cs
Normal file
272
components/editorControls/macrocontainer/Editor.cs
Normal file
@@ -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<string> _allowedMacros;
|
||||
private int _maxNumber, _preferedHeight, _preferedWidth;
|
||||
|
||||
private LinkButton _addMacro;
|
||||
private Literal _limit;
|
||||
|
||||
|
||||
|
||||
public Editor(IData data, List<string> 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", "<script type=\"text/javascript\" src=\"" + GlobalSettings.Path + "/js/submodal/common.js\"></script><script type=\"text/javascript\" src=\"" + GlobalSettings.Path + "/js/submodal/subModal.js\"></script><link href=\"" + GlobalSettings.Path + "/js/submodal/subModal.css\" type=\"text/css\" rel=\"stylesheet\"></link>");
|
||||
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("<div id=\"" + ID + "container\" class=\"macrocontainer\">"));
|
||||
|
||||
Regex tagregex = new Regex("<[^>]*(>|$)", RegexOptions.Singleline | RegexOptions.ExplicitCapture | RegexOptions.Compiled);
|
||||
MatchCollection tags = tagregex.Matches(_data.Value.ToString());
|
||||
|
||||
List<int> editornumbers = new List<int>();
|
||||
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("</div>"));
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
/// <summary>
|
||||
/// All Possible Macro types
|
||||
/// </summary>
|
||||
private static List<Type> _macroControlTypes = null;
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value based on the type of control
|
||||
/// </summary>
|
||||
/// <param name="macroControl"></param>
|
||||
/// <returns></returns>
|
||||
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
|
||||
/// <summary>
|
||||
/// All Possible Macro types
|
||||
/// </summary>
|
||||
private static List<Type> MacroControlTypes
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_macroControlTypes == null || _macroControlTypes.Count == 0)
|
||||
{
|
||||
//Populate the list with all the types of IMacroGuiRendering
|
||||
_macroControlTypes = new List<Type>();
|
||||
_macroControlTypes = TypeFinder.FindClassesOfType<IMacroGuiRendering>(true);
|
||||
}
|
||||
|
||||
return _macroControlTypes;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
334
components/editorControls/macrocontainer/MacroEditor.cs
Normal file
334
components/editorControls/macrocontainer/MacroEditor.cs
Normal file
@@ -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<string> _allowedMacros;
|
||||
private DropDownList _macroSelectDropdown;
|
||||
private LinkButton _delete;
|
||||
private Table _formTable;
|
||||
private Hashtable _dataValues;
|
||||
private string _data;
|
||||
|
||||
public MacroEditor(string Data, List<string> 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("<div id=\"container" + ID + "\" class=\"macroeditor\">");
|
||||
_macroSelectDropdown.RenderControl(writer);
|
||||
writer.Write(" ");//<a style=\"color: red;\" href=\"javascript:deletemacro('" + _macroSelectDropdown.ClientID + "','"+ID+"container' )\">Delete</a>");
|
||||
_delete.RenderControl(writer);
|
||||
_formTable.RenderControl(writer);
|
||||
writer.Write("</div>");
|
||||
}
|
||||
|
||||
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<PersistableMacroProperty> props = new List<PersistableMacroProperty>();
|
||||
|
||||
//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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renders a from based on the properties of the macro
|
||||
/// </summary>
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a new TableRow to the table. with two cells that holds the Caption and the form element
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="formElement"></param>
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds an Umbraco Macro tag if a user selected a macro
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
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("<?UMBRACO_MACRO ");
|
||||
|
||||
//Alias Attribute
|
||||
sb.AppendFormat(" macroalias=\"{0}\" ", SelectedMacroAlias);
|
||||
|
||||
foreach (PersistableMacroProperty prop in SelectedProperties)
|
||||
{
|
||||
//Make sure we find the correct Unique ID
|
||||
string ControlIdToFind = ID + "_" + prop.Alias;
|
||||
string value = MacroControlFactory.GetValueFromMacroControl(_formTable.FindControl(ControlIdToFind));
|
||||
sb.AppendFormat(" {0}=\"{1}\" ", prop.Alias, value);
|
||||
}
|
||||
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<PersistableMacroProperty> SelectedProperties
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ViewState[ID + "controls"] == null)
|
||||
{
|
||||
return new List<PersistableMacroProperty>();
|
||||
}
|
||||
else
|
||||
{
|
||||
return (List<PersistableMacroProperty>)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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
/// <summary>
|
||||
/// Macro Caption
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set { _name = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Macro Alias
|
||||
/// </summary>
|
||||
public string Alias
|
||||
{
|
||||
get { return _alias; }
|
||||
set { _alias = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Macro Value
|
||||
/// </summary>
|
||||
public string Value
|
||||
{
|
||||
get { return _value; }
|
||||
set { _value = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AssemblyName of the Property of teh Macro
|
||||
/// </summary>
|
||||
public string AssemblyName
|
||||
{
|
||||
get { return _assemblyName; }
|
||||
set { _assemblyName = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TypeName of the property of the macro
|
||||
/// </summary>
|
||||
public string TypeName
|
||||
{
|
||||
get { return _typeName; }
|
||||
set { _typeName = value; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
303
components/editorControls/macrocontainer/PrevalueEditor.cs
Normal file
303
components/editorControls/macrocontainer/PrevalueEditor.cs
Normal file
@@ -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<string> _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
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="dataType"></param>
|
||||
public PrevalueEditor(umbraco.cms.businesslogic.datatype.BaseDataType dataType)
|
||||
{
|
||||
Datatype = dataType;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
/// <summary>
|
||||
/// Initializes controls
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the form
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
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
|
||||
/// <summary>
|
||||
/// Returns the selected Macro's in a comma seperated string
|
||||
/// </summary>
|
||||
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<string>(
|
||||
"select value from cmsDataTypePreValues where datatypenodeid = @datatypenodeid",
|
||||
Application.SqlHelper.CreateParameter("@datatypenodeid", Datatype.DataTypeDefinitionId));
|
||||
}
|
||||
else
|
||||
{
|
||||
return _configuration;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<string> AllowedMacros
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_allowedMacros == null)
|
||||
{
|
||||
List<string> result = new List<string>();
|
||||
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
|
||||
/// <summary>
|
||||
/// Reference to the datatype
|
||||
/// </summary>
|
||||
public umbraco.cms.businesslogic.datatype.BaseDataType Datatype
|
||||
{
|
||||
get { return _datatype; }
|
||||
set { _datatype = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the editor
|
||||
/// </summary>
|
||||
public Control Editor
|
||||
{
|
||||
get { return this; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save settings
|
||||
/// </summary>
|
||||
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
|
||||
|
||||
}
|
||||
}
|
||||
@@ -252,6 +252,13 @@
|
||||
<Compile Include="listbox\ListBoxKeysDataType.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="macrocontainer\DataType.cs" />
|
||||
<Compile Include="macrocontainer\Editor.cs" />
|
||||
<Compile Include="macrocontainer\MacroContainerEvent.cs" />
|
||||
<Compile Include="macrocontainer\MacroControlFactory.cs" />
|
||||
<Compile Include="macrocontainer\MacroEditor.cs" />
|
||||
<Compile Include="macrocontainer\PersistableMacroProperty.cs" />
|
||||
<Compile Include="macrocontainer\PrevalueEditor.cs" />
|
||||
<Compile Include="mediapicker\mediaChooser.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
|
||||
@@ -1192,6 +1192,10 @@
|
||||
</Compile>
|
||||
<Compile Include="umbraco\Trees\BaseMediaTree.cs" />
|
||||
<Compile Include="umbraco\Trees\MediaRecycleBin.cs" />
|
||||
<Compile Include="umbraco\webservices\MacroContainerService.asmx.cs">
|
||||
<DependentUpon>MacroContainerService.asmx</DependentUpon>
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="umbraco\webservices\MediaPickerService.asmx.cs">
|
||||
<DependentUpon>MediaPickerService.asmx</DependentUpon>
|
||||
<SubType>Component</SubType>
|
||||
@@ -1488,6 +1492,8 @@
|
||||
<Content Include="umbraco\dialogs\ExportCode.aspx" />
|
||||
<Content Include="umbraco\dialogs\mediaPicker.aspx" />
|
||||
<Content Include="umbraco\images\editor\spellchecker.gif" />
|
||||
<Content Include="umbraco\js\sortable\jquery-ui-1.7.2.custom.min.js" />
|
||||
<Content Include="umbraco\webservices\MacroContainerService.asmx" />
|
||||
<Content Include="umbraco\webservices\MediaPickerService.asmx" />
|
||||
<Content Include="umbraco_client\Application\JQuery\jquery.cookie.js" />
|
||||
<Content Include="umbraco_client\imagecropper\Jcrop.gif" />
|
||||
|
||||
34
umbraco/presentation/umbraco/js/sortable/jquery-ui-1.7.2.custom.min.js
vendored
Normal file
34
umbraco/presentation/umbraco/js/sortable/jquery-ui-1.7.2.custom.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
<%@ WebService Language="C#" CodeBehind="MacroContainerService.asmx.cs" Class="umbraco.presentation.webservices.MacroContainerService" %>
|
||||
@@ -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>
|
||||
/// Summary description for MacroContainerService
|
||||
/// </summary>
|
||||
[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;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user