/// <summary> /// Returns the form definition for the web part zone properties. /// </summary> private FormInfo BuildFormInfo(WebPartZoneInstance webPartZone) { FormInfo fi = null; string formDefinition = String.Empty; // Dashboard zone properties if ((pti != null) && (pti.PageTemplateType == PageTemplateTypeEnum.Dashboard)) { formDefinition = PortalFormHelper.LoadProperties("WebPartZone", "Dashboard.xml"); } // UI page template properties else if ((pti != null) && (pti.PageTemplateType == PageTemplateTypeEnum.UI)) { formDefinition = PortalFormHelper.LoadProperties("WebPartZone", "UI.xml"); } // Classic web part/widget properties else { formDefinition = PortalFormHelper.LoadProperties("WebPartZone", "Standard.xml"); } if (!String.IsNullOrEmpty(formDefinition)) { // Load properties fi = new FormInfo(formDefinition); fi.UpdateExistingFields(fi); DataRow dr = fi.GetDataRow(); LoadDataRowFromWebPartZone(dr, webPartZone); } return(fi); }
/// <summary> /// Generate form info for widget. /// </summary> /// <param name="wi">Widget info</param> private FormInfo CreateFormInfo(WidgetInfo wi) { WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID); if (wpi != null) { string widgetProperties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties); return(PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, String.Empty, widgetProperties, null, false)); } return(null); }
/// <summary> /// Gets the form info for the given web part /// </summary> private FormInfo GetWebPartFormInfo() { // Load parent EnsureParentWebPartInfo(); if (wpi == null) { return(null); } string wpProperties = wpi.WebPartProperties; // Use parent web part if is defined if (parentWpi != null) { wpProperties = parentWpi.WebPartProperties; } // Get before FormInfo FormInfo beforeFI = null; if (BeforeFormDefinition == null) { beforeFI = PortalFormHelper.GetPositionFormInfo((WebPartTypeEnum)wpi.WebPartType, PropertiesPosition.Before); } else { beforeFI = new FormInfo(BeforeFormDefinition); } // Get after FormInfo FormInfo afterFI = null; if (AfterFormDefinition == null) { afterFI = PortalFormHelper.GetPositionFormInfo((WebPartTypeEnum)wpi.WebPartType, PropertiesPosition.After); } else { afterFI = new FormInfo(AfterFormDefinition); } // Add 'General' category at the beginning if no one is specified if (!string.IsNullOrEmpty(wpProperties) && (!wpProperties.StartsWithCSafe("<form><category", true))) { wpProperties = wpProperties.Insert(6, "<category name=\"" + GetString("general.general") + "\" />"); } // Get merged web part FormInfo FormInfo fi = PortalFormHelper.GetWebPartFormInfo(wpi.WebPartName, wpProperties, beforeFI, afterFI, true); return(fi); }
/// <summary> /// Returns form info with widget properties. /// </summary> /// <param name="wi">Widget</param> protected FormInfo GetWidgetProperties(WidgetInfo wi) { WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID); if (wpi != null) { string widgetProperties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties); return(PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, zoneType, widgetProperties, false)); } return(null); }
/// <summary> /// Returns form info with widget properties. /// </summary> /// <param name="wi">Widget</param> protected FormInfo GetWidgetProperties(WidgetInfo wi) { WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID); if (wpi != null) { string widgetProperties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties); FormInfo zoneTypeDefinition = PortalFormHelper.GetPositionFormInfo(zoneType); FormInfo fi = PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, Enum.GetName(typeof(WidgetZoneTypeEnum), zoneType), widgetProperties, zoneTypeDefinition, false); return(fi); } return(null); }
/// <summary> /// Generate form info for webpart. /// </summary> /// <param name="wpi">Web part info</param> private FormInfo CreateFormInfo(WebPartInfo wpi) { if (wpi != null) { // Get parent webpart if webpart is inherited if (wpi.WebPartParentID != 0) { WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null) { wpi = pwpi; } } } return(PortalFormHelper.GetWebPartFormInfo(wpi.WebPartName + FormHelper.CORE, wpi.WebPartProperties, null, null, false)); }
/// <summary> /// XML created, save it. /// </summary> protected void defaultValueEditor_XMLCreated(object sender, EventArgs e) { if (!String.IsNullOrEmpty(defaultValueEditor.ErrorMessage)) { ShowError(defaultValueEditor.ErrorMessage); return; } if (wi != null) { // Load xml definition if (wi.WebPartParentID > 0) { // Load the form definition string before = PortalFormHelper.GetWebPartProperties(WebPartTypeEnum.Standard, PropertiesPosition.Before); string after = PortalFormHelper.GetWebPartProperties(WebPartTypeEnum.Standard, PropertiesPosition.Before); string formDef = FormHelper.CombineFormDefinitions(before, after); // Web part default values contains either properties or changed "system" values // First Remove records with same name as "system properties" => only actual webpart's properties remains string filteredDef = defaultValueEditor.FitlerDefaultValuesDefinition(wi.WebPartDefaultValues, formDef, false); WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WebPartParentID); // Remove records with same name as parent's property - its already stored in webpart's properties if (wpi != null) { filteredDef = defaultValueEditor.FitlerDefaultValuesDefinition(filteredDef, wpi.WebPartProperties, true); } // If inherited web part merge webpart's properties hier with default system values wi.WebPartDefaultValues = FormHelper.CombineFormDefinitions(filteredDef, defaultValueEditor.DefaultValueXMLDefinition); } else { wi.WebPartProperties = defaultValueEditor.DefaultValueXMLDefinition; } // Sav web part info WebPartInfoProvider.SetWebPartInfo(wi); // Redirect with saved assign string url = URLHelper.RemoveParameterFromUrl(URLRewriter.CurrentURL, "saved"); url = URLHelper.AddParameterToUrl(url, "saved", "1"); URLHelper.Redirect(url); } }
protected void Page_Load(object sender, EventArgs e) { int widgetID = QueryHelper.GetInteger("widgetID", 0); // Default values XML load XmlDocument xmlBefore = new XmlDocument(); XmlDocument xmlAfter = new XmlDocument(); ucDefaultValueEditor.XMLCreated += new EventHandler(ucDefaultValueEditor_XMLCreated); // If saved is found in query string if (!RequestHelper.IsPostBack() && (QueryHelper.GetInteger("saved", 0) == 1)) { ShowChangesSaved(); } // Load the form definition string before = PortalFormHelper.LoadProperties("Widget", "Before.xml"); string after = PortalFormHelper.LoadProperties("Widget", "After.xml"); string formDef = FormHelper.CombineFormDefinitions(before, after); // Get the widget info WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo(widgetID); if (wi != null) { // Load default values for current web part XmlDocument xmlDefault = LoadDefaultValuesXML(wi, formDef); // Set field editor if (wi.WidgetDefaultValues == String.Empty) { ucDefaultValueEditor.DefaultValueXMLDefinition = "<form></form>"; } else { // WebPartDefaultValues contains changed fields versus default XML settings (stored in files) ucDefaultValueEditor.DefaultValueXMLDefinition = wi.WidgetDefaultValues; } ucDefaultValueEditor.LoadHiddenFields = true; ucDefaultValueEditor.SourceXMLDefinition = xmlDefault.DocumentElement.OuterXml; } }
/// <summary> /// Returns form info with webpart properties. /// </summary> /// <param name="wpi">Web part info</param> protected FormInfo GetWebPartProperties(WebPartInfo wpi) { if (wpi != null) { // Before form string before = PortalFormHelper.GetWebPartProperties((WebPartTypeEnum)wpi.WebPartType, PropertiesPosition.Before); FormInfo bfi = new FormInfo(before); // After form string after = PortalFormHelper.GetWebPartProperties((WebPartTypeEnum)wpi.WebPartType, PropertiesPosition.After); FormInfo afi = new FormInfo(after); // Add general category to first items in webpart without category string properties = FormHelper.EnsureDefaultCategory(wpi.WebPartProperties, GetString("general.general")); return(PortalFormHelper.GetWebPartFormInfo(wpi.WebPartName, properties, bfi, afi, true)); } return(null); }
protected void Page_Load(object sender, EventArgs e) { int webPartId = QueryHelper.GetInteger("webpartid", 0); // Default values XML load ucDefaultValueEditor.XMLCreated += new EventHandler(ucDefaultValueEditor_XMLCreated); // If saved is found in query string if (!RequestHelper.IsPostBack() && (QueryHelper.GetInteger("saved", 0) == 1)) { ShowChangesSaved(); } // Load the form definition string before = PortalFormHelper.GetWebPartProperties(WebPartTypeEnum.Standard, PropertiesPosition.Before); string after = PortalFormHelper.GetWebPartProperties(WebPartTypeEnum.Standard, PropertiesPosition.After); string formDef = FormHelper.CombineFormDefinitions(before, after); // Get the web part info WebPartInfo wi = WebPartInfoProvider.GetWebPartInfo(webPartId); EditedObject = wi; if (wi != null) { // Load default values for current web part XmlDocument xmlDefault = LoadDefaultValuesXML(wi, formDef); // Set field editor if (String.IsNullOrEmpty(wi.WebPartDefaultValues)) { ucDefaultValueEditor.DefaultValueXMLDefinition = "<form></form>"; } else { // WebPartDefaultValues contains changed fields versus default XML settings (stored in files) ucDefaultValueEditor.DefaultValueXMLDefinition = wi.WebPartDefaultValues; } ucDefaultValueEditor.SourceXMLDefinition = xmlDefault.DocumentElement.OuterXml; } }
/// <summary> /// Returns form info with webpart properties. /// </summary> /// <param name="wpi">Web part info</param> protected FormInfo GetWebPartProperties(WebPartInfo wpi) { if (wpi != null) { // Before form string before = PortalFormHelper.GetWebPartProperties((WebPartTypeEnum)wpi.WebPartType, PropertiesPosition.Before); FormInfo bfi = new FormInfo(before); // After form string after = PortalFormHelper.GetWebPartProperties((WebPartTypeEnum)wpi.WebPartType, PropertiesPosition.After); FormInfo afi = new FormInfo(after); // Add general category to first items in webpart without category string properties = wpi.WebPartProperties; if (!string.IsNullOrEmpty(properties) && (!properties.StartsWithCSafe("<form><category", true))) { properties = properties.Insert(6, "<category name=\"" + GetString("general.general") + "\" />"); } return(PortalFormHelper.GetWebPartFormInfo(wpi.WebPartName, properties, bfi, afi, true)); } return(null); }
/// <summary> /// Adds the inline widget without the properties dialog. /// </summary> /// <param name="widgetId">The widget id</param> private string AddInlineWidgetWithoutDialog(int widgetId) { string script = string.Empty; if (widgetId > 0) { // New widget - load widget info by id WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo(widgetId); if ((wi != null) && wi.WidgetForInline) { // Test permission for user var currentUser = MembershipContext.AuthenticatedUser; if (!WidgetRoleInfoProvider.IsWidgetAllowed(widgetId, currentUser.UserID, AuthenticationHelper.IsAuthenticated())) { return(string.Empty); } // If user is editor, more properties are shown WidgetZoneTypeEnum zoneType = WidgetZoneTypeEnum.User; if (currentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Editor, SiteContext.CurrentSiteName)) { zoneType = WidgetZoneTypeEnum.Editor; } WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID); // Merge the parent web part properties definition with the widget properties definition string widgetProperties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties); // Create the FormInfo for the current widget properties definition FormInfo fi = PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, zoneType, widgetProperties, true); DataRow dr = null; if (fi != null) { // Get data rows with required columns dr = PortalHelper.CombineWithDefaultValues(fi, wi); // Load default values for new widget fi.LoadDefaultValues(dr, FormResolveTypeEnum.Visible); // Override default value and set title as widget display name DataHelper.SetDataRowValue(dr, "WidgetTitle", wi.WidgetDisplayName); } // Save inline widget script script = PortalHelper.GetAddInlineWidgetScript(wi, dr, fi.GetFields(true, true)); script += " CloseDialog(false);"; if (!string.IsNullOrEmpty(script)) { // Add to recently used widgets collection MembershipContext.AuthenticatedUser.UserSettings.UpdateRecentlyUsedWidget(wi.WidgetName); } } } return(script); }
protected void Page_Load(object sender, EventArgs e) { // Setup info/error message placeholder if (MessagesPlaceHolder != null) { MessagesPlaceHolder.UseRelativePlaceHolder = false; form.EnsureMessagesPlaceholder(MessagesPlaceHolder); } // Load default properties from XML XmlDocument xml = new XmlDocument(); xml.Load(ResolveUrl(HttpContext.Current.Server.MapPath(PortalFormHelper.BEFOREPROPERTIESDEFINITION))); // Load UI element and element's page template (if any) mUIElementInfo = UIElementInfoProvider.GetUIElementInfo(QueryHelper.GetInteger("elementID", 0)); if (mUIElementInfo != null) { PageTemplateInfo pti = null; if (mUIElementInfo.ElementType == UIElementTypeEnum.PageTemplate) { pti = PageTemplateInfoProvider.GetPageTemplateInfo(mUIElementInfo.ElementPageTemplateID); } form.Enabled = ((SystemContext.DevelopmentMode || mUIElementInfo.ElementIsCustom) && (!UIElementInfoProvider.AllowEditOnlyCurrentModule || (mUIElementInfo.ElementResourceID == QueryHelper.GetInteger("moduleId", 0)))); // Create form info FormInfo fi = (pti != null) ? pti.PageTemplatePropertiesForm : PortalFormHelper.GetUIElementDefaultPropertiesForm(UIElementPropertiesPosition.Both); form.FormInformation = fi; // Load data row from properties DataRow dr = fi.GetDataRow(); fi.LoadDefaultValues(dr); if ((mUIElementInfo == null) || !mUIElementInfo.IsApplication) { fi.RemoveFormField("DescriptionLink"); } XmlData customData = new XmlData(); // Load element properties XmlData data = new XmlData(); data.AllowMacros = true; data.LoadData(mUIElementInfo.ElementProperties); form.MacroTable = data.MacroTable; // Fill template datarow with element's properties. If template does not contain such column, add it to custom foreach (String col in data.ColumnNames) { if (col.StartsWith(UIContextData.CATEGORYNAMEPREFIX, StringComparison.Ordinal)) { if (!RequestHelper.IsPostBack()) { String catName = col.Substring(UIContextData.CATEGORYNAMEPREFIX.Length); FormCategoryInfo fci = fi.GetFormCategory(catName); if (fci != null) { fci.SetPropertyValue(FormCategoryPropertyEnum.CollapsedByDefault, ValidationHelper.GetBoolean(data[col], false).ToString().ToLowerInvariant()); } } } else { if (dr.Table.Columns.Contains(col)) { DataHelper.SetDataRowValue(dr, col, data[col]); } else { customData[col] = data[col]; } } } dr["CustomProperties"] = customData.GetData(); form.DataRow = dr; form.LoadData(dr); form.FormInformation = fi; // Master page style for margin CurrentMaster.PanelContent.CssClass = "WebpartProperties PageContent"; form.OnAfterSave += form_OnAfterSave; } else { EditedObject = null; } }
/// <summary> /// Loads the widget form. /// </summary> private void LoadForm() { // Setup basic form on live site formCustom.AllowMacroEditing = false; formCustom.IsLiveSite = IsLiveSite; // Load settings if (!String.IsNullOrEmpty(Request.Form[hdnIsNewWebPart.UniqueID])) { IsNewWidget = ValidationHelper.GetBoolean(Request.Form[hdnIsNewWebPart.UniqueID], false); } if (!String.IsNullOrEmpty(Request.Form[hdnInstanceGUID.UniqueID])) { InstanceGUID = ValidationHelper.GetGuid(Request.Form[hdnInstanceGUID.UniqueID], Guid.Empty); } // Try to find the widget variant in the database and set its VariantID if (IsNewVariant) { Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable; if (properties != null) { // Get the variant code name from the WindowHelper string variantName = ValidationHelper.GetString(properties["codename"], string.Empty); // Check if the variant exists in the database int variantIdFromDB = VariantHelper.GetVariantID(VariantMode, PageTemplateId, variantName, false); // Set the variant id from the database if (variantIdFromDB > 0) { VariantID = variantIdFromDB; IsNewVariant = false; } } } EnsureDashboard(); if (!String.IsNullOrEmpty(WidgetId) && !IsInline) { if (CurrentPageInfo == null) { ShowError(GetString("Widgets.Properties.aliasnotfound")); pnlFormArea.Visible = false; return; } // Get template instance mTemplateInstance = CMSPortalManager.GetTemplateInstanceForEditing(CurrentPageInfo); if (!IsNewWidget) { // Get the instance of widget mWidgetInstance = mTemplateInstance.GetWebPart(InstanceGUID, WidgetId); if (mWidgetInstance == null) { ShowError(GetString("Widgets.Properties.WidgetNotFound")); pnlFormArea.Visible = false; return; } if ((VariantID > 0) && (mWidgetInstance != null) && (mWidgetInstance.PartInstanceVariants != null)) { // Check OnlineMarketing permissions. if (CheckPermissions("Read")) { mWidgetInstance = CurrentPageInfo.DocumentTemplateInstance.GetWebPart(InstanceGUID, WidgetId); mWidgetInstance = mWidgetInstance.PartInstanceVariants.Find(v => v.VariantID.Equals(VariantID)); // Set the widget variant mode if (mWidgetInstance != null) { VariantMode = mWidgetInstance.VariantMode; } } else { // Not authorized for OnlineMarketing - Manage. RedirectToInformation(String.Format(GetString("general.permissionresource"), "Read", (VariantMode == VariantModeEnum.ContentPersonalization) ? "CMS.ContentPersonalization" : "CMS.MVTest")); } } // Get widget info by widget name(widget type) mWidgetInfo = WidgetInfoProvider.GetWidgetInfo(mWidgetInstance.WebPartType); } // Widget instance hasn't created yet else { mWidgetInfo = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(WidgetId, 0)); } // Keep xml version if (mWidgetInstance != null) { mXmlVersion = mWidgetInstance.XMLVersion; } UIContext.EditedObject = mWidgetInfo; // Get the zone to which it inserts WebPartZoneInstance zone = mTemplateInstance.GetZone(ZoneId); if ((ZoneType == WidgetZoneTypeEnum.None) && (zone != null)) { ZoneType = zone.WidgetZoneType; } // Check security var currentUser = MembershipContext.AuthenticatedUser; switch (ZoneType) { // Group zone => Only group widgets and group admin case WidgetZoneTypeEnum.Group: // Should always be, only group widget are allowed in group zone if (!mWidgetInfo.WidgetForGroup || (!currentUser.IsGroupAdministrator(CurrentPageInfo.NodeGroupID) && ((PortalContext.ViewMode != ViewModeEnum.Design) || ((PortalContext.ViewMode == ViewModeEnum.Design) && (!currentUser.IsAuthorizedPerResource("CMS.Design", "Design")))))) { if (OnNotAllowed != null) { OnNotAllowed(this, null); } } break; // Widget must be allowed for editor zones case WidgetZoneTypeEnum.Editor: if (!mWidgetInfo.WidgetForEditor) { if (OnNotAllowed != null) { OnNotAllowed(this, null); } } break; // Widget must be allowed for user zones case WidgetZoneTypeEnum.User: if (!mWidgetInfo.WidgetForUser) { if (OnNotAllowed != null) { OnNotAllowed(this, null); } } break; // Widget must be allowed for dashboard zones case WidgetZoneTypeEnum.Dashboard: if (!mWidgetInfo.WidgetForDashboard) { if (OnNotAllowed != null) { OnNotAllowed(this, null); } } break; } // Check security if ((ZoneType != WidgetZoneTypeEnum.Group) && !WidgetRoleInfoProvider.IsWidgetAllowed(mWidgetInfo, currentUser.UserID, AuthenticationHelper.IsAuthenticated())) { if (OnNotAllowed != null) { OnNotAllowed(this, null); } } // Get form schemas mWebPartInfo = WebPartInfoProvider.GetWebPartInfo(mWidgetInfo.WidgetWebPartID); string widgetProperties = FormHelper.MergeFormDefinitions(mWebPartInfo.WebPartProperties, mWidgetInfo.WidgetProperties); FormInfo fi = PortalFormHelper.GetWidgetFormInfo(mWidgetInfo.WidgetName, ZoneType, widgetProperties, true, mWidgetInfo.WidgetDefaultValues); if (fi != null) { fi.ContextResolver.Settings.RelatedObject = mTemplateInstance; // Check if there are some editable properties var ffi = fi.GetFields(true, false); if ((ffi == null) || (ffi.Count == 0)) { ShowInformation(GetString("widgets.emptyproperties")); } DataRow dr = fi.GetDataRow(); // Load overridden values for new widget if (IsNewWidget || (mXmlVersion > 0)) { fi.LoadDefaultValues(dr, FormResolveTypeEnum.WidgetVisible); } if (IsNewWidget) { // Override default value and set title as widget display name DataHelper.SetDataRowValue(dr, "WidgetTitle", ResHelper.LocalizeString(mWidgetInfo.WidgetDisplayName)); } // Load values from existing widget LoadDataRowFromWidget(dr, fi); // Init HTML toolbar if exists InitHTMLToobar(fi); // Init the form InitForm(formCustom, dr, fi); // Set the context name formCustom.ControlContext.ContextName = CMS.Base.Web.UI.ControlContext.WIDGET_PROPERTIES; } } if (IsInline) { // Load text definition from session string definition = ValidationHelper.GetString(SessionHelper.GetValue("WidgetDefinition"), String.Empty); if (String.IsNullOrEmpty(definition)) { definition = Request.Form[hdnWidgetDefinition.UniqueID]; } else { hdnWidgetDefinition.Value = definition; } Hashtable parameters = null; string widgetName = String.Empty; if (IsNewWidget) { // New widget - load widget info by id if (!String.IsNullOrEmpty(WidgetId)) { mWidgetInfo = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(WidgetId, 0)); } else { // Try to get widget from codename widgetName = QueryHelper.GetString("WidgetName", String.Empty); mWidgetInfo = WidgetInfoProvider.GetWidgetInfo(widgetName); } } else { if (definition == null) { DisplayError("widget.failedtoload"); return; } // Parse definition parameters = CMSDialogHelper.GetHashTableFromString(definition); // Trim control name if (parameters["name"] != null) { widgetName = parameters["name"].ToString(); } mWidgetInfo = WidgetInfoProvider.GetWidgetInfo(widgetName); } if (mWidgetInfo == null) { DisplayError("widget.failedtoload"); return; } // If widget cant be used as inline if (!mWidgetInfo.WidgetForInline) { DisplayError("widget.cantbeusedasinline"); return; } // Test permission for user var currentUser = MembershipContext.AuthenticatedUser; if (!WidgetRoleInfoProvider.IsWidgetAllowed(mWidgetInfo, currentUser.UserID, AuthenticationHelper.IsAuthenticated())) { mIsValidWidget = false; OnNotAllowed(this, null); } // If user is editor, more properties are shown WidgetZoneTypeEnum zoneType = WidgetZoneTypeEnum.User; if (currentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Editor, SiteContext.CurrentSiteName)) { zoneType = WidgetZoneTypeEnum.Editor; } WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(mWidgetInfo.WidgetWebPartID); string widgetProperties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, mWidgetInfo.WidgetProperties); FormInfo fi = PortalFormHelper.GetWidgetFormInfo(mWidgetInfo.WidgetName, zoneType, widgetProperties, true, mWidgetInfo.WidgetDefaultValues); if (fi != null) { // Check if there are some editable properties mFields = fi.GetFields(true, true); if ((mFields == null) || !mFields.Any()) { ShowInformation(GetString("widgets.emptyproperties")); } // Get datarows with required columns DataRow dr = PortalHelper.CombineWithDefaultValues(fi, mWidgetInfo); if (IsNewWidget) { // Load default values for new widget fi.LoadDefaultValues(dr, FormResolveTypeEnum.WidgetVisible); } else { foreach (string key in parameters.Keys) { object value = parameters[key]; // Test if given property exists if (dr.Table.Columns.Contains(key) && (value != null)) { try { dr[key] = DataHelper.ConvertValue(value, dr.Table.Columns[key].DataType); } catch { } } } } // Override default value and set title as widget display name DataHelper.SetDataRowValue(dr, "WidgetTitle", mWidgetInfo.WidgetDisplayName); // Init HTML toolbar if exists InitHTMLToobar(fi); // Init the form InitForm(formCustom, dr, fi); // Set the context name formCustom.ControlContext.ContextName = CMS.Base.Web.UI.ControlContext.WIDGET_PROPERTIES; } } }
protected void Page_Load(object sender, EventArgs e) { StringSafeDictionary <object> decodedProperties = new StringSafeDictionary <object>(); foreach (DictionaryEntry param in Properties) { // Decode special CK editor char String str = String.Empty; if (param.Value != null) { str = param.Value.ToString().Replace("%25", "%"); } decodedProperties[(string)param.Key] = HttpUtility.UrlDecode(str); } Properties = decodedProperties; string widgetName = ValidationHelper.GetString(Properties["name"], String.Empty); // Widget name must be specified if (String.IsNullOrEmpty(widgetName)) { AddErrorWebPart("widgets.invalidname", null); return; } WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo(widgetName); if (wi == null) { AddErrorWebPart("widget.failedtoload", null); return; } WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID); if (wpi == null) { return; } //no widgets can be used as inline if (!wi.WidgetForInline) { AddErrorWebPart("widgets.cantbeusedasinline", null); return; } try { FormInfo fi = null; DataRow dr = null; using (var cs = new CachedSection <FormInfo>(ref fi, 1440, (PortalContext.ViewMode == ViewModeEnum.LiveSite), null, "inlinewidgetcontrol", wi.WidgetID, wpi.WebPartID)) { if (cs.LoadData) { // Merge widget and it's parent webpart properties string props = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties); // Prepare form const WidgetZoneTypeEnum zoneType = WidgetZoneTypeEnum.Editor; fi = PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, zoneType, props, true, wi.WidgetDefaultValues); // Apply changed values dr = fi.GetDataRow(); fi.LoadDefaultValues(dr); if (cs.Cached) { cs.CacheDependency = CacheHelper.GetCacheDependency("cms.webpart|byid|" + wpi.WebPartID + "\n" + "cms.widget|byid|" + wi.WidgetID); } cs.Data = fi; } } // Get datarow if (dr == null) { dr = fi.GetDataRow(); fi.LoadDefaultValues(dr); } // Incorporate inline parameters to datarow string publicFields = ";containertitle;container;"; if (wi.WidgetPublicFileds != null) { publicFields += ";" + wi.WidgetPublicFileds.ToLowerCSafe() + ";"; } // Load the widget control string url = null; // Set widget layout WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wi.WidgetLayoutID); if (wpli != null) { // Load specific layout through virtual path url = wpli.Generalized.GetVirtualFileRelativePath(WebPartLayoutInfo.EXTERNAL_COLUMN_CODE, wpli.WebPartLayoutVersionGUID); } else { // Load regularly url = WebPartInfoProvider.GetWebPartUrl(wpi, false); } CMSAbstractWebPart control = (CMSAbstractWebPart)Page.LoadUserControl(url); control.PartInstance = new WebPartInstance(); // Use current page placeholder control.PagePlaceholder = PortalHelper.FindParentPlaceholder(this); // Set all form values to webpart foreach (DataColumn column in dr.Table.Columns) { object value = dr[column]; string columnName = column.ColumnName.ToLowerCSafe(); //Resolve set values by user if (Properties.Contains(columnName)) { FormFieldInfo ffi = fi.GetFormField(columnName); if ((ffi != null) && ffi.Visible && ((ffi.DisplayIn == null) || !ffi.DisplayIn.Contains(FormInfo.DISPLAY_CONTEXT_DASHBOARD))) { value = Properties[columnName]; } } // Resolve macros in defined in default values if (!String.IsNullOrEmpty(value as string)) { // Do not resolve macros for public fields if (publicFields.IndexOfCSafe(";" + columnName + ";") < 0) { // Check whether current column bool avoidInjection = control.SQLProperties.Contains(";" + columnName + ";"); // Resolve macros MacroSettings settings = new MacroSettings() { AvoidInjection = avoidInjection, }; value = control.ContextResolver.ResolveMacros(value.ToString(), settings); } } control.PartInstance.SetValue(column.ColumnName, value); } control.PartInstance.IsWidget = true; // Load webpart content control.OnContentLoaded(); // Add webpart to controls collection Controls.Add(control); // Handle DisableViewstate setting control.EnableViewState = !control.DisableViewState; } catch (Exception ex) { AddErrorWebPart("widget.failedtoload", ex); } }
protected void Page_Load(object sender, EventArgs e) { eObject = UIContext.EditedObject as BaseInfo; // If saved is found in query string if (!RequestHelper.IsPostBack() && (QueryHelper.GetInteger("saved", 0) == 1)) { ShowChangesSaved(); } string before = String.Empty; string after = String.Empty; String objectType = UIContextHelper.GetObjectType(UIContext); switch (objectType.ToLowerCSafe()) { case "cms.webpart": defaultValueColumName = "WebPartDefaultValues"; before = PortalFormHelper.GetWebPartProperties(WebPartTypeEnum.Standard, PropertiesPosition.Before); after = PortalFormHelper.GetWebPartProperties(WebPartTypeEnum.Standard, PropertiesPosition.After); defaultSet = FormHelper.CombineFormDefinitions(before, after); WebPartInfo wi = eObject as WebPartInfo; // If inherited web part load parent properties if (wi.WebPartParentID > 0) { WebPartInfo parentInfo = WebPartInfoProvider.GetWebPartInfo(wi.WebPartParentID); if (parentInfo != null) { properties = FormHelper.MergeFormDefinitions(parentInfo.WebPartProperties, wi.WebPartProperties); } } else { properties = wi.WebPartProperties; } break; case "cms.widget": before = PortalFormHelper.LoadProperties("Widget", "Before.xml"); after = PortalFormHelper.LoadProperties("Widget", "After.xml"); defaultSet = FormHelper.CombineFormDefinitions(before, after); defaultValueColumName = "WidgetDefaultValues"; WidgetInfo wii = eObject as WidgetInfo; if (wii != null) { WebPartInfo wiiWp = WebPartInfoProvider.GetWebPartInfo(wii.WidgetWebPartID); if (wiiWp != null) { properties = FormHelper.MergeFormDefinitions(wiiWp.WebPartProperties, wii.WidgetProperties); } } break; } // Get the web part info if (eObject != null) { String defVal = ValidationHelper.GetString(eObject.GetValue(defaultValueColumName), string.Empty); defaultSet = LoadDefaultValuesXML(defaultSet); fieldEditor.Mode = FieldEditorModeEnum.SystemWebPartProperties; fieldEditor.FormDefinition = FormHelper.MergeFormDefinitions(defaultSet, defVal); fieldEditor.OnAfterDefinitionUpdate += fieldEditor_OnAfterDefinitionUpdate; fieldEditor.OriginalFormDefinition = defaultSet; fieldEditor.WebPartId = eObject.Generalized.ObjectID; } ScriptHelper.HideVerticalTabs(Page); }
void EditForm_OnBeforeSave(object sender, EventArgs e) { elementInfo = (UIElementInfo)EditForm.EditedObject; // Clear icon field based on icon type int type = EditForm.FieldControls["ElementIconType"].Value.ToInteger(0); if (type == 0) { elementInfo.ElementIconClass = ""; } else { elementInfo.ElementIconPath = ""; } // Check unique code name UIElementInfo testUI = UIElementInfoProvider.GetUIElementInfo(elementInfo.ElementResourceID, elementInfo.ElementName); if ((testUI != null) && (testUI.ElementID != elementInfo.ElementID)) { ShowError(GetString("ui.element.alreadyexists")); EditForm.StopProcessing = true; return; } UIElementInfo oldItem = UIContext.EditedObject as UIElementInfo; // If new element or display name has changed or parent changed, refresh tree and recalculate order if ((oldItem != null) && ((oldItem.ElementParentID != elementInfo.ElementParentID) || (oldItem.ElementDisplayName != elementInfo.ElementDisplayName)) || (ElementID == 0)) { // If element is new or changed parent, put him in the end of the order, otherwise it stays on it's place if ((ElementID == 0) || (oldItem.ElementParentID != elementInfo.ElementParentID)) { elementInfo.ElementOrder = UIElementInfoProvider.GetLastElementOrder(elementInfo.ElementParentID) + 1; } refreshTree = true; } // Clear target URL for page template type if (elementInfo.ElementType == UIElementTypeEnum.PageTemplate) { elementInfo.ElementTargetURL = null; } else { // Empty Page Template ID for non page template type elementInfo.ElementPageTemplateID = 0; } // Add javascript prefix for TargetURL if javascript type is selected if ((elementInfo.ElementType == UIElementTypeEnum.Javascript) && !elementInfo.ElementTargetURL.StartsWithCSafe("javascript", true)) { elementInfo.ElementTargetURL = "javascript:" + elementInfo.ElementTargetURL; } if (isNew) { elementInfo.ElementIsCustom = !SystemContext.DevelopmentMode; } // For new elements or when template is changed, create new element's properties based on default values bool templateChanged = ValidationHelper.GetBoolean(EditForm.FieldControls["ElementPageTemplateID"].GetValue("TemplateChanged"), false); if (isNew || templateChanged) { // Get page template if any template is selected PageTemplateInfo pti = (elementInfo.ElementPageTemplateID > 0) ? PageTemplateInfoProvider.GetPageTemplateInfo(elementInfo.ElementPageTemplateID) : null; // Create form info based on either template combined with default general data (XML file) or default general data only (if no template is selected) FormInfo fi = (pti != null) ? pti.PageTemplatePropertiesForm : PortalFormHelper.GetUIElementDefaultPropertiesForm(UIElementPropertiesPosition.Both); // Create XMLData collection for current element (this make sense only for template change). XmlData data = new XmlData(); data.LoadData(elementInfo.ElementProperties); // Apply default data to element's properties, but only if has not it's own data (based by column name) foreach (FormFieldInfo ffi in fi.GetFields(true, true)) { if (!data.ColumnNames.Contains(ffi.Name) && !String.IsNullOrEmpty(ffi.DefaultValue)) { data[ffi.Name] = ffi.DefaultValue; } } elementInfo.ElementProperties = data.GetData(); } }
protected void Page_Load(object sender, EventArgs e) { string aliasPath = QueryHelper.GetString("aliaspath", ""); string webpartId = QueryHelper.GetString("webpartid", ""); string zoneId = QueryHelper.GetString("zoneid", ""); Guid webpartGuid = QueryHelper.GetGuid("webpartguid", Guid.Empty); int templateId = QueryHelper.GetInteger("templateId", 0); PageTemplateInfo pti = null; if (templateId > 0) { pti = PageTemplateInfoProvider.GetPageTemplateInfo(templateId); } if (pti == null) { var siteName = SiteContext.CurrentSiteName; PageInfo pi = PageInfoProvider.GetPageInfo(siteName, aliasPath, LocalizationContext.PreferredCultureCode, null, SiteInfoProvider.CombineWithDefaultCulture(siteName)); if (pi != null) { pti = pi.UsedPageTemplateInfo; } } if (pti != null) { // Get web part WebPartInstance webPart = pti.TemplateInstance.GetWebPart(webpartGuid, webpartId); if (webPart != null) { StringBuilder sb = new StringBuilder(); Hashtable properties = webPart.Properties; // Get the webpart object WebPartInfo wi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType); if (wi != null) { // Add the header sb.Append("Webpart properties (" + wi.WebPartDisplayName + ")" + Environment.NewLine + Environment.NewLine); sb.Append("Alias path: " + aliasPath + Environment.NewLine); sb.Append("Zone ID: " + zoneId + Environment.NewLine + Environment.NewLine); string wpProperties = "<default></default>"; // Get the form info object and load it with the data if (wi.WebPartParentID > 0) { // Load parent properties WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WebPartParentID); if (wpi != null) { wpProperties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WebPartProperties); } } else { wpProperties = wi.WebPartProperties; } FormInfo fi = new FormInfo(wpProperties); // General properties of webparts string beforeFormDefinition = PortalFormHelper.GetWebPartProperties((WebPartTypeEnum)wi.WebPartType, PropertiesPosition.Before); string afterFormDefinition = PortalFormHelper.GetWebPartProperties((WebPartTypeEnum)wi.WebPartType, PropertiesPosition.After); // General properties before custom if (!String.IsNullOrEmpty(beforeFormDefinition)) { // Load before definition fi = new FormInfo(FormHelper.MergeFormDefinitions(beforeFormDefinition, wpProperties, true)); // Add Default category for first before items sb.Append(Environment.NewLine + "Default" + Environment.NewLine + Environment.NewLine + Environment.NewLine); } // General properties after custom if (!String.IsNullOrEmpty(afterFormDefinition)) { // Load after definition fi = new FormInfo(FormHelper.MergeFormDefinitions(fi.GetXmlDefinition(), afterFormDefinition, true)); } // Generate all properties sb.Append(GetProperties(fi.GetFormElements(true, false), webPart)); // Send the text file to the user to download UTF8Encoding enc = new UTF8Encoding(); byte[] file = enc.GetBytes(sb.ToString()); Response.AddHeader("Content-disposition", "attachment; filename=webpartproperties_" + HTTPHelper.GetDispositionFilename(webPart.ControlID) + ".txt"); Response.ContentType = "text/plain"; Response.BinaryWrite(file); RequestHelper.EndResponse(); } } } }
protected void Page_Load(object sender, EventArgs e) { StringSafeDictionary <object> decodedProperties = new StringSafeDictionary <object>(); foreach (DictionaryEntry param in mProperties) { // Decode special CK editor char String str = String.Empty; if (param.Value != null) { str = param.Value.ToString().Replace("%25", "%"); } decodedProperties[param.Key] = HttpUtility.UrlDecode(str); } mProperties = decodedProperties; string widgetName = ValidationHelper.GetString(mProperties["name"], String.Empty); // Widget name must be specified if (String.IsNullOrEmpty(widgetName)) { AddErrorWebPart("widgets.invalidname", null); return; } WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo(widgetName); if (wi == null) { AddErrorWebPart("widget.failedtoload", null); return; } WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID); if (wpi == null) { return; } //no widgets can be used as inline if (!wi.WidgetForInline) { AddErrorWebPart("widgets.cantbeusedasinline", null); return; } try { // Merge widget and it's parent webpart properties string properties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties); // Prepare form WidgetZoneTypeEnum zoneType = WidgetZoneTypeEnum.Editor; FormInfo zoneTypeDefinition = PortalFormHelper.GetPositionFormInfo(zoneType); FormInfo fi = PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, Enum.GetName(typeof(WidgetZoneTypeEnum), zoneType), properties, zoneTypeDefinition, true); // Apply changed values DataRow dr = PortalHelper.CombineWithDefaultValues(fi, wi); fi.LoadDefaultValues(dr); // Incorporate inline parameters to datarow string publicFields = ";containertitle;container;"; if (wi.WidgetPublicFileds != null) { publicFields += ";" + wi.WidgetPublicFileds.ToLowerCSafe() + ";"; } // Load the widget control string url = null; // Set widget layout WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wi.WidgetLayoutID); if (wpli != null) { // Load specific layout through virtual path url = wpli.GetVirtualFileRelativePath(WebPartLayoutInfo.EXTERNAL_COLUMN_CODE, wpli.WebPartLayoutVersionGUID); } else { // Load regularly url = WebPartInfoProvider.GetWebPartUrl(wpi, false); } CMSAbstractWebPart control = (CMSAbstractWebPart)Page.LoadUserControl(url); control.PartInstance = new WebPartInstance(); // Set all form values to webpart foreach (DataColumn column in dr.Table.Columns) { object value = dr[column]; string columnName = column.ColumnName.ToLowerCSafe(); //Resolve set values by user if (mProperties.Contains(columnName)) { FormFieldInfo ffi = fi.GetFormField(columnName); if ((ffi != null) && ffi.Visible && (!ffi.DisplayIn.Contains(FormInfo.DISPLAY_CONTEXT_DASHBOARD))) { value = mProperties[columnName]; } } // Resolve macros in defined in default values if (!String.IsNullOrEmpty(value as string)) { // Do not resolve macros for public fields if (publicFields.IndexOfCSafe(";" + columnName + ";") < 0) { // Check whether current column bool avoidInjection = control.SQLProperties.Contains(";" + columnName + ";"); // Resolve macros value = control.ContextResolver.ResolveMacros(value.ToString(), avoidInjection); } } control.PartInstance.SetValue(column.ColumnName, value); } control.PartInstance.IsWidget = true; // Load webpart content control.OnContentLoaded(); // Add webpart to controls collection Controls.Add(control); } catch (Exception ex) { AddErrorWebPart("widget.failedtoload", ex); } }
/// <summary> /// Generate editor table. /// </summary> public void GenerateEditor() { FormInfo fi = null; // Call handlers if (OnEditorLoaded != null) { fi = OnEditorLoaded(); } else { // Get parent web part info WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(ParentWebPartID); if (wpi != null) { // Create form info and load xml definition fi = PortalFormHelper.GetWebPartFormInfo(wpi.WebPartName + FormHelper.CORE, wpi.WebPartProperties, null, null, false); } else { fi = new FormInfo(SourceXMLDefinition); } } if (fi != null) { dr = fi.GetDataRow(false); // Get definition elements var infos = fi.GetFormElements(true, false); // create table part Literal table1 = new Literal(); pnlEditor.Controls.Add(table1); table1.Text = "<table cellpadding=\"3\">"; // Hashtable counter int i = 0; bool categoryExists = false; // Check all items in object array foreach (object contrl in infos) { // Generate row for form category if (contrl is FormCategoryInfo) { // Load category info FormCategoryInfo fci = contrl as FormCategoryInfo; if (fci != null) { CreateCategory(fci.CategoryCaption); categoryExists = true; } } else { // Ensure the default category if (!categoryExists) { CreateCategory(GetString("General.General")); categoryExists = true; } // Get form field info FormFieldInfo ffi = contrl as FormFieldInfo; if (ffi != null) { CreateField(ffi, ref i); } } } // End table part Literal table6 = new Literal(); pnlEditor.Controls.Add(table6); table6.Text = "</table>"; } }
public void BindData() { if (WebpartId != "") { // Get page info pi = CMSWebPartPropertiesPage.GetPageInfo(AliasPath, PageTemplateId, CultureCode); if (pi == null) { Visible = false; return; } // Get page template info pti = pi.UsedPageTemplateInfo; if (pti != null) { // Get web part instance webPart = pti.GetWebPart(InstanceGUID, WebpartId); if (webPart == null) { CMSPage.EditedObject = null; return; } // Get the web part info WebPartInfo wpi = WebPartInfoProvider.GetBaseWebPart(webPart.WebPartType); if (wpi == null) { return; } // Get webpart properties (XML) string wpProperties = wpi.WebPartProperties; FormInfo fi = PortalFormHelper.GetWebPartFormInfo(wpi.WebPartName + FormHelper.CORE, wpi.WebPartProperties, null, null, false); // Get datarow with required columns DataRow dr = fi.GetDataRow(); // Bind drop down list if (!RequestHelper.IsPostBack()) { DataTable dropTable = new DataTable(); dropTable.Columns.Add("name"); foreach (DataColumn column in dr.Table.Columns) { dropTable.Rows.Add(column.ColumnName); } dropTable.DefaultView.Sort = "name"; drpProperty.DataTextField = "name"; drpProperty.DataValueField = "name"; drpProperty.DataSource = dropTable.DefaultView; drpProperty.DataBind(); } // Bind grid view DataTable table = new DataTable(); table.Columns.Add("LocalProperty"); table.Columns.Add("SourceProperty"); bindings = webPart.Bindings; foreach (DataColumn column in dr.Table.Columns) { string propertyName = column.ColumnName.ToLowerCSafe(); if (bindings.ContainsKey(propertyName)) { WebPartBindingInfo bi = (WebPartBindingInfo)bindings[propertyName]; table.Rows.Add(column.ColumnName, bi.SourceWebPart + "." + bi.SourceProperty); } } gvBinding.DataSource = table; gvBinding.DataBind(); } } }