/// <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> /// 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 templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(CurrentPageInfo); if (!IsNewWidget) { // Get the instance of widget widgetInstance = templateInstance.GetWebPart(InstanceGUID, WidgetId); if (widgetInstance == null) { ShowError(GetString("Widgets.Properties.WidgetNotFound")); pnlFormArea.Visible = false; return; } if ((VariantID > 0) && (widgetInstance != null) && (widgetInstance.PartInstanceVariants != null)) { // Check OnlineMarketing permissions. if (CheckPermissions("Read")) { widgetInstance = CurrentPageInfo.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 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) wi = WidgetInfoProvider.GetWidgetInfo(widgetInstance.WebPartType); } // Widget instance hasn't created yet else { wi = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(WidgetId, 0)); } // Keep xml version if (widgetInstance != null) { xmlVersion = widgetInstance.XMLVersion; } UIContext.EditedObject = wi; // Get the zone to which it inserts WebPartZoneInstance zone = templateInstance.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 (!wi.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 (!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 dashboard 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, AuthenticationHelper.IsAuthenticated())) { if (OnNotAllowed != null) { OnNotAllowed(this, null); } } // Get form schemas wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID); FormInfo zoneTypeDefinition = PortalFormHelper.GetPositionFormInfo(ZoneType); string widgetProperties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties); FormInfo fi = PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, Enum.GetName(typeof(WidgetZoneTypeEnum), ZoneType), widgetProperties, zoneTypeDefinition, true, wi.WidgetDefaultValues); if (fi != null) { fi.ContextResolver.Settings.RelatedObject = templateInstance; // Check if there are some editable properties var ffi = fi.GetFields(true, false).ToList<FormFieldInfo>(); if ((ffi == null) || (ffi.Count == 0)) { ShowInformation(GetString("widgets.emptyproperties")); } DataRow dr = fi.GetDataRow(); // Load overridden values for new widget if (IsNewWidget || (xmlVersion > 0)) { fi.LoadDefaultValues(dr, FormResolveTypeEnum.WidgetVisible); } if (IsNewWidget) { // Override default value and set title as widget display name DataHelper.SetDataRowValue(dr, "WidgetTitle", ResHelper.LocalizeString(wi.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.ExtendedControls.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)) { wi = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(WidgetId, 0)); } else { // Try to get widget from codename widgetName = QueryHelper.GetString("WidgetName", String.Empty); wi = 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(); } wi = WidgetInfoProvider.GetWidgetInfo(widgetName); } if (wi == null) { DisplayError("widget.failedtoload"); return; } // If widget cant be used as inline if (!wi.WidgetForInline) { DisplayError("widget.cantbeusedasinline"); return; } // Test permission for user var currentUser = MembershipContext.AuthenticatedUser; if (!WidgetRoleInfoProvider.IsWidgetAllowed(wi, currentUser.UserID, AuthenticationHelper.IsAuthenticated())) { isValidWidget = 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(wi.WidgetWebPartID); string widgetProperties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties); FormInfo zoneTypeDefinition = PortalFormHelper.GetPositionFormInfo(zoneType); FormInfo fi = PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, Enum.GetName(typeof(WidgetZoneTypeEnum), zoneType), widgetProperties, zoneTypeDefinition, true, wi.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, wi); 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", wi.WidgetDisplayName); // Init HTML toolbar if exists InitHTMLToobar(fi); // Init the form InitForm(formCustom, dr, fi); // Set the context name formCustom.ControlContext.ContextName = CMS.ExtendedControls.ControlContext.WIDGET_PROPERTIES; } } }
protected void Page_Load(object sender, EventArgs e) { StringSafeDictionary <object> decodedProperties = new StringSafeDictionary <object>(); foreach (DictionaryEntry param in Properties) { // Decode special CK editor char String str = String.Empty; if (param.Value != null) { str = param.Value.ToString().Replace("%25", "%"); } decodedProperties[(string)param.Key] = HttpUtility.UrlDecode(str); } Properties = decodedProperties; string widgetName = ValidationHelper.GetString(Properties["name"], String.Empty); // Widget name must be specified if (String.IsNullOrEmpty(widgetName)) { AddErrorWebPart("widgets.invalidname", null); return; } WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo(widgetName); if (wi == null) { AddErrorWebPart("widget.failedtoload", null); return; } WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID); if (wpi == null) { return; } //no widgets can be used as inline if (!wi.WidgetForInline) { AddErrorWebPart("widgets.cantbeusedasinline", null); return; } try { FormInfo fi = null; DataRow dr = null; using (var cs = new CachedSection <FormInfo>(ref fi, 1440, (PortalContext.ViewMode == ViewModeEnum.LiveSite), null, "inlinewidgetcontrol", wi.WidgetID, wpi.WebPartID)) { if (cs.LoadData) { // Merge widget and it's parent webpart properties string props = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties); // Prepare form const WidgetZoneTypeEnum zoneType = WidgetZoneTypeEnum.Editor; fi = PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, zoneType, props, true, wi.WidgetDefaultValues); // Apply changed values dr = fi.GetDataRow(); fi.LoadDefaultValues(dr); if (cs.Cached) { cs.CacheDependency = CacheHelper.GetCacheDependency("cms.webpart|byid|" + wpi.WebPartID + "\n" + "cms.widget|byid|" + wi.WidgetID); } cs.Data = fi; } } // Get datarow if (dr == null) { dr = fi.GetDataRow(); fi.LoadDefaultValues(dr); } // Incorporate inline parameters to datarow string publicFields = ";containertitle;container;"; if (wi.WidgetPublicFileds != null) { publicFields += ";" + wi.WidgetPublicFileds.ToLowerCSafe() + ";"; } // Load the widget control string url = null; // Set widget layout WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wi.WidgetLayoutID); if (wpli != null) { // Load specific layout through virtual path url = wpli.Generalized.GetVirtualFileRelativePath(WebPartLayoutInfo.EXTERNAL_COLUMN_CODE, wpli.WebPartLayoutVersionGUID); } else { // Load regularly url = WebPartInfoProvider.GetWebPartUrl(wpi, false); } CMSAbstractWebPart control = (CMSAbstractWebPart)Page.LoadUserControl(url); control.PartInstance = new WebPartInstance(); // Use current page placeholder control.PagePlaceholder = PortalHelper.FindParentPlaceholder(this); // Set all form values to webpart foreach (DataColumn column in dr.Table.Columns) { object value = dr[column]; string columnName = column.ColumnName.ToLowerCSafe(); //Resolve set values by user if (Properties.Contains(columnName)) { FormFieldInfo ffi = fi.GetFormField(columnName); if ((ffi != null) && ffi.Visible && ((ffi.DisplayIn == null) || !ffi.DisplayIn.Contains(FormInfo.DISPLAY_CONTEXT_DASHBOARD))) { value = Properties[columnName]; } } // Resolve macros in defined in default values if (!String.IsNullOrEmpty(value as string)) { // Do not resolve macros for public fields if (publicFields.IndexOfCSafe(";" + columnName + ";") < 0) { // Check whether current column bool avoidInjection = control.SQLProperties.Contains(";" + columnName + ";"); // Resolve macros MacroSettings settings = new MacroSettings() { AvoidInjection = avoidInjection, }; value = control.ContextResolver.ResolveMacros(value.ToString(), settings); } } control.PartInstance.SetValue(column.ColumnName, value); } control.PartInstance.IsWidget = true; // Load webpart content control.OnContentLoaded(); // Add webpart to controls collection Controls.Add(control); // Handle DisableViewstate setting control.EnableViewState = !control.DisableViewState; } catch (Exception ex) { AddErrorWebPart("widget.failedtoload", ex); } }
/// <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); } } }
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> /// Initializes the control properties. /// </summary> protected void SetupControl() { if (StopProcessing) { // Do nothing } else { pi = CMSContext.CurrentPageInfo; if (pi != null) { CMSPagePlaceholder parentPlaceHolder = PortalHelper.FindParentPlaceholder(this); // Nothing to render, nothing to do if ((!DisplayAddButton && !DisplayResetButton) || ((parentPlaceHolder != null) && (parentPlaceHolder.UsingDefaultPage))) { Visible = false; return; } CurrentUserInfo currentUser = CMSContext.CurrentUser; zoneType = WidgetZoneTypeCode.ToEnum(WidgetZoneType); // Check security if (((zoneType == WidgetZoneTypeEnum.Group) && !currentUser.IsGroupAdministrator(pi.NodeGroupID)) || ((zoneType == WidgetZoneTypeEnum.User || zoneType == WidgetZoneTypeEnum.Dashboard) && !currentUser.IsAuthenticated())) { Visible = false; resetAllowed = false; return; } // Displaying - Editor zone only in edit mode, User/Group zone only in Live site/Preview mode if (((zoneType == WidgetZoneTypeEnum.Editor) && ((CMSContext.ViewMode != ViewModeEnum.Edit)&&(CMSContext.ViewMode != ViewModeEnum.EditLive))) || (((zoneType == WidgetZoneTypeEnum.User) || (zoneType == WidgetZoneTypeEnum.Group)) && ((CMSContext.ViewMode != ViewModeEnum.LiveSite) && (CMSContext.ViewMode != ViewModeEnum.Preview))) || ((zoneType == WidgetZoneTypeEnum.Dashboard) && ((CMSContext.ViewMode != ViewModeEnum.DashboardWidgets) || (String.IsNullOrEmpty(PortalContext.DashboardName))))) { Visible = false; resetAllowed = false; return; } // Get current document TreeNode currentNode = DocumentHelper.GetDocument(pi.DocumentID, TreeProvider); if (((zoneType == WidgetZoneTypeEnum.Editor) && (!currentUser.IsEditor || (currentUser.IsAuthorizedPerDocument(currentNode, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied)))) { Visible = false; resetAllowed = false; return; } // If use checkin checkout enabled, check if document is checkout by current user if (zoneType == WidgetZoneTypeEnum.Editor) { if (currentNode != null) { WorkflowManager wm = WorkflowManager.GetInstance(TreeProvider); // Get workflow info WorkflowInfo wi = wm.GetNodeWorkflow(currentNode); // Check if node is under workflow and if use checkin checkout enabled if ((wi != null) && (wi.UseCheckInCheckOut(CMSContext.CurrentSiteName))) { int checkedOutBy = currentNode.DocumentCheckedOutByUserID; // Check if document is checkout by current user if (checkedOutBy != CMSContext.CurrentUser.UserID) { Visible = false; resetAllowed = false; return; } } } } // Find widget zone PageTemplateInfo pti = pi.UsedPageTemplateInfo; // ZodeID specified directly if (!String.IsNullOrEmpty(WidgetZoneID)) { zoneInstance = pti.GetZone(WidgetZoneID); } // Zone not find or specified zone is not of correct type if ((zoneInstance != null) && (zoneInstance.WidgetZoneType != zoneType)) { zoneInstance = null; } // For delete all variants all zones are necessary if (parentPlaceHolder != null) { var zones = parentPlaceHolder.WebPartZones; if (zones != null) { foreach (CMSWebPartZone zone in zones) { if ((zone.ZoneInstance != null) && (zone.ZoneInstance.WidgetZoneType == zoneType)) { zoneInstances.Add(zone.ZoneInstance); if (zoneInstance == null) { zoneInstance = zone.ZoneInstance; } } } } } // No suitable zones on the page, nothing to do if (zoneInstance == null) { Visible = false; resetAllowed = false; return; } // Adding is enabled if (DisplayAddButton) { pnlAdd.Visible = true; lnkAddWidget.Visible = true; lnkAddWidget.Text = HTMLHelper.HTMLEncode(DataHelper.GetNotEmpty(AddButtonText, GetString("widgets.addwidget"))); int templateId = 0; if (pi.UsedPageTemplateInfo != null) { templateId = pi.UsedPageTemplateInfo.PageTemplateId; } addScript = "NewWidget('" + HttpUtility.UrlEncode(zoneInstance.ZoneID) + "', '" + HttpUtility.UrlEncode(pi.NodeAliasPath) + "', '" + templateId + "'); return false;"; lnkAddWidget.Attributes.Add("onclick", addScript); } // Reset is enabled if (DisplayResetButton) { pnlReset.Visible = true; btnReset.Text = HTMLHelper.HTMLEncode(DataHelper.GetNotEmpty(ResetButtonText, GetString("widgets.resettodefault"))); btnReset.Click += new EventHandler(btnReset_Click); // Add confirmation if required if (ResetConfirmationRequired) { btnReset.Attributes.Add("onclick", "if (!confirm('" + GetString("widgets.resetzoneconfirmtext") + "')) return false;"); } } // Set the panel css clas with dependence on actions zone type switch (zoneType) { // Editor case WidgetZoneTypeEnum.Editor: pnlWidgetActions.CssClass = "EditorWidgetActions"; break; // User case WidgetZoneTypeEnum.User: pnlWidgetActions.CssClass = "UserWidgetActions"; break; // Group case WidgetZoneTypeEnum.Group: pnlWidgetActions.CssClass = "GroupWidgetActions"; break; // Dashboard case WidgetZoneTypeEnum.Dashboard: { if (pnlContextHelp.Controls.Count == 0) { // Load help control dynamically (due to faster start compilation) var help = this.LoadUserControl("~/CMSAdminControls/UI/PageElements/Help.ascx") as HelpControl; help.TopicName = "dashboard"; } } break; } } } }
/// <summary> /// Initializes the control properties. /// </summary> protected void SetupControl() { if (StopProcessing) { // Do nothing } else { if (CurrentPageInfo != null) { PageInfo pi = CurrentPageInfo; // Make visible, visibility according to the current state will be set later (solves issue with changing visibility during postbacks) Visible = true; CMSPagePlaceholder parentPlaceHolder = PortalHelper.FindParentPlaceholder(this); // Nothing to render, nothing to do if ((!DisplayAddButton && !DisplayResetButton) || ((parentPlaceHolder != null) && (parentPlaceHolder.UsingDefaultPage || (parentPlaceHolder.PageInfo.DocumentID != pi.DocumentID)))) { Visible = false; return; } var currentUser = MembershipContext.AuthenticatedUser; zoneType = WidgetZoneType.ToEnum <WidgetZoneTypeEnum>(); // Check security if (((zoneType == WidgetZoneTypeEnum.Group) && !currentUser.IsGroupAdministrator(pi.NodeGroupID)) || ((zoneType == WidgetZoneTypeEnum.User || zoneType == WidgetZoneTypeEnum.Dashboard) && !AuthenticationHelper.IsAuthenticated())) { Visible = false; resetAllowed = false; return; } // Displaying - Editor zone only in edit mode, User/Group zone only in Live site/Preview mode if (((zoneType == WidgetZoneTypeEnum.Editor) && !PortalManager.ViewMode.IsOneOf(ViewModeEnum.Edit, ViewModeEnum.EditDisabled, ViewModeEnum.EditLive)) || (((zoneType == WidgetZoneTypeEnum.User) || (zoneType == WidgetZoneTypeEnum.Group)) && !PortalManager.ViewMode.IsOneOf(ViewModeEnum.LiveSite, ViewModeEnum.Preview)) || ((zoneType == WidgetZoneTypeEnum.Dashboard) && ((PortalManager.ViewMode != ViewModeEnum.DashboardWidgets) || (String.IsNullOrEmpty(PortalContext.DashboardName))))) { Visible = false; resetAllowed = false; return; } // Get current document TreeNode currentNode = DocumentHelper.GetDocument(pi.DocumentID, TreeProvider); if (((zoneType == WidgetZoneTypeEnum.Editor) && (!currentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Editor, SiteContext.CurrentSiteName) || (currentUser.IsAuthorizedPerDocument(currentNode, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied)))) { Visible = false; resetAllowed = false; return; } // If use checkin checkout enabled, check if document is checkout by current user if (zoneType == WidgetZoneTypeEnum.Editor) { if (currentNode != null) { WorkflowManager wm = WorkflowManager.GetInstance(TreeProvider); // Get workflow info WorkflowInfo wi = wm.GetNodeWorkflow(currentNode); // Check if node is under workflow and if use checkin checkout enabled if ((wi != null) && (wi.UseCheckInCheckOut(SiteContext.CurrentSiteName))) { int checkedOutBy = currentNode.DocumentCheckedOutByUserID; // Check if document is checkout by current user if (checkedOutBy != MembershipContext.AuthenticatedUser.UserID) { Visible = false; resetAllowed = false; return; } } } } // Find widget zone PageTemplateInfo pti = pi.UsedPageTemplateInfo; // ZodeID specified directly if (!String.IsNullOrEmpty(WidgetZoneID)) { zoneInstance = pti.TemplateInstance.GetZone(WidgetZoneID); } // Zone not find or specified zone is not of correct type if ((zoneInstance != null) && (zoneInstance.WidgetZoneType != zoneType)) { zoneInstance = null; } // For delete all variants all zones are necessary if (parentPlaceHolder != null) { var zones = parentPlaceHolder.WebPartZones; if (zones != null) { foreach (CMSWebPartZone zone in zones) { if ((zone.ZoneInstance != null) && (zone.ZoneInstance.WidgetZoneType == zoneType)) { zoneInstances.Add(zone.ZoneInstance); if (zoneInstance == null) { zoneInstance = zone.ZoneInstance; } } } } } // No suitable zones on the page, nothing to do if (zoneInstance == null) { Visible = false; resetAllowed = false; return; } // Adding is enabled if (DisplayAddButton) { btnAddWidget.Visible = true; btnAddWidget.Text = GetAddWidgetButtonText(); int templateId = 0; if (pi.UsedPageTemplateInfo != null) { templateId = pi.UsedPageTemplateInfo.PageTemplateId; } addScript = (PortalContext.ViewMode == ViewModeEnum.EditLive ? "OEDeactivateWebPartBorder({ webPartSpanId: $cmsj('.OnSiteMenuTable').parent().attr('id').replace('OE_OE_', 'OE_')}, null );" : String.Empty) + "NewWidget(new zoneProperties('" + zoneInstance.ZoneID + "', '" + pi.NodeAliasPath + "', '" + templateId + "')); return false;"; btnAddWidget.Attributes.Add("onclick", addScript); } // Reset is enabled if (DisplayResetButton) { btnReset.Visible = true; btnReset.Text = GetResetButtonText(); btnReset.Click += new EventHandler(btnReset_Click); // Add confirmation if required if (ResetConfirmationRequired) { btnReset.Attributes.Add("onclick", "if (!confirm(" + ScriptHelper.GetString(PortalHelper.LocalizeStringForUI("widgets.resetzoneconfirmtext")) + ")) return false;"); } } // Set the panel css clas with dependence on actions zone type switch (zoneType) { // Editor case WidgetZoneTypeEnum.Editor: pnlWidgetActions.CssClass = "EditorWidgetActions"; break; // User case WidgetZoneTypeEnum.User: pnlWidgetActions.CssClass = "UserWidgetActions"; break; // Group case WidgetZoneTypeEnum.Group: pnlWidgetActions.CssClass = "GroupWidgetActions"; break; } } } }
/// <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; } } } }
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> /// Initializes the control properties. /// </summary> protected void SetupControl() { if (StopProcessing) { // Do nothing } else { if (CurrentPageInfo != null) { PageInfo pi = CurrentPageInfo; // Make visible, visibility according to the current state will be set later (solves issue with changing visibility during postbacks) Visible = true; CMSPagePlaceholder parentPlaceHolder = PortalHelper.FindParentPlaceholder(this); // Nothing to render, nothing to do if ((!DisplayAddButton && !DisplayResetButton) || ((parentPlaceHolder != null) && (parentPlaceHolder.UsingDefaultPage || (parentPlaceHolder.PageInfo.DocumentID != pi.DocumentID)))) { Visible = false; return; } var currentUser = MembershipContext.AuthenticatedUser; zoneType = WidgetZoneTypeCode.ToEnum(WidgetZoneType); // Check security if (((zoneType == WidgetZoneTypeEnum.Group) && !currentUser.IsGroupAdministrator(pi.NodeGroupID)) || ((zoneType == WidgetZoneTypeEnum.User || zoneType == WidgetZoneTypeEnum.Dashboard) && !AuthenticationHelper.IsAuthenticated())) { Visible = false; resetAllowed = false; return; } // Displaying - Editor zone only in edit mode, User/Group zone only in Live site/Preview mode if (((zoneType == WidgetZoneTypeEnum.Editor) && !PortalManager.ViewMode.IsOneOf(ViewModeEnum.Edit, ViewModeEnum.EditDisabled, ViewModeEnum.EditLive)) || (((zoneType == WidgetZoneTypeEnum.User) || (zoneType == WidgetZoneTypeEnum.Group)) && !PortalManager.ViewMode.IsOneOf(ViewModeEnum.LiveSite, ViewModeEnum.Preview)) || ((zoneType == WidgetZoneTypeEnum.Dashboard) && ((PortalManager.ViewMode != ViewModeEnum.DashboardWidgets) || (String.IsNullOrEmpty(PortalContext.DashboardName))))) { Visible = false; resetAllowed = false; return; } // Get current document TreeNode currentNode = DocumentHelper.GetDocument(pi.DocumentID, TreeProvider); if (((zoneType == WidgetZoneTypeEnum.Editor) && (!currentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Editor, SiteContext.CurrentSiteName) || (currentUser.IsAuthorizedPerDocument(currentNode, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied)))) { Visible = false; resetAllowed = false; return; } // If use checkin checkout enabled, check if document is checkout by current user if (zoneType == WidgetZoneTypeEnum.Editor) { if (currentNode != null) { WorkflowManager wm = WorkflowManager.GetInstance(TreeProvider); // Get workflow info WorkflowInfo wi = wm.GetNodeWorkflow(currentNode); // Check if node is under workflow and if use checkin checkout enabled if ((wi != null) && (wi.UseCheckInCheckOut(SiteContext.CurrentSiteName))) { int checkedOutBy = currentNode.DocumentCheckedOutByUserID; // Check if document is checkout by current user if (checkedOutBy != MembershipContext.AuthenticatedUser.UserID) { Visible = false; resetAllowed = false; return; } } } } // Find widget zone PageTemplateInfo pti = pi.UsedPageTemplateInfo; // ZodeID specified directly if (!String.IsNullOrEmpty(WidgetZoneID)) { zoneInstance = pti.TemplateInstance.GetZone(WidgetZoneID); } // Zone not find or specified zone is not of correct type if ((zoneInstance != null) && (zoneInstance.WidgetZoneType != zoneType)) { zoneInstance = null; } // For delete all variants all zones are necessary if (parentPlaceHolder != null) { var zones = parentPlaceHolder.WebPartZones; if (zones != null) { foreach (CMSWebPartZone zone in zones) { if ((zone.ZoneInstance != null) && (zone.ZoneInstance.WidgetZoneType == zoneType)) { zoneInstances.Add(zone.ZoneInstance); if (zoneInstance == null) { zoneInstance = zone.ZoneInstance; } } } } } // No suitable zones on the page, nothing to do if (zoneInstance == null) { Visible = false; resetAllowed = false; return; } // Adding is enabled if (DisplayAddButton) { btnAddWidget.Visible = true; btnAddWidget.Text = GetAddWidgetButtonText(); int templateId = 0; if (pi.UsedPageTemplateInfo != null) { templateId = pi.UsedPageTemplateInfo.PageTemplateId; } addScript = (PortalContext.ViewMode == ViewModeEnum.EditLive ? "OEDeactivateWebPartBorder({ webPartSpanId: $cmsj('.OnSiteMenuTable').parent().attr('id').replace('OE_OE_', 'OE_')}, null );" : String.Empty) + "NewWidget(new zoneProperties('" + zoneInstance.ZoneID + "', '" + pi.NodeAliasPath + "', '" + templateId + "')); return false;"; btnAddWidget.Attributes.Add("onclick", addScript); } // Reset is enabled if (DisplayResetButton) { btnReset.Visible = true; btnReset.Text = GetResetButtonText(); btnReset.Click += new EventHandler(btnReset_Click); // Add confirmation if required if (ResetConfirmationRequired) { btnReset.Attributes.Add("onclick", "if (!confirm(" + ScriptHelper.GetLocalizedString("widgets.resetzoneconfirmtext") + ")) return false;"); } } // Set the panel css clas with dependence on actions zone type switch (zoneType) { // Editor case WidgetZoneTypeEnum.Editor: pnlWidgetActions.CssClass = "EditorWidgetActions"; break; // User case WidgetZoneTypeEnum.User: pnlWidgetActions.CssClass = "UserWidgetActions"; break; // Group case WidgetZoneTypeEnum.Group: pnlWidgetActions.CssClass = "GroupWidgetActions"; break; } } } }
/// <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 the control properties. /// </summary> protected void SetupControl() { if (StopProcessing) { // Do nothing } else { pi = CMSContext.CurrentPageInfo; if (pi != null) { CMSPagePlaceholder parentPlaceHolder = PortalHelper.FindParentPlaceholder(this); // Nothing to render, nothing to do if ((!DisplayAddButton && !DisplayResetButton) || ((parentPlaceHolder != null) && (parentPlaceHolder.UsingDefaultPage))) { Visible = false; return; } CurrentUserInfo currentUser = CMSContext.CurrentUser; zoneType = WidgetZoneTypeCode.ToEnum(WidgetZoneType); // Check security if (((zoneType == WidgetZoneTypeEnum.Group) && !currentUser.IsGroupAdministrator(pi.NodeGroupID)) || ((zoneType == WidgetZoneTypeEnum.User || zoneType == WidgetZoneTypeEnum.Dashboard) && !currentUser.IsAuthenticated())) { Visible = false; resetAllowed = false; return; } // Displaying - Editor zone only in edit mode, User/Group zone only in Live site/Preview mode if (((zoneType == WidgetZoneTypeEnum.Editor) && ((CMSContext.ViewMode != ViewModeEnum.Edit) && (CMSContext.ViewMode != ViewModeEnum.EditLive))) || (((zoneType == WidgetZoneTypeEnum.User) || (zoneType == WidgetZoneTypeEnum.Group)) && ((CMSContext.ViewMode != ViewModeEnum.LiveSite) && (CMSContext.ViewMode != ViewModeEnum.Preview))) || ((zoneType == WidgetZoneTypeEnum.Dashboard) && ((CMSContext.ViewMode != ViewModeEnum.DashboardWidgets) || (String.IsNullOrEmpty(PortalContext.DashboardName))))) { Visible = false; resetAllowed = false; return; } // Get current document TreeNode currentNode = DocumentHelper.GetDocument(pi.DocumentID, TreeProvider); if (((zoneType == WidgetZoneTypeEnum.Editor) && (!currentUser.IsEditor || (currentUser.IsAuthorizedPerDocument(currentNode, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied)))) { Visible = false; resetAllowed = false; return; } // If use checkin checkout enabled, check if document is checkout by current user if (zoneType == WidgetZoneTypeEnum.Editor) { if (currentNode != null) { WorkflowManager wm = WorkflowManager.GetInstance(TreeProvider); // Get workflow info WorkflowInfo wi = wm.GetNodeWorkflow(currentNode); // Check if node is under workflow and if use checkin checkout enabled if ((wi != null) && (wi.UseCheckInCheckOut(CMSContext.CurrentSiteName))) { int checkedOutBy = currentNode.DocumentCheckedOutByUserID; // Check if document is checkout by current user if (checkedOutBy != CMSContext.CurrentUser.UserID) { Visible = false; resetAllowed = false; return; } } } } // Find widget zone PageTemplateInfo pti = pi.UsedPageTemplateInfo; // ZodeID specified directly if (!String.IsNullOrEmpty(WidgetZoneID)) { zoneInstance = pti.GetZone(WidgetZoneID); } // Zone not find or specified zone is not of correct type if ((zoneInstance != null) && (zoneInstance.WidgetZoneType != zoneType)) { zoneInstance = null; } // For delete all variants all zones are necessary if (parentPlaceHolder != null) { var zones = parentPlaceHolder.WebPartZones; if (zones != null) { foreach (CMSWebPartZone zone in zones) { if ((zone.ZoneInstance != null) && (zone.ZoneInstance.WidgetZoneType == zoneType)) { zoneInstances.Add(zone.ZoneInstance); if (zoneInstance == null) { zoneInstance = zone.ZoneInstance; } } } } } // No suitable zones on the page, nothing to do if (zoneInstance == null) { Visible = false; resetAllowed = false; return; } // Adding is enabled if (DisplayAddButton) { pnlAdd.Visible = true; lnkAddWidget.Visible = true; lnkAddWidget.Text = HTMLHelper.HTMLEncode(DataHelper.GetNotEmpty(AddButtonText, GetString("widgets.addwidget"))); int templateId = 0; if (pi.UsedPageTemplateInfo != null) { templateId = pi.UsedPageTemplateInfo.PageTemplateId; } addScript = "NewWidget('" + HttpUtility.UrlEncode(zoneInstance.ZoneID) + "', '" + HttpUtility.UrlEncode(pi.NodeAliasPath) + "', '" + templateId + "'); return false;"; lnkAddWidget.Attributes.Add("onclick", addScript); } // Reset is enabled if (DisplayResetButton) { pnlReset.Visible = true; btnReset.Text = HTMLHelper.HTMLEncode(DataHelper.GetNotEmpty(ResetButtonText, GetString("widgets.resettodefault"))); btnReset.Click += new EventHandler(btnReset_Click); // Add confirmation if required if (ResetConfirmationRequired) { btnReset.Attributes.Add("onclick", "if (!confirm('" + GetString("widgets.resetzoneconfirmtext") + "')) return false;"); } } // Set the panel css clas with dependence on actions zone type switch (zoneType) { // Editor case WidgetZoneTypeEnum.Editor: pnlWidgetActions.CssClass = "EditorWidgetActions"; break; // User case WidgetZoneTypeEnum.User: pnlWidgetActions.CssClass = "UserWidgetActions"; break; // Group case WidgetZoneTypeEnum.Group: pnlWidgetActions.CssClass = "GroupWidgetActions"; break; // Dashboard case WidgetZoneTypeEnum.Dashboard: { if (pnlContextHelp.Controls.Count == 0) { // Load help control dynamically (due to faster start compilation) var help = this.LoadUserControl("~/CMSAdminControls/UI/PageElements/Help.ascx") as HelpControl; help.TopicName = "dashboard"; } } break; } } } }
/// <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> /// 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>"; } }
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); }
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); }
protected void Page_Load(object sender, EventArgs e) { Hashtable decodedProperties = new Hashtable(); foreach (DictionaryEntry param in mProperties) { // Decode special CK editor char String str = String.Empty; if (param.Value != null) { str = param.Value.ToString().Replace("%25", "%"); } decodedProperties[param.Key] = HttpUtility.UrlDecode(str); } mProperties = decodedProperties; string widgetName = ValidationHelper.GetString(mProperties["name"], String.Empty); // Widget name must be specified if (String.IsNullOrEmpty(widgetName)) { AddErrorWebPart("widgets.invalidname", null); return; } WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo(widgetName); if (wi == null) { AddErrorWebPart("widget.failedtoload", null); return; } WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID); if (wpi == null) { return; } //no widgets can be used as inline if (!wi.WidgetForInline) { AddErrorWebPart("widgets.cantbeusedasinline", null); return; } try { // Merge widget and it's parent webpart properties string properties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties); // Prepare form WidgetZoneTypeEnum zoneType = WidgetZoneTypeEnum.Editor; FormInfo zoneTypeDefinition = PortalHelper.GetPositionFormInfo(zoneType); FormInfo fi = FormHelper.GetWidgetFormInfo(wi.WidgetName, Enum.GetName(typeof(WidgetZoneTypeEnum), zoneType), properties, zoneTypeDefinition, true); // Apply changed values DataRow dr = fi.GetDataRow(); fi.LoadDefaultValues(dr); // Incorporate inline parameters to datarow string publicFields = ";containertitle;container;"; if (wi.WidgetPublicFileds != null) { publicFields += ";" + wi.WidgetPublicFileds.ToLower() + ";"; } // Load the webpart(widget) control string url = WebPartInfoProvider.GetWebPartUrl(wpi, false); CMSAbstractWebPart control = (CMSAbstractWebPart)Page.LoadControl(url); control.PartInstance = new WebPartInstance(); // Set all form values to webpart foreach (DataColumn column in dr.Table.Columns) { object value = dr[column]; string columnName = column.ColumnName.ToLower(); //Resolve set values by user if (mProperties.Contains(columnName)) { FormFieldInfo ffi = fi.GetFormField(columnName); if ((ffi != null) && ffi.Visible && (!ffi.DisplayIn.Contains(FormInfo.DISPLAY_CONTEXT_DASHBOARD))) { value = mProperties[columnName]; } } // Resolve macros in defined in default values if (!String.IsNullOrEmpty(value as string)) { // Do not resolve macros for public fields if (publicFields.IndexOf(";" + columnName + ";") < 0) { // Check whether current column bool avoidInjection = control.SQLProperties.Contains(";" + columnName + ";"); // Resolve macros value = control.ContextResolver.ResolveMacros(value.ToString(), avoidInjection); } } control.PartInstance.SetValue(column.ColumnName, value); } // Load webpart content control.OnContentLoaded(); // Add webpart to controls collection this.Controls.Add(control); } catch (Exception ex) { AddErrorWebPart("widget.failedtoload", ex); } }
/// <summary> /// Adds the inline widget without the properties dialog. /// </summary> /// <param name="widgetId">The widget id</param> private string AddInlineWidgetWithoutDialog(int widgetId) { string script = string.Empty; if (widgetId > 0) { // New widget - load widget info by id WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo(widgetId); if ((wi != null) && wi.WidgetForInline) { // Test permission for user var currentUser = MembershipContext.AuthenticatedUser; if (!WidgetRoleInfoProvider.IsWidgetAllowed(widgetId, currentUser.UserID, AuthenticationHelper.IsAuthenticated())) { return(string.Empty); } // If user is editor, more properties are shown WidgetZoneTypeEnum zoneType = WidgetZoneTypeEnum.User; if (currentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Editor, SiteContext.CurrentSiteName)) { zoneType = WidgetZoneTypeEnum.Editor; } WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID); // Merge the parent web part properties definition with the widget properties definition string widgetProperties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties); // Create the FormInfo for the current widget properties definition FormInfo fi = PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, zoneType, widgetProperties, true); DataRow dr = null; if (fi != null) { // Get data rows with required columns dr = PortalHelper.CombineWithDefaultValues(fi, wi); // Load default values for new widget fi.LoadDefaultValues(dr, FormResolveTypeEnum.Visible); // Override default value and set title as widget display name DataHelper.SetDataRowValue(dr, "WidgetTitle", wi.WidgetDisplayName); } // Save inline widget script script = PortalHelper.GetAddInlineWidgetScript(wi, dr, fi.GetFields(true, true)); script += " CloseDialog(false);"; if (!string.IsNullOrEmpty(script)) { // Add to recently used widgets collection MembershipContext.AuthenticatedUser.UserSettings.UpdateRecentlyUsedWidget(wi.WidgetName); } } } return(script); }
/// <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; } } }