private void AddControlNew(Property p, TabPage tp, string cap) { IDataType dt = p.PropertyType.DataTypeDefinition.DataType; //check that property editor has been set for the data type used by this property if (dt != null) { dt.DataEditor.Editor.ID = string.Format("prop_{0}", p.PropertyType.Alias); dt.Data.PropertyId = p.Id; //Add the DataType to an internal dictionary, which will be used to call the save method on the IDataEditor //and to retrieve the value from IData in editContent.aspx.cs, so that it can be set on the legacy Document class. DataTypes.Add(p.PropertyType.Alias, dt); // check for buttons IDataFieldWithButtons df1 = dt.DataEditor.Editor as IDataFieldWithButtons; if (df1 != null) { ((Control)df1).ID = p.PropertyType.Alias; if (df1.MenuIcons.Length > 0) { tp.Menu.InsertSplitter(); } // Add buttons int c = 0; bool atEditHtml = false; bool atSplitter = false; foreach (object o in df1.MenuIcons) { try { MenuIconI m = (MenuIconI)o; MenuIconI mi = tp.Menu.NewIcon(); mi.ImageURL = m.ImageURL; mi.OnClickCommand = m.OnClickCommand; mi.AltText = m.AltText; mi.ID = tp.ID + "_" + m.ID; if (m.ID == "html") { atEditHtml = true; } else { atEditHtml = false; } atSplitter = false; } catch { tp.Menu.InsertSplitter(); atSplitter = true; } // Testing custom styles in editor if (atSplitter && atEditHtml && dt.DataEditor.TreatAsRichTextEditor) { DropDownList ddl = tp.Menu.NewDropDownList(); ddl.Style.Add("margin-bottom", "5px"); ddl.Items.Add(ui.Text("buttons", "styleChoose")); ddl.ID = tp.ID + "_editorStyle"; if (StyleSheet.GetAll().Length > 0) { foreach (StyleSheet s in StyleSheet.GetAll()) { foreach (StylesheetProperty sp in s.Properties) { ddl.Items.Add(new ListItem(sp.Text, sp.Alias)); } } } ddl.Attributes.Add("onChange", "addStyle(this, '" + p.PropertyType.Alias + "');"); atEditHtml = false; } c++; } } // check for element additions IMenuElement menuElement = dt.DataEditor.Editor as IMenuElement; if (menuElement != null) { // add separator tp.Menu.InsertSplitter(); // add the element tp.Menu.NewElement(menuElement.ElementName, menuElement.ElementIdPreFix + p.Id.ToString(), menuElement.ElementClass, menuElement.ExtraMenuWidth); } Pane pp = new Pane(); Control holder = new Control(); holder.Controls.Add(dt.DataEditor.Editor); if (p.PropertyType.DataTypeDefinition.DataType.DataEditor.ShowLabel) { string caption = p.PropertyType.Name; if (p.PropertyType.Description != null && p.PropertyType.Description != String.Empty) { switch (UmbracoConfig.For.UmbracoSettings().Content.PropertyContextHelpOption) { case "icon": caption += " <img src=\"" + this.ResolveUrl(SystemDirectories.Umbraco) + "/images/help.png\" class=\"umbPropertyContextHelp\" alt=\"" + p.PropertyType.Description + "\" title=\"" + p.PropertyType.Description + "\" />"; break; case "text": caption += "<br /><small>" + umbraco.library.ReplaceLineBreaks(p.PropertyType.Description) + "</small>"; break; } } pp.addProperty(caption, holder); } else { pp.addProperty(holder); } // Validation if (p.PropertyType.Mandatory) { try { var rq = new RequiredFieldValidator { ControlToValidate = dt.DataEditor.Editor.ID, CssClass = "error" }; rq.Style.Add(HtmlTextWriterStyle.Display, "block"); rq.Style.Add(HtmlTextWriterStyle.Padding, "2px"); var component = dt.DataEditor.Editor; // holder.FindControl(rq.ControlToValidate); var attribute = (ValidationPropertyAttribute)TypeDescriptor.GetAttributes(component)[typeof(ValidationPropertyAttribute)]; PropertyDescriptor pd = null; if (attribute != null) { pd = TypeDescriptor.GetProperties(component, null)[attribute.Name]; } if (pd != null) { rq.EnableClientScript = false; rq.Display = ValidatorDisplay.Dynamic; string[] errorVars = { p.PropertyType.Name, cap }; rq.ErrorMessage = ui.Text("errorHandling", "errorMandatory", errorVars) + "<br/>"; holder.Controls.AddAt(0, rq); } } catch (Exception valE) { HttpContext.Current.Trace.Warn("contentControl", "EditorControl (" + dt.DataTypeName + ") does not support validation", valE); } } // RegExp Validation if (p.PropertyType.ValidationRegExp != "") { try { var rv = new RegularExpressionValidator { ControlToValidate = dt.DataEditor.Editor.ID, CssClass = "error" }; rv.Style.Add(HtmlTextWriterStyle.Display, "block"); rv.Style.Add(HtmlTextWriterStyle.Padding, "2px"); var component = dt.DataEditor.Editor; // holder.FindControl(rq.ControlToValidate); var attribute = (ValidationPropertyAttribute)TypeDescriptor.GetAttributes(component)[typeof(ValidationPropertyAttribute)]; PropertyDescriptor pd = null; if (attribute != null) { pd = TypeDescriptor.GetProperties(component, null)[attribute.Name]; } if (pd != null) { rv.ValidationExpression = p.PropertyType.ValidationRegExp; rv.EnableClientScript = false; rv.Display = ValidatorDisplay.Dynamic; string[] errorVars = { p.PropertyType.Name, cap }; rv.ErrorMessage = ui.Text("errorHandling", "errorRegExp", errorVars) + "<br/>"; holder.Controls.AddAt(0, rv); } } catch (Exception valE) { HttpContext.Current.Trace.Warn("contentControl", "EditorControl (" + dt.DataTypeName + ") does not support validation", valE); } } // This is once again a nasty nasty hack to fix gui when rendering wysiwygeditor if (dt.DataEditor.TreatAsRichTextEditor) { tp.Controls.Add(dt.DataEditor.Editor); } else { Panel ph = new Panel(); ph.Attributes.Add("style", "padding: 0; position: relative;"); // NH 4.7.1, latest styles added to support CP item: 30363 ph.Controls.Add(pp); tp.Controls.Add(ph); } } else { var ph = new Panel(); var pp = new Pane(); var missingPropertyEditorLabel = new Literal { Text = ui.Text("errors", "missingPropertyEditorErrorMessage") }; pp.addProperty(p.PropertyType.Name, missingPropertyEditorLabel); ph.Attributes.Add("style", "padding: 0; position: relative;"); ph.Controls.Add(pp); tp.Controls.Add(ph); } }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["id"] != null) { createdPackage = cms.businesslogic.packager.CreatedPackage.GetById(int.Parse(Request.QueryString["id"])); pack = createdPackage.Data; /* CONTENT */ cp = new ContentPicker(); content.Controls.Add(cp); bt_submitButton.Attributes.Add("onClick", "window.location = 'submitpackage.aspx?id=" + pack.Id.ToString() + "'; return false;"); if (string.IsNullOrEmpty(pack.PackagePath) == false) { packageUmbFile.Text = " <a href='" + Page.ResolveClientUrl(pack.PackagePath) + "'>Download</a>"; if (cms.businesslogic.packager.repositories.Repository.getAll().Count > 0) { bt_submitButton.Visible = true; } } else { packageUmbFile.Text = "<em>This package is not published</em>"; } if (Page.IsPostBack == false) { ClientTools .SetActiveTreeType(TreeDefinitionCollection.Instance.FindTree <loadPackages>().Tree.Alias) .SyncTree("-1,init," + loadPackages.PACKAGE_TREE_PREFIX + createdPackage.Data.Id, false); packageAuthorName.Text = pack.Author; packageAuthorUrl.Text = pack.AuthorUrl; packageLicenseName.Text = pack.License; packageLicenseUrl.Text = pack.LicenseUrl; packageName.Text = pack.Name; packageReadme.Text = pack.Readme; packageVersion.Text = pack.Version; packageUrl.Text = pack.Url; /*ACTIONS XML*/ tb_actions.Text = pack.Actions; cp.Value = pack.ContentNodeId.ToString(); //startNode.Value = pack.ContentNodeId.ToString(); packageContentSubdirs.Checked = pack.ContentLoadChildNodes; /*TEMPLATES */ Template[] umbTemplates = Template.GetAllAsList().ToArray(); foreach (Template tmp in umbTemplates) { ListItem li = new ListItem(tmp.Text, tmp.Id.ToString()); if (pack.Templates.Contains(tmp.Id.ToString())) { li.Selected = true; } templates.Items.Add(li); } /* DOC TYPES */ DocumentType[] docs = DocumentType.GetAllAsList().ToArray(); foreach (DocumentType dc in docs) { ListItem li = new ListItem(dc.Text, dc.Id.ToString()); if (pack.Documenttypes.Contains(dc.Id.ToString())) { li.Selected = true; } documentTypes.Items.Add(li); } /*Stylesheets */ StyleSheet[] sheets = StyleSheet.GetAll(); foreach (StyleSheet st in sheets) { ListItem li = new ListItem(st.Text, st.Id.ToString()); if (pack.Stylesheets.Contains(st.Id.ToString())) { li.Selected = true; } stylesheets.Items.Add(li); } /* MACROS */ Macro[] umbMacros = Macro.GetAll(); foreach (Macro m in umbMacros) { ListItem li = new ListItem(m.Name, m.Id.ToString()); if (pack.Macros.Contains(m.Id.ToString())) { li.Selected = true; } macros.Items.Add(li); } /*Langauges */ Language[] umbLanguages = Language.getAll; foreach (Language l in umbLanguages) { ListItem li = new ListItem(l.FriendlyName, l.id.ToString()); if (pack.Languages.Contains(l.id.ToString())) { li.Selected = true; } languages.Items.Add(li); } /*Dictionary Items*/ Dictionary.DictionaryItem[] umbDictionary = Dictionary.getTopMostItems; foreach (Dictionary.DictionaryItem d in umbDictionary) { string liName = d.key; if (d.hasChildren) { liName += " <small>(Including all child items)</small>"; } ListItem li = new ListItem(liName, d.id.ToString()); if (pack.DictionaryItems.Contains(d.id.ToString())) { li.Selected = true; } dictionary.Items.Add(li); } /*Data types */ cms.businesslogic.datatype.DataTypeDefinition[] umbDataType = cms.businesslogic.datatype.DataTypeDefinition.GetAll(); foreach (cms.businesslogic.datatype.DataTypeDefinition umbDtd in umbDataType) { ListItem li = new ListItem(umbDtd.Text, umbDtd.Id.ToString()); if (pack.DataTypes.Contains(umbDtd.Id.ToString())) { li.Selected = true; } cbl_datatypes.Items.Add(li); } /* FILES */ packageFilesRepeater.DataSource = pack.Files; packageFilesRepeater.DataBind(); packageControlPath.Text = pack.LoadControl; } else { ClientTools .SetActiveTreeType(TreeDefinitionCollection.Instance.FindTree <loadPackages>().Tree.Alias) .SyncTree("-1,init," + loadPackages.PACKAGE_TREE_PREFIX + createdPackage.Data.Id, true); } } }
private void addControlNew(Property p, TabPage tp, string Caption) { IDataType dt = p.PropertyType.DataTypeDefinition.DataType; dt.DataEditor.Editor.ID = string.Format("prop_{0}", p.PropertyType.Alias); dt.Data.PropertyId = p.Id; // check for buttons IDataFieldWithButtons df1 = dt.DataEditor.Editor as IDataFieldWithButtons; if (df1 != null) { // df1.Alias = p.PropertyType.Alias; /* * // df1.Version = _content.Version; * editDataType.Data.PropertyId = p.Id; */ ((Control)df1).ID = p.PropertyType.Alias; if (df1.MenuIcons.Length > 0) { tp.Menu.InsertSplitter(); } // Add buttons int c = 0; bool atEditHtml = false; bool atSplitter = false; foreach (object o in df1.MenuIcons) { try { MenuIconI m = (MenuIconI)o; MenuIconI mi = tp.Menu.NewIcon(); mi.ImageURL = m.ImageURL; mi.OnClickCommand = m.OnClickCommand; mi.AltText = m.AltText; mi.ID = tp.ID + "_" + m.ID; if (m.ID == "html") { atEditHtml = true; } else { atEditHtml = false; } atSplitter = false; } catch { tp.Menu.InsertSplitter(); atSplitter = true; } // Testing custom styles in editor if (atSplitter && atEditHtml && dt.DataEditor.TreatAsRichTextEditor) { DropDownList ddl = tp.Menu.NewDropDownList(); ddl.Style.Add("margin-bottom", "5px"); ddl.Items.Add(ui.Text("buttons", "styleChoose", null)); ddl.ID = tp.ID + "_editorStyle"; if (StyleSheet.GetAll().Length > 0) { foreach (StyleSheet s in StyleSheet.GetAll()) { foreach (StylesheetProperty sp in s.Properties) { ddl.Items.Add(new ListItem(sp.Text, sp.Alias)); } } } ddl.Attributes.Add("onChange", "addStyle(this, '" + p.PropertyType.Alias + "');"); atEditHtml = false; } c++; } } // check for element additions IMenuElement menuElement = dt.DataEditor.Editor as IMenuElement; if (menuElement != null) { // add separator tp.Menu.InsertSplitter(); // add the element tp.Menu.NewElement(menuElement.ElementName, menuElement.ElementIdPreFix + p.Id.ToString(), menuElement.ElementClass, menuElement.ExtraMenuWidth); } // fieldData.Alias = p.PropertyType.Alias; // ((Control) fieldData).ID = p.PropertyType.Alias; // fieldData.Text = p.Value.ToString(); _dataFields.Add(dt.DataEditor.Editor); Pane pp = new Pane(); Control holder = new Control(); holder.Controls.Add(dt.DataEditor.Editor); if (p.PropertyType.DataTypeDefinition.DataType.DataEditor.ShowLabel) { string caption = p.PropertyType.Name; if (p.PropertyType.Description != null && p.PropertyType.Description != String.Empty) { switch (UmbracoSettings.PropertyContextHelpOption) { case "icon": caption += " <img src=\"" + this.ResolveUrl(SystemDirectories.Umbraco) + "/images/help.png\" class=\"umbPropertyContextHelp\" alt=\"" + p.PropertyType.Description + "\" title=\"" + p.PropertyType.Description + "\" />"; break; case "text": caption += "<br /><small>" + umbraco.library.ReplaceLineBreaks(p.PropertyType.Description) + "</small>"; break; } } pp.addProperty(caption, holder); } else { pp.addProperty(holder); } // Validation if (p.PropertyType.Mandatory) { try { RequiredFieldValidator rq = new RequiredFieldValidator(); rq.ControlToValidate = dt.DataEditor.Editor.ID; Control component = dt.DataEditor.Editor; // holder.FindControl(rq.ControlToValidate); ValidationPropertyAttribute attribute = (ValidationPropertyAttribute) TypeDescriptor.GetAttributes(component)[typeof(ValidationPropertyAttribute)]; PropertyDescriptor pd = null; if (attribute != null) { pd = TypeDescriptor.GetProperties(component, (Attribute[])null)[attribute.Name]; } if (pd != null) { rq.EnableClientScript = false; rq.Display = ValidatorDisplay.Dynamic; string[] errorVars = { p.PropertyType.Name, Caption }; rq.ErrorMessage = ui.Text("errorHandling", "errorMandatory", errorVars, null) + "<br/>"; holder.Controls.AddAt(0, rq); } } catch (Exception valE) { HttpContext.Current.Trace.Warn("contentControl", "EditorControl (" + dt.DataTypeName + ") does not support validation", valE); } } // RegExp Validation if (p.PropertyType.ValidationRegExp != "") { try { RegularExpressionValidator rv = new RegularExpressionValidator(); rv.ControlToValidate = dt.DataEditor.Editor.ID; Control component = dt.DataEditor.Editor; // holder.FindControl(rq.ControlToValidate); ValidationPropertyAttribute attribute = (ValidationPropertyAttribute) TypeDescriptor.GetAttributes(component)[typeof(ValidationPropertyAttribute)]; PropertyDescriptor pd = null; if (attribute != null) { pd = TypeDescriptor.GetProperties(component, (Attribute[])null)[attribute.Name]; } if (pd != null) { rv.ValidationExpression = p.PropertyType.ValidationRegExp; rv.EnableClientScript = false; rv.Display = ValidatorDisplay.Dynamic; string[] errorVars = { p.PropertyType.Name, Caption }; rv.ErrorMessage = ui.Text("errorHandling", "errorRegExp", errorVars, null) + "<br/>"; holder.Controls.AddAt(0, rv); } } catch (Exception valE) { HttpContext.Current.Trace.Warn("contentControl", "EditorControl (" + dt.DataTypeName + ") does not support validation", valE); } } // This is once again a nasty nasty hack to fix gui when rendering wysiwygeditor if (dt.DataEditor.TreatAsRichTextEditor) { tp.Controls.Add(dt.DataEditor.Editor); } else { Panel ph = new Panel(); ph.Attributes.Add("style", "padding: 0px 0px 0px 0px"); ph.Controls.Add(pp); tp.Controls.Add(ph); } }