/// <summary> /// Indicates whether this control should be enabled and editing allowed. /// </summary> /// <param name="viewMode">The view mode.</param> private bool IsEnabled(ViewModeEnum viewMode) { return((viewMode.IsEdit()) && DocumentManager.AllowSave); }
/// <summary> /// Handles the PreRender event of the Page control. /// </summary> protected void Page_PreRender(object sender, EventArgs e) { if (stopProcessing) { Visible = false; return; } // Show the warning panel when there is a running MVT test if ((viewMode != ViewModeEnum.Preview) && MVTestInfoProvider.ContainsRunningMVTest(DocumentContext.CurrentAliasPath, SiteContext.CurrentSiteID, DocumentContext.CurrentPageInfo.DocumentCulture)) { plcRunningTestWarning.Visible = true; } if (RequestHelper.IsPostBack()) { // Reload the combination panel because one of the combination could have been removed ReloadData(true); } // Set the OnChange attribute => Save the variant slider configuration into a cookie and raise a postback combinationSelector.DropDownSelect.Attributes.Add("onchange", "SaveCombinationPanelSelection(); " + Page.ClientScript.GetPostBackEventReference(this, "combinationchanged") + "; return false;"); MVTCombinationInfo ci = null; if (DocumentContext.CurrentDocument != null) { int templateId = DocumentContext.CurrentDocument.GetUsedPageTemplateId(); // Get the combination name from cookie string combinationName = CookieHelper.GetValue(cookieTestName); if (string.IsNullOrEmpty(combinationName)) { // CombinationName is not defined, use the default combination for the page template ci = MVTCombinationInfoProvider.GetDefaultCombinationInfo(templateId); } else { // Keep current instance node TreeNode tn = DocumentContext.CurrentDocument; // Use the defined combination ci = MVTCombinationInfoProvider.GetMVTCombinationInfo(tn.NodeAliasPath, combinationName, SiteContext.CurrentSiteName, tn.DocumentCulture); if (ci == null) { // Combination not found (can happen after deleting a variant), use the default combination for the page template ci = MVTCombinationInfoProvider.GetDefaultCombinationInfo(templateId); } } } // Show the combination panel only if there are any combinations for the document pnlMvtCombination.Enabled = combinationSelector.HasData; if (ci != null) { int combinationId = ci.MVTCombinationID; // Setup the combination panel values combinationSelector.DropDownSelect.SelectedValue = ci.MVTCombinationName; chkEnabled.Checked = ci.MVTCombinationEnabled; txtCustomName.Text = ResHelper.LocalizeString(ci.MVTCombinationCustomName, currentUser.PreferredUICultureCode); // Create javascript variables of the combination panel. Used when changing combination by the variation slider/arrows StringBuilder combinationJSList = new StringBuilder(); combinationJSList.Append("var mvtCPselector = document.getElementById('" + combinationSelector.DropDownSelect.ClientID + "');"); combinationJSList.Append("var mvtCPenabled = document.getElementById('" + chkEnabled.ClientID + "');"); combinationJSList.Append("var mvtCPcustomName = document.getElementById('" + txtCustomName.ClientID + "');"); combinationJSList.Append("var mvtCPcurrentCombinationName = document.getElementById('" + hdnCurrentCombination.ClientID + "');"); // Generate the JS configuration array for the Edit and Design view modes only (modes where the variant sliders can be used) if (viewMode.IsOneOf(ViewModeEnum.Edit, ViewModeEnum.EditDisabled) || PortalContext.IsDesignMode(viewMode)) { // Get variants for the selected combination DataSet dsSelectedCombinationVariants = MVTVariantInfoProvider.GetMVTVariants(ci.MVTCombinationPageTemplateID, combinationId); #region "Generate javascript arrays used for changing the selected combination according to the selected variants" // List of compulsory combination variants (used for the combination JS array only). // For example: // Selected combination contains WidgetVariantID3 + ZoneVariantID5 and the user is in the Edit mode. // Therefore compulsory combination variants will be only containing the zone variant ID 5-> that means: only combinations with this compulsory variant will be proceed // This ensures a correct behavior of the combination panel when changing the variant sliders. combinationJSList.Append("var compulsoryCombinationVariants = ["); int compulsoryCombinationVariantsCounter = 0; // Fill the array 'compulsoryCombinationVariants' if (!DataHelper.DataSourceIsEmpty(dsSelectedCombinationVariants)) { // Edit mode if ((viewMode.IsEdit()) || (viewMode == ViewModeEnum.EditDisabled)) { foreach (DataRow row in dsSelectedCombinationVariants.Tables[0].Rows) { // Process web part and zones only if (ValidationHelper.GetInteger(row["MVTVariantDocumentID"], 0) == 0) { if (compulsoryCombinationVariantsCounter > 0) { combinationJSList.Append(","); } // Add the web part/zone to the JS array combinationJSList.Append(ValidationHelper.GetInteger(row["MVTVariantID"], 0)); compulsoryCombinationVariantsCounter++; } } } // Design mode else if (PortalContext.IsDesignMode(viewMode)) { foreach (DataRow row in dsSelectedCombinationVariants.Tables[0].Rows) { // Process widgets only if (ValidationHelper.GetInteger(row["MVTVariantDocumentID"], 0) > 0) { if (compulsoryCombinationVariantsCounter > 0) { combinationJSList.Append(","); } // Add the widget to the JS array combinationJSList.Append(ValidationHelper.GetInteger(row["MVTVariantID"], 0)); compulsoryCombinationVariantsCounter++; } } } } combinationJSList.Append("];"); // combinationsArray - array containing configuration of each combination displayed in the combination panel. // This array is used after the user changes a variant slider and the new combination (selected by the combination panel) is to be calculated. combinationJSList.Append("var combinationsArray = ["); int combinationCount = 0; foreach (ListItem item in combinationSelector.DropDownSelect.Items) { // Get the combination object MVTCombinationInfo cObj = MVTCombinationInfoProvider.GetMVTCombinationInfo(combinationSelector.PageTemplateID, item.Value); if (cObj != null) { DataSet cVariants = MVTVariantInfoProvider.GetMVTVariants(cObj.MVTCombinationPageTemplateID, cObj.MVTCombinationID); if (combinationCount > 0) { combinationJSList.Append(","); } combinationJSList.Append("['"); combinationJSList.Append(cObj.MVTCombinationName); combinationJSList.Append("',"); combinationJSList.Append(cObj.MVTCombinationEnabled.ToString().ToLowerCSafe()); combinationJSList.Append(","); combinationJSList.Append(ScriptHelper.GetString(ResHelper.LocalizeString(cObj.MVTCombinationCustomName, currentUser.PreferredUICultureCode))); // Generate the unique variant IDs code (format: 155_158_180) - must be ordered by variantID combinationJSList.Append(",'"); if (!DataHelper.DataSourceIsEmpty(cVariants)) { int variantCount = 0; foreach (DataRow row in cVariants.Tables[0].Rows) { if (variantCount > 0) { combinationJSList.Append("_"); } combinationJSList.Append(ValidationHelper.GetString(row["MVTVariantID"], "0")); variantCount++; } } combinationJSList.Append("']"); combinationCount++; } } combinationJSList.Append("];"); #endregion // Choose the correct variant from all rendered variants for a current web part (used in Content->Design/Edit page) if (!DataHelper.DataSourceIsEmpty(dsSelectedCombinationVariants)) { combinationJSList.Append("function SetCombinationVariants() {"); bool variantWasSet = false; // Process all the variants of the selected combination foreach (DataRow row in dsSelectedCombinationVariants.Tables[0].Rows) { bool itemIsZoneVariant = string.IsNullOrEmpty(ValidationHelper.GetString(row["MVTVariantInstanceGUID"], string.Empty)); string itemIdentifier; if (itemIsZoneVariant) { // Zone itemIdentifier = "Variant_Zone_" + HTMLHelper.HTMLEncode(ValidationHelper.GetString(row["MVTVariantZoneID"], string.Empty)); } else { // Web part/widget itemIdentifier = "Variant_WP_" + ValidationHelper.GetGuid(row["MVTVariantInstanceGUID"], Guid.Empty).ToString("N"); } // Set the appropriate variant int itemVariantId = ValidationHelper.GetInteger(row["MVTVariantID"], 0); combinationJSList.Append("SetVariant('" + itemIdentifier + "', " + itemVariantId + ");"); variantWasSet = true; } if (variantWasSet) { // Refresh the combination panel if any variant was set manually combinationJSList.Append("UpdateCombinationPanel();"); } combinationJSList.Append("}"); } } // Save the current combination id in javascript combinationJSList.Append("mvtCPcurrentCombinationName.value = '" + ci.MVTCombinationName + "';"); // Register the JS arrays and current variants ScriptHelper.RegisterStartupScript(this, typeof(string), "combinationJSList", ScriptHelper.GetScript(combinationJSList.ToString())); } // Display the "set as result" button when there any MVT variants in the page if ((currentUser != null) && (currentUser.IsAuthorizedPerResource("CMS.Design", "Design"))) { plcUseCombination.Visible = combinationSelector.DropDownSelect.Items.Count > 1; } }
/// <summary> /// Saves widget properties. /// </summary> public bool Save() { if (VariantID > 0) { // Check MVT/CP security if (!CheckPermissions("Manage")) { DisplayError("general.modifynotallowed"); return(false); } } // Save the data if ((CurrentPageInfo != null) && (mTemplateInstance != null) && SaveForm(formCustom)) { ViewModeEnum viewMode = PortalContext.ViewMode; // Check manage permission for non-livesite version if (!viewMode.IsLiveSite() && viewMode != ViewModeEnum.DashboardWidgets && viewMode != ViewModeEnum.UserWidgets) { if (CurrentUser.IsAuthorizedPerDocument(CurrentPageInfo.NodeID, CurrentPageInfo.ClassName, NodePermissionsEnum.Modify) != AuthorizationResultEnum.Allowed) { DisplayError("general.modifynotallowed"); return(false); } // Check design permissions if (PortalContext.IsDesignMode(viewMode, false) && !PortalContext.CurrentUserIsDesigner) { RedirectToAccessDenied("CMS.Design", "Design"); } } PageTemplateInfo pti = mTemplateInstance.ParentPageTemplate; if (PortalContext.IsDesignMode(viewMode) && SynchronizationHelper.IsCheckedOutByOtherUser(pti)) { string userName = null; UserInfo ui = UserInfoProvider.GetUserInfo(pti.Generalized.IsCheckedOutByUserID); if (ui != null) { userName = HTMLHelper.HTMLEncode(ui.GetFormattedUserName(IsLiveSite)); } DisplayError(string.Format(GetString("ObjectEditMenu.CheckedOutByAnotherUser"), pti.TypeInfo.ObjectType, pti.DisplayName, userName)); return(false); } // Get the zone mWebPartZoneInstance = mTemplateInstance.EnsureZone(ZoneId); if (mWebPartZoneInstance != null) { mWebPartZoneInstance.WidgetZoneType = ZoneType; // Add new widget if (IsNewWidget) { bool isLayoutZone = (QueryHelper.GetBoolean("layoutzone", false)); int widgetID = ValidationHelper.GetInteger(WidgetId, 0); // Create new widget instance mWidgetInstance = PortalHelper.AddNewWidget(widgetID, ZoneId, ZoneType, isLayoutZone, mTemplateInstance); } // Ensure handling of the currently edited object (if not exists -> redirect) UIContext.EditedObject = mWidgetInstance; mWidgetInstance.XMLVersion = 1; if (IsNewVariant) { mWidgetInstance = mWidgetInstance.Clone(); // Check whether the editor widgets have been already customized if (CurrentPageInfo.DocumentTemplateInstance.WebPartZones.Count == 0) { // There are no customized editor widgets yet => copy the default editor widgets from the page template under the document (to enable customization) // Save to the document as editor admin changes TreeNode node = DocumentHelper.GetDocument(CurrentPageInfo.DocumentID, mTreeProvider); // Extract and set the document web parts node.SetValue("DocumentWebParts", mTemplateInstance.GetZonesXML(WidgetZoneTypeEnum.Editor)); // Save the document DocumentHelper.UpdateDocument(node, mTreeProvider); } } bool isLayoutWidget = ((mWebPartInfo != null) && ((WebPartTypeEnum)mWebPartInfo.WebPartType == WebPartTypeEnum.Layout)); // Get basicform's datarow and update widget SaveFormToWidget(formCustom, mTemplateInstance, isLayoutWidget); // Ensure unique id for new widget variant or layout widget if (IsNewVariant || (isLayoutWidget && IsNewWidget)) { string controlId = GetUniqueWidgetId(mWidgetInfo.WidgetName); if (!string.IsNullOrEmpty(controlId)) { mWidgetInstance.ControlID = controlId; } else { DisplayError("Unable to generate unique widget id."); return(false); } } // Allow set dashboard in design mode if ((ZoneType == WidgetZoneTypeEnum.Dashboard) && String.IsNullOrEmpty(PortalContext.DashboardName)) { viewMode = ViewModeEnum.Design; PortalContext.SetViewMode(ViewModeEnum.Design); } bool isWidgetVariant = (VariantID > 0) || IsNewVariant; if (!isWidgetVariant) { // Save the changes if ((viewMode.IsEdit(true) || viewMode.IsEditLive()) && (ZoneType == WidgetZoneTypeEnum.Editor)) { if (DocumentManager.AllowSave) { // Store the editor widgets in the temporary interlayer PortalContext.SaveEditorWidgets(CurrentPageInfo.DocumentID, mTemplateInstance.GetZonesXML(WidgetZoneTypeEnum.Editor)); } } else { // Save the changes CMSPortalManager.SaveTemplateChanges(CurrentPageInfo, mTemplateInstance, ZoneType, viewMode, mTreeProvider); } } else if ((viewMode.IsEdit()) && (ZoneType == WidgetZoneTypeEnum.Editor)) { Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable; VariantHelper.SaveWebPartVariantChanges(mWidgetInstance, VariantID, 0, VariantMode, properties); // Log widget variant synchronization TreeNode node = DocumentHelper.GetDocument(CurrentPageInfo.DocumentID, mTreeProvider); DocumentSynchronizationHelper.LogDocumentChange(node, TaskTypeEnum.UpdateDocument, mTreeProvider); } } // Reload the form (because of macro values set only by JS) formCustom.ReloadData(); // Display info message ShowChangesSaved(); // Clear the cached web part CacheHelper.TouchKey("webpartinstance|" + InstanceGUID.ToString().ToLowerCSafe()); return(true); } return(false); }
/// <summary> /// Indicates whether this control should be enabled and editing allowed. /// </summary> /// <param name="viewMode">The view mode.</param> private bool IsEnabled(ViewModeEnum viewMode) { return (viewMode.IsEdit()) && DocumentManager.AllowSave; }