コード例 #1
0
    /// <summary>
    // Setups the web part toolbar control.
    /// </summary>
    private void SetupControl()
    {
        // Initialize controls variables
        isRTLCulture           = CultureHelper.IsUICultureRTL();
        defaultWebPartImageUrl = GetImageUrl("Objects/CMS_WebPart/notavailable.png");

        // Load the web part category selector
        categorySelector.ReloadData(false);

        // Add the "Recently used" item to the category selector
        ListItem listItem = new ListItem();

        listItem.Text  = ResHelper.GetString("webparts.recentlyusedshort", prefferedUICultureCode);
        listItem.Value = CATEGORY_RECENTLY_USED;
        categorySelector.DropDownListControl.Items.Insert(0, listItem);
        categorySelector.DropDownListControl.CssClass = "WPTCategories";

        // Ensure that when selected item is changed then the web part repeater update panel will be also updated
        categorySelector.DropDownListControl.Attributes.Add("onchange", "wptCategoryChanged();");

        // Setup the handlers
        btnPopupOK.Click       += new EventHandler(btnPopupOK_Click);
        repItems.ItemDataBound += new RepeaterItemEventHandler(repItems_ItemDataBound);

        // Setup the resource strings and tooltips
        lblWptEnabled.Text  = ResHelper.GetString("adm.user.lblusershowwebparttoolbar", prefferedUICultureCode);
        lblWptPosition.Text = ResHelper.GetString("general.position", prefferedUICultureCode);

        btnPopupOK.Text     = ResHelper.GetString("general.ok", prefferedUICultureCode);
        btnPopupCancel.Text = ResHelper.GetString("general.cancel", prefferedUICultureCode);

        pnlTrash.ToolTip = ResHelper.GetString("webparttoolbar.trashtooltip", prefferedUICultureCode);

        btnConfigBtn.ToolTip       = ResHelper.GetString("general.settings", prefferedUICultureCode);
        btnConfigBtn.ImageUrl      = GetImageUrl("CMSModules/CMS_PortalEngine/Configure.png");
        btnConfigBtn.OnClientClick = "showModalPopup('" + ucPopupDialog.ClientID + "', '" + ucPopupDialog.ClientID + "_background'); return false;";

        // Setup the toolbar web part list drag-and-drop extender
        ddExtender.TargetControlID     = scrollPanel.ScrollAreaContainer.ID;
        ddExtender.DropCueID           = pnlCue.ID;
        ddExtender.DragItemClass       = "WPTSelectorEnvelope";
        ddExtender.DragItemHandleClass = "WPTHandle";
        ddExtender.OnClientDrop        = "";
        ddExtender.OnClientBeforeDrop  = "wptListOnBeforeDrop";

        // Setup the drag-and-drop extender for highlighted web parts as well.
        // This solves the issue when changing categories (using the drop down) and you highlight a web part before the init script for drag-and-drop is run.
        ddExtenderHovered.TargetControlID     = scrollPanel.ScrollAreaContainer.ID;
        ddExtenderHovered.DropCueID           = pnlCue.ID;
        ddExtenderHovered.DragItemClass       = "WPTSelectorEnvelopeHover";
        ddExtenderHovered.DragItemHandleClass = "WPTHandle";
        ddExtenderHovered.OnClientDrop        = "";
        ddExtenderHovered.OnClientBeforeDrop  = "wptListOnBeforeDrop";

        // Setup the trash drag-and-drop extender
        trashExtender.TargetControlID     = pnlTrashDropArea.ID;
        trashExtender.DropCueID           = pnlTrashCue.ID;
        trashExtender.DragItemClass       = "";
        trashExtender.DragItemHandleClass = "";
        trashExtender.OnClientDrop        = "wptTrashOnDrop";
        trashExtender.OnClientBeforeDrop  = "wptTrashOnBeforeDrop";

        // Hide the compulsory drag-and-drop panel Cue, it is not being used
        pnlCue.Style.Add("display", "none");
        pnlCue.Style.Add("position", "absolute");

        // Setup the modal popup title
        titleElem.TitleText     = ResHelper.GetString("webparttoolbar.properties", prefferedUICultureCode);
        titleElem.HelpTopicName = "CMS_Design_WPT_Settings";
        titleElem.HelpName      = "CMS_Design_WPT_Settings";
        titleElem.HelpIconUrl   = GetImageUrl("General/HelpLargeDark.png");

        pnlLoader.Controls.Add(new LiteralControl(CMSUpdateProgress.GetDefaultContent(Page)));

        pnlMaximize.Attributes.Add("onclick", "wptMaximize();");
        pnlMinimize.Attributes.Add("onclick", "wptMinimize();");
    }
コード例 #2
0
    /// <summary>
    /// Handles the PreRender event of the Page control.
    /// </summary>
    protected void Page_PreRender(object sender, EventArgs e)
    {
        if (stopProcessing)
        {
            this.Visible = false;
            return;
        }

        // Show the warning panel when there is a running MVT test
        if ((viewMode != ViewModeEnum.Preview) &&
            (ModuleCommands.OnlineMarketingContainsRunningMVTest(CMSContext.CurrentAliasPath, CMSContext.CurrentSiteID, CMSContext.CurrentPageInfo.DocumentCulture)))
        {
            plcRunningTestWarning.Visible = true;
        }

        // Setup the Update progress panel
        loading.ProgressHTML = "<div class=\"MVTLoading\" style=\"display: none;\" id=\"" + loading.ClientID + "\">" + CMSUpdateProgress.GetDefaultContent(this.Page) + "</div>";
        loading.DisplayAfter = 200;

        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 (CMSContext.CurrentDocument != null)
        {
            // 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(CMSContext.CurrentDocument.DocumentPageTemplateID);
            }
            else
            {
                // Keep current instance node
                TreeNode tn = CMSContext.CurrentDocument;

                // Use the defined combination
                ci = MVTCombinationInfoProvider.GetMVTCombinationInfo(tn.NodeAliasPath, combinationName, CMSContext.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(CMSContext.CurrentDocument.DocumentPageTemplateID);
                }
            }
        }

        // 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.ToString();
            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 + "');");
            // Move the update progress panel to the body element. This will fix the absolute/relative positioning issue.
            combinationJSList.Append("function InitUpdateProgress() { $j(document.body).prepend($j('#", loading.ClientID, "')); }");

            // Generate the JS configuration array for the Edit and Design view modes only (modes where the variatn sliders can be used)
            if ((viewMode == ViewModeEnum.Edit) || (viewMode == ViewModeEnum.EditDisabled) ||
                (viewMode == ViewModeEnum.Design) || (viewMode == ViewModeEnum.DesignDisabled))
            {
                // 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 behaviour of the combination panel when changing the variant sliders.
                combinationJSList.Append("var compulsoryCombinationVariants = [");
                int compulsoryCombinationVariantsCounter = 0;

                // Fill the array 'compulsoryCombinationVariants'
                if (!SqlHelperClass.DataSourceIsEmpty(dsSelectedCombinationVariants))
                {
                    // Edit mode
                    if ((viewMode == ViewModeEnum.Edit) || (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 ((viewMode == ViewModeEnum.Design) || (viewMode == ViewModeEnum.DesignDisabled))
                    {
                        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 containg 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().ToLower());
                        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 (!SqlHelperClass.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

                // Temporary variables
                Guid   instanceGuid      = Guid.Empty;
                string variantGuid       = string.Empty;
                string itemIdentifier    = string.Empty;
                int    itemVariantId     = 0;
                bool   itemIsZoneVariant = false;

                // Choose the correct variant from all rendered variants for a current web part (used in Content->Desing/Edit page)
                if (!SqlHelperClass.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)
                    {
                        itemIsZoneVariant = string.IsNullOrEmpty(ValidationHelper.GetString(row["MVTVariantInstanceGUID"], string.Empty));
                        itemVariantId     = ValidationHelper.GetInteger(row["MVTVariantID"], 0);

                        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
                        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;
        }
    }