/// <summary> /// Load event handler. /// </summary> protected override void OnLoad(EventArgs e) { base.OnLoad(e); var viewMode = ViewModeCode.FromString(QueryHelper.GetString("viewmode", String.Empty)); var hash = QueryHelper.GetString("hash", String.Empty); LiveSiteWidgetsParameters dialogParameters = new LiveSiteWidgetsParameters(aliasPath, viewMode) { ZoneId = zoneId, ZoneType = zoneType, InstanceGuid = instanceGuid, TemplateId = templateId, IsInlineWidget = inline }; if (!dialogParameters.ValidateHash(hash)) { return; } // Register the OnSave event handler FramesManager.OnSave += (sender, arg) => { return(widgetProperties.OnSave()); }; // Register the OnApply event handler FramesManager.OnApply += (sender, arg) => { return(widgetProperties.OnApply()); }; }
protected override void OnPreRender(EventArgs e) { if (Visible) { if (pnlEdit.Visible) { // Register other scripts which are necessary in edit mode if (UseProgressScript) { ScriptHelper.RegisterLoader(Page); } // Register script StringBuilder sb = new StringBuilder(); sb.AppendLine("function Delete_" + menuElem.ClientID + "(NodeID) { " + Page.ClientScript.GetPostBackEventReference(btnDelete, null) + "; } \n"); sb.AppendLine("function " + formElem.ClientID + "_RefreshForm(){" + Page.ClientScript.GetPostBackEventReference(btnRefresh, "") + " }"); // Register the scripts AddScript(sb.ToString()); ScriptHelper.RegisterBootstrapScripts(Page); if (formElem.FieldControls != null) { // Disable maximize plugin on HTML editors var htmlControls = formElem.FormInformation.GetFields(FormFieldControlTypeEnum.HtmlAreaControl); foreach (FormFieldInfo field in htmlControls) { Control control = formElem.FieldControls[field.Name]; CMSHtmlEditor htmlEditor = ControlsHelper.GetChildControl(control, typeof(CMSHtmlEditor)) as CMSHtmlEditor; if (htmlEditor != null) { var parameters = new LiveSiteWidgetsParameters(CurrentDocument.NodeAliasPath, PortalContext.ViewMode) { IsInlineWidget = true }; htmlEditor.Node = CurrentDocument; htmlEditor.RemovePlugins.Add("maximize"); htmlEditor.Config["CurrentHash"] = parameters.GetHashString(); htmlEditor.Config["CurrentViewMode"] = PortalContext.ViewMode.ToStringRepresentation(); } } } if (!NewDocument && !NewCulture) { formElem.Enabled = AllowSave; } } } base.OnPreRender(e); }
/// <summary> /// Handles the Load event of the Page control. /// </summary> protected void Page_Load(object sender, EventArgs e) { // Public user is not allowed for widgets if (!AuthenticationHelper.IsAuthenticated()) { RedirectToAccessDenied(GetString("widgets.security.notallowed")); } var aliasPath = QueryHelper.GetString("aliaspath", String.Empty); var zoneId = QueryHelper.GetString("zoneid", String.Empty); var zoneType = QueryHelper.GetString("zonetype", "").ToEnum <WidgetZoneTypeEnum>(); var templateId = QueryHelper.GetInteger("templateid", 0); var instanceGuid = QueryHelper.GetGuid("instanceguid", Guid.Empty); var viewMode = ViewModeCode.FromString(QueryHelper.GetString("viewmode", String.Empty)); var hash = QueryHelper.GetString("hash", String.Empty); var inline = QueryHelper.GetBoolean("inline", false); LiveSiteWidgetsParameters dialogParameters = new LiveSiteWidgetsParameters(aliasPath, viewMode) { ZoneId = zoneId, ZoneType = zoneType, InstanceGuid = instanceGuid, TemplateId = templateId, IsInlineWidget = inline }; if (!dialogParameters.ValidateHash(hash)) { return; } selectElem.AliasPath = aliasPath; selectElem.CultureCode = QueryHelper.GetString("culture", LocalizationContext.PreferredCultureCode); selectElem.ZoneId = zoneId; selectElem.ZoneType = zoneType; bool isInline = QueryHelper.GetBoolean("inline", false); selectElem.IsInline = isInline; // Base tag is added in master page AddBaseTag = false; // Proceeds the current item selection StringBuilder script = new StringBuilder(); script.Append(@" function SelectCurrentWidget() {"); if (isInline) { // Skip initial configuration for inline widgets is not supported on the live site script.Append(@" selectedSkipDialog = false;"); } script.Append(@" SelectWidget(selectedValue, selectedSkipDialog); } function SelectWidget(value, skipDialog) { if ((value != null) && (value != '')) {"); if (isInline) { script.Append(@" var editor = wopener.currentEditor || wopener.CMSPlugin.currentEditor; if (editor) { editor.getCommand('InsertWidget').open(value); } CloseDialog(false);"); } else { script.Append(@" if (wopener.OnSelectWidget) { wopener.OnSelectWidget(value, skipDialog); } CloseDialog();"); } script.Append(@" } else { alert(document.getElementById('", hdnMessage.ClientID, @"').value); } } "); ScriptHelper.RegisterStartupScript(this, typeof(string), "WidgetSelector", script.ToString(), true); selectElem.SelectFunction = "SelectWidget"; selectElem.IsLiveSite = true; // Set the title and icon PageTitle.TitleText = GetString("widgets.selectortitle"); // Remove default css class if (CurrentMaster.PanelBody != null) { Panel pnl = CurrentMaster.PanelContent; if (pnl != null) { pnl.CssClass = String.Empty; } } }
/// <summary> /// Handles the Load event of the Page control. /// </summary> protected void Page_Load(object sender, EventArgs e) { // Public user is not allowed for widgets if (!AuthenticationHelper.IsAuthenticated()) { RedirectToAccessDenied(GetString("widgets.security.notallowed")); } var viewMode = ViewModeCode.FromString(QueryHelper.GetString("viewmode", String.Empty)); var hash = QueryHelper.GetString("hash", String.Empty); LiveSiteWidgetsParameters dialogparameters = new LiveSiteWidgetsParameters(aliasPath, viewMode) { ZoneId = zoneId, ZoneType = zoneType, InstanceGuid = instanceGuid, TemplateId = templateId, IsInlineWidget = inline }; if (!dialogparameters.ValidateHash(hash)) { return; } // Set page title Page.Title = GetString(isNewWidget ? "widgets.propertiespage.titlenew" : "widgets.propertiespage.title"); if ((widgetId != string.Empty) && (aliasPath != string.Empty)) { // Get page info var siteName = SiteContext.CurrentSiteName; PageInfo pi = PageInfoProvider.GetPageInfo(siteName, aliasPath, LocalizationContext.PreferredCultureCode, null, SiteInfoProvider.CombineWithDefaultCulture(siteName)); if (pi == null) { return; } // Get template instance PageTemplateInstance templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(pi); // Get widget from instance WidgetInfo wi = null; if (!isNewWidget) { // Get the instance of widget WebPartInstance widgetInstance = templateInstance.GetWebPart(instanceGuid, widgetId); if (widgetInstance == null) { return; } // Get widget info by widget name(widget type) wi = WidgetInfoProvider.GetWidgetInfo(widgetInstance.WebPartType); } // Widget instance hasn't created yet else { wi = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(widgetId, 0)); } if (wi != null) { WebPartZoneInstance zone = templateInstance.GetZone(zoneId); if (zone != null) { var currentUser = MembershipContext.AuthenticatedUser; bool checkSecurity = true; // Check security // It is group zone type but widget is not allowed in group if (zone.WidgetZoneType == WidgetZoneTypeEnum.Group) { // Should always be, only group widget are allowed in group zone if (wi.WidgetForGroup) { if (!currentUser.IsGroupAdministrator(pi.NodeGroupID)) { RedirectToAccessDenied(GetString("widgets.security.notallowed")); } // All ok, don't check classic security checkSecurity = false; } } if (checkSecurity && !WidgetRoleInfoProvider.IsWidgetAllowed(wi, currentUser.UserID, AuthenticationHelper.IsAuthenticated())) { RedirectToAccessDenied(GetString("widgets.security.notallowed")); } } } } // If all ok, set up frames rowsFrameset.Attributes.Add("rows", string.Format("{0}, *", TitleOnlyHeight)); frameHeader.Attributes.Add("src", "widgetproperties_header.aspx" + RequestContext.CurrentQueryString); if (inline && !isNewWidget) { frameContent.Attributes.Add("src", ResolveUrl("~/CMSPages/Blank.htm")); } else { frameContent.Attributes.Add("src", "widgetproperties_properties_frameset.aspx" + RequestContext.CurrentQueryString); } }
/// <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; } var dialogParams = new LiveSiteWidgetsParameters(pi.NodeAliasPath, ViewMode) { ZoneId = zoneInstance.ZoneID, TemplateId = templateId, }; var hash = dialogParams.GetHashString(); 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 + "', undefined, undefined, undefined, undefined, '" + ViewMode + "', '" + hash + "')); 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; } } } }