/// <summary> /// Sets the current combination as default /// </summary> protected void btnUseCombination_Click(object sender, EventArgs e) { if ((DocumentContext.CurrentPageInfo != null)) { // Keep current page template instance PageInfo pi = DocumentContext.CurrentPageInfo; // Get combination from cookies string combinationName = CookieHelper.GetValue(cookieTestName); // Get the page template id int templateId = GetPageTemplateId(pi); // Get combination info MVTCombinationInfo currentCombination = MVTCombinationInfoProvider.GetMVTCombinationInfo(templateId, combinationName); // Get default combination info MVTCombinationInfo defaultCombination = MVTCombinationInfoProvider.GetDefaultCombinationInfo(templateId); // Check whether default and current combination exists if ((currentCombination != null) && (defaultCombination != null)) { // Do not save default combination if (currentCombination.MVTCombinationID != defaultCombination.MVTCombinationID) { // Copy the combination custom name defaultCombination.MVTCombinationCustomName = currentCombination.MVTCombinationCustomName; defaultCombination.Update(); // Tree provider instance TreeProvider tp = new TreeProvider(currentUser); // Documents - use the Preview view mode to ensure that only chosen variant will be rendered (Design mode renders all web part/zone variants and does not combine the instance with the variants) PageTemplateInstance instance = MVTestInfoProvider.CombineWithMVT(pi, pi.UsedPageTemplateInfo.TemplateInstance, currentCombination.MVTCombinationID, ViewModeEnum.Preview); CMSPortalManager.SaveTemplateChanges(pi, instance, WidgetZoneTypeEnum.None, ViewModeEnum.Design, tp); // Widgets - use the Preview view mode to ensure that only chosen variant will be rendered (Edit mode renders all widget variants and does not combine the instance with the variants) instance = MVTestInfoProvider.CombineWithMVT(pi, pi.DocumentTemplateInstance, currentCombination.MVTCombinationID, ViewModeEnum.Preview); CMSPortalManager.SaveTemplateChanges(pi, instance, WidgetZoneTypeEnum.Editor, ViewModeEnum.Edit, tp); } // Remove all variants var variants = MVTVariantInfoProvider.GetMVTVariants().WhereEquals("MVTVariantPageTemplateID", templateId); foreach (MVTVariantInfo info in variants) { MVTVariantInfoProvider.DeleteMVTVariantInfo(info); } // Clear cached template info pi.UsedPageTemplateInfo.Update(); // Redirect to the same page to update the current view URLHelper.Redirect(RequestContext.CurrentURL); } } }
/// <summary> /// Sets the current combination as default /// </summary> void btnUseCombination_Click(object sender, EventArgs e) { if ((CMSContext.CurrentPageInfo != null)) { // Keep current page template insatnce PageInfo pi = CMSContext.CurrentPageInfo; // Set the selected combination (from cookie by default) MVTestInfo mvTestInfo = MVTestInfoProvider.GetRunningTest(CMSContext.CurrentAliasPath, CMSContext.CurrentSiteID, CMSContext.CurrentDocumentCulture.CultureCode); // Get combination from cookies string combinationName = CookieHelper.GetValue(cookieTestName); // Get combination info MVTCombinationInfo currentCombination = MVTCombinationInfoProvider.GetMVTCombinationInfo(pi.DocumentPageTemplateID, combinationName); // Get default combination info MVTCombinationInfo defaultCombination = MVTCombinationInfoProvider.GetDefaultCombinationInfo(pi.DocumentPageTemplateID); // Check whether default and current combination exists if ((currentCombination != null) && (defaultCombination != null)) { // Do not save default combination if (currentCombination.MVTCombinationID != defaultCombination.MVTCombinationID) { // Copy the combination custom name defaultCombination.MVTCombinationCustomName = currentCombination.MVTCombinationCustomName; defaultCombination.Update(); // Tree provider instance TreeProvider tp = new TreeProvider(currentUser); // Documents - use the Preview view mode to ensure that only chosen variant will be rendered (Design mode renders all web part/zone variants and does not combine the instance with the variants) PageTemplateInstance instance = MVTestInfoProvider.CombineWithMVT(pi, pi.PageTemplateInfo.TemplateInstance, currentCombination.MVTCombinationID, ViewModeEnum.Preview); CMSPortalManager.SaveTemplateChanges(pi, pi.PageTemplateInfo, instance, WidgetZoneTypeEnum.None, ViewModeEnum.Design, tp); // Widgets - use the Preview view mode to ensure that only chosen variant will be rendered (Edit mode renders all widget variants and does not combine the instance with the variants) instance = MVTestInfoProvider.CombineWithMVT(pi, pi.DocumentTemplateInstance, currentCombination.MVTCombinationID, ViewModeEnum.Preview); CMSPortalManager.SaveTemplateChanges(pi, pi.PageTemplateInfo, instance, WidgetZoneTypeEnum.Editor, ViewModeEnum.Edit, tp); } // Remove all variants InfoDataSet <MVTVariantInfo> variants = MVTVariantInfoProvider.GetMVTVariants("MVTVariantPageTemplateID = " + pi.DocumentPageTemplateID, null); if (!DataHelper.DataSourceIsEmpty(variants)) { foreach (MVTVariantInfo info in variants) { MVTVariantInfoProvider.DeleteMVTVariantInfo(info); } } // Clear cached template info pi.PageTemplateInfo.Update(); // Redirect to the same page to update the current view URLHelper.Redirect(URLHelper.CurrentURL); } } }
/// <summary> /// Control ID validation. /// </summary> protected void formElem_OnItemValidation(object sender, ref string errorMessage) { Control ctrl = (Control)sender; if (CMSString.Compare(ctrl.ID, "widgetcontrolid", true) == 0) { TextBox ctrlTextbox = (TextBox)ctrl; string newId = ctrlTextbox.Text; var pti = CMSPortalManager.GetTemplateInstanceForEditing(CurrentPageInfo); // Validate unique ID WebPartInstance existingPart = pti.GetWebPart(newId); if ((existingPart != null) && (existingPart != mWidgetInstance) && (existingPart.InstanceGUID != mWidgetInstance.InstanceGUID)) { // Error - duplicated IDs errorMessage = GetString("Widgets.Properties.ErrorUniqueID"); } } }
/// <summary> /// Initializes menu. /// </summary> protected void InitalizeMenu() { if (!String.IsNullOrEmpty(widgetId) || !String.IsNullOrEmpty(widgetName)) { WidgetInfo wi = null; // Get page info PageInfo pi = CMSWebPartPropertiesPage.GetPageInfo(aliasPath, templateId, culture); if (pi == null) { Visible = false; return; } // Get template instance PageTemplateInstance templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(pi); if (templateInstance != null) { // Get zone type WebPartZoneInstance zoneInstance = templateInstance.GetZone(zoneId); if (zoneInstance != null) { zoneType = zoneInstance.WidgetZoneType; } if (!isNewWidget) { // Get web part WebPartInstance widget = templateInstance.GetWebPart(instanceGuid, widgetId); if ((widget != null) && widget.IsWidget) { // WebPartType = codename, get widget by codename wi = WidgetInfoProvider.GetWidgetInfo(widget.WebPartType); // Set the variant mode (MVT/Content personalization) variantMode = widget.VariantMode; } } } // New widget if (isNewWidget) { int id = ValidationHelper.GetInteger(widgetId, 0); if (id > 0) { wi = WidgetInfoProvider.GetWidgetInfo(id); } else if (!String.IsNullOrEmpty(widgetName)) { wi = WidgetInfoProvider.GetWidgetInfo(widgetName); } } // Get widget info from name if not found yet if ((wi == null) && (!String.IsNullOrEmpty(widgetName))) { wi = WidgetInfoProvider.GetWidgetInfo(widgetName); } if (wi != null) { pageTitle.TitleText = GetString("Widgets.Properties.Title") + " (" + HTMLHelper.HTMLEncode(ResHelper.LocalizeString(wi.WidgetDisplayName)) + ")"; } // Use live or non live dialogs string documentationUrl = String.Empty; // If no zone type defined or not inline => do not show documentation switch (zoneType) { case WidgetZoneTypeEnum.Dashboard: case WidgetZoneTypeEnum.Editor: case WidgetZoneTypeEnum.Group: case WidgetZoneTypeEnum.User: documentationUrl = ResolveUrl("~/CMSModules/Widgets/Dialogs/WidgetDocumentation.aspx"); break; // If no zone set => do not create documentation link default: if (inline) { documentationUrl = ResolveUrl("~/CMSModules/Widgets/Dialogs/WidgetDocumentation.aspx"); } else { return; } break; } // Generate documentation link Literal ltr = new Literal(); pageTitle.RightPlaceHolder.Controls.Add(ltr); // Ensure correct parameters in documentation URL documentationUrl += URLHelper.GetQuery(RequestContext.CurrentURL); if (wi != null) { documentationUrl = URLHelper.UpdateParameterInUrl(documentationUrl, "widgetid", wi.WidgetID.ToString()); } string docScript = "NewWindow('" + ScriptHelper.GetString(documentationUrl, encapsulate: false) + "', 'WebPartPropertiesDocumentation', 800, 800); return false;"; string tooltip = GetString("help.tooltip"); ltr.Text += String.Format ("<div class=\"action-button\"><a onclick=\"{0}\" href=\"#\"><span class=\"sr-only\">{1}</span><i class=\"icon-modal-question cms-icon-80\" title=\"{1}\" aria-hidden=\"true\"></i></a></div>", HTMLHelper.EncodeForHtmlAttribute(docScript), tooltip); } }
protected override void OnLoad(EventArgs e) { plImg = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/plus.png"); minImg = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/minus.png"); if (WebpartID != String.Empty) { wpi = WebPartInfoProvider.GetWebPartInfo(WebpartID); } // Ensure correct view mode if (String.IsNullOrEmpty(AliasPath)) { // Ensure the dashboard mode for the dialog if (!string.IsNullOrEmpty(DashboardName)) { PortalContext.SetRequestViewMode(ViewModeEnum.DashboardWidgets); PortalContext.DashboardName = DashboardName; PortalContext.DashboardSiteName = DashboardSiteName; } // Ensure the design mode for the dialog else { PortalContext.SetRequestViewMode(ViewModeEnum.Design); } } if (WidgetID != 0) { PageInfo pi = null; try { // Load page info from alias path and page template pi = CMSWebPartPropertiesPage.GetPageInfo(AliasPath, PageTemplateID, CultureCode); } catch (PageNotFoundException) { // Do not throw exception if page info not found (e.g. bad alias path) } if (pi != null) { PageTemplateInstance templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(pi); if (templateInstance != null) { // Get the instance of widget WebPartInstance widgetInstance = templateInstance.GetWebPart(InstanceGUID); // Info for zone type WebPartZoneInstance zone = templateInstance.GetZone(ZoneID); if (zone != null) { zoneType = zone.WidgetZoneType; } if (widgetInstance != null) { // Create widget from webpart instance wi = WidgetInfoProvider.GetWidgetInfo(widgetInstance.WebPartType); } } } // If inline widget display columns as in editor zone if (IsInline) { zoneType = WidgetZoneTypeEnum.Editor; } // If no zone set (only global admins allowed to continue) if (zoneType == WidgetZoneTypeEnum.None) { if (!MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.GlobalAdmin)) { RedirectToAccessDenied(GetString("attach.actiondenied")); } } // If wi is still null (new item f.e.) if (wi == null) { // Try to get widget info directly by ID wi = WidgetInfoProvider.GetWidgetInfo(WidgetID); } } String itemDescription = String.Empty; String itemType = String.Empty; String itemDisplayName = String.Empty; String itemDocumentation = String.Empty; String itemIcon = String.Empty; int itemID = 0; // Check whether webpart was found if (wpi != null) { itemDescription = wpi.WebPartDescription; itemType = WebPartInfo.OBJECT_TYPE; itemID = wpi.WebPartID; itemDisplayName = wpi.WebPartDisplayName; itemDocumentation = wpi.WebPartDocumentation; itemIcon = PortalHelper.GetIconHtml(wpi.WebPartThumbnailGUID, wpi.WebPartIconClass ?? PortalHelper.DefaultWebPartIconClass); } // Or widget was found else if (wi != null) { itemDescription = wi.WidgetDescription; itemType = WidgetInfo.OBJECT_TYPE; itemID = wi.WidgetID; itemDisplayName = wi.WidgetDisplayName; itemDocumentation = wi.WidgetDocumentation; itemIcon = PortalHelper.GetIconHtml(wi.WidgetThumbnailGUID, wi.WidgetIconClass ?? PortalHelper.DefaultWidgetIconClass); } if ((wpi != null) || (wi != null)) { // Get WebPart (widget) icon ltrImage.Text = itemIcon; // Set description of webpart ltlDescription.Text = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(itemDescription)); // Get description from parent weboart if webpart is inherited if ((wpi != null) && (string.IsNullOrEmpty(wpi.WebPartDescription) && (wpi.WebPartParentID > 0))) { WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null) { ltlDescription.Text = HTMLHelper.HTMLEncode(pwpi.WebPartDescription); } } FormInfo fi = null; // Generate properties if (wpi != null) { // Get form info from parent if webpart is inherited if (wpi.WebPartParentID != 0) { WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null) { fi = GetWebPartProperties(pwpi); } } else { fi = GetWebPartProperties(wpi); } } else if (wi != null) { fi = GetWidgetProperties(wi); } // Generate properties if (fi != null) { GenerateProperties(fi); } // Generate documentation text if (itemDocumentation == null || itemDocumentation.Trim() == "") { if ((wpi != null) && (wpi.WebPartParentID != 0)) { WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null && pwpi.WebPartDocumentation.Trim() != "") { ltlContent.Text = HTMLHelper.ResolveUrls(pwpi.WebPartDocumentation, null); } else { ltlContent.Text = "<br /><div style=\"padding-left:5px; font-weight: bold;\">" + GetString("WebPartDocumentation.DocumentationText") + "</div><br />"; } } else { ltlContent.Text = "<br /><div style=\"padding-left:5px; font-weight: bold;\">" + GetString("WebPartDocumentation.DocumentationText") + "</div><br />"; } } else { ltlContent.Text = HTMLHelper.ResolveUrls(itemDocumentation, null); } } ScriptHelper.RegisterJQuery(Page); string script = @" $cmsj(document.body).ready(initializeResize); function initializeResize () { resizeareainternal(); $cmsj(window).resize(function() { resizeareainternal(); }); } function resizeareainternal () { var height = document.body.clientHeight ; var panel = document.getElementById ('" + divScrolable.ClientID + @"'); // Get parent footer to count proper height (with padding included) var footer = $cmsj('#divFooter'); panel.style.height = (height - footer.outerHeight() - panel.offsetTop) +'px'; }"; ScriptHelper.RegisterClientScriptBlock(Page, typeof(Page), "mainScript", ScriptHelper.GetScript(script)); // Init tabs tabControlElem.UsePostback = true; tabControlElem.AddTab(new UITabItem() { Text = GetString("webparts.documentation"), }); tabControlElem.AddTab(new UITabItem() { Text = GetString("general.properties"), }); // Disable caching Response.Cache.SetNoStore(); base.OnLoad(e); }
/// <summary> /// Saves widget properties. /// </summary> public bool Save() { if (VariantID > 0) { // Check MVT/CP security if (!CheckPermissions("Manage")) { DisplayError("general.modifynotallowed"); return(false); } } // Save the data if ((pi != null) && (templateInstance != null) && SaveForm(formCustom)) { // Check manage permission for non-livesite version if ((CMSContext.ViewMode != ViewModeEnum.LiveSite) && (CMSContext.ViewMode != ViewModeEnum.DashboardWidgets)) { if (CMSContext.CurrentUser.IsAuthorizedPerDocument(pi.NodeID, pi.ClassName, NodePermissionsEnum.Modify) != AuthorizationResultEnum.Allowed) { return(false); } } PageTemplateInfo pti = templateInstance.ParentPageTemplate; if ((CMSContext.ViewMode == ViewModeEnum.Design) && CMSObjectHelper.IsCheckedOutByOtherUser(pti)) { string userName = null; UserInfo ui = UserInfoProvider.GetUserInfo(pti.Generalized.IsCheckedOutByUserID); if (ui != null) { userName = HTMLHelper.HTMLEncode(ui.GetFormattedUserName(IsLiveSite)); } DisplayError(string.Format(GetString("ObjectEditMenu.CheckedOutByAnotherUser"), pti.ObjectType, pti.DisplayName, userName)); return(false); } // Get the zone zone = templateInstance.EnsureZone(ZoneId); if (zone != null) { zone.WidgetZoneType = zoneType; // Add new widget if (IsNewWidget) { bool isLayoutZone = (QueryHelper.GetBoolean("layoutzone", false)); int widgetID = ValidationHelper.GetInteger(WidgetId, 0); // Create new widget instance widgetInstance = PortalHelper.AddNewWidget(widgetID, ZoneId, ZoneType, isLayoutZone, templateInstance, null); } widgetInstance.XMLVersion = 1; if (IsNewVariant) { widgetInstance = widgetInstance.Clone(); if (pi.DocumentTemplateInstance.WebPartZones.Count == 0) { // Save to the document as editor admin changes TreeNode node = DocumentHelper.GetDocument(pi.DocumentID, tree); // Extract and set the document web parts node.SetValue("DocumentWebParts", templateInstance.GetZonesXML(WidgetZoneTypeEnum.Editor)); // Save the document DocumentHelper.UpdateDocument(node, tree); } } // Get basicform's datarow and update widget SaveFormToWidget(formCustom, templateInstance); if (IsNewVariant) { // Ensures unique id for new widget variant widgetInstance.ControlID = WebPartZoneInstance.GetUniqueWebPartId(wi.WidgetName, zone.ParentTemplateInstance); } // Allow set dashboard in design mode if ((zoneType == WidgetZoneTypeEnum.Dashboard) && String.IsNullOrEmpty(PortalContext.DashboardName)) { PortalContext.SetViewMode(ViewModeEnum.Design); } bool isWidgetVariant = (VariantID > 0) || IsNewVariant; if (!isWidgetVariant) { // Save the changes CMSPortalManager.SaveTemplateChanges(pi, templateInstance, zoneType, CMSContext.ViewMode, tree); } else if ((CMSContext.ViewMode == ViewModeEnum.Edit) && (zoneType == WidgetZoneTypeEnum.Editor)) { Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable; PortalHelper.SaveWebPartVariantChanges(widgetInstance, VariantID, 0, VariantMode, properties); // Clear the document template templateInstance.ParentPageTemplate.ParentPageInfo.DocumentTemplateInstance = null; // Log widget variant synchronization TreeNode node = DocumentHelper.GetDocument(pi.DocumentID, tree); DocumentSynchronizationHelper.LogDocumentChange(node, TaskTypeEnum.UpdateDocument, tree); } } // Reload the form (because of macro values set only by JS) formCustom.ReloadData(); // Clear the cached web part if (InstanceGUID != null) { CacheHelper.TouchKey("webpartinstance|" + InstanceGUID.ToString().ToLowerCSafe()); } return(true); } return(false); }
/// <summary> /// Saves widget properties. /// </summary> public bool Save() { if (VariantID > 0) { // Check MVT/CP security if (!CheckPermissions("Manage")) { ShowError("general.modifynotallowed"); return(false); } } // Save the data if ((pi != null) && (pti != null) && (templateInstance != null) && SaveForm(formCustom)) { // Check manage permission for non-livesite version if ((CMSContext.ViewMode != ViewModeEnum.LiveSite) && (CMSContext.ViewMode != ViewModeEnum.DashboardWidgets)) { if (CMSContext.CurrentUser.IsAuthorizedPerDocument(pi.NodeId, pi.ClassName, NodePermissionsEnum.Modify) != AuthorizationResultEnum.Allowed) { return(false); } } // Get the zone zone = templateInstance.EnsureZone(ZoneId); if (zone != null) { zone.WidgetZoneType = zoneType; // Add new widget if (IsNewWidget) { AddWidget(); } if (IsNewVariant) { widgetInstance = widgetInstance.Clone(); if (pi.DocumentTemplateInstance.WebPartZones.Count == 0) { // Save to the document as editor admin changes TreeNode node = DocumentHelper.GetDocument(pi.DocumentId, tree); // Extract and set the document web parts node.SetValue("DocumentWebParts", templateInstance.GetZonesXML(WidgetZoneTypeEnum.Editor)); // Save the document DocumentHelper.UpdateDocument(node, tree); } } // Get basicform's datarow and update widget SaveFormToWidget(formCustom); if (IsNewVariant) { // Ensures unique id for new widget variant widgetInstance.ControlID = WebPartZoneInstance.GetUniqueWebPartId(wi.WidgetName, zone.ParentTemplateInstance); } // Allow set dashboard in design mode if ((zoneType == WidgetZoneTypeEnum.Dashboard) && String.IsNullOrEmpty(PortalContext.DashboardName)) { PortalContext.SetViewMode(ViewModeEnum.Design); } bool isWidgetVariant = (VariantID > 0) || IsNewVariant; if (!isWidgetVariant) { // Save the changes CMSPortalManager.SaveTemplateChanges(pi, pti, templateInstance, zoneType, CMSContext.ViewMode, tree); } else if ((CMSContext.ViewMode == ViewModeEnum.Edit) && (zoneType == WidgetZoneTypeEnum.Editor)) { // Save the variant properties if ((widgetInstance != null) && (widgetInstance.ParentZone != null) && (widgetInstance.ParentZone.ParentTemplateInstance != null) && (widgetInstance.ParentZone.ParentTemplateInstance.ParentPageTemplate != null)) { string variantName = string.Empty; string variantDisplayName = string.Empty; string variantDisplayCondition = string.Empty; string variantDescription = string.Empty; bool variantEnabled = true; string zoneId = widgetInstance.ParentZone.ZoneID; int templateId = widgetInstance.ParentZone.ParentTemplateInstance.ParentPageTemplate.PageTemplateId; Guid instanceGuid = Guid.Empty; XmlDocument doc = new XmlDocument(); XmlNode xmlWebParts = null; xmlWebParts = widgetInstance.GetXmlNode(doc); instanceGuid = InstanceGUID; Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable; if (properties != null) { variantName = ValidationHelper.GetString(properties["codename"], string.Empty); variantDisplayName = ValidationHelper.GetString(properties["displayname"], string.Empty); variantDescription = ValidationHelper.GetString(properties["description"], string.Empty); variantEnabled = ValidationHelper.GetBoolean(properties["enabled"], true); if (VariantMode == VariantModeEnum.ContentPersonalization) { variantDisplayCondition = ValidationHelper.GetString(properties["condition"], string.Empty); } } // Save the web part variant properties if (VariantMode == VariantModeEnum.MVT) { ModuleCommands.OnlineMarketingSaveMVTVariant(VariantID, variantName, variantDisplayName, variantDescription, variantEnabled, zoneId, widgetInstance.InstanceGUID, templateId, pi.DocumentId, xmlWebParts); } else if (VariantMode == VariantModeEnum.ContentPersonalization) { ModuleCommands.OnlineMarketingSaveContentPersonalizationVariant(VariantID, variantName, variantDisplayName, variantDescription, variantEnabled, variantDisplayCondition, zoneId, widgetInstance.InstanceGUID, templateId, pi.DocumentId, xmlWebParts); } // Clear the document template templateInstance.ParentPageTemplate.ParentPageInfo.DocumentTemplateInstance = null; // Log widget variant synchronization TreeNode node = DocumentHelper.GetDocument(pi.DocumentId, tree); DocumentSynchronizationHelper.LogDocumentChange(node, TaskTypeEnum.UpdateDocument, tree); } } } // Reload the form (because of macro values set only by JS) formCustom.ReloadData(); // Clear the cached web part if (InstanceGUID != null) { CacheHelper.TouchKey("webpartinstance|" + InstanceGUID.ToString().ToLower()); } return(true); } return(false); }
/// <summary> /// Saves webpart properties. /// </summary> public bool Save() { // Check MVT/CP security if (VariantID > 0) { // Check OnlineMarketing permissions. if (!CheckPermissions("Manage")) { ShowError(GetString("general.modifynotallowed")); return(false); } } // Save the data if ((pi != null) && (pti != null) && (templateInstance != null) && SaveForm(form)) { if (SynchronizationHelper.IsCheckedOutByOtherUser(pti)) { string userName = null; UserInfo ui = UserInfoProvider.GetUserInfo(pti.Generalized.IsCheckedOutByUserID); if (ui != null) { userName = HTMLHelper.HTMLEncode(ui.GetFormattedUserName(IsLiveSite)); } ShowError(string.Format(GetString("ObjectEditMenu.CheckedOutByAnotherUser"), pti.TypeInfo.ObjectType, pti.DisplayName, userName)); return(false); } // Add web part if new if (IsNewWebPart) { int webpartId = ValidationHelper.GetInteger(WebPartID, 0); // Ensure layout zone flag if (QueryHelper.GetBoolean("layoutzone", false)) { WebPartZoneInstance zone = pti.TemplateInstance.EnsureZone(ZoneID); zone.LayoutZone = true; } webPartInstance = PortalHelper.AddNewWebPart(webpartId, ZoneID, false, ZoneVariantID, Position, templateInstance); // Set default layout if (wpi.WebPartParentID > 0) { WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetDefaultLayout(wpi.WebPartID); if (wpli != null) { webPartInstance.SetValue("WebPartLayout", wpli.WebPartLayoutCodeName); } } } webPartInstance.XMLVersion = 1; if (IsNewVariant) { webPartInstance = webPartInstance.Clone(); webPartInstance.VariantMode = VariantModeFunctions.GetVariantModeEnum(QueryHelper.GetString("variantmode", String.Empty).ToLowerInvariant()); } // Get basic form's data row and update web part SaveFormToWebPart(form); // Set new position if set if (PositionLeft > 0) { webPartInstance.SetValue("PositionLeft", PositionLeft); } if (PositionTop > 0) { webPartInstance.SetValue("PositionTop", PositionTop); } bool isWebPartVariant = (VariantID > 0) || (ZoneVariantID > 0) || IsNewVariant; if (!isWebPartVariant) { // Save the changes CMSPortalManager.SaveTemplateChanges(pi, templateInstance, WidgetZoneTypeEnum.None, ViewModeEnum.Design, tree); } else { Hashtable varProperties = WindowHelper.GetItem("variantProperties") as Hashtable; // Save changes to the web part variant VariantHelper.SaveWebPartVariantChanges(webPartInstance, VariantID, ZoneVariantID, VariantMode, varProperties); } // Reload the form (because of macro values set only by JS) form.ReloadData(); // Clear the cached web part CacheHelper.TouchKey("webpartinstance|" + InstanceGUID.ToString().ToLowerInvariant()); ShowChangesSaved(); return(true); } if (webPartInstance?.ParentZone?.ParentTemplateInstance != null) { // Reload the zone/web part variants when saving of the form fails webPartInstance.ParentZone.ParentTemplateInstance.LoadVariants(true, VariantModeEnum.None); } return(false); }
/// <summary> /// Saves widget properties. /// </summary> public bool Save() { if (VariantID > 0) { // Check MVT/CP security if (!CheckPermissions("Manage")) { DisplayError("general.modifynotallowed"); return(false); } } // Save the data if ((CurrentPageInfo != null) && (mTemplateInstance != null) && SaveForm(formCustom)) { ViewModeEnum viewMode = PortalContext.ViewMode; // Check manage permission for non-livesite version if (!viewMode.IsLiveSite() && viewMode != ViewModeEnum.DashboardWidgets && viewMode != ViewModeEnum.UserWidgets) { if (CurrentUser.IsAuthorizedPerDocument(CurrentPageInfo.NodeID, CurrentPageInfo.ClassName, NodePermissionsEnum.Modify) != AuthorizationResultEnum.Allowed) { DisplayError("general.modifynotallowed"); return(false); } // Check design permissions if (PortalContext.IsDesignMode(viewMode, false) && !PortalContext.CurrentUserIsDesigner) { RedirectToAccessDenied("CMS.Design", "Design"); } } PageTemplateInfo pti = mTemplateInstance.ParentPageTemplate; if (PortalContext.IsDesignMode(viewMode) && SynchronizationHelper.IsCheckedOutByOtherUser(pti)) { string userName = null; UserInfo ui = UserInfoProvider.GetUserInfo(pti.Generalized.IsCheckedOutByUserID); if (ui != null) { userName = HTMLHelper.HTMLEncode(ui.GetFormattedUserName(IsLiveSite)); } DisplayError(string.Format(GetString("ObjectEditMenu.CheckedOutByAnotherUser"), pti.TypeInfo.ObjectType, pti.DisplayName, userName)); return(false); } // Get the zone mWebPartZoneInstance = mTemplateInstance.EnsureZone(ZoneId); if (mWebPartZoneInstance != null) { mWebPartZoneInstance.WidgetZoneType = ZoneType; // Add new widget if (IsNewWidget) { bool isLayoutZone = (QueryHelper.GetBoolean("layoutzone", false)); int widgetID = ValidationHelper.GetInteger(WidgetId, 0); // Create new widget instance mWidgetInstance = PortalHelper.AddNewWidget(widgetID, ZoneId, ZoneType, isLayoutZone, mTemplateInstance); } // Ensure handling of the currently edited object (if not exists -> redirect) UIContext.EditedObject = mWidgetInstance; mWidgetInstance.XMLVersion = 1; if (IsNewVariant) { mWidgetInstance = mWidgetInstance.Clone(); // Check whether the editor widgets have been already customized if (CurrentPageInfo.DocumentTemplateInstance.WebPartZones.Count == 0) { // There are no customized editor widgets yet => copy the default editor widgets from the page template under the document (to enable customization) // Save to the document as editor admin changes TreeNode node = DocumentHelper.GetDocument(CurrentPageInfo.DocumentID, mTreeProvider); // Extract and set the document web parts node.SetValue("DocumentWebParts", mTemplateInstance.GetZonesXML(WidgetZoneTypeEnum.Editor)); // Save the document DocumentHelper.UpdateDocument(node, mTreeProvider); } } bool isLayoutWidget = ((mWebPartInfo != null) && ((WebPartTypeEnum)mWebPartInfo.WebPartType == WebPartTypeEnum.Layout)); // Get basicform's datarow and update widget SaveFormToWidget(formCustom, mTemplateInstance, isLayoutWidget); // Ensure unique id for new widget variant or layout widget if (IsNewVariant || (isLayoutWidget && IsNewWidget)) { string controlId = GetUniqueWidgetId(mWidgetInfo.WidgetName); if (!string.IsNullOrEmpty(controlId)) { mWidgetInstance.ControlID = controlId; } else { DisplayError("Unable to generate unique widget id."); return(false); } } // Allow set dashboard in design mode if ((ZoneType == WidgetZoneTypeEnum.Dashboard) && String.IsNullOrEmpty(PortalContext.DashboardName)) { viewMode = ViewModeEnum.Design; PortalContext.SetViewMode(ViewModeEnum.Design); } bool isWidgetVariant = (VariantID > 0) || IsNewVariant; if (!isWidgetVariant) { // Save the changes if ((viewMode.IsEdit(true) || viewMode.IsEditLive()) && (ZoneType == WidgetZoneTypeEnum.Editor)) { if (DocumentManager.AllowSave) { // Store the editor widgets in the temporary interlayer PortalContext.SaveEditorWidgets(CurrentPageInfo.DocumentID, mTemplateInstance.GetZonesXML(WidgetZoneTypeEnum.Editor)); } } else { // Save the changes CMSPortalManager.SaveTemplateChanges(CurrentPageInfo, mTemplateInstance, ZoneType, viewMode, mTreeProvider); } } else if ((viewMode.IsEdit()) && (ZoneType == WidgetZoneTypeEnum.Editor)) { Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable; VariantHelper.SaveWebPartVariantChanges(mWidgetInstance, VariantID, 0, VariantMode, properties); // Log widget variant synchronization TreeNode node = DocumentHelper.GetDocument(CurrentPageInfo.DocumentID, mTreeProvider); DocumentSynchronizationHelper.LogDocumentChange(node, TaskTypeEnum.UpdateDocument, mTreeProvider); } } // Reload the form (because of macro values set only by JS) formCustom.ReloadData(); // Display info message ShowChangesSaved(); // Clear the cached web part CacheHelper.TouchKey("webpartinstance|" + InstanceGUID.ToString().ToLowerCSafe()); return(true); } return(false); }
/// <summary> /// Saves webpart properties. /// </summary> public bool Save() { // Check MVT/CP security if (VariantID > 0) { // Check OnlineMarketing permissions. if (!CheckPermissions("Manage")) { lblError.Visible = true; lblError.Text = GetString("general.modifynotallowed"); return(false); } } // Save the data if ((pi != null) && (pti != null) && (templateInstance != null) && SaveForm(form)) { // Add web part if new if (IsNewWebPart) { AddWebPart(); } WebPartInstance originalWebPartInstance = webPartInstance; if (IsNewVariant) { webPartInstance = webPartInstance.Clone(); webPartInstance.VariantMode = VariantModeFunctions.GetVariantModeEnum(QueryHelper.GetString("variantmode", String.Empty).ToLower()); } // Get basicform's datarow and update webpart SaveFormToWebPart(form); bool isWebPartVariant = (VariantID > 0) || (ZoneVariantID > 0) || IsNewVariant; if (!isWebPartVariant) { // Save the changes CMSPortalManager.SaveTemplateChanges(pi, pti, templateInstance, WidgetZoneTypeEnum.None, ViewModeEnum.Design, tree); } else { // Save the variant properties if ((webPartInstance != null) && (webPartInstance.ParentZone != null) && (!webPartInstance.ParentZone.HasVariants) && // Save only if the parent zone does not have any variants (webPartInstance.ParentZone.ParentTemplateInstance != null) && (webPartInstance.ParentZone.ParentTemplateInstance.ParentPageTemplate != null)) { string variantName = string.Empty; string variantDisplayName = string.Empty; string variantDisplayCondition = string.Empty; string variantDescription = string.Empty; bool variantEnabled = true; string zoneId = webPartInstance.ParentZone.ZoneID; int templateId = webPartInstance.ParentZone.ParentTemplateInstance.ParentPageTemplate.PageTemplateId; Guid instanceGuid = Guid.Empty; XmlDocument doc = new XmlDocument(); XmlNode xmlWebParts = null; if (ZoneVariantID > 0) { // This webpart is in a zone variant therefore save the whole variant webparts xmlWebParts = webPartInstance.ParentZone.GetXmlNode(doc); if (VariantMode == VariantModeEnum.MVT) { // MVT variant ModuleCommands.OnlineMarketingSaveMVTVariantWebParts(ZoneVariantID, xmlWebParts); } else if (VariantMode == VariantModeEnum.ContentPersonalization) { // Content personalization variant ModuleCommands.OnlineMarketingSaveContentPersonalizationVariantWebParts(ZoneVariantID, xmlWebParts); } } else { // web part/widget variant xmlWebParts = webPartInstance.GetXmlNode(doc); instanceGuid = InstanceGUID; Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable; if (properties != null) { variantName = ValidationHelper.GetString(properties["codename"], string.Empty); variantDisplayName = ValidationHelper.GetString(properties["displayname"], string.Empty); variantDescription = ValidationHelper.GetString(properties["description"], string.Empty); variantEnabled = ValidationHelper.GetBoolean(properties["enabled"], true); if (VariantMode == VariantModeEnum.ContentPersonalization) { variantDisplayCondition = ValidationHelper.GetString(properties["condition"], string.Empty); } } // Save the web part variant properties if (VariantMode == VariantModeEnum.MVT) { // MVT variant ModuleCommands.OnlineMarketingSaveMVTVariant(VariantID, variantName, variantDisplayName, variantDescription, variantEnabled, zoneId, webPartInstance.InstanceGUID, templateId, 0, xmlWebParts); } else if (VariantMode == VariantModeEnum.ContentPersonalization) { // Content personalization variant ModuleCommands.OnlineMarketingSaveContentPersonalizationVariant(VariantID, variantName, variantDisplayName, variantDescription, variantEnabled, variantDisplayCondition, zoneId, webPartInstance.InstanceGUID, templateId, 0, xmlWebParts); } // The variants are cached -> Reload if (originalWebPartInstance != null) { originalWebPartInstance.LoadVariants(true, VariantMode); } } } } // Reload the form (because of macro values set only by JS) form.ReloadData(); // Clear the cached web part if (InstanceGUID != null) { CacheHelper.TouchKey("webpartinstance|" + InstanceGUID.ToString().ToLower()); } return(true); } else if ((webPartInstance != null) && (webPartInstance.ParentZone != null)) { // Reload the zone/web part variants when saving of the form fails webPartInstance.ParentZone.LoadVariants(true, VariantModeEnum.None); } return(false); }
/// <summary> /// Initializes menu. /// </summary> protected void InitalizeMenu() { string zoneId = QueryHelper.GetString("zoneid", ""); bool isNewWidget = QueryHelper.GetBoolean("isnew", false); WidgetZoneTypeEnum zoneType = WidgetZoneTypeEnum.None; if (!String.IsNullOrEmpty(widgetId) || !String.IsNullOrEmpty(widgetName)) { WidgetInfo wi = null; // get pageinfo PageInfo pi = null; try { pi = CMSWebPartPropertiesPage.GetPageInfo(aliasPath, templateId); } catch (PageNotFoundException) { // Do not throw exception if page info not found (e.g. bad alias path) } if (pi == null) { this.Visible = false; return; } // Get template instance PageTemplateInstance templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(pi); if (templateInstance != null) { // Get zone type WebPartZoneInstance zoneInstance = templateInstance.GetZone(zoneId); if (zoneInstance != null) { zoneType = zoneInstance.WidgetZoneType; } if (!isNewWidget) { // Get web part WebPartInstance widget = templateInstance.GetWebPart(instanceGuid, widgetId); if ((widget != null) && widget.IsWidget) { // WebPartType = codename, get widget by codename wi = WidgetInfoProvider.GetWidgetInfo(widget.WebPartType); // Set the variant mode (MVT/Content personalization) variantMode = widget.VariantMode; } } } // New widget if (isNewWidget) { int id = ValidationHelper.GetInteger(widgetId, 0); if (id > 0) { wi = WidgetInfoProvider.GetWidgetInfo(id); } else if (!String.IsNullOrEmpty(widgetName)) { wi = WidgetInfoProvider.GetWidgetInfo(widgetName); } } // Get widget info from name if not found yet if ((wi == null) && (!String.IsNullOrEmpty(widgetName))) { wi = WidgetInfoProvider.GetWidgetInfo(widgetName); } if (wi != null) { PageTitle.TitleText = GetString("Widgets.Properties.Title") + " (" + HTMLHelper.HTMLEncode(ResHelper.LocalizeString(wi.WidgetDisplayName)) + ")"; } // Use live or non live dialogs string documentationUrl = String.Empty; // If no zonetype defined or not inline dont show documentation switch (zoneType) { case WidgetZoneTypeEnum.Dashboard: case WidgetZoneTypeEnum.Editor: case WidgetZoneTypeEnum.Group: case WidgetZoneTypeEnum.User: documentationUrl = ResolveUrl("~/CMSModules/Widgets/Dialogs/WidgetDocumentation.aspx"); break; // If no zone set dont create documentation link default: if (isInline) { documentationUrl = ResolveUrl("~/CMSModules/Widgets/Dialogs/WidgetDocumentation.aspx"); } else { return; } break; } // Generate documentation link Literal ltr = new Literal(); PageTitle.RightPlaceHolder.Controls.Add(ltr); // Ensure correct parameters in documentation url documentationUrl += URLHelper.GetQuery(URLHelper.CurrentURL); if (!String.IsNullOrEmpty(widgetName)) { documentationUrl = URLHelper.UpdateParameterInUrl(documentationUrl, "widgetname", widgetName); } if (!String.IsNullOrEmpty(widgetId)) { documentationUrl = URLHelper.UpdateParameterInUrl(documentationUrl, "widgetid", widgetId); } string docScript = "NewWindow('" + documentationUrl + "', 'WebPartPropertiesDocumentation', 800, 800); return false;"; ltr.Text = "<table cellpadding=\"0\" cellspacing=\"0\"><tr><td>"; ltr.Text += "<a onclick=\"" + docScript + "\" href=\"#\"><img src=\"" + ResolveUrl(GetImageUrl("CMSModules/CMS_PortalEngine/Documentation.png")) + "\" style=\"border-width: 0px;\"></a>"; ltr.Text += "</td>"; ltr.Text += "<td>"; ltr.Text += "<a onclick=\"" + docScript + "\" href=\"#\">" + GetString("WebPartPropertie.DocumentationLink") + "</a>"; ltr.Text += "</td></tr></table>"; tabsElem.OnTabCreated += new UITabs.TabCreatedEventHandler(tabElem_OnTabCreated); tabsElem.UrlTarget = "widgetpropertiescontent"; tabsElem.OpenTabContentAfterLoad = !isInline; } }
/// <summary> /// Saves web part zone properties. /// </summary> public bool Save() { if (ZoneVariantID > 0) { // Check OnlineMarketing permissions if (!CheckPermissions("Manage")) { lblError.Visible = true; lblError.Text = GetString("general.modifynotallowed"); return(false); } } // Save the data if (formElem.SaveData("")) { DataRow dr = formElem.DataRow; // Get basicform's datarow and update the fields if ((webPartZone != null) && (dr != null) && (pti != null)) { // New variant // Clone original zone WebPartZoneInstance originalWebPartZone = webPartZone; if (IsNewVariant) { webPartZone = pti.EnsureZone(webPartZone.ZoneID); // Ensure that all the zones which are not saved in the template already will be saved now // This is a case for new layout zones if (!webPartZone.HasVariants) { TreeProvider tree = new TreeProvider(CMSContext.CurrentUser); CMSPortalManager.SaveTemplateChanges(pi, pti, pti.TemplateInstance, WidgetZoneTypeEnum.None, ViewModeEnum.Design, tree); } webPartZone = webPartZone.Clone(); bool webPartIdExists = false; int offset = 0; string webPartControlId = string.Empty; // Re-generate web part unique IDs foreach (WebPartInstance wpi in webPartZone.WebParts) { webPartIdExists = false; offset = 0; // Set new web part unique ID string baseId = Regex.Replace(wpi.ControlID, "\\d+$", ""); do { webPartControlId = WebPartZoneInstance.GetUniqueWebPartId(baseId, pti.TemplateInstance, offset); // Check if the returned web part control id is already used in the new zone variant webPartIdExists = (webPartZone.GetWebPart(webPartControlId) != null); offset++; } while (webPartIdExists); wpi.ControlID = webPartControlId; wpi.InstanceGUID = new Guid(); } } // If zone type changed, delete all webparts in the zone if (ValidationHelper.GetString(webPartZone.GetValue("WidgetZoneType"), "") != ValidationHelper.GetString(dr["WidgetZoneType"], "")) { // Remove all variants if (variantMode == VariantModeEnum.MVT) { ModuleCommands.OnlineMarketingRemoveMVTWebPartVariants(webPartZone.WebParts); } else if (variantMode == VariantModeEnum.ContentPersonalization) { ModuleCommands.OnlineMarketingRemoveContentPersonalizationWebPartVariants(webPartZone.WebParts); } webPartZone.WebParts.Clear(); } foreach (DataColumn column in dr.Table.Columns) { webPartZone.MacroTable[column.ColumnName.ToLower()] = formElem.MacroTable[column.ColumnName.ToLower()]; webPartZone.SetValue(column.ColumnName, dr[column]); } // Ensure the layout zone flag webPartZone.LayoutZone = QueryHelper.GetBoolean("layoutzone", false); // Save standard zone if ((ZoneVariantID == 0) && (!IsNewVariant)) { // Update page template PageTemplateInfoProvider.SetPageTemplateInfo(pti); } else { // Save zone variant if ((webPartZone != null) && (webPartZone.ParentTemplateInstance != null) && (webPartZone.ParentTemplateInstance.ParentPageTemplate != null) && (!webPartZone.WebPartsContainVariants)) // Save only if any of the child web parts does not have variants { // Save the variant properties string variantName = string.Empty; string variantDisplayName = string.Empty; string variantDisplayCondition = string.Empty; string variantDescription = string.Empty; bool variantEnabled = true; string zoneId = webPartZone.ZoneID; int templateId = webPartZone.ParentTemplateInstance.ParentPageTemplate.PageTemplateId; XmlDocument doc = new XmlDocument(); XmlNode xmlWebParts = webPartZone.GetXmlNode(doc); // Get variant description properties Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable; if (properties != null) { variantName = ValidationHelper.GetString(properties["codename"], string.Empty); variantDisplayName = ValidationHelper.GetString(properties["displayname"], string.Empty); variantDescription = ValidationHelper.GetString(properties["description"], string.Empty); variantEnabled = ValidationHelper.GetBoolean(properties["enabled"], true); if (PortalContext.ContentPersonalizationEnabled) { variantDisplayCondition = ValidationHelper.GetString(properties["condition"], string.Empty); } } if (variantMode == VariantModeEnum.MVT) { // Save MVT variant properties mZoneVariantID = ModuleCommands.OnlineMarketingSaveMVTVariant(ZoneVariantID, variantName, variantDisplayName, variantDescription, variantEnabled, zoneId, Guid.Empty, templateId, 0, xmlWebParts); } else if (variantMode == VariantModeEnum.ContentPersonalization) { // Save Content personalization variant properties mZoneVariantID = ModuleCommands.OnlineMarketingSaveContentPersonalizationVariant(ZoneVariantID, variantName, variantDisplayName, variantDescription, variantEnabled, variantDisplayCondition, zoneId, Guid.Empty, templateId, 0, xmlWebParts); } // The variants are cached -> Reload if (originalWebPartZone != null) { originalWebPartZone.LoadVariants(true, variantMode); } } } // Reload the form (because of macro values set only by JS) this.formElem.LoadData(dr); return(true); } else { return(false); } } else { return(false); } }
protected override void OnLoad(EventArgs e) { plImg = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/plus.png"); minImg = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/minus.png"); if (WebpartID != String.Empty) { wpi = WebPartInfoProvider.GetWebPartInfo(WebpartID); } // Ensure correct view mode if (String.IsNullOrEmpty(AliasPath)) { // Ensure the dashboard mode for the dialog if (!string.IsNullOrEmpty(DashboardName)) { PortalContext.SetRequestViewMode(ViewModeEnum.DashboardWidgets); PortalContext.DashboardName = DashboardName; PortalContext.DashboardSiteName = DashboardSiteName; } // Ensure the design mode for the dialog else { PortalContext.SetRequestViewMode(ViewModeEnum.Design); } } if (WidgetID != String.Empty) { PageInfo pi = null; try { // Load page info from alias path and page template pi = CMSWebPartPropertiesPage.GetPageInfo(AliasPath, PageTemplateID, CultureCode); } catch (PageNotFoundException) { // Do not throw exception if page info not found (e.g. bad alias path) } if (pi != null) { PageTemplateInstance templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(pi); if (templateInstance != null) { // Get the instance of widget WebPartInstance widgetInstance = templateInstance.GetWebPart(InstanceGUID, WidgetID); // Info for zone type WebPartZoneInstance zone = templateInstance.GetZone(ZoneID); if (zone != null) { zoneType = zone.WidgetZoneType; } if (widgetInstance != null) { // Create widget from webpart instance wi = WidgetInfoProvider.GetWidgetInfo(widgetInstance.WebPartType); } } } // If inline widget display columns as in editor zone if (IsInline) { zoneType = WidgetZoneTypeEnum.Editor; } // If no zone set (only global admins allowed to continue) if (zoneType == WidgetZoneTypeEnum.None) { if (!CMSContext.CurrentUser.UserSiteManagerAdmin) { RedirectToAccessDenied(GetString("attach.actiondenied")); } } // If wi is still null (new item f.e.) if (wi == null) { // Try to get widget info directly by ID if (!IsNew) { wi = WidgetInfoProvider.GetWidgetInfo(WidgetID); } else { wi = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(WidgetID, 0)); } } } String itemDescription = String.Empty; String itemType = String.Empty; String itemDisplayName = String.Empty; String itemDocumentation = String.Empty; int itemID = 0; // Check whether webpart was found if (wpi != null) { itemDescription = wpi.WebPartDescription; itemType = PortalObjectType.WEBPART; itemID = wpi.WebPartID; itemDisplayName = wpi.WebPartDisplayName; itemDocumentation = wpi.WebPartDocumentation; } // Or widget was found else if (wi != null) { itemDescription = wi.WidgetDescription; itemType = PortalObjectType.WIDGET; itemID = wi.WidgetID; itemDisplayName = wi.WidgetDisplayName; itemDocumentation = wi.WidgetDocumentation; } if ((wpi != null) || (wi != null)) { // Get WebPart (widget) image DataSet ds = MetaFileInfoProvider.GetMetaFiles(itemID, itemType); // Set image url of exists if (!DataHelper.DataSourceIsEmpty(ds)) { MetaFileInfo mtfi = new MetaFileInfo(ds.Tables[0].Rows[0]); if (mtfi != null) { if (mtfi.MetaFileImageWidth > 385) { imgTeaser.Width = 385; } imgTeaser.ImageUrl = ResolveUrl("~/CMSPages/GetMetaFile.aspx?fileguid=" + mtfi.MetaFileGUID.ToString()); } } else { // Set default image imgTeaser.ImageUrl = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/imagenotavailable.png"); } // Additional image information imgTeaser.ToolTip = HTMLHelper.HTMLEncode(itemDisplayName); imgTeaser.AlternateText = HTMLHelper.HTMLEncode(itemDisplayName); // Set description of webpart ltlDescription.Text = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(itemDescription)); // Get description from parent weboart if webpart is inherited if ((wpi != null) && (string.IsNullOrEmpty(wpi.WebPartDescription) && (wpi.WebPartParentID > 0))) { WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null) { ltlDescription.Text = HTMLHelper.HTMLEncode(pwpi.WebPartDescription); } } FormInfo fi = null; // Generate properties if (wpi != null) { // Get form info from parent if webpart is inherited if (wpi.WebPartParentID != 0) { WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null) { fi = GetWebPartProperties(pwpi); } } else { fi = GetWebPartProperties(wpi); } } else if (wi != null) { fi = GetWidgetProperties(wi); } // Generate properties if (fi != null) { GenerateProperties(fi); } // Generate documentation text if (itemDocumentation == null || itemDocumentation.Trim() == "") { if ((wpi != null) && (wpi.WebPartParentID != 0)) { WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null && pwpi.WebPartDocumentation.Trim() != "") { ltlContent.Text = HTMLHelper.ResolveUrls(pwpi.WebPartDocumentation, null); } else { ltlContent.Text = "<br /><div style=\"padding-left:5px; font-weight: bold;\">" + GetString("WebPartDocumentation.DocumentationText") + "</div><br />"; } } else { ltlContent.Text = "<br /><div style=\"padding-left:5px; font-weight: bold;\">" + GetString("WebPartDocumentation.DocumentationText") + "</div><br />"; } } else { ltlContent.Text = HTMLHelper.ResolveUrls(itemDocumentation, null); } } ScriptHelper.RegisterJQuery(Page); string script = @" $j(document.body).ready(initializeResize); function initializeResize () { resizeareainternal(); $j(window).resize(function() { resizeareainternal(); }); } function resizeareainternal () { var height = document.body.clientHeight ; var panel = document.getElementById ('" + divScrolable.ClientID + @"'); // Get parent footer to count proper height (with padding included) var footer = $j('.PageFooterLine'); panel.style.height = (height - footer.outerHeight() - panel.offsetTop) +'px'; }"; ScriptHelper.RegisterClientScriptBlock(Page, typeof(Page), "mainScript", ScriptHelper.GetScript(script)); string[,] tabs = new string[4, 4]; tabs[0, 0] = GetString("webparts.documentation"); tabs[1, 0] = GetString("general.properties"); tabControlElem.Tabs = tabs; tabControlElem.UsePostback = true; // Disable caching Response.Cache.SetNoStore(); base.OnLoad(e); }
/// <summary> /// Handles the Load event of the Page control. /// </summary> protected void Page_Load(object sender, EventArgs e) { // Public user is not allowed for widgets if (!AuthenticationHelper.IsAuthenticated()) { RedirectToAccessDenied(GetString("widgets.security.notallowed")); } var viewMode = ViewModeCode.FromString(QueryHelper.GetString("viewmode", String.Empty)); var hash = QueryHelper.GetString("hash", String.Empty); LiveSiteWidgetsParameters dialogparameters = new LiveSiteWidgetsParameters(aliasPath, viewMode) { ZoneId = zoneId, ZoneType = zoneType, InstanceGuid = instanceGuid, TemplateId = templateId, IsInlineWidget = inline }; if (!dialogparameters.ValidateHash(hash)) { return; } // Set page title Page.Title = GetString(isNewWidget ? "widgets.propertiespage.titlenew" : "widgets.propertiespage.title"); if ((widgetId != string.Empty) && (aliasPath != string.Empty)) { // Get page info var siteName = SiteContext.CurrentSiteName; PageInfo pi = PageInfoProvider.GetPageInfo(siteName, aliasPath, LocalizationContext.PreferredCultureCode, null, SiteInfoProvider.CombineWithDefaultCulture(siteName)); if (pi == null) { return; } // Get template instance PageTemplateInstance templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(pi); // Get widget from instance WidgetInfo wi = null; if (!isNewWidget) { // Get the instance of widget WebPartInstance widgetInstance = templateInstance.GetWebPart(instanceGuid, widgetId); if (widgetInstance == null) { return; } // Get widget info by widget name(widget type) wi = WidgetInfoProvider.GetWidgetInfo(widgetInstance.WebPartType); } // Widget instance hasn't created yet else { wi = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(widgetId, 0)); } if (wi != null) { WebPartZoneInstance zone = templateInstance.GetZone(zoneId); if (zone != null) { var currentUser = MembershipContext.AuthenticatedUser; bool checkSecurity = true; // Check security // It is group zone type but widget is not allowed in group if (zone.WidgetZoneType == WidgetZoneTypeEnum.Group) { // Should always be, only group widget are allowed in group zone if (wi.WidgetForGroup) { if (!currentUser.IsGroupAdministrator(pi.NodeGroupID)) { RedirectToAccessDenied(GetString("widgets.security.notallowed")); } // All ok, don't check classic security checkSecurity = false; } } if (checkSecurity && !WidgetRoleInfoProvider.IsWidgetAllowed(wi, currentUser.UserID, AuthenticationHelper.IsAuthenticated())) { RedirectToAccessDenied(GetString("widgets.security.notallowed")); } } } } // If all ok, set up frames rowsFrameset.Attributes.Add("rows", string.Format("{0}, *", TitleOnlyHeight)); frameHeader.Attributes.Add("src", "widgetproperties_header.aspx" + RequestContext.CurrentQueryString); if (inline && !isNewWidget) { frameContent.Attributes.Add("src", ResolveUrl("~/CMSPages/Blank.htm")); } else { frameContent.Attributes.Add("src", "widgetproperties_properties_frameset.aspx" + RequestContext.CurrentQueryString); } }
protected void Page_Load(object sender, EventArgs e) { // Public user is not allowed for widgets if (!CMSContext.CurrentUser.IsAuthenticated()) { RedirectToAccessDenied(GetString("widgets.security.notallowed")); } string widgetId = QueryHelper.GetString("widgetid", String.Empty); string aliasPath = QueryHelper.GetString("aliasPath", String.Empty); string zoneId = QueryHelper.GetString("zoneid", String.Empty); Guid instanceGUID = QueryHelper.GetGuid("instanceguid", Guid.Empty); bool isNewWidget = QueryHelper.GetBoolean("isnew", false); bool inline = QueryHelper.GetBoolean("inline", false); // Set page title Page.Title = GetString(isNewWidget ? "widgets.propertiespage.titlenew" : "widgets.propertiespage.title"); if ((widgetId != string.Empty) && (aliasPath != string.Empty)) { // Get pageinfo PageInfo pi = null; try { pi = PageInfoProvider.GetPageInfo(CMSContext.CurrentSiteName, aliasPath, CMSContext.PreferredCultureCode, null, CMSContext.CurrentSite.CombineWithDefaultCulture); } catch (PageNotFoundException) { // Do not throw exception if page info not found (e.g. bad alias path) } if (pi == null) { return; } // Get template instance PageTemplateInstance templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(pi); // Get widget from instance WidgetInfo wi = null; if (!isNewWidget) { // Get the instance of widget WebPartInstance widgetInstance = templateInstance.GetWebPart(instanceGUID, widgetId); if (widgetInstance == null) { return; } // Get widget info by widget name(widget type) wi = WidgetInfoProvider.GetWidgetInfo(widgetInstance.WebPartType); } // Widget instance hasn't created yet else { wi = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(widgetId, 0)); } if (wi != null) { WebPartZoneInstance zone = templateInstance.GetZone(zoneId); if (zone != null) { CurrentUserInfo currentUser = CMSContext.CurrentUser; bool checkSecurity = true; // Check security // It is group zone type but widget is not allowed in group if (zone.WidgetZoneType == WidgetZoneTypeEnum.Group) { // Should always be, only group widget are allowed in group zone if (wi.WidgetForGroup) { if (!currentUser.IsGroupAdministrator(pi.NodeGroupID)) { RedirectToAccessDenied(GetString("widgets.security.notallowed")); } // All ok, don't check classic security checkSecurity = false; } } if (checkSecurity && !WidgetRoleInfoProvider.IsWidgetAllowed(wi, currentUser.UserID, currentUser.IsAuthenticated())) { RedirectToAccessDenied(GetString("widgets.security.notallowed")); } } } } // If all ok, set up frames frameHeader.Attributes.Add("src", "widgetproperties_header.aspx" + URLHelper.Url.Query); if (inline && !isNewWidget) { frameContent.Attributes.Add("src", ResolveUrl("~/CMSPages/Blank.htm")); } else { frameContent.Attributes.Add("src", "widgetproperties_properties_frameset.aspx" + URLHelper.Url.Query); } }
/// <summary> /// Handles the Load event of the Page control. /// </summary> protected void Page_Load(object sender, EventArgs e) { string widgetId = QueryHelper.GetString("widgetid", String.Empty); string aliasPath = QueryHelper.GetString("aliasPath", String.Empty); int templateId = QueryHelper.GetInteger("templateid", 0); string zoneId = QueryHelper.GetString("zoneid", String.Empty); Guid instanceGUID = QueryHelper.GetGuid("instanceguid", Guid.Empty); bool isNewWidget = QueryHelper.GetBoolean("isnew", false); bool inline = QueryHelper.GetBoolean("inline", false); int variantId = QueryHelper.GetInteger("variantid", 0); string culture = QueryHelper.GetString("culture", CMSContext.PreferredCultureCode); // Set page title Page.Title = GetString(isNewWidget ? "widgets.propertiespage.titlenew" : "widgets.propertiespage.title"); // Resize the header (enlarge) to make a space for the tabs header when displaying a widget variant if (variantId > 0) { rowsFrameset.Attributes.Add("rows", "67, *"); } // Ensure correct view mode if (String.IsNullOrEmpty(aliasPath)) { // Ensure the dashboard mode for the dialog if (QueryHelper.Contains("dashboard")) { PortalContext.SetRequestViewMode(ViewModeEnum.DashboardWidgets); PortalContext.DashboardName = QueryHelper.GetString("dashboard", String.Empty); PortalContext.DashboardSiteName = QueryHelper.GetString("sitename", String.Empty); } // Ensure the design mode for the dialog else { PortalContext.SetRequestViewMode(ViewModeEnum.Design); } } if (widgetId != "") { // Get pageinfo PageInfo pi = null; try { pi = CMSWebPartPropertiesPage.GetPageInfo(aliasPath, templateId, culture); } catch (PageNotFoundException) { // Do not throw exception if page info not found (e.g. bad alias path) } if (pi == null) { return; } // Get template instance PageTemplateInstance templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(pi); // Get widget from instance WidgetInfo wi = null; if (!isNewWidget) { // Get the instance of widget WebPartInstance widgetInstance = templateInstance.GetWebPart(instanceGUID, widgetId); if (widgetInstance == null) { return; } // Get widget info by widget name(widget type) wi = WidgetInfoProvider.GetWidgetInfo(widgetInstance.WebPartType); } // Widget instance hasn't created yet else { wi = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(widgetId, 0)); } if (wi != null) { WebPartZoneInstance zone = templateInstance.GetZone(zoneId); if (zone != null) { CurrentUserInfo currentUser = CMSContext.CurrentUser; switch (zone.WidgetZoneType) { // Group zone => Only group widgets and group admin case WidgetZoneTypeEnum.Group: // Should always be, only group widget are allowed in group zone if (!wi.WidgetForGroup || (!currentUser.IsGroupAdministrator(pi.NodeGroupID) && ((CMSContext.ViewMode != ViewModeEnum.Design) || ((CMSContext.ViewMode == ViewModeEnum.Design) && (!currentUser.IsAuthorizedPerResource("CMS.Design", "Design")))))) { RedirectToAccessDenied(GetString("widgets.security.notallowed")); } break; // Widget must be allowed for editor zones case WidgetZoneTypeEnum.Editor: if (!wi.WidgetForEditor) { RedirectToAccessDenied(GetString("widgets.security.notallowed")); } break; // Widget must be allowed for user zones case WidgetZoneTypeEnum.User: if (!wi.WidgetForUser) { RedirectToAccessDenied(GetString("widgets.security.notallowed")); } break; } if ((zone.WidgetZoneType != WidgetZoneTypeEnum.Group) && !WidgetRoleInfoProvider.IsWidgetAllowed(wi, currentUser.UserID, currentUser.IsAuthenticated())) { RedirectToAccessDenied(GetString("widgets.security.notallowed")); } } // If all ok, set up frames frameHeader.Attributes.Add("src", "widgetproperties_header.aspx" + URLHelper.Url.Query); frameContent.Attributes.Add("src", "widgetproperties_properties_frameset.aspx" + URLHelper.Url.Query); } } frameHeader.Attributes.Add("src", "widgetproperties_header.aspx" + URLHelper.Url.Query); if (inline && !isNewWidget) { frameContent.Attributes.Add("src", ResolveUrl("~/CMSPages/Blank.htm")); } else { frameContent.Attributes.Add("src", "widgetproperties_properties_frameset.aspx" + URLHelper.Url.Query); } }
/// <summary> /// Saves web part zone properties. /// </summary> public bool Save() { if (ZoneVariantID > 0) { // Check OnlineMarketing permissions if (!CheckPermissions("Manage")) { ShowInformation(GetString("general.modifynotallowed")); return(false); } } // Save the data if (formElem.SaveData("")) { DataRow dr = formElem.DataRow; // Get basicform's datarow and update the fields if ((webPartZone != null) && (dr != null) && (pti != null)) { webPartZone.XMLVersion = 1; // New variant if (IsNewVariant) { webPartZone = pti.TemplateInstance.EnsureZone(webPartZone.ZoneID); // Ensure that all the zones which are not saved in the template already will be saved now // This is a case for new layout zones if (!webPartZone.HasVariants) { TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser); CMSPortalManager.SaveTemplateChanges(pi, pti.TemplateInstance, WidgetZoneTypeEnum.None, ViewModeEnum.Design, tree); } webPartZone = webPartZone.Clone(); string webPartControlId = string.Empty; // Re-generate web part unique IDs foreach (WebPartInstance wpi in webPartZone.WebParts) { bool webPartIdExists = false; int offset = 0; // Set new web part unique ID string baseId = Regex.Replace(wpi.ControlID, "\\d+$", ""); do { webPartControlId = WebPartZoneInstance.GetUniqueWebPartId(baseId, pti.TemplateInstance, offset); // Check if the returned web part control id is already used in the new zone variant webPartIdExists = (webPartZone.GetWebPart(webPartControlId) != null); offset++; } while (webPartIdExists); wpi.ControlID = webPartControlId; wpi.InstanceGUID = new Guid(); } } // If zone type changed, delete all webparts in the zone if (dr.Table.Columns.Contains("WidgetZoneType") && ValidationHelper.GetString(webPartZone.GetValue("WidgetZoneType"), "") != ValidationHelper.GetString(dr["WidgetZoneType"], "")) { webPartZone.RemoveAllWebParts(); } foreach (DataColumn column in dr.Table.Columns) { webPartZone.MacroTable[column.ColumnName.ToLowerCSafe()] = formElem.MacroTable[column.ColumnName.ToLowerCSafe()]; webPartZone.SetValue(column.ColumnName, dr[column]); } // Ensure the layout zone flag webPartZone.LayoutZone = QueryHelper.GetBoolean("layoutzone", false); // Save standard zone if ((ZoneVariantID == 0) && (!IsNewVariant)) { // Update page template PageTemplateInfoProvider.SetPageTemplateInfo(pti); } else { // Save zone variant if ((webPartZone != null) && (webPartZone.ParentTemplateInstance != null) && (webPartZone.ParentTemplateInstance.ParentPageTemplate != null) && (!webPartZone.WebPartsContainVariants)) // Save only if any of the child web parts does not have variants { // Save the variant properties VariantSettings variant = new VariantSettings() { ID = ZoneVariantID, ZoneID = webPartZone.ZoneID, PageTemplateID = webPartZone.ParentTemplateInstance.ParentPageTemplate.PageTemplateId, }; // Get variant description properties Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable; if (properties != null) { variant.Name = ValidationHelper.GetString(properties["codename"], string.Empty); variant.DisplayName = ValidationHelper.GetString(properties["displayname"], string.Empty); variant.Description = ValidationHelper.GetString(properties["description"], string.Empty); variant.Enabled = ValidationHelper.GetBoolean(properties["enabled"], true); if (PortalContext.ContentPersonalizationEnabled) { variant.Condition = ValidationHelper.GetString(properties["condition"], string.Empty); } } mZoneVariantID = VariantHelper.SetVariant(variantMode, variant, webPartZone.GetXmlNode()); // The variants are cached -> Reload pti.TemplateInstance.LoadVariants(true, VariantModeEnum.None); } } // Reload the form (because of macro values set only by JS) formElem.LoadData(dr); ShowChangesSaved(); return(true); } else { return(false); } } else { return(false); } }
/// <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> /// Generate documentation page. /// </summary> protected override void OnInit(EventArgs e) { base.OnInit(e); // Get current resolver resolver = CMSContext.CurrentResolver.CreateContextChild(); plImg = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/plus.png"); minImg = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/minus.png"); webPartId = QueryHelper.GetString("webPartId", String.Empty); if (webPartId != String.Empty) { wpi = WebPartInfoProvider.GetWebPartInfo(webPartId); } string aliasPath = QueryHelper.GetString("aliaspath", String.Empty); // Ensure correct view mode if (String.IsNullOrEmpty(aliasPath)) { // Ensure the dashboard mode for the dialog if (QueryHelper.Contains("dashboard")) { PortalContext.SetRequestViewMode(ViewModeEnum.DashboardWidgets); PortalContext.DashboardName = QueryHelper.GetString("dashboard", String.Empty); PortalContext.DashboardSiteName = QueryHelper.GetString("sitename", String.Empty); } // Ensure the design mode for the dialog else { PortalContext.SetRequestViewMode(ViewModeEnum.Design); } } // If widgetId is in query create widget documentation widgetID = QueryHelper.GetString("widgetId", String.Empty); if (widgetID != String.Empty) { // Get widget from instance string zoneId = QueryHelper.GetString("zoneid", String.Empty); Guid instanceGuid = QueryHelper.GetGuid("instanceGuid", Guid.Empty); int templateID = QueryHelper.GetInteger("templateID", 0); bool newItem = QueryHelper.GetBoolean("isNew", false); bool isInline = QueryHelper.GetBoolean("Inline", false); PageInfo pi = null; try { // Load page info from alias path and page template pi = CMSWebPartPropertiesPage.GetPageInfo(aliasPath, templateID); } catch (PageNotFoundException) { // Do not throw exception if page info not found (e.g. bad alias path) } if (pi != null) { PageTemplateInstance templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(pi); if (templateInstance != null) { // Get the instance of widget WebPartInstance widgetInstance = templateInstance.GetWebPart(instanceGuid, widgetID); // Info for zone type WebPartZoneInstance zone = templateInstance.GetZone(zoneId); if (zone != null) { zoneType = zone.WidgetZoneType; } if (widgetInstance != null) { // Create widget from webpart instance wi = WidgetInfoProvider.GetWidgetInfo(widgetInstance.WebPartType); } } } // If inline widget display columns as in editor zone if (isInline) { zoneType = WidgetZoneTypeEnum.Editor; } // If no zone set (only global admins allowed to continue) if (zoneType == WidgetZoneTypeEnum.None) { if (!CMSContext.CurrentUser.UserSiteManagerAdmin) { RedirectToAccessDenied(GetString("attach.actiondenied")); } } // If wi is still null (new item f.e.) if (wi == null) { // Try to get widget info directly by ID if (!newItem) { wi = WidgetInfoProvider.GetWidgetInfo(widgetID); } else { wi = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(widgetID, 0)); } } } String itemDescription = String.Empty; String itemType = String.Empty; String itemDisplayName = String.Empty; String itemDocumentation = String.Empty; int itemID = 0; // Check whether webpart was found if (wpi != null) { itemDescription = wpi.WebPartDescription; itemType = PortalObjectType.WEBPART; itemID = wpi.WebPartID; itemDisplayName = wpi.WebPartDisplayName; itemDocumentation = wpi.WebPartDocumentation; } // Or widget was found else if (wi != null) { itemDescription = wi.WidgetDescription; itemType = PortalObjectType.WIDGET; itemID = wi.WidgetID; itemDisplayName = wi.WidgetDisplayName; itemDocumentation = wi.WidgetDocumentation; } if ((wpi != null) || (wi != null)) { // Get WebPart (widget) image DataSet ds = MetaFileInfoProvider.GetMetaFiles(itemID, itemType); // Set image url of exists if (!DataHelper.DataSourceIsEmpty(ds)) { MetaFileInfo mtfi = new MetaFileInfo(ds.Tables[0].Rows[0]); if (mtfi != null) { if (mtfi.MetaFileImageWidth > 385) { imgTeaser.Width = 385; } imgTeaser.ImageUrl = ResolveUrl("~/CMSPages/GetMetaFile.aspx?fileguid=" + mtfi.MetaFileGUID.ToString()); } } else { // Set default image imgTeaser.ImageUrl = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/imagenotavailable.png"); } // Additional image information imgTeaser.ToolTip = HTMLHelper.HTMLEncode(itemDisplayName); imgTeaser.AlternateText = HTMLHelper.HTMLEncode(itemDisplayName); // Set description of webpart ltlDescription.Text = HTMLHelper.HTMLEncode(itemDescription); // Get description from parent weboart if webpart is inherited if ((wpi != null) && ((wpi.WebPartDescription == null || wpi.WebPartDescription == "") && (wpi.WebPartParentID > 0))) { WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null) { ltlDescription.Text = HTMLHelper.HTMLEncode(pwpi.WebPartDescription); } } FormInfo fi = null; // Generate properties if (wpi != null) { // Get form info from parent if webpart is inherited if (wpi.WebPartParentID != 0) { WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null) { fi = GetWebPartProperties(pwpi); } } else { fi = GetWebPartProperties(wpi); } } else if (wi != null) { fi = GetWidgetProperties(wi); } // Generate properties if (fi != null) { GenerateProperties(fi); } // Generate documentation text if (itemDocumentation == null || itemDocumentation.Trim() == "") { if ((wpi != null) && (wpi.WebPartParentID != 0)) { WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null && pwpi.WebPartDocumentation.Trim() != "") { ltlContent.Text = HTMLHelper.ResolveUrls(pwpi.WebPartDocumentation, null); } else { ltlContent.Text = "<br /><div style=\"padding-left:5px; font-weight: bold;\">" + GetString("WebPartDocumentation.DocumentationText") + "</div><br />"; } } else { ltlContent.Text = "<br /><div style=\"padding-left:5px; font-weight: bold;\">" + GetString("WebPartDocumentation.DocumentationText") + "</div><br />"; } } else { ltlContent.Text = HTMLHelper.ResolveUrls(itemDocumentation, null); } } }
/// <summary> /// Initializes menu. /// </summary> protected void InitalizeMenu() { string zoneId = QueryHelper.GetString("zoneid", string.Empty); string culture = QueryHelper.GetString("culture", CMSContext.PreferredCultureCode); Guid instanceGuid = QueryHelper.GetGuid("instanceguid", Guid.Empty); bool isNewWidget = QueryHelper.GetBoolean("isnew", false); WidgetZoneTypeEnum zoneType = WidgetZoneTypeEnum.None; if (!String.IsNullOrEmpty(widgetId) || !String.IsNullOrEmpty(widgetName)) { WidgetInfo wi = null; // get pageinfo PageInfo pi = null; try { pi = CMSWebPartPropertiesPage.GetPageInfo(aliasPath, templateId, culture); } catch (PageNotFoundException) { // Do not throw exception if page info not found (e.g. bad alias path) } if (pi == null) { Visible = false; return; } // Get template instance PageTemplateInstance templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(pi); if (templateInstance != null) { // Get zone type WebPartZoneInstance zoneInstance = templateInstance.GetZone(zoneId); if (zoneInstance != null) { zoneType = zoneInstance.WidgetZoneType; } // Get web part WebPartInstance widget = templateInstance.GetWebPart(instanceGuid, widgetId); if ((widget != null) && widget.IsWidget) { // WebPartType = codename, get widget by codename wi = WidgetInfoProvider.GetWidgetInfo(widget.WebPartType); } } // New widget if (isNewWidget) { int id = ValidationHelper.GetInteger(widgetId, 0); if (id > 0) { wi = WidgetInfoProvider.GetWidgetInfo(id); } else if (!String.IsNullOrEmpty(widgetName)) { wi = WidgetInfoProvider.GetWidgetInfo(widgetName); } } // Get widget info from name if not found yet if ((wi == null) && (!String.IsNullOrEmpty(widgetName))) { wi = WidgetInfoProvider.GetWidgetInfo(widgetName); } if (wi != null) { PageTitle.TitleText = GetString("Widgets.Properties.Title") + " (" + HTMLHelper.HTMLEncode(ResHelper.LocalizeString(wi.WidgetDisplayName)) + ")"; } // If no zonetype defined or not inline dont show documentation string documentationUrl = String.Empty; switch (zoneType) { case WidgetZoneTypeEnum.Dashboard: case WidgetZoneTypeEnum.Editor: case WidgetZoneTypeEnum.Group: case WidgetZoneTypeEnum.User: documentationUrl = ResolveUrl("~/CMSModules/Widgets/LiveDialogs/WidgetDocumentation.aspx"); break; // If no zone set dont create documentation link default: if (isInline) { documentationUrl = ResolveUrl("~/CMSModules/Widgets/Dialogs/WidgetDocumentation.aspx"); } else { return; } break; } // Generate documentation link Literal ltr = new Literal(); PageTitle.RightPlaceHolder.Controls.Add(ltr); // Ensure correct parameters in documentation url documentationUrl += URLHelper.GetQuery(URLHelper.CurrentURL); if (!String.IsNullOrEmpty(widgetName)) { documentationUrl = URLHelper.UpdateParameterInUrl(documentationUrl, "widgetname", widgetName); } if (!String.IsNullOrEmpty(widgetId)) { documentationUrl = URLHelper.UpdateParameterInUrl(documentationUrl, "widgetid", widgetId); } string docScript = "NewWindow('" + documentationUrl + "', 'WebPartPropertiesDocumentation', 800, 800); return false;"; ltr.Text += "<a onclick=\"" + docScript + "\" href=\"#\"><img src=\"" + ResolveUrl(GetImageUrl("General/HelpLargeDark.png")) + "\" style=\"border-width: 0px;\"></a>"; } }
/// <summary> /// Handles the Load event of the Page control. /// </summary> protected void Page_Load(object sender, EventArgs e) { RegisterModalPageScripts(); // Set page title Page.Title = GetString(isNewWidget ? "widgets.propertiespage.titlenew" : "widgets.propertiespage.title"); // Resize the header (enlarge) to make a space for the tabs header when displaying a widget variant var headerHeight = TitleOnlyHeight; if (variantId > 0) { headerHeight = TabsFrameHeight; } rowsFrameset.Attributes.Add("rows", string.Format("{0}, *", headerHeight)); // Ensure correct view mode if (String.IsNullOrEmpty(aliasPath)) { // Ensure the dashboard mode for the dialog if (QueryHelper.Contains("dashboard")) { PortalContext.SetRequestViewMode(ViewModeEnum.DashboardWidgets); PortalContext.DashboardName = QueryHelper.GetString("dashboard", String.Empty); PortalContext.DashboardSiteName = QueryHelper.GetString("sitename", String.Empty); } // Ensure the design mode for the dialog else { PortalContext.SetRequestViewMode(ViewModeEnum.Design); } } if (widgetId != "") { // Get template instance PageTemplateInstance templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(PageInfo); // Get widget from instance WidgetInfo wi; if (!isNewWidget) { // Get the instance of widget WebPartInstance widgetInstance = templateInstance.GetWebPart(instanceGuid, widgetId); if (widgetInstance == null) { return; } // Get widget info by widget name(widget type) wi = WidgetInfoProvider.GetWidgetInfo(widgetInstance.WebPartType); } // Widget instance hasn't created yet else { wi = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(widgetId, 0)); } if (wi != null) { WebPartZoneInstance zone = templateInstance.GetZone(zoneId); if (zone != null) { var currentUser = MembershipContext.AuthenticatedUser; switch (zone.WidgetZoneType) { // Group zone => Only group widgets and group admin case WidgetZoneTypeEnum.Group: // Should always be, only group widget are allowed in group zone if (!wi.WidgetForGroup || (!currentUser.IsGroupAdministrator(PageInfo.NodeGroupID) && ((PortalContext.ViewMode != ViewModeEnum.Design) || ((PortalContext.ViewMode == ViewModeEnum.Design) && (!currentUser.IsAuthorizedPerResource("CMS.Design", "Design")))))) { RedirectToAccessDenied(GetString("widgets.security.notallowed")); } break; // Widget must be allowed for editor zones case WidgetZoneTypeEnum.Editor: if (!wi.WidgetForEditor) { RedirectToAccessDenied(GetString("widgets.security.notallowed")); } break; // Widget must be allowed for user zones case WidgetZoneTypeEnum.User: if (!wi.WidgetForUser) { RedirectToAccessDenied(GetString("widgets.security.notallowed")); } break; } if ((zone.WidgetZoneType != WidgetZoneTypeEnum.Group) && !WidgetRoleInfoProvider.IsWidgetAllowed(wi, currentUser.UserID, AuthenticationHelper.IsAuthenticated())) { RedirectToAccessDenied(GetString("widgets.security.notallowed")); } } // If all ok, set up frames frameHeader.Attributes.Add("src", "widgetproperties_header.aspx" + RequestContext.CurrentQueryString); frameContent.Attributes.Add("src", "widgetproperties_properties_frameset.aspx" + RequestContext.CurrentQueryString); } } frameHeader.Attributes.Add("src", "widgetproperties_header.aspx" + RequestContext.CurrentQueryString); if (inline && !isNewWidget) { frameContent.Attributes.Add("src", ResolveUrl("~/CMSPages/Blank.htm")); } else { frameContent.Attributes.Add("src", "widgetproperties_properties_frameset.aspx" + RequestContext.CurrentQueryString); } }
/// <summary> /// Page load. /// </summary> protected void Page_Load(object sender, EventArgs e) { if (StopProcessing) { return; } treeElem.OnItemSelected += treeElem_OnItemSelected; if (!RequestHelper.IsPostBack()) { // Select root by default ResetToDefault(); } // Different behavior of flat selector for different group zones if (IsInline) { // Inline widget flatElem.SelectInlineWidgets = true; treeElem.SelectInlineWidgets = true; } else if (IsDashboard) { // Dashboard zone flatElem.SelectDashboardWidgets = true; treeElem.SelectDashboardWidgets = true; } else if (!String.IsNullOrEmpty(ZoneId)) { // Get pageinfo PageInfo pi = null; try { pi = CMSWebPartPropertiesPage.GetPageInfo(AliasPath, PageTemplateId, CultureCode); } catch (PageNotFoundException) { // Do not throw exception if page info not found (e.g. bad alias path) } PageTemplateInstance templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(pi); if (templateInstance != null) { WidgetZoneTypeEnum zoneType = ZoneType; // Get settings of the zone if present in the template WebPartZoneInstance zone = templateInstance.GetZone(ZoneId); if ((zoneType == WidgetZoneTypeEnum.None) && (zone != null)) { zoneType = zone.WidgetZoneType; } // Set flags to flat element by type of widget zone if (zoneType == WidgetZoneTypeEnum.Group) { flatElem.SelectGroupWidgets = true; treeElem.SelectGroupWidgets = true; flatElem.GroupID = pi.NodeGroupID; } else if (zoneType == WidgetZoneTypeEnum.User) { flatElem.SelectUserWidgets = true; treeElem.SelectUserWidgets = true; } else if (zoneType == WidgetZoneTypeEnum.Editor) { flatElem.SelectEditorWidgets = true; treeElem.SelectEditorWidgets = true; } } } }
/// <summary> /// Init event handler. /// </summary> protected override void OnInit(EventArgs e) { base.OnInit(e); // 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 = 0; if (VariantMode == VariantModeEnum.MVT) { variantIdFromDB = ModuleCommands.OnlineMarketingGetMVTVariantId(PageTemplateId, variantName); } else if (VariantMode == VariantModeEnum.ContentPersonalization) { variantIdFromDB = ModuleCommands.OnlineMarketingGetContentPersonalizationVariantId(PageTemplateId, variantName); } // Set the variant id from the database if (variantIdFromDB > 0) { VariantID = variantIdFromDB; IsNewVariant = false; } } } EnsureDashboard(); if (!String.IsNullOrEmpty(WidgetId) && !IsInline) { // Get pageinfo try { pi = CMSWebPartPropertiesPage.GetPageInfo(AliasPath, PageTemplateId); } catch (PageNotFoundException) { // Do not throw exception if page info not found (e.g. bad alias path) } if (pi == null) { lblInfo.Text = GetString("Widgets.Properties.aliasnotfound"); lblInfo.Visible = true; pnlFormArea.Visible = false; return; } // Get template pti = pi.PageTemplateInfo; // Get template instance templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(pi); if (!IsNewWidget) { // Get the instance of widget widgetInstance = templateInstance.GetWebPart(InstanceGUID, WidgetId); if (widgetInstance == null) { lblInfo.Text = GetString("Widgets.Properties.WidgetNotFound"); lblInfo.Visible = true; pnlFormArea.Visible = false; return; } if ((VariantID > 0) && (widgetInstance != null) && (widgetInstance.PartInstanceVariants != null)) { // Check OnlineMarketing permissions. if (CheckPermissions("Read")) { widgetInstance = pi.DocumentTemplateInstance.GetWebPart(InstanceGUID, WidgetId); widgetInstance = widgetInstance.PartInstanceVariants.Find(v => v.VariantID.Equals(VariantID)); // Set the widget variant mode if (widgetInstance != null) { VariantMode = widgetInstance.VariantMode; } } else { // Not authorised 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) wi = WidgetInfoProvider.GetWidgetInfo(widgetInstance.WebPartType); } // Widget instance hasn't created yet else { wi = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(WidgetId, 0)); } CMSPage.EditedObject = wi; zoneType = ZoneType; // Get the zone to which it inserts WebPartZoneInstance zone = templateInstance.GetZone(ZoneId); if ((zoneType == WidgetZoneTypeEnum.None) && (zone != null)) { zoneType = zone.WidgetZoneType; } // Check security CurrentUserInfo currentUser = CMSContext.CurrentUser; 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 (!wi.WidgetForGroup || (!currentUser.IsGroupAdministrator(pi.NodeGroupId) && ((CMSContext.ViewMode != ViewModeEnum.Design) || ((CMSContext.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 (!wi.WidgetForEditor) { if (OnNotAllowed != null) { OnNotAllowed(this, null); } } break; // Widget must be allowed for user zones case WidgetZoneTypeEnum.User: if (!wi.WidgetForUser) { if (OnNotAllowed != null) { OnNotAllowed(this, null); } } break; // Widget must be allowed for dasboard zones case WidgetZoneTypeEnum.Dashboard: if (!wi.WidgetForDashboard) { if (OnNotAllowed != null) { OnNotAllowed(this, null); } } break; } // Check security if ((zoneType != WidgetZoneTypeEnum.Group) && !WidgetRoleInfoProvider.IsWidgetAllowed(wi, currentUser.UserID, currentUser.IsAuthenticated())) { if (OnNotAllowed != null) { OnNotAllowed(this, null); } } // Get form schemas wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID); FormInfo zoneTypeDefinition = PortalHelper.GetPositionFormInfo(zoneType); string widgetProperties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties); FormInfo fi = FormHelper.GetWidgetFormInfo(wi.WidgetName, Enum.GetName(typeof(WidgetZoneTypeEnum), zoneType), widgetProperties, zoneTypeDefinition, true); if (fi != null) { // Check if there are some editable properties FormFieldInfo[] ffi = fi.GetFields(true, false); if ((ffi == null) || (ffi.Length == 0)) { lblInfo.Visible = true; lblInfo.Text = GetString("widgets.emptyproperties"); } // Get datarows with required columns DataRow dr = CombineWithDefaultValues(fi, wi); // Load default values for new widget if (IsNewWidget) { fi.LoadDefaultValues(dr, FormResolveTypeEnum.Visible); // Overide default value and set title as widget display name DataHelper.SetDataRowValue(dr, "WidgetTitle", ResHelper.LocalizeString(wi.WidgetDisplayName)); } // Load values from existing widget LoadDataRowFromWidget(dr); // Init HTML toolbar if exists InitHTMLToobar(fi); // Init the form InitForm(formCustom, dr, fi); // Set the context name formCustom.ControlContext.ContextName = CMS.SiteProvider.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; if (IsNewWidget) { // new wdiget - load widget info by id if (!String.IsNullOrEmpty(WidgetId)) { wi = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(WidgetId, 0)); } else { // Try to get widget from codename mName = QueryHelper.GetString("WidgetName", String.Empty); wi = WidgetInfoProvider.GetWidgetInfo(mName); } } else { if (definition == null) { ShowError("widget.failedtoload"); return; } //parse defininiton parameters = CMSDialogHelper.GetHashTableFromString(definition); //trim control name if (parameters["name"] != null) { mName = parameters["name"].ToString(); } wi = WidgetInfoProvider.GetWidgetInfo(mName); } if (wi == null) { ShowError("widget.failedtoload"); return; } //If widget cant be used asi inline if (!wi.WidgetForInline) { ShowError("widget.cantbeusedasinline"); return; } //Test permission for user CurrentUserInfo currentUser = CMSContext.CurrentUser; if (!WidgetRoleInfoProvider.IsWidgetAllowed(wi, currentUser.UserID, currentUser.IsAuthenticated())) { mIsValidWidget = false; OnNotAllowed(this, null); } //If user is editor, more properties are shown WidgetZoneTypeEnum zoneType = WidgetZoneTypeEnum.User; if (currentUser.IsEditor) { zoneType = WidgetZoneTypeEnum.Editor; } WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID); string widgetProperties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties); FormInfo zoneTypeDefinition = PortalHelper.GetPositionFormInfo(zoneType); FormInfo fi = FormHelper.GetWidgetFormInfo(wi.WidgetName, Enum.GetName(typeof(WidgetZoneTypeEnum), zoneType), widgetProperties, zoneTypeDefinition, true); if (fi != null) { // Check if there are some editable properties mFields = fi.GetFields(true, true); if ((mFields == null) || (mFields.Length == 0)) { lblInfo.Visible = true; lblInfo.Text = GetString("widgets.emptyproperties"); } // Get datarows with required columns DataRow dr = CombineWithDefaultValues(fi, wi); if (IsNewWidget) { // Load default values for new widget fi.LoadDefaultValues(dr, FormResolveTypeEnum.Visible); } else { foreach (string key in parameters.Keys) { string value = parameters[key].ToString(); // Test if given property exists if (dr.Table.Columns.Contains(key) && !String.IsNullOrEmpty(value)) { try { dr[key] = value; } catch { } } } } // Overide default value and set title as widget display name DataHelper.SetDataRowValue(dr, "WidgetTitle", wi.WidgetDisplayName); // Init HTML toolbar if exists InitHTMLToobar(fi); // Init the form InitForm(formCustom, dr, fi); // Set the context name formCustom.ControlContext.ContextName = CMS.SiteProvider.ControlContext.WIDGET_PROPERTIES; } } }