private string GetValueDropDown(CustomPropertyData _propertyDataList, int count) { StringBuilder result = new StringBuilder(); int iObj = 0; result.Append("<select disabled name=\"selCustPropVal" + count + "\" id=\"selCustPropVal" + count + "\">"); if (!(_propertyDataList == null)) { for (iObj = 0; iObj <= _propertyDataList.Items.Count - 1; iObj++) { if (_propertyDataList.Items[iObj].IsDefault) { result.Append("<option selected value=\"" + _propertyDataList.Items[iObj].PropertyValue + "\">"); result.Append(_propertyDataList.Items[iObj].PropertyValue); result.Append("</option>"); } else { result.Append("<option value=\"" + _propertyDataList.Items[iObj].PropertyValue + "\">"); result.Append(_propertyDataList.Items[iObj].PropertyValue); result.Append("</option>"); } } } result.Append("</select>"); return result.ToString(); }
/// <summary> /// Returns the markup to render the custom property value data to the page (supporting /// 'ViewAll' mode). /// </summary> /// <param name="propertyList">List of properties to display</param> /// <param name="count">Index of property to render</param> /// <returns>Markup for the custom property's value field</returns> private string GetValueUI(CustomPropertyData propertyList, int count ) { StringBuilder result = new StringBuilder(); int itemIndex = 0; if (propertyList.Items.Count == 0) { result.Append("None"); } else { switch (propertyList.PropertyDataType) { case EkEnumeration.CustomPropertyItemDataType.String: if (propertyList.Items.Count == 1) { result = new StringBuilder(); if (propertyList.Items[0].PropertyValue == null) { result.Append("None"); } else { result.Append("<textarea disabled style='height: 50px; width: 150px;' onchange='javascript:updateText(this);' id='txtTextValue' name='txtTextValue'>" + EkFunctions.HtmlEncode(propertyList.Items[itemIndex].PropertyValue.ToString()) + "</textarea>"); } } else { result.Append("<select style='width: 150px;' disabled name=\"selCustPropVal" + count + "\" id=\"selCustPropVal" + count + "\">"); if (propertyList != null) { for (itemIndex = 0; itemIndex < propertyList.Items.Count; itemIndex++) { if (propertyList.Items[itemIndex].PropertyValue != null) { result.Append("<option value=\"" + propertyList.Items[itemIndex].PropertyValue + "\">"); result.Append(EkFunctions.HtmlEncode(propertyList.Items[itemIndex].PropertyValue.ToString())); result.Append("</option>"); } } } result.Append("</select>"); } break; case EkEnumeration.CustomPropertyItemDataType.Boolean: if (propertyList.Items.Count > 0) { if (propertyList.Items[itemIndex].PropertyValue.ToString().ToLower() == "true") { result.Append("<label type='radio' id='radYes' name='radYes' value='Yes' /><span class='label'>" + _messageHelper.GetMessage("lbl coupon yes") + "</span>"); } else { result.Append("<label type='radio' id='radYes' name='radYes' value='Yes' /><span class='label'>" + _messageHelper.GetMessage("lbl no") + "</span>"); } } break; case EkEnumeration.CustomPropertyItemDataType.DateTime: if (propertyList.Items.Count == 1) { if (propertyList.Items[0].PropertyValue != null) { result.Append("<input style='width: 150px;' disabled value='"); result.Append(((DateTime)propertyList.Items[0].PropertyValue).ToString("F")); result.Append("'/>"); } else { result.Append("None"); } } else { result.Append("<select style='width: 150px;' disabled name=\"selCustPropVal" + count + "\" id=\"selCustPropVal" + count + "\">"); for (itemIndex = 0; itemIndex < propertyList.Items.Count; itemIndex++) { DateTime dateTimeValue; result.Append("<option value=\"" + propertyList.Items[itemIndex].PropertyValue + "\">"); if (DateTime.TryParse(propertyList.Items[itemIndex].PropertyValue.ToString(), out dateTimeValue)) { // Display long format date/time value for consistency with // date/time selector. result.Append(dateTimeValue.ToString("F")); } else { result.Append(propertyList.Items[itemIndex].PropertyValue); } result.Append("</option>"); } result.Append("</select>"); } break; default: if (propertyList.Items.Count == 1) { if (propertyList.Items[0].PropertyValue != null) { result.Append("<input style='width: 150px;' disabled value='"); result.Append(propertyList.Items[0].PropertyValue.ToString()); result.Append("'/>"); } else { result.Append("None"); } } else { result.Append("<select style='width: 150px;' disabled name=\"selCustPropVal" + count + "\" id=\"selCustPropVal" + count + "\">"); if (propertyList != null) { for (itemIndex = 0; itemIndex < propertyList.Items.Count; itemIndex++) { result.Append("<option value=\"" + propertyList.Items[itemIndex].PropertyValue + "\">"); result.Append(propertyList.Items[itemIndex].PropertyValue); result.Append("</option>"); } } result.Append("</select>"); } break; } } return result.ToString(); }
/// <summary> /// Returns a delimited string of property values (rendered to the page /// via javascript). /// </summary> /// <param name="data">Custom property data from which to extract values</param> /// <returns>Delimited string of values</returns> private string GetPropertyValueString(CustomPropertyData data) { StringBuilder propertyValues = new StringBuilder(); foreach (CustomPropertyItemData itemData in data.Items) { if (propertyValues.Length > 0) { propertyValues.Append(ValueDelimiter); } if (itemData.PropertyValue != null) { if (data.PropertyDataType == EkEnumeration.CustomPropertyItemDataType.DateTime) { DateTime dateTimeValue = (DateTime)itemData.PropertyValue; propertyValues.AppendFormat( NameValuePairFormatMask, Uri.EscapeDataString(dateTimeValue.ToString("F")), Uri.EscapeDataString(itemData.PropertyValue.ToString())); } else { propertyValues.Append(Uri.EscapeDataString(itemData.PropertyValue.ToString())); } } } return propertyValues.ToString(); }
/// <summary> /// Retrieves custom property input data from the form fields. /// </summary> /// <returns>CustomPropertyData instance populated with form input</returns> private CustomPropertyData GetCustomPropertyDataFromInput() { CustomPropertyData customPropertyData = new CustomPropertyData() { PropertyName = txtPropertyName.Text, IsEditable = chkEditable.Checked, IsEnabled = chkEnabled.Checked, LanguageId = _language, PropertyDataType = (EkEnumeration.CustomPropertyItemDataType)Enum.Parse( typeof(EkEnumeration.CustomPropertyItemDataType), ddDataTypes.SelectedValue), PropertyStyleType = (EkEnumeration.CustomPropertyStyleType)Enum.Parse( typeof(EkEnumeration.CustomPropertyStyleType), ddDisplayTypes.SelectedValue), CmsObjectType = (EkEnumeration.CustomPropertyObjectType)Enum.Parse( typeof(EkEnumeration.CustomPropertyObjectType), ddObjectTypes.SelectedValue) }; customPropertyData.PropertyId = _translate || _pageAction.ToLower() == PageActionEdit ? _propertyId : 0; foreach (string value in GetPropertyValuesFromString(propertyValues.Value)) { object propertyValue = null; if (!string.IsNullOrEmpty(value)) { switch (customPropertyData.PropertyDataType) { case EkEnumeration.CustomPropertyItemDataType.Boolean: bool boolValue; bool.TryParse(HttpUtility.UrlDecode(value), out boolValue); propertyValue = boolValue; break; case EkEnumeration.CustomPropertyItemDataType.DateTime: DateTime dateTimeValue; DateTime.TryParse(HttpUtility.UrlDecode(value), out dateTimeValue); propertyValue = dateTimeValue; break; default: propertyValue = HttpUtility.UrlDecode(value); break; } } customPropertyData.AddItem(propertyValue, false); } return customPropertyData; }
/// <summary> /// Prepares the page for display in 'Add' mode (including the /// addition of a translated property). /// </summary> private void DisplayAdd() { pnlViewAll.Visible = false; pnlAddEdit.Visible = true; // Populate drop downs with default options PopulateDropDownLists(); if (_translate) { // If the requested property data does not exist and we're // in translation mode, retrieve the original data to // be translated. CustomPropertyData originalData = _customPropertyApi.GetItem( _propertyId, // Current property ID _originalLanguage); // Language of property to translate // If the original data exists and represents a valid // property, continue with the translation. if (originalData != null && originalData.PropertyId != 0) { // Duplicate the property data for the new language // and add it to the database. CustomPropertyData customPropertyData = new CustomPropertyData() { PropertyId = originalData.PropertyId, PropertyName = originalData.PropertyName, PropertyDataType = originalData.PropertyDataType, PropertyStyleType = originalData.PropertyStyleType, CmsObjectType = originalData.CmsObjectType, IsEditable = originalData.IsEditable, IsEnabled = originalData.IsEnabled, Items = originalData.Items, LanguageId = _language }; // Load custom property data into the form fields. LoadPropertyData(customPropertyData); } } else { // If we're not translating an existing property, // just display an empty form. idRow.Visible = false; lblLanguage.Text = _siteApi.GetLanguageById(_language).Name; lblLanguage.ToolTip = lblLanguage.Text; chkEditable.Checked = true; chkEnabled.Checked = true; } ddObjectTypes.Enabled = false; }
/// <summary> /// Populates form fields with the specified custom property data. /// </summary> /// <param name="propertyData">Data to populate fields with</param> private void LoadPropertyData(CustomPropertyData propertyData) { txtPropertyName.Text = propertyData.PropertyName; lblID.Text = propertyData.PropertyId.ToString(); lblID.ToolTip = lblID.Text; lblLanguage.Text = _siteApi.GetLanguageById(propertyData.LanguageId).Name; lblLanguage.ToolTip = lblLanguage.Text; chkEditable.Checked = propertyData.IsEditable; chkEnabled.Checked = propertyData.IsEnabled; ddDataTypes.SelectedValue = propertyData.PropertyDataType.ToString(); ddDisplayTypes.SelectedValue = propertyData.PropertyStyleType.ToString(); propertyValues.Value = GetPropertyValueString(propertyData); }