/// <summary> /// Loads the web part form. /// </summary> protected void LoadForm() { // Load settings if (!string.IsNullOrEmpty(Request.Form[hdnIsNewWebPart.UniqueID])) { IsNewWebPart = ValidationHelper.GetBoolean(Request.Form[hdnIsNewWebPart.UniqueID], false); } if (!string.IsNullOrEmpty(Request.Form[hdnInstanceGUID.UniqueID])) { InstanceGUID = ValidationHelper.GetGuid(Request.Form[hdnInstanceGUID.UniqueID], Guid.Empty); } // Indicates whether the new variant should be chosen when closing this dialog selectNewVariant = IsNewVariant; // Try to find the web part variant in the database and set its VariantID if (IsNewVariant) { Hashtable varProperties = WindowHelper.GetItem("variantProperties") as Hashtable; if (varProperties != null) { // Get the variant code name from the WindowHelper string variantName = ValidationHelper.GetString(varProperties["codename"], string.Empty); // Check if the variant exists in the database int variantIdFromDB = VariantHelper.GetVariantID(VariantMode, PageTemplateID, variantName, true); // Set the variant id from the database if (variantIdFromDB > 0) { VariantID = variantIdFromDB; IsNewVariant = false; } } } if (!String.IsNullOrEmpty(WebPartID)) { // Get the page info pi = CMSWebPartPropertiesPage.GetPageInfo(AliasPath, PageTemplateID, CultureCode); if (pi == null) { ShowError(GetString("general.pagenotfound")); pnlExport.Visible = false; return; } // Get template pti = pi.UsedPageTemplateInfo; // Get template instance templateInstance = pti.TemplateInstance; if (!IsNewWebPart) { // Standard zone webPartInstance = templateInstance.GetWebPart(InstanceGUID, WebPartID); // If the web part not found, try to find it among the MVT/CP variants if (webPartInstance == null) { // MVT/CP variant // Clone templateInstance to avoid caching of the temporary template instance loaded with CP/MVT variants var tempTemplateInstance = templateInstance.Clone(); tempTemplateInstance.LoadVariants(false, VariantModeEnum.None); webPartInstance = tempTemplateInstance.GetWebPart(InstanceGUID, -1); // Set the VariantMode according to the selected web part/zone variant if (webPartInstance?.ParentZone != null) { VariantMode = (webPartInstance.VariantMode != VariantModeEnum.None) ? webPartInstance.VariantMode : webPartInstance.ParentZone.VariantMode; } else { VariantMode = VariantModeEnum.None; } } else { // Ensure that the ZoneVariantID is not set when the web part was found in a regular zone ZoneVariantID = 0; } if ((VariantID > 0) && webPartInstance?.PartInstanceVariants != null) { // Check OnlineMarketing permissions. if (CheckPermissions("Read")) { webPartInstance = webPartInstance.FindVariant(VariantID); } else { // Not authorized for OnlineMarketing - Manage. RedirectToInformation(String.Format(GetString("general.permissionresource"), "Read", (VariantMode == VariantModeEnum.ContentPersonalization) ? "CMS.ContentPersonalization" : "CMS.MVTest")); } } if (webPartInstance == null) { UIContext.EditedObject = null; return; } } // Keep xml version if (webPartInstance != null) { xmlVersion = webPartInstance.XMLVersion; } // Get the form info FormInfo fi = GetWebPartFormInfo(); // Get the form definition if (fi != null) { fi.ContextResolver.Settings.RelatedObject = templateInstance; form.AllowMacroEditing = true; // Get data row with required columns DataRow dr = fi.GetDataRow(); if (IsNewWebPart || (xmlVersion > 0)) { fi.LoadDefaultValues(dr); } // Load values from existing web part LoadDataRowFromWebPart(dr, webPartInstance, fi); // Set a unique WebPartControlID for the new variant if (IsNewVariant || IsNewWebPart) { dr["WebPartControlID"] = GetUniqueWebPartId(); } // Init the form InitForm(form, dr, fi); DisplayExportPropertiesButton(); } else { UIContext.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; } } }
/// <summary> /// OnInit event (BasicForm initialization). /// </summary> protected override void OnInit(EventArgs e) { base.OnInit(e); string zoneId = QueryHelper.GetString("zoneid", ""); string aliasPath = QueryHelper.GetString("aliaspath", ""); int templateId = QueryHelper.GetInteger("templateid", 0); string culture = QueryHelper.GetString("culture", LocalizationContext.PreferredCultureCode); mZoneVariantID = QueryHelper.GetInteger("variantid", 0); mIsNewVariant = QueryHelper.GetBoolean("isnewvariant", false); variantMode = VariantModeFunctions.GetVariantModeEnum(QueryHelper.GetString("variantmode", string.Empty)); // When displaying an existing variant of a web part, get the variant mode for its original web part if (ZoneVariantID > 0) { PageTemplateInfo pti = PageTemplateInfoProvider.GetPageTemplateInfo(templateId); if ((pti != null) && ((pti.TemplateInstance != null))) { // Get the original webpart and retrieve its variant mode WebPartZoneInstance zoneInstance = pti.TemplateInstance.GetZone(zoneId); if ((zoneInstance != null) && (zoneInstance.VariantMode != VariantModeEnum.None)) { variantMode = zoneInstance.VariantMode; } } } // Try to find the zone 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, templateId, variantName, true); // Set the variant id from the database if (variantIdFromDB > 0) { mZoneVariantID = variantIdFromDB; mIsNewVariant = false; } } } if (!String.IsNullOrEmpty(zoneId)) { // Get page info pi = CMSWebPartPropertiesPage.GetPageInfo(aliasPath, templateId, culture); if (pi == null) { ShowInformation(GetString("webpartzone.notfound")); pnlFormArea.Visible = false; return; } // Get template pti = PageTemplateInfoProvider.GetPageTemplateInfo(templateId); if (pti != null) { // Get web part zone pti.TemplateInstance.EnsureZone(zoneId); webPartZone = pti.TemplateInstance.GetZone(zoneId); if ((ZoneVariantID > 0) && (webPartZone != null) && (webPartZone.ZoneInstanceVariants != null)) { // Check OnlineMarketing permissions if (CheckPermissions("Read")) { webPartZone = webPartZone.ZoneInstanceVariants.Find(v => v.VariantID.Equals(ZoneVariantID)); } else { // Not authorized for OnlineMarketing - Manage. RedirectToInformation(String.Format(GetString("general.permissionresource"), "Read", (variantMode == VariantModeEnum.ContentPersonalization) ? "CMS.ContentPersonalization" : "CMS.MVTest")); } } if (webPartZone == null) { ShowInformation(GetString("webpartzone.notfound")); pnlFormArea.Visible = false; return; } FormInfo fi = BuildFormInfo(webPartZone); // Get the DataRow and fill the data row with values DataRow dr = fi.GetDataRow(); foreach (DataColumn column in dr.Table.Columns) { try { DataHelper.SetDataRowValue(dr, column.ColumnName, webPartZone.GetValue(column.ColumnName)); } catch { } } // Initialize Form formElem.DataRow = dr; formElem.MacroTable = webPartZone.MacroTable; formElem.SubmitButton.Visible = false; formElem.SiteName = SiteContext.CurrentSiteName; formElem.FormInformation = fi; formElem.OnAfterDataLoad += formElem_OnAfterDataLoad; // HTML editor toolbar if (fi.UsesHtmlArea()) { plcToolbarPadding.Visible = true; plcToolbar.Visible = true; pnlFormArea.Height = 285; } } } }
protected void ContextMenu_OnReloadData(object sender, EventArgs e) { int nodeId = ValidationHelper.GetInteger(ContextMenu.Parameter, 0); // Get the node TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser); TreeNode node = tree.SelectSingleNode(nodeId); if (node != null) { // Hide Properties for wireframe plcProperties.Visible &= !node.IsWireframe(); if (plcProperties.Visible) { // Properties menu var elements = UIElementInfoProvider.GetChildUIElements("CMS.Content", "Properties"); if (!DataHelper.DataSourceIsEmpty(elements)) { var index = 0; UserInfo user = MembershipContext.AuthenticatedUser; foreach (var elem in elements) { // If UI element is available and user has permission to show it then add it if (UIContextHelper.CheckElementAvailabilityInUI(elem) && user.IsAuthorizedPerUIElement(elem.ElementResourceID, elem.ElementName)) { var elementName = elem.ElementName; switch (elementName.ToLower()) { case "properties.languages": if (!CultureSiteInfoProvider.IsSiteMultilingual(SiteContext.CurrentSiteName) || !CultureSiteInfoProvider.LicenseVersionCheck()) { continue; } break; case "properties.wireframe": if (node.NodeWireframeTemplateID <= 0) { continue; } break; case "properties.variants": if (!LicenseHelper.IsFeatureAvailableInUI(FeatureEnum.ContentPersonalization, ModuleName.ONLINEMARKETING) || !ResourceSiteInfoProvider.IsResourceOnSite("CMS.ContentPersonalization", SiteContext.CurrentSiteName) || !PortalContext.ContentPersonalizationEnabled || (VariantHelper.GetVariantID(VariantModeEnum.ContentPersonalization, node.GetUsedPageTemplateId(), String.Empty) <= 0)) { continue; } break; case "properties.workflow": case "properties.versions": if (node.GetWorkflow() == null) { continue; } break; } var item = new ContextMenuItem(); item.ID = "p" + index; item.Attributes.Add("onclick", String.Format("Properties(GetContextMenuParameter('nodeMenu'), '{0}');", elementName)); item.Text = ResHelper.LocalizeString(elem.ElementDisplayName); pnlPropertiesMenu.Controls.Add(item); index++; } } if (index == 0) { // Hide 'Properties' menu if user has no permission for at least one properties section plcProperties.Visible = false; } } } } else { iNoNode.Visible = true; plcFirstLevelContainer.Visible = false; } }
protected void OnTabCreated(object sender, TabCreatedEventArgs e) { if (e.Tab == null) { return; } var tab = e.Tab; var element = e.UIElement; var manager = DocumentManager; var node = manager.Node; bool splitViewSupported = PortalContext.ViewMode != ViewModeEnum.EditLive; string elementName = element.ElementName.ToLowerCSafe(); if (DocumentUIHelper.IsElementHiddenForNode(element, node)) { e.Tab = null; return; } switch (elementName) { case "properties.languages": splitViewSupported = false; if (!CultureSiteInfoProvider.IsSiteMultilingual(SiteContext.CurrentSiteName) || !CultureSiteInfoProvider.LicenseVersionCheck()) { e.Tab = null; return; } break; case "properties.security": case "properties.relateddocs": case "properties.linkeddocs": splitViewSupported = false; break; case "properties.variants": if (DataHelper.GetNotEmpty(RequestContext.CurrentDomain, "") != "") { // Check license and whether content personalization is enabled and whether exists at least one variant for current template if ((node == null) || !LicenseHelper.IsFeatureAvailableInUI(FeatureEnum.ContentPersonalization, ModuleName.ONLINEMARKETING) || !ResourceSiteInfoProvider.IsResourceOnSite("CMS.ContentPersonalization", SiteContext.CurrentSiteName) || !PortalContext.ContentPersonalizationEnabled || (VariantHelper.GetVariantID(VariantModeEnum.ContentPersonalization, node.GetUsedPageTemplateId(), String.Empty) <= 0)) { e.Tab = null; return; } } break; case "properties.workflow": case "properties.versions": if (manager.Workflow == null) { e.Tab = null; return; } break; case "properties.personas": tab.RedirectUrl = URLHelper.AddParameterToUrl(tab.RedirectUrl, "objectid", manager.NodeID.ToString(CultureInfo.InvariantCulture)); break; } // UI elements could have a different display name if content only document is selected tab.Text = DocumentUIHelper.GetUIElementDisplayName(element, node); // Ensure split view mode if (splitViewSupported && UIContext.DisplaySplitMode) { tab.RedirectUrl = DocumentUIHelper.GetSplitViewUrl(tab.RedirectUrl); } }