コード例 #1
0
        public bool SameDevice(string identifier)
        {
            if (!string.IsNullOrEmpty(DevicePath))
            {
                return(identifier == DevicePath);
            }
            else
            {
                return(identifier == InstanceGUID.ToString());
            }

            return(false);
        }
コード例 #2
0
    private NameValueCollection GetQueryStringParameters()
    {
        NameValueCollection queryStringParameters = null;

        if (DocumentManager.AllowSave)
        {
            queryStringParameters = new NameValueCollection()
            {
                { PageBuilderHelper.EDITING_INSTANCE_QUERY_NAME, InstanceGUID.ToString() }
            };
        }

        return(queryStringParameters);
    }
コード例 #3
0
    /// <summary>
    /// Prepares the layout of the web part.
    /// </summary>
    protected override void PrepareLayout()
    {
        StartLayout();

        string height = ValidationHelper.GetString(GetValue("Height"), "");

        // Prepare the data for equal heights script
        bool equal = EqualHeight;

        string groupClass = null;

        if (equal)
        {
            groupClass = "Cols_" + InstanceGUID.ToString().Replace("-", "");
        }

        if (IsDesign)
        {
            Append("<table class=\"LayoutTable\" cellspacing=\"0\" style=\"width: 100%;\">");

            if (ViewModeIsDesign())
            {
                Append("<tr><td class=\"LayoutHeader\">");

                // Add header container
                AddHeaderContainer();

                Append("</td></tr>");
            }

            Append("<tr><td>");
        }

        // Prepare automatic width
        string autoWidth = null;
        int    cols      = LeftColumns + RightColumns;

        if (CenterColumn)
        {
            cols++;
        }
        if (cols > 0)
        {
            autoWidth = ((100 - cols) / cols) + "%";
        }

        // Encapsulating div
        if (IsDesign && AllowDesignMode)
        {
            Append("<div id=\"", ShortClientID, "_all\">");
        }
        else
        {
            Append("<div>");
        }

        // Left columns
        CreateColumns(LeftColumns, height, equal, groupClass, autoWidth, false);

        // Right columns
        CreateColumns(RightColumns, height, equal, groupClass, autoWidth, true);

        // Center column
        if (CenterColumn)
        {
            if (IsDesign && AllowDesignMode)
            {
                Append("<div style=\"overflow: auto;\" class=\"LayoutCenterColumn\">");
            }

            Append("<div");

            // Cell class
            string thisColumnClass = ValidationHelper.GetString(GetValue("CenterColumnCSSClass"), "");
            if (equal)
            {
                thisColumnClass = CSSHelper.JoinClasses(thisColumnClass, groupClass);
            }

            if (!String.IsNullOrEmpty(thisColumnClass))
            {
                Append(" class=\"");
                Append(thisColumnClass);
                Append("\"");
            }

            string style = "overflow: auto;";

            // Height
            if (!equal)
            {
                height = DataHelper.GetNotEmpty(GetValue("CenterColumnHeight"), height);
            }
            if (!String.IsNullOrEmpty(height))
            {
                style += " height: " + height + ";";
            }

            // Append style
            if (!String.IsNullOrEmpty(style))
            {
                Append(" style=\"");
                Append(style);
                Append("\"");
            }

            if (IsDesign)
            {
                Append(" id=\"", ShortClientID, "_col_c\"");
            }

            Append(">");

            // Add the zone
            AddZone(ID + "_center", "Center");

            Append("</div>");

            if (IsDesign)
            {
                // Vertical resizer for center column
                if (AllowDesignMode && !equal)
                {
                    Append("<div class=\"VerticalResizer\" onmousedown=\"" + GetVerticalResizerScript("col_c", "CenterColumnHeight") + " return false;\">&nbsp;</div>");
                }

                Append("</div>");
            }
        }

        // End of encapsulating div
        Append("<div style=\"clear: both;\"></div></div>");

        if (IsDesign)
        {
            Append("</td></tr>");

            // Footer with actions
            if (AllowDesignMode)
            {
                // Vertical resizer for all columns
                if (equal)
                {
                    Append("<tr><td class=\"VerticalResizer\" onmousedown=\"" + GetVerticalResizerScript("all", "Height", null, "SetAllHeight_" + groupClass) + " return false;\">&nbsp;</td></tr>");
                }

                Append("<tr><td class=\"LayoutFooter cms-bootstrap\"><div class=\"LayoutFooterContent\">");

                // Pane actions
                Append("<div class=\"LayoutLeftActions\">");
                AppendAddAction(ResHelper.GetString("Layout.AddLeftColumn"), "LeftColumns");
                if (LeftColumns > 0)
                {
                    AppendRemoveAction(ResHelper.GetString("Layout.RemoveLeftColumn"), "LeftColumns");
                }
                Append("</div>");

                Append("<div class=\"LayoutRightActions\">");
                AppendAddAction(ResHelper.GetString("Layout.AddRightColumn"), "RightColumns");
                if (RightColumns > 0)
                {
                    AppendRemoveAction(ResHelper.GetString("Layout.RemoveRightColumn"), "RightColumns");
                }
                Append("</div>");

                Append("</div></td></tr>");
            }

            Append("</table>");
        }

        FinishLayout();

        // Enforce equal height with a javascript
        if (equal)
        {
            PortalHelper.RegisterLayoutsScript(this.Page);
            ScriptHelper.RegisterScriptFile(Page, "jquery/jquery-equalheight.js");

            StringBuilder sb = new StringBuilder();

            sb.Append(
                @"
function SetAllHeight_", groupClass, @"(h) {
    SetAllHeight('", groupClass, @"', h);
}

InitEqualHeight('", groupClass, @"');
"
                );

            ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "EqualHeight_" + groupClass, ScriptHelper.GetScript(sb.ToString()));
        }
    }
