public override Control DataEditorControls(XmlNode xml, Dictionary<string, object> properties) { //properties should be multiType properties ie. Name, Description, Mandatory, Validation Panel pnlDataEditor = new Panel(); Label lblDataEditor = new Label() { Text = properties["Name"].ToString() }; Literal litDescription = new Literal() { Text = properties["Description"].ToString() }; seDataEditor = new SimpleEditor(null); pnlDataEditor.Controls.Add(lblDataEditor); pnlDataEditor.Controls.Add(litDescription); pnlDataEditor.Controls.Add(seDataEditor); if (xml != null) { //Anything special about the xml? no - just do innertext seDataEditor.Text = xml.InnerText; } return pnlDataEditor; }
/// <summary> /// Generates the add box to add new items to the list /// </summary> /// <returns>Html representation of the fields in the add box.</returns> /// <remarks> /// There are actually a few things happening here: /// 1. The prevalue properties are examined one after the other, /// for each item the appropriate control is added to the box (e.g. textstring, true/false). /// The control gets the id field{DTDId}_{id of the prevalue property} /// 2. While looping through the prevalues the xml schema is build up alongside and stored in m_hiddenXmlSchema. /// This schema is used to build the xml representation of the value for this property as well as to build the relationship /// in JS between the data and the dynamically added fields of each item. /// </remarks> private Table GenerateAddBox() { var table = new Table(); table.Attributes.Add("class", "ECaddBoxTable"); TableRow row; TableCell cell; var xmlSchema = new StringBuilder(); xmlSchema.Append("<item id=\"\">"); //decode the list of controls in the prevalue field and add them to the controls var prevalueSplit = _prevalue.Split(new[] { "||" }, 1000, StringSplitOptions.None); foreach (var pv in prevalueSplit) { if (string.IsNullOrEmpty(pv.Trim())) continue; var id = string.Empty; var name = string.Empty; var alias = string.Empty; var description = string.Empty; var showInTitle = false; var type = "Textstring"; var required = false; var validation = string.Empty; var attributes = pv.Split('|'); foreach (var attribute in attributes) { if (!string.IsNullOrEmpty(attribute.Trim())) { var attr = attribute.Trim(); if (attr.StartsWith("id:")) { id = attr.Substring(3).Trim(); } if (attr.StartsWith("Name:")) { name = attr.Substring(5).Trim(); } if (attr.StartsWith("Alias:")) { alias = attr.Substring(6).Trim(); } if (attr.StartsWith("Description:")) { description = System.Web.HttpUtility.HtmlEncode(attr.Substring(12).Trim().Replace("<", "<").Replace(">", ">")); } if (attr.StartsWith("Show in title?")) { bool.TryParse(attr.Substring(14).Trim(), out showInTitle); } if (attr.StartsWith("Type:")) { type = attr.Substring(5).Trim(); } if (attr.StartsWith("Required?")) { bool.TryParse(attr.Substring(9).Trim(), out required); } if (attr.StartsWith("Validation:")) { validation = attr.Substring(11).Trim().Replace("@@@", "|"); } } } if (!string.IsNullOrEmpty(id) && !string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(alias) && !string.IsNullOrEmpty(type)) { row = new TableRow(); cell = new TableCell { // ReSharper disable LocalizableElement Text = name + "<br /><small>" + description + "</small>" // ReSharper restore LocalizableElement }; cell.Attributes.Add("class", "ECfirst"); row.Cells.Add(cell); cell = new TableCell(); if (type == "-87") { var dataTypeDefinition = new DataTypeDefinition(-87); //var dt = dataTypeDefinition.DataType; var dt = new editorctrls_tinyMCE3.tinyMCE3dataType(); dt.DataTypeDefinitionId = -87; //cell.Controls.Add(new TextBox { Text = dataTypeDefinition.DataType.DataTypeName }); //addControlNew(dataTypeDefinition.DataType, cell, alias, int.Parse(id)); dt.DataEditor.Editor.ID = string.Format("prop_{0}", alias); dt.Data.PropertyId = int.Parse(id); //IDataEditor de = new dt.DataEditor.Editor(); cell.Controls.Add(dt.DataEditor.Editor); } else { switch (type) { case "Textstring": var tfe = new editorctrls_textfield.TextFieldEditor( new DefaultData(new editorctrls_textfield.TextFieldDataType())) {ID = string.Format("field{0}_{1}", DTDId, id)}; cell.Controls.Add(tfe); break; case "Textbox multiple": var tfm = new editorctrls_textfield.TextFieldEditor( new DefaultData( new editorctrls_textfieldmultiple.textfieldMultipleDataType())) { ID = string.Format("field{0}_{1}", DTDId, id), TextMode = TextBoxMode.MultiLine, Rows = 5 }; cell.Controls.Add(tfm); break; case "True/false": var yesno = new yesNo( new DefaultData( new editorctrls_yesno.YesNoDataType())) { ID = string.Format("field{0}_{1}", DTDId, id) }; yesno.LabelAttributes.Add("style", "display: none;"); cell.Controls.Add(yesno); break; case "Content picker": cell.Controls.Add(new SimpleContentPicker { ID = string.Format("field{0}_{1}", DTDId, id) }); break; case "Media picker": cell.Controls.Add(new SimpleMediaPicker { ID = string.Format("field{0}_{1}", DTDId, id) }); break; case "Simple editor": var simpleEditor = new editorctrls_simpleEditor.SimpleEditor( new DefaultData( new editorctrls_simpleEditor.simpleEditorDataType())) { ID = string.Format("field{0}_{1}", DTDId, id) }; cell.Controls.Add(simpleEditor); break; case "Date picker": var datePicker = new dateField( new DefaultData( new editorctrls_datepicker.DateDataType())); cell.Controls.Add(datePicker); cell.ID = string.Format("field{0}_{1}", DTDId, id); break; case "Richtext editor": //ataType //var d = new Document(123); //Property p = d.getProperty("asdf"); //PropertyType.GetAll() //var richtextBox = new TinyMCE( // new DefaultData( // new tinyMCE3dataType()), ((editorCtrls.tinymce.tinyMCEPreValueConfigurator)PrevalueEditor).Configuration); break; default: var tfeDefault = new editorctrls_textfield.TextFieldEditor( new DefaultData(new editorctrls_textfield.TextFieldDataType())) {ID = string.Format("field{0}_{1}", DTDId, id)}; cell.Controls.Add(tfeDefault); break; } } cell.Attributes.Add("class", "ECsecond"); row.Cells.Add(cell); table.Rows.Add(row); xmlSchema.Append(string.Format("<{0} propertyid=\"{1}\" name=\"{2}\" description=\"{3}\" type=\"{4}\" showintitle=\"{5}\" required=\"{6}\" validation=\"{7}\">|value{1}|</{0}>", alias, id, name, description, type, showInTitle, required, validation)); } } xmlSchema.Append("</item>"); _hiddenXmlSchema = new HtmlInputHidden { ID = string.Format("EChiddenXmlSchema{0}", DTDId), Value = Uri.EscapeDataString(xmlSchema.ToString()), EnableViewState = true }; row = new TableRow(); row.Cells.Add(new TableCell()); cell = new TableCell(); // ReSharper disable LocalizableElement cell.Controls.Add(new Literal { Text = "<a href=\"#\" id=\"addPropertyLink" + DTDId + "\" title=\"create a new item with the above values\" class=\"ECaddPropertyLink\"><div class=\"ECbigButton\"></div></a>" }); // ReSharper restore LocalizableElement cell.Attributes.Add("class", "ECsecond"); row.Cells.Add(cell); table.Rows.Add(row); return table; }