protected void SetupPropertyEditor() { List<GlobalWidgetPropertySettings> collection = new List<GlobalWidgetPropertySettings>(); if (propertydic.Count > 0) { GlobalSettingsRow.Visible = true; foreach (KeyValuePair<PropertyInfo, GlobalWidgetData> item in propertydic) { GlobalWidgetPropertySettings conv = new GlobalWidgetPropertySettings(); conv.PropertyName = (string)item.Key.Name; conv.Type = item.Key.PropertyType; conv.value = item.Value.getDefault; conv.Settings = item.Value.PropertySettings; collection.Add(conv); } LoadSavedProps(collection); globalProps.DataSource = collection; globalProps.DataBind(); } else { GlobalSettingsRow.Visible = false; } }
protected void GenerateInputField(Control owner, GlobalWidgetPropertySettings data) { Type type = data.Type; object value = data.value; //DateTime, int, long, double, bool, string, Enumeration EkEnumeration.OrderByDirection() if (!type.IsEnum) { if (type.Name == typeof(string).Name) { TextBox text = new TextBox(); text.ID = "value"; text.Text = System.Convert.ToString(value); text.CssClass = "freetext"; if (data.Settings == GlobalPropertyAttributes.PasswordField) { text.TextMode = TextBoxMode.Password; text.Attributes.Add("value", System.Convert.ToString(value)); } owner.Controls.Add(text); } else if (type.Name == typeof(DateTime).Name) { HiddenField hdnvalue = new HiddenField(); hdnvalue.ID = "value"; hdnvalue.Value = System.Convert.ToDateTime(value).ToString(); owner.Controls.Add(hdnvalue); TextBox text = new TextBox(); text.ID = "textinput"; text.Text = System.Convert.ToDateTime(value).ToString(); text.CssClass = "datetime"; text.Attributes.Add("hiddenfield", hdnvalue.ClientID); owner.Controls.Add(text); System.Web.UI.HtmlControls.HtmlGenericControl span = new System.Web.UI.HtmlControls.HtmlGenericControl(); span.TagName = "span"; span.Attributes.Add("class", "displayParsedDate"); owner.Parent.FindControl("phExtraOutput").Controls.Add(span); } else if (type.Name == typeof(int).Name) { TextBox text = new TextBox(); text.ID = "value"; text.Text = System.Convert.ToString(System.Convert.ToInt32(value).ToString()); text.CssClass = "integer"; owner.Controls.Add(text); } else if (type.Name == typeof(long).Name) { TextBox text = new TextBox(); text.ID = "value"; text.Text = System.Convert.ToString(System.Convert.ToInt64(value).ToString()); text.CssClass = "integer"; owner.Controls.Add(text); } else if (type.Name == typeof(double).Name) { TextBox text = new TextBox(); text.ID = "value"; text.Text = System.Convert.ToString(System.Convert.ToDouble(value).ToString()); text.CssClass = "double"; owner.Controls.Add(text); } else if (type.Name == typeof(bool).Name) { DropDownList list = new DropDownList(); list.ID = "value"; list.Items.Add(new ListItem("True", "true")); list.Items.Add(new ListItem("False", "false")); if (System.Convert.ToBoolean(value) == true) { list.SelectedIndex = 0; } else { list.SelectedIndex = 1; } owner.Controls.Add(list); } else { string ex = "Unsupported global property specified in " + info.ControlURL + "\r\n"; ex += "The type " + type.Name + " is not supported by this version of the Portal Framework. Only the following types are supported: " + "\r\n"; ex += "DateTime, int, long, double, bool, string, Enumeration"; throw (new Exception(ex)); } } else //is an enum { DropDownList list = new DropDownList(); list.ID = "value"; string[] items = System.Enum.GetNames(type); foreach (string item in items) { ListItem li = new ListItem(); li.Text = item; li.Value = item; if ((value != null) && item == System.Enum.GetName(type, value)) { li.Selected = true; } list.Items.Add(li); } owner.Controls.Add(list); } }
protected void SaveProperties(object sender, System.EventArgs e) { StringBuilder str = new StringBuilder(); if (m_widgetID < 0) { ShowError("Could not find that widget"); return; } List<GlobalWidgetPropertySettings> collection = new List<GlobalWidgetPropertySettings>(); if (propertydic.Count > 0) { foreach (KeyValuePair<PropertyInfo, GlobalWidgetData> item in propertydic) { GlobalWidgetPropertySettings conv = new GlobalWidgetPropertySettings(); conv.PropertyName = (string)item.Key.Name; conv.Type = item.Key.PropertyType; conv.value = item.Value.getDefault; collection.Add(conv); } foreach (RepeaterItem propertyitem in globalProps.Items) { Label lblpropname = (Label)(propertyitem.FindControl("lblPropertyName")); foreach (GlobalWidgetPropertySettings listitem in collection) { if (listitem.PropertyName == lblpropname.Text) { PlaceHolder ph = (PlaceHolder)(propertyitem.FindControl("phValue")); Control cntpropval = ph.FindControl("value"); decodeValue(listitem.Type, cntpropval, ref listitem.value); } } } } System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(List<GlobalWidgetPropertySettings>)); System.IO.StringWriter s = new System.IO.StringWriter(); serializer.Serialize(s, collection); //now serialize collection into settings string title = Request.Form[txtTitle.UniqueID]; // for some reason, the submit doesn't automatically update txtTitle.Text and txtLabel.Text string label = Request.Form[txtLabel.UniqueID]; if (!m_refWidgetModel.Update(m_widgetID, title, label, (string)lblFilename.Text, (string)(s.GetStringBuilder().ToString()), true)) { ShowError("Could not update widget"); } successmessage.Text = "Properties Successfully saved"; successmessage.ToolTip = successmessage.Text; str.AppendLine(" window.parent.$ektron(\'#editWidget\').modalHide();"); viewset.SetActiveView(viewSuccess); Ektron.Cms.API.JS.RegisterJSBlock(this, str.ToString(), "HideEditModal"); }
private void saveGlobalWidgetProperties() { List<GlobalWidgetPropertySettings> settingsList = new List<GlobalWidgetPropertySettings>(); PropertyInfo[] globalProperties = this.GetType().GetProperties(); foreach (PropertyInfo pi in globalProperties) { GlobalWidgetPropertySettings setting = new GlobalWidgetPropertySettings(); GlobalWidgetData[] propertyAttributes = (GlobalWidgetData[])pi.GetCustomAttributes(typeof(GlobalWidgetData), true); if (propertyAttributes != null && propertyAttributes.Length > 0) { setting.PropertyName = pi.Name; setting.Type = pi.PropertyType; setting.value = pi.GetValue(this, null); settingsList.Add(setting); } } XmlSerializer serializer = new XmlSerializer(typeof(List<GlobalWidgetPropertySettings>)); StringWriter s = new StringWriter(); serializer.Serialize(s, settingsList); WidgetTypeData widgetData = new WidgetTypeData(); WidgetTypeModel m_refWidgetModel = new WidgetTypeModel(); m_refWidgetModel.FindByID(_host.WidgetInfo.ID, out widgetData); m_refWidgetModel.Update(widgetData.ID, widgetData.Title, widgetData.Title, widgetData.ControlURL, s.GetStringBuilder().ToString(), true); }