コード例 #4
0
    /// <summary>
    /// Saves webpart properties.
    /// </summary>
    public bool Save()
    {
        // Check MVT/CP security
        if (VariantID > 0)
        {
            // Check OnlineMarketing permissions.
            if (!CheckPermissions("Manage"))
            {
                ShowError(GetString("general.modifynotallowed"));
                return(false);
            }
        }

        // Save the data
        if ((pi != null) && (pti != null) && (templateInstance != null) && SaveForm(form))
        {
            if (SynchronizationHelper.IsCheckedOutByOtherUser(pti))
            {
                string   userName = null;
                UserInfo ui       = UserInfoProvider.GetUserInfo(pti.Generalized.IsCheckedOutByUserID);
                if (ui != null)
                {
                    userName = HTMLHelper.HTMLEncode(ui.GetFormattedUserName(IsLiveSite));
                }

                ShowError(string.Format(GetString("ObjectEditMenu.CheckedOutByAnotherUser"), pti.TypeInfo.ObjectType, pti.DisplayName, userName));
                return(false);
            }

            // Add web part if new
            if (IsNewWebPart)
            {
                int webpartId = ValidationHelper.GetInteger(WebPartID, 0);

                // Ensure layout zone flag
                if (QueryHelper.GetBoolean("layoutzone", false))
                {
                    WebPartZoneInstance zone = pti.TemplateInstance.EnsureZone(ZoneID);
                    zone.LayoutZone = true;
                }

                webPartInstance = PortalHelper.AddNewWebPart(webpartId, ZoneID, false, ZoneVariantID, Position, templateInstance);

                // Set default layout
                if (wpi.WebPartParentID > 0)
                {
                    WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetDefaultLayout(wpi.WebPartID);
                    if (wpli != null)
                    {
                        webPartInstance.SetValue("WebPartLayout", wpli.WebPartLayoutCodeName);
                    }
                }
            }

            webPartInstance.XMLVersion = 1;
            if (IsNewVariant)
            {
                webPartInstance             = webPartInstance.Clone();
                webPartInstance.VariantMode = VariantModeFunctions.GetVariantModeEnum(QueryHelper.GetString("variantmode", String.Empty).ToLowerInvariant());
            }

            // Get basic form's data row and update web part
            SaveFormToWebPart(form);

            // Set new position if set
            if (PositionLeft > 0)
            {
                webPartInstance.SetValue("PositionLeft", PositionLeft);
            }
            if (PositionTop > 0)
            {
                webPartInstance.SetValue("PositionTop", PositionTop);
            }

            bool isWebPartVariant = (VariantID > 0) || (ZoneVariantID > 0) || IsNewVariant;
            if (!isWebPartVariant)
            {
                // Save the changes
                CMSPortalManager.SaveTemplateChanges(pi, templateInstance, WidgetZoneTypeEnum.None, ViewModeEnum.Design, tree);
            }
            else
            {
                Hashtable varProperties = WindowHelper.GetItem("variantProperties") as Hashtable;
                // Save changes to the web part variant
                VariantHelper.SaveWebPartVariantChanges(webPartInstance, VariantID, ZoneVariantID, VariantMode, varProperties);
            }

            // Reload the form (because of macro values set only by JS)
            form.ReloadData();

            // Clear the cached web part
            CacheHelper.TouchKey("webpartinstance|" + InstanceGUID.ToString().ToLowerInvariant());

            ShowChangesSaved();

            return(true);
        }

        if (webPartInstance?.ParentZone?.ParentTemplateInstance != null)
        {
            // Reload the zone/web part variants when saving of the form fails
            webPartInstance.ParentZone.ParentTemplateInstance.LoadVariants(true, VariantModeEnum.None);
        }

        return(false);
    }
