using System; using System.Collections.Generic; using System.Linq; using System.Text; using umbraco.cms.businesslogic.datatype; using System.Web.UI.WebControls; namespace umbraco.editorControls.SettingControls.Pickers { public class Content : DataEditorSettingType { private ContentPickerWithXpathOption cc = new ContentPickerWithXpathOption(); private string _val = string.Empty; public override string Value { get { return cc.Value; } set { if (!string.IsNullOrEmpty(value)) _val = value; } } public override System.Web.UI.Control RenderControl(DataEditorSetting sender) { cc.ShowXPath = false; cc.ID = sender.GetName().Replace(" ", "_"); cc.Value = _val; return cc; } } public class ContentWithXpath : DataEditorSettingType { private ContentPickerWithXpathOption cc = new ContentPickerWithXpathOption(); private string _val = string.Empty; public override string Value { get { return cc.Value; } set { if (!string.IsNullOrEmpty(value)) _val = value; } } public override System.Web.UI.Control RenderControl(DataEditorSetting sender) { cc.ShowXPath = true; cc.ID = sender.GetName().Replace(" ", "_"); cc.Value = _val; return cc; } } public class ContentPickerWithXpathOption : WebControl { private bool _showXPath = true; public bool ShowXPath { get { return _showXPath; } set { _showXPath = value; } } private umbraco.controls.ContentPicker cc; private TextBox tb; public ContentPickerWithXpathOption() { EnsureChildControls(); } protected override void OnInit(EventArgs e) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "contentpickerxpath", @" function showXpathTextbox(control) { $('.picker',$('#' + control)).hide(); $('.xpath',$('#' + control)).show(); } function showContentPicker(control) { $('.xpath',$('#' + control)).hide(); $('.xpath input',$('#' + control)).val(''); $('.picker',$('#' + control)).show(); } ", true); base.OnInit(e); } protected override void CreateChildControls() { cc = new umbraco.controls.ContentPicker(); this.Controls.Add(cc); if (_showXPath) { tb = new TextBox(); tb.CssClass = "guiInputText guiInputStandardSize"; this.Controls.Add(tb); } } protected override void RenderChildren(System.Web.UI.HtmlTextWriter writer) { writer.Write(string.Format("
", tb.Text != string.Empty ? " style=\"display:none\"" : "")); cc.RenderControl(writer); if (_showXPath) { writer.Write(string.Format( " Or enter Xpath", this.ClientID)); writer.Write("
"); writer.Write(string.Format("
", !(tb.Text != string.Empty) ? " style=\"display:none\"" : "")); tb.RenderControl(writer); writer.Write(string.Format( " Or pick node", this.ClientID)); } writer.Write("
"); } private string _val = string.Empty; public string Value { get { if (_showXPath && tb.Text != string.Empty) return tb.Text; else return cc.Text; } set { if (!string.IsNullOrEmpty(value)) { _val = value; int nodeId; if (int.TryParse(_val, out nodeId)) cc.Text = _val; else if (ShowXPath) tb.Text = _val; } } } } }