/// <summary> /// Saves widget properties. /// </summary> public bool Save() { if (VariantID > 0) { // Check MVT/CP security if (!CheckPermissions("Manage")) { DisplayError("general.modifynotallowed"); return(false); } } // Save the data if ((pi != null) && (templateInstance != null) && SaveForm(formCustom)) { // Check manage permission for non-livesite version if ((CMSContext.ViewMode != ViewModeEnum.LiveSite) && (CMSContext.ViewMode != ViewModeEnum.DashboardWidgets)) { if (CMSContext.CurrentUser.IsAuthorizedPerDocument(pi.NodeID, pi.ClassName, NodePermissionsEnum.Modify) != AuthorizationResultEnum.Allowed) { return(false); } } PageTemplateInfo pti = templateInstance.ParentPageTemplate; if ((CMSContext.ViewMode == ViewModeEnum.Design) && CMSObjectHelper.IsCheckedOutByOtherUser(pti)) { string userName = null; UserInfo ui = UserInfoProvider.GetUserInfo(pti.Generalized.IsCheckedOutByUserID); if (ui != null) { userName = HTMLHelper.HTMLEncode(ui.GetFormattedUserName(IsLiveSite)); } DisplayError(string.Format(GetString("ObjectEditMenu.CheckedOutByAnotherUser"), pti.ObjectType, pti.DisplayName, userName)); return(false); } // Get the zone zone = templateInstance.EnsureZone(ZoneId); if (zone != null) { zone.WidgetZoneType = zoneType; // Add new widget if (IsNewWidget) { bool isLayoutZone = (QueryHelper.GetBoolean("layoutzone", false)); int widgetID = ValidationHelper.GetInteger(WidgetId, 0); // Create new widget instance widgetInstance = PortalHelper.AddNewWidget(widgetID, ZoneId, ZoneType, isLayoutZone, templateInstance, null); } widgetInstance.XMLVersion = 1; if (IsNewVariant) { widgetInstance = widgetInstance.Clone(); if (pi.DocumentTemplateInstance.WebPartZones.Count == 0) { // Save to the document as editor admin changes TreeNode node = DocumentHelper.GetDocument(pi.DocumentID, tree); // Extract and set the document web parts node.SetValue("DocumentWebParts", templateInstance.GetZonesXML(WidgetZoneTypeEnum.Editor)); // Save the document DocumentHelper.UpdateDocument(node, tree); } } // Get basicform's datarow and update widget SaveFormToWidget(formCustom, templateInstance); if (IsNewVariant) { // Ensures unique id for new widget variant widgetInstance.ControlID = WebPartZoneInstance.GetUniqueWebPartId(wi.WidgetName, zone.ParentTemplateInstance); } // Allow set dashboard in design mode if ((zoneType == WidgetZoneTypeEnum.Dashboard) && String.IsNullOrEmpty(PortalContext.DashboardName)) { PortalContext.SetViewMode(ViewModeEnum.Design); } bool isWidgetVariant = (VariantID > 0) || IsNewVariant; if (!isWidgetVariant) { // Save the changes CMSPortalManager.SaveTemplateChanges(pi, templateInstance, zoneType, CMSContext.ViewMode, tree); } else if ((CMSContext.ViewMode == ViewModeEnum.Edit) && (zoneType == WidgetZoneTypeEnum.Editor)) { Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable; PortalHelper.SaveWebPartVariantChanges(widgetInstance, VariantID, 0, VariantMode, properties); // Clear the document template templateInstance.ParentPageTemplate.ParentPageInfo.DocumentTemplateInstance = null; // Log widget variant synchronization TreeNode node = DocumentHelper.GetDocument(pi.DocumentID, tree); DocumentSynchronizationHelper.LogDocumentChange(node, TaskTypeEnum.UpdateDocument, tree); } } // Reload the form (because of macro values set only by JS) formCustom.ReloadData(); // Clear the cached web part if (InstanceGUID != null) { CacheHelper.TouchKey("webpartinstance|" + InstanceGUID.ToString().ToLowerCSafe()); } return(true); } return(false); }
/// <summary> /// Gets new table header cell which contains label and rollback image. /// </summary> /// <param name="suffixID">ID suffix</param> /// <param name="documentID">Document ID</param> /// <param name="versionID">Version history ID</param> /// <param name="action">Action</param> private TableHeaderCell GetRollbackTableHeaderCell(string suffixID, ObjectVersionHistoryInfo objectVersion) { TableHeaderCell tblHeaderCell = new TableHeaderCell(); // Label Label lblValue = new Label(); lblValue.ID = "lbl" + suffixID; lblValue.Text = HTMLHelper.HTMLEncode(GetVersionNumber(objectVersion.VersionNumber, objectVersion.VersionModifiedWhen)); // Panel Panel pnlLabel = new Panel(); pnlLabel.ID = "pnlLabel" + suffixID; pnlLabel.CssClass = "LeftAlign"; pnlLabel.Controls.Add(lblValue); tblHeaderCell.Controls.Add(pnlLabel); // Add rollback controls if user authorized to modify selected object if (UserInfoProvider.IsAuthorizedPerObject(objectVersion.VersionObjectType, PermissionsEnum.Modify, CMSContext.CurrentSiteName, CMSContext.CurrentUser)) { // Rollback panel Panel pnlImage = new Panel(); pnlImage.ID = "pnlRollback" + suffixID; pnlImage.CssClass = "RightAlign"; // Rollback image Image imgRollback = new Image(); imgRollback.ID = "imgRollback" + suffixID; string tooltip = null; string confirmText = null; var info = CMSObjectHelper.GetObjectById(Version.VersionObjectType, Version.VersionObjectID); var rollbackEnabled = !CMSObjectHelper.IsCheckedOutByOtherUser(info); // Set image action and description according to roll back type if (chkDisplayAllData.Checked) { tooltip = GetString("objectversioning.versionlist.versionfullrollbacktooltip"); confirmText = GetString("objectversioning.versionlist.confirmfullrollback"); imgRollback.ImageUrl = GetImageUrl(rollbackEnabled ? "CMSModules/CMS_RecycleBin/restorechilds.png" : "CMSModules/CMS_RecycleBin/restorechildsdisabled.png"); } else { tooltip = GetString("history.versionrollbacktooltip"); confirmText = GetString("Unigrid.ObjectVersionHistory.Actions.Rollback.Confirmation"); imgRollback.ImageUrl = GetImageUrl(rollbackEnabled ? "Design/Controls/UniGrid/Actions/undo.png" : "Design/Controls/UniGrid/Actions/undodisabled.png"); } imgRollback.AlternateText = tooltip; imgRollback.ToolTip = tooltip; imgRollback.Style.Add("cursor", "pointer"); // Prepare onclick script if (rollbackEnabled) { var confirmScript = "if (confirm(\"" + confirmText + "\")) { "; confirmScript += ControlsHelper.GetPostBackEventReference(this, objectVersion.VersionID + "|" + chkDisplayAllData.Checked) + "; return false; }"; imgRollback.Attributes.Add("onclick", confirmScript); } pnlImage.Controls.Add(imgRollback); tblHeaderCell.Controls.Add(pnlImage); } return(tblHeaderCell); }
/// <summary> /// Saves webpart properties. /// </summary> public bool Save() { // Check MVT/CP security if (VariantID > 0) { // Check OnlineMarketing permissions. if (!CheckPermissions("Manage")) { ShowError("general.modifynotallowed"); return(false); } } // Save the data if ((pi != null) && (pti != null) && (templateInstance != null) && SaveForm(form)) { if (CMSObjectHelper.IsCheckedOutByOtherUser(pti)) { string userName = null; UserInfo ui = UserInfoProvider.GetUserInfo(pti.Generalized.IsCheckedOutByUserID); if (ui != null) { userName = HTMLHelper.HTMLEncode(ui.GetFormattedUserName(IsLiveSite)); } ShowError(string.Format(GetString("ObjectEditMenu.CheckedOutByAnotherUser"), pti.ObjectType, pti.DisplayName, userName)); return(false); } // Add web part if new if (IsNewWebPart) { int webpartId = ValidationHelper.GetInteger(WebpartId, 0); // Ensure layout zone flag if (QueryHelper.GetBoolean("layoutzone", false)) { WebPartZoneInstance zone = pti.EnsureZone(ZoneId); zone.LayoutZone = true; } webPartInstance = PortalHelper.AddNewWebPart(webpartId, ZoneId, false, ZoneVariantID, Position, templateInstance, null); } webPartInstance.XMLVersion = 1; WebPartInstance originalWebPartInstance = webPartInstance; if (IsNewVariant) { webPartInstance = webPartInstance.Clone(); webPartInstance.VariantMode = VariantModeFunctions.GetVariantModeEnum(QueryHelper.GetString("variantmode", String.Empty).ToLowerCSafe()); } // Get basic form's data row and update web part SaveFormToWebPart(form); // Set new position if set if (PositionLeft > 0) { webPartInstance.SetValue("PositionLeft", PositionLeft); } if (PositionTop > 0) { webPartInstance.SetValue("PositionTop", PositionTop); } bool isWebPartVariant = (VariantID > 0) || (ZoneVariantID > 0) || IsNewVariant; if (!isWebPartVariant) { // Save the changes CMSPortalManager.SaveTemplateChanges(pi, templateInstance, WidgetZoneTypeEnum.None, ViewModeEnum.Design, tree); } else { Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable; // Save changes to the web part variant PortalHelper.SaveWebPartVariantChanges(webPartInstance, VariantID, ZoneVariantID, VariantMode, properties); } // Reload the form (because of macro values set only by JS) form.ReloadData(); // Clear the cached web part if (InstanceGUID != null) { CacheHelper.TouchKey("webpartinstance|" + InstanceGUID.ToString().ToLowerCSafe()); } ShowChangesSaved(); return(true); } else if ((webPartInstance != null) && (webPartInstance.ParentZone != null) && (webPartInstance.ParentZone.ParentTemplateInstance != null)) { // Reload the zone/web part variants when saving of the form fails webPartInstance.ParentZone.ParentTemplateInstance.LoadVariants(true, VariantModeEnum.None); } return(false); }