コード例 #5
0
    /// <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);
    }
コード例 #6
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (!StopProcessing)
        {
            #region "Caching options"

            // Set caching options if server processing is enabled
            if (DataSourceControl != null && EnableServerProcessing)
            {
                BasicBingMaps.CacheItemName = DataSourceControl.CacheItemName;
                BasicBingMaps.CacheMinutes  = DataSourceControl.CacheMinutes;

                // Cache depends only on data source and properties of data source web part
                string cacheDependencies = CacheHelper.GetCacheDependencies(DataSourceControl.CacheDependencies, DataSourceControl.GetDefaultCacheDependencies());
                // All view modes, except LiveSite mode
                if (PortalContext.ViewMode != ViewModeEnum.LiveSite)
                {
                    // Cache depends on data source, properties of data source web part and properties of BasicBingMaps web part
                    cacheDependencies += "webpartinstance|" + InstanceGUID.ToString().ToLowerCSafe();
                }
                BasicBingMaps.CacheDependencies = cacheDependencies;
            }

            #endregion


            #region "Map properties"

            CMSMapProperties mp = new CMSMapProperties();
            mp.Location = DefaultLocation;
            mp.EnableKeyboardShortcuts = EnableKeyboardShortcuts;
            mp.EnableMapDragging       = EnableMapDragging;
            mp.Height = Height;
            mp.Width  = Width;
            mp.EnableServerProcessing = EnableServerProcessing;
            mp.Longitude             = Longitude;
            mp.Latitude              = Latitude;
            mp.LatitudeField         = LatitudeField;
            mp.LongitudeField        = LongitudeField;
            mp.LocationField         = LocationField;
            mp.MapKey                = MapKey;
            mp.MapType               = MapType;
            mp.Scale                 = Scale;
            mp.ShowNavigationControl = ShowNavigationControl;
            mp.ShowScaleControl      = ShowScaleControl;
            mp.ToolTipField          = ToolTipField;
            mp.IconField             = IconField;
            mp.ZoomScale             = ZoomScale;
            mp.MapId                 = ClientID;

            #endregion


            BasicBingMaps.MapProperties          = mp;
            BasicBingMaps.HideControlForZeroRows = HideControlForZeroRows;
            BasicBingMaps.DataBindByDefault      = false;
            BasicBingMaps.MainScriptPath         = "~/CMSWebParts/Maps/Basic/BasicBingMaps_files/BingMaps.js";

            // Add basic maps control to the filter collection
            EnsureFilterControl();

            if (!String.IsNullOrEmpty(ZeroRowsText))
            {
                BasicBingMaps.ZeroRowsText = ZeroRowsText;
            }
        }
    }
コード例 #7
0
    /// <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);
    }
コード例 #8
0
    /// <summary>
    /// Saves webpart properties.
    /// </summary>
    public bool Save()
    {
        // Check MVT/CP security
        if (VariantID > 0)
        {
            // Check OnlineMarketing permissions.
            if (!CheckPermissions("Manage"))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("general.modifynotallowed");
                return(false);
            }
        }

        // Save the data
        if ((pi != null) && (pti != null) && (templateInstance != null) && SaveForm(form))
        {
            // Add web part if new
            if (IsNewWebPart)
            {
                AddWebPart();
            }

            WebPartInstance originalWebPartInstance = webPartInstance;
            if (IsNewVariant)
            {
                webPartInstance             = webPartInstance.Clone();
                webPartInstance.VariantMode = VariantModeFunctions.GetVariantModeEnum(QueryHelper.GetString("variantmode", String.Empty).ToLower());
            }

            // Get basicform's datarow and update webpart
            SaveFormToWebPart(form);

            bool isWebPartVariant = (VariantID > 0) || (ZoneVariantID > 0) || IsNewVariant;
            if (!isWebPartVariant)
            {
                // Save the changes
                CMSPortalManager.SaveTemplateChanges(pi, pti, templateInstance, WidgetZoneTypeEnum.None, ViewModeEnum.Design, tree);
            }
            else
            {
                // Save the variant properties
                if ((webPartInstance != null) &&
                    (webPartInstance.ParentZone != null) &&
                    (!webPartInstance.ParentZone.HasVariants) && // Save only if the parent zone does not have any variants
                    (webPartInstance.ParentZone.ParentTemplateInstance != null) &&
                    (webPartInstance.ParentZone.ParentTemplateInstance.ParentPageTemplate != null))
                {
                    string      variantName             = string.Empty;
                    string      variantDisplayName      = string.Empty;
                    string      variantDisplayCondition = string.Empty;
                    string      variantDescription      = string.Empty;
                    bool        variantEnabled          = true;
                    string      zoneId       = webPartInstance.ParentZone.ZoneID;
                    int         templateId   = webPartInstance.ParentZone.ParentTemplateInstance.ParentPageTemplate.PageTemplateId;
                    Guid        instanceGuid = Guid.Empty;
                    XmlDocument doc          = new XmlDocument();
                    XmlNode     xmlWebParts  = null;

                    if (ZoneVariantID > 0)
                    {
                        // This webpart is in a zone variant therefore save the whole variant webparts
                        xmlWebParts = webPartInstance.ParentZone.GetXmlNode(doc);
                        if (VariantMode == VariantModeEnum.MVT)
                        {
                            // MVT variant
                            ModuleCommands.OnlineMarketingSaveMVTVariantWebParts(ZoneVariantID, xmlWebParts);
                        }
                        else if (VariantMode == VariantModeEnum.ContentPersonalization)
                        {
                            // Content personalization variant
                            ModuleCommands.OnlineMarketingSaveContentPersonalizationVariantWebParts(ZoneVariantID, xmlWebParts);
                        }
                    }
                    else
                    {
                        // web part/widget variant
                        xmlWebParts  = webPartInstance.GetXmlNode(doc);
                        instanceGuid = InstanceGUID;

                        Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable;
                        if (properties != null)
                        {
                            variantName        = ValidationHelper.GetString(properties["codename"], string.Empty);
                            variantDisplayName = ValidationHelper.GetString(properties["displayname"], string.Empty);
                            variantDescription = ValidationHelper.GetString(properties["description"], string.Empty);
                            variantEnabled     = ValidationHelper.GetBoolean(properties["enabled"], true);
                            if (VariantMode == VariantModeEnum.ContentPersonalization)
                            {
                                variantDisplayCondition = ValidationHelper.GetString(properties["condition"], string.Empty);
                            }
                        }

                        // Save the web part variant properties
                        if (VariantMode == VariantModeEnum.MVT)
                        {
                            // MVT variant
                            ModuleCommands.OnlineMarketingSaveMVTVariant(VariantID, variantName, variantDisplayName, variantDescription, variantEnabled, zoneId, webPartInstance.InstanceGUID, templateId, 0, xmlWebParts);
                        }
                        else if (VariantMode == VariantModeEnum.ContentPersonalization)
                        {
                            // Content personalization variant
                            ModuleCommands.OnlineMarketingSaveContentPersonalizationVariant(VariantID, variantName, variantDisplayName, variantDescription, variantEnabled, variantDisplayCondition, zoneId, webPartInstance.InstanceGUID, templateId, 0, xmlWebParts);
                        }

                        // The variants are cached -> Reload
                        if (originalWebPartInstance != null)
                        {
                            originalWebPartInstance.LoadVariants(true, VariantMode);
                        }
                    }
                }
            }

            // Reload the form (because of macro values set only by JS)
            form.ReloadData();

            // Clear the cached web part
            if (InstanceGUID != null)
            {
                CacheHelper.TouchKey("webpartinstance|" + InstanceGUID.ToString().ToLower());
            }

            return(true);
        }
        else if ((webPartInstance != null) && (webPartInstance.ParentZone != null))
        {
            // Reload the zone/web part variants when saving of the form fails
            webPartInstance.ParentZone.LoadVariants(true, VariantModeEnum.None);
        }

        return(false);
    }
コード例 #9
0
    /// <summary>
    /// Saves widget properties.
    /// </summary>
    public bool Save()
    {
        if (VariantID > 0)
        {
            // Check MVT/CP security
            if (!CheckPermissions("Manage"))
            {
                ShowError("general.modifynotallowed");
                return(false);
            }
        }

        // Save the data
        if ((pi != null) && (pti != null) && (templateInstance != null) && SaveForm(formCustom))
        {
            // Check manage permission for non-livesite version
            if ((CMSContext.ViewMode != ViewModeEnum.LiveSite) && (CMSContext.ViewMode != ViewModeEnum.DashboardWidgets))
            {
                if (CMSContext.CurrentUser.IsAuthorizedPerDocument(pi.NodeId, pi.ClassName, NodePermissionsEnum.Modify) != AuthorizationResultEnum.Allowed)
                {
                    return(false);
                }
            }

            // Get the zone
            zone = templateInstance.EnsureZone(ZoneId);

            if (zone != null)
            {
                zone.WidgetZoneType = zoneType;

                // Add new widget
                if (IsNewWidget)
                {
                    AddWidget();
                }

                if (IsNewVariant)
                {
                    widgetInstance = widgetInstance.Clone();

                    if (pi.DocumentTemplateInstance.WebPartZones.Count == 0)
                    {
                        // Save to the document as editor admin changes
                        TreeNode node = DocumentHelper.GetDocument(pi.DocumentId, tree);

                        // Extract and set the document web parts
                        node.SetValue("DocumentWebParts", templateInstance.GetZonesXML(WidgetZoneTypeEnum.Editor));

                        // Save the document
                        DocumentHelper.UpdateDocument(node, tree);
                    }
                }

                // Get basicform's datarow and update widget
                SaveFormToWidget(formCustom);

                if (IsNewVariant)
                {
                    // Ensures unique id for new widget variant
                    widgetInstance.ControlID = WebPartZoneInstance.GetUniqueWebPartId(wi.WidgetName, zone.ParentTemplateInstance);
                }

                // Allow set dashboard in design mode
                if ((zoneType == WidgetZoneTypeEnum.Dashboard) && String.IsNullOrEmpty(PortalContext.DashboardName))
                {
                    PortalContext.SetViewMode(ViewModeEnum.Design);
                }

                bool isWidgetVariant = (VariantID > 0) || IsNewVariant;
                if (!isWidgetVariant)
                {
                    // Save the changes
                    CMSPortalManager.SaveTemplateChanges(pi, pti, templateInstance, zoneType, CMSContext.ViewMode, tree);
                }
                else if ((CMSContext.ViewMode == ViewModeEnum.Edit) && (zoneType == WidgetZoneTypeEnum.Editor))
                {
                    // Save the variant properties
                    if ((widgetInstance != null) &&
                        (widgetInstance.ParentZone != null) &&
                        (widgetInstance.ParentZone.ParentTemplateInstance != null) &&
                        (widgetInstance.ParentZone.ParentTemplateInstance.ParentPageTemplate != null))
                    {
                        string      variantName             = string.Empty;
                        string      variantDisplayName      = string.Empty;
                        string      variantDisplayCondition = string.Empty;
                        string      variantDescription      = string.Empty;
                        bool        variantEnabled          = true;
                        string      zoneId       = widgetInstance.ParentZone.ZoneID;
                        int         templateId   = widgetInstance.ParentZone.ParentTemplateInstance.ParentPageTemplate.PageTemplateId;
                        Guid        instanceGuid = Guid.Empty;
                        XmlDocument doc          = new XmlDocument();
                        XmlNode     xmlWebParts  = null;

                        xmlWebParts  = widgetInstance.GetXmlNode(doc);
                        instanceGuid = InstanceGUID;

                        Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable;
                        if (properties != null)
                        {
                            variantName        = ValidationHelper.GetString(properties["codename"], string.Empty);
                            variantDisplayName = ValidationHelper.GetString(properties["displayname"], string.Empty);
                            variantDescription = ValidationHelper.GetString(properties["description"], string.Empty);
                            variantEnabled     = ValidationHelper.GetBoolean(properties["enabled"], true);

                            if (VariantMode == VariantModeEnum.ContentPersonalization)
                            {
                                variantDisplayCondition = ValidationHelper.GetString(properties["condition"], string.Empty);
                            }
                        }

                        // Save the web part variant properties
                        if (VariantMode == VariantModeEnum.MVT)
                        {
                            ModuleCommands.OnlineMarketingSaveMVTVariant(VariantID, variantName, variantDisplayName, variantDescription, variantEnabled, zoneId, widgetInstance.InstanceGUID, templateId, pi.DocumentId, xmlWebParts);
                        }
                        else if (VariantMode == VariantModeEnum.ContentPersonalization)
                        {
                            ModuleCommands.OnlineMarketingSaveContentPersonalizationVariant(VariantID, variantName, variantDisplayName, variantDescription, variantEnabled, variantDisplayCondition, zoneId, widgetInstance.InstanceGUID, templateId, pi.DocumentId, xmlWebParts);
                        }

                        // Clear the document template
                        templateInstance.ParentPageTemplate.ParentPageInfo.DocumentTemplateInstance = null;

                        // Log widget variant synchronization
                        TreeNode node = DocumentHelper.GetDocument(pi.DocumentId, tree);
                        DocumentSynchronizationHelper.LogDocumentChange(node, TaskTypeEnum.UpdateDocument, tree);
                    }
                }
            }

            // Reload the form (because of macro values set only by JS)
            formCustom.ReloadData();

            // Clear the cached web part
            if (InstanceGUID != null)
            {
                CacheHelper.TouchKey("webpartinstance|" + InstanceGUID.ToString().ToLower());
            }

            return(true);
        }

        return(false);
    }