Beispiel #1
0
    /// <summary>
    /// Handles the OnSaved event of the editElem control.
    /// </summary>
    protected void UIFormControl_OnBeforeSaved(object sender, EventArgs e)
    {
        if (editElem.ValidateData())
        {
            // Add the properties to the window helper
            Hashtable parameters = new Hashtable();
            parameters.Add("displayname", ValidationHelper.GetString(editElem.UIFormControl.FieldControls["VariantDisplayName"].Value, string.Empty));
            parameters.Add("codename", editElem.VariantCodeName);
            parameters.Add("description", ValidationHelper.GetString(editElem.UIFormControl.FieldControls["VariantDescription"].Value, string.Empty));
            parameters.Add("enabled", ValidationHelper.GetBoolean(editElem.UIFormControl.FieldControls["VariantEnabled"].Value, false));
            parameters.Add("condition", ValidationHelper.GetString(editElem.UIFormControl.FieldControls["VariantDisplayCondition"].Value, string.Empty));
            WindowHelper.Add("variantProperties", parameters);

            // Set a script to open the web part properties modal dialog
            string query = URLHelper.GetQuery(URLHelper.CurrentURL);
            query = URLHelper.RemoveUrlParameter(query, "nodeid");
            query = URLHelper.AddUrlParameter(query, "variantmode", VariantModeFunctions.GetVariantModeString(VariantModeEnum.ContentPersonalization));

            // Choose the correct javascript method for opening web part/zone properties
            string functionName = string.Empty;

            switch (variantType)
            {
            case VariantTypeEnum.WebPart:
                functionName = "OnAddWebPartVariant";
                break;

            case VariantTypeEnum.Widget:
                functionName = "OnAddWidgetVariant";
                query        = URLHelper.RemoveUrlParameter(query, "varianttype");
                string widgetId = QueryHelper.GetString("webpartid", string.Empty);
                query = URLHelper.RemoveUrlParameter(query, "webpartid");
                query = URLHelper.AddParameterToUrl(query, "widgetid", widgetId);
                break;

            case VariantTypeEnum.Zone:
                functionName = "OnAddWebPartZoneVariant";
                break;
            }

            // Setup the script for opening web part/zone properties
            string script = @"
            function OpenVariantProperties()
            {
                if (wopener." + functionName + @")
                {
                    wopener." + functionName + "('" + query + @"');
                }
                CloseDialog();
            }

            window.onload = OpenVariantProperties;";

            ltrScript.Text = ScriptHelper.GetScript(script);
        }

        // Do not save the variant. Will be saved when saving the web part/zone properties.
        editElem.UIFormControl.StopProcessing = true;
    }
Beispiel #2
0
    /// <summary>
    /// Handles the PreRender event of the Page control.
    /// </summary>
    protected void Page_PreRender(object sender, EventArgs e)
    {
        if (stopProcessing)
        {
            Visible = false;
            return;
        }

        // Check permissions
        if (!CheckPermissions("Manage"))
        {
            // Hide add/remove variant buttons when the Manage permission is not allowed
            plcRemoveVariant.Visible = false;
            plcAddVariant.Visible    = false;
        }

        // Hide buttons in the template edit in the site manager
        if (DocumentContext.CurrentDocument == null)
        {
            plcRemoveVariant.Visible = false;
            plcAddVariant.Visible    = false;
            plcVariantList.Visible   = false;
        }

        // Get the sum of all variants
        int totalVariants = 0;

        switch (SliderMode)
        {
        case VariantTypeEnum.Zone:
            // Zone
            if ((WebPartZoneControl != null) &&
                (WebPartZoneControl.HasVariants) &&
                (WebPartZoneControl.ZoneInstance != null) &&
                (WebPartZoneControl.ZoneInstance.ZoneInstanceVariants != null))
            {
                totalVariants = WebPartZoneControl.ZoneInstance.ZoneInstanceVariants.Count;
            }
            break;

        case VariantTypeEnum.WebPart:
        case VariantTypeEnum.Widget:
            // Web part
            // Widget
            if ((WebPartControl != null) &&
                (WebPartControl.HasVariants) &&
                (WebPartControl.PartInstance != null) &&
                (WebPartControl.PartInstance.PartInstanceVariants != null))
            {
                totalVariants = WebPartControl.PartInstance.PartInstanceVariants.Count;
            }
            break;
        }

        // Increase by 1 to include the original webpart
        totalVariants++;

        // Reset the slider state (correct variant for the current combination is chosen by javascript in window.onload)
        txtSlider.Text = "1";
        if (isRTL)
        {
            // Reverse position index when in RTL
            txtSlider.Text = totalVariants.ToString();
        }

        // Change the slider CSS class if used for widgets
        if ((WebPartControl != null) &&
            WebPartControl.IsWidget)
        {
            pnlVariations.CssClass = "WidgetVariantSlider";
        }

        // Setup the variant slider extender
        sliderExtender.Minimum        = 1;
        sliderExtender.Maximum        = totalVariants;
        sliderExtender.Steps          = totalVariants;
        sliderExtender.HandleImageUrl = GetImageUrl("Design/Controls/VariantSlider/slider.png");

        if (isRTL)
        {
            // RTL culture - set the javascript variable
            ScriptHelper.RegisterStartupScript(Page, typeof(string), "VariantSliderRTL", ScriptHelper.GetScript("variantSliderIsRTL = true;"));
        }

        // Change the arrows design for MVT
        if ((VariantMode == VariantModeEnum.MVT) || !PortalContext.ContentPersonalizationEnabled)
        {
            //pnlLeft.CssClass = "SliderLeftMVT";
            //pnlRight.CssClass = "SliderRightMVT";
        }

        CssRegistration.RegisterBootstrap(Page);

        sliderExtender.HandleCssClass = "slider-horizontal-handle";
        sliderExtender.RailCssClass   = "slider-horizontal-rail";
        lblTotal.Text = totalVariants.ToString();

        txtSlider.Attributes.Add("onchange", "$cmsj('#" + hdnSliderPosition.ClientID + "').change();");
        txtSlider.Style.Add("display", "none");

        // Prepare the parameters
        string zoneId = string.Empty;

        PageInfo pi = PagePlaceholder.PageInfo;

        string aliasPath  = pi.NodeAliasPath;
        string templateId = pi.GetUsedPageTemplateId().ToString();

        string webPartName        = string.Empty;
        string instanceGuidString = string.Empty;

        switch (SliderMode)
        {
        case VariantTypeEnum.Zone:
            // Zone
            zoneId = WebPartZoneControl.ZoneInstance.ZoneID;
            break;

        case VariantTypeEnum.WebPart:
        case VariantTypeEnum.Widget:
            // Web part
            zoneId             = WebPartControl.PartInstance.ParentZone.ZoneID;
            instanceGuidString = WebPartControl.InstanceGUID.ToString();
            webPartName        = WebPartControl.PartInstance.ControlID;
            break;
        }

        // Setup tooltips
        pnlLeft.ToolTip          = ResHelper.GetString("variantslider.btnleft", UICulture);
        pnlRight.ToolTip         = ResHelper.GetString("variantslider.btnright", UICulture);
        imgRemoveVariant.ToolTip = ResHelper.GetString("variantslider.btnremove", UICulture);
        imgVariantList.ToolTip   = ResHelper.GetString("variantslider.btnlist", UICulture);

        // Setup default behaviour - no action executed
        imgRemoveVariantDisabled.Attributes.Add("onclick", "return false;");
        imgVariantList.Attributes.Add("onclick", "return false;");

        // Cancel propagation of the double-click event (skips opening the web part properties dialog)
        pnlVariations.Attributes.Add("ondblclick", "CancelEventPropagation(event)");

        // Hidden field used for changing the slider position. The position of the slider is stored also here because of the usage of the slider arrows.
        hdnSliderPosition.Style.Add("display", "none");
        hdnSliderPosition.Attributes.Add("onchange", "OnHiddenChanged(this, document.getElementById('" + lblPart.ClientID + "'), '" + uniqueCode + "', '" + sliderExtender.BehaviorID + @"' );");

        String zoneIdPar    = (WebPartControl != null) ? "GetActualZoneId('wp_" + WebPartControl.InstanceGUID.ToString("N") + "')" : "'" + zoneId + "'";
        string dialogParams = zoneIdPar + ", '" + webPartName + "', '" + aliasPath + "', '" + instanceGuidString + "', " + templateId + ", '" + VariantTypeFunctions.GetVariantTypeString(SliderMode) + "'";

        // Allow edit actions
        if (totalVariants == 1)
        {
            if (SliderMode == VariantTypeEnum.Widget)
            {
                plcRemoveVariant.Visible = false;
                plcVariantList.Visible   = false;
                plcSliderPanel.Visible   = false;
                var  cui       = MembershipContext.AuthenticatedUser;
                bool manageMVT = cui.IsAuthorizedPerResource("cms.mvtest", "manage") && cui.IsAuthorizedPerResource("cms.mvtest", "read");
                bool manageCP  = cui.IsAuthorizedPerResource("cms.contentpersonalization", "manage") && cui.IsAuthorizedPerResource("cms.contentpersonalization", "read");

                if (PortalContext.MVTVariantsEnabled && PortalContext.ContentPersonalizationEnabled && manageMVT && manageCP)
                {
                    pnlAddVariantWrapper.Attributes.Add("onclick", "OpenMenuAddWidgetVariant(this, '" + WebPartControl.ShortClientID + "'); return false;");
                    imgAddVariant.ToolTip = ResHelper.GetString("variantslider.btnadd", UICulture);

                    // Script for opening a new variant dialog window and activating widget border to prevent to widget border from hiding
                    // when the user moves his mouse to the 'add widget' context menu.
                    string script = @"
function OpenMenuAddWidgetVariant(menuPositionEl, targetId) {
    currentContextMenuId = targetId;
    ContextMenu('addWidgetVariantMenu', menuPositionEl, webPartLocation[targetId + '_container'], true);
    AutoPostitionContextMenu('addWidgetVariantMenu');
}";
                    ScriptHelper.RegisterStartupScript(this, typeof(string), "OpenMenuAddWidgetVariantScript", ScriptHelper.GetScript(script));
                }
                else
                {
                    if (PortalContext.MVTVariantsEnabled && manageMVT)
                    {
                        imgAddVariant.Attributes.Add("onclick", "AddMVTVariant(" + dialogParams + "); return false;");
                        imgAddVariant.ToolTip = ResHelper.GetString("variantslider.btnaddmvt", UICulture);
                    }
                    else if (PortalContext.ContentPersonalizationEnabled && manageCP)
                    {
                        imgAddVariant.Attributes.Add("onclick", "AddPersonalizationVariant(" + dialogParams + "); return false;");
                        imgAddVariant.ToolTip = ResHelper.GetString("variantslider.btnaddpesronalization", UICulture);
                    }
                }
            }
        }
        else
        {
            if (VariantMode == VariantModeEnum.MVT)
            {
                imgAddVariant.Attributes.Add("onclick", "AddMVTVariant(" + dialogParams + "); return false;");
                imgAddVariant.ToolTip = ResHelper.GetString("variantslider.btnaddmvt", UICulture);
            }
            else
            {
                imgAddVariant.Attributes.Add("onclick", "AddPersonalizationVariant(" + dialogParams + "); return false;");
                imgAddVariant.ToolTip = ResHelper.GetString("variantslider.btnaddpesronalization", UICulture);
            }
        }

        if ((totalVariants > 1) || (SliderMode == VariantTypeEnum.Widget))
        {
            // Register only for full postback or first page load
            if (!RequestHelper.IsAsyncPostback())
            {
                if ((VariantMode == VariantModeEnum.MVT))
                {
                    // Activate the variant list button fot MVT
                    imgVariantList.Attributes.Add("onclick", "ListMVTVariants(" + dialogParams + ", '" + uniqueCode + "'); return false;");
                }
                else if (VariantMode == VariantModeEnum.ContentPersonalization)
                {
                    // Activate the variant list button for Content personalization
                    imgVariantList.Attributes.Add("onclick", "ListPersonalizationVariants(" + dialogParams + ", '" + uniqueCode + "'); return false;");
                }

                // Assign the onclick event for he Remove variant button
                imgRemoveVariant.Attributes.Add("onclick", "RemoveVariantPostBack_" + uniqueCode + @"(); return false");

                // Register Remove variant script
                string removeVariantScript = @"
                function RemoveVariantPostBack_" + uniqueCode + @"() {
                    if (confirm(" + ScriptHelper.GetLocalizedString("variantslider.removeconfirm") + @")) {" +
                                             DocumentManager.GetAllowSubmitScript() + @"
                        var postBackCode = '" + uniqueCode + ":remove:' + GetCurrentVariantId('" + uniqueCode + @"');
                        SetVariant('" + uniqueCode + @"', 0);"
                                             + ControlsHelper.GetPostBackEventReference(this, "#").Replace("'#'", "postBackCode") + @";
                    }
                }";

                ScriptHelper.RegisterStartupScript(Page, typeof(string), "removeVariantScript_" + uniqueCode, ScriptHelper.GetScript(removeVariantScript));

                int step = 1;
                if (isRTL)
                {
                    // Reverse step direction
                    step = -1;
                }
                // Assign the onclick events for the slider arrows
                pnlLeft.Attributes.Add("onclick", "OnSliderChanged(event, '" + hdnSliderPosition.ClientID + "', " + totalVariants + ", " + step * (-1) + ");");
                pnlRight.Attributes.Add("onclick", "OnSliderChanged(event, '" + hdnSliderPosition.ClientID + "', " + totalVariants + ", " + step + ");");

                // Get all variants GUIDs
                List <string> variantIDsArray        = new List <string>();
                List <string> variantControlIDsArray = new List <string>();
                List <string> divIDsArray            = new List <string>();

                switch (SliderMode)
                {
                case VariantTypeEnum.Zone:
                    // Zone
                    if ((WebPartZoneControl != null) &&
                        (WebPartZoneControl.ZoneInstance != null) &&
                        (WebPartZoneControl.ZoneInstance.ZoneInstanceVariants != null))
                    {
                        // Fill the variant IDs array
                        variantIDsArray = WebPartZoneControl.ZoneInstance.ZoneInstanceVariants.Select(zone => zone.VariantID.ToString()).ToList <string>();
                        // First item is the original zone (variantid=0)
                        variantIDsArray.Insert(0, "0");

                        // Fill the variant control IDs array
                        variantControlIDsArray = WebPartZoneControl.ZoneInstance.ZoneInstanceVariants.Select(zone => "\"" + (!string.IsNullOrEmpty(ValidationHelper.GetString(zone.Properties["zonetitle"], string.Empty)) ? HTMLHelper.HTMLEncode(zone.Properties["zonetitle"].ToString()) : zone.ZoneID) + "\"").ToList <string>();
                        // First item is the original web part/widget
                        variantControlIDsArray.Insert(0, "\"" + (!string.IsNullOrEmpty(WebPartZoneControl.ZoneTitle) ? HTMLHelper.HTMLEncode(WebPartZoneControl.ZoneTitle) : WebPartZoneControl.ZoneInstance.ZoneID) + "\"");

                        // Fill the DIV tag IDs array
                        divIDsArray = WebPartZoneControl.ZoneInstance.ZoneInstanceVariants.Select(zone => "\"Variant_" + VariantModeFunctions.GetVariantModeString(zone.VariantMode) + "_" + zone.VariantID.ToString() + "\"").ToList <string>();
                        // First item is the original web part
                        divIDsArray.Insert(0, "\"" + uniqueCode + "\"");
                    }
                    break;

                case VariantTypeEnum.WebPart:
                case VariantTypeEnum.Widget:
                    // Web part or widget
                    if ((WebPartControl != null) &&
                        (WebPartControl.PartInstance != null) &&
                        (WebPartControl.PartInstance.PartInstanceVariants != null))
                    {
                        // Fill the variant IDs array
                        variantIDsArray = WebPartControl.PartInstance.PartInstanceVariants.Select(webpart => webpart.VariantID.ToString()).ToList <string>();
                        // First item is the original web part/widget (variantid=0)
                        variantIDsArray.Insert(0, "0");

                        // Fill the variant control IDs array
                        variantControlIDsArray = WebPartControl.PartInstance.PartInstanceVariants.Select(webpart => "\"" + (!string.IsNullOrEmpty(ValidationHelper.GetString(webpart.Properties["webparttitle"], string.Empty)) ? HTMLHelper.HTMLEncode(webpart.Properties["webparttitle"].ToString()) : webpart.ControlID) + "\"").ToList <string>();
                        // First item is the original web part/widget
                        variantControlIDsArray.Insert(0, "\"" + (!string.IsNullOrEmpty(ValidationHelper.GetString(WebPartControl.PartInstance.Properties["webparttitle"], string.Empty)) ? HTMLHelper.HTMLEncode(WebPartControl.PartInstance.Properties["webparttitle"].ToString()) : WebPartControl.PartInstance.ControlID) + "\"");

                        // Fill the DIV tag IDs array
                        divIDsArray = WebPartControl.PartInstance.PartInstanceVariants.Select(webpart => "\"Variant_" + VariantModeFunctions.GetVariantModeString(webpart.VariantMode) + "_" + webpart.VariantID + "\"").ToList <string>();
                        // First item is the original web part/widget
                        divIDsArray.Insert(0, "\"" + uniqueCode + "\"");
                    }
                    break;
                }

                // Create a javascript arrays:
                // Fill the following javascript array: itemCodesArray.push([variantIDs], [divIDs], actualSliderPosition, totalVariants, variantSliderId, sliderElement, hiddenElem_SliderPosition, zoneId, webPartInstanceGuid)
                StringBuilder sb = new StringBuilder();
                sb.Append("itemIDs = [");
                sb.Append(String.Join(",", variantIDsArray.ToArray()));
                sb.Append("]; divIDs = [");
                sb.Append(String.Join(",", divIDsArray.ToArray()));
                sb.Append("]; itemControlIDs = [");
                sb.Append(String.Join(",", variantControlIDsArray.ToArray()));
                sb.Append("];");
                sb.Append("itemCodes = [itemIDs, divIDs, itemControlIDs, 1, "); // 0, 1, 2, 3 (see the details in the 'variants.js' file)
                sb.Append(totalVariants);                                       // 4
                sb.Append(", \"");
                sb.Append(pnlVariations.ClientID);                              // 5
                sb.Append("\", \"");
                sb.Append(sliderExtender.ClientID);                             // 6
                sb.Append("_handleImage\", \"");
                sb.Append(hdnSliderPosition.ClientID);                          // 7
                sb.Append("\", \"");
                if (SliderMode == VariantTypeEnum.Zone)                         // 8
                {
                    sb.Append(WebPartZoneControl.TitleLabel.ClientID);
                }
                else
                {
                    // Display label only for web parts (editor widgets have title hidden)
                    if (WebPartControl.TitleLabel != null)
                    {
                        sb.Append(WebPartControl.TitleLabel.ClientID);
                    }
                }
                sb.Append("\", \"");
                sb.Append(zoneId);                      // 9
                sb.Append("\", \"");
                if (SliderMode != VariantTypeEnum.Zone) // 10
                {
                    sb.Append(instanceGuidString);
                }
                sb.Append("\", \"");
                sb.Append(VariantModeFunctions.GetVariantModeString(VariantMode)); // 11
                sb.Append("\", \"");
                sb.Append(pnlVariations.ClientID);                                 // 12
                sb.Append("\"]; itemCodesAssociativeArray[\"");
                sb.Append(uniqueCode);
                sb.Append("\"] = itemCodes;");

                ScriptHelper.RegisterStartupScript(Page, typeof(string), sliderExtender.ClientID + "_InitScript", sb.ToString(), true);
            }
        }
        else
        {
            Visible = false;
        }
    }
    /// <summary>
    /// Tabs the elem_ on tab created.
    /// </summary>
    protected string[] tabElem_OnTabCreated(CMS.SiteProvider.UIElementInfo element, string[] parameters, int tabIndex)
    {
        // Show/hide context help for some tabs
        String script       = "SetTabsContext('');";
        String defaultParam = parameters[1];

        switch (element.ElementName.ToLower())
        {
        case "widgetproperties.variant":
            script = "SetTabsContext('variants');";
            String varName = (variantMode == VariantModeEnum.MVT) ? "mvtvariant_edit" : "cpvariant_edit";
            defaultParam = "if (window.SetHelpTopic) { window.SetHelpTopic('helpTopic', '" + varName + "')}";

            bool isNewVariant = QueryHelper.GetBoolean("isnewvariant", false);
            int  variantId    = QueryHelper.GetInteger("variantid", 0);

            // Set the variant mode into the tab url
            if ((variantMode != VariantModeEnum.None) && (parameters.Length > 2))
            {
                parameters[2] = URLHelper.AddParameterToUrl(parameters[2], "variantmode", VariantModeFunctions.GetVariantModeString(variantMode));
            }

            if ((variantId <= 0) || isNewVariant)
            {
                return(null);
            }
            break;
        }

        parameters[1] = script + defaultParam;
        return(parameters);
    }
Beispiel #4
0
    /// <summary>
    /// Tabs the elem_ on tab created.
    /// </summary>
    protected void tabElem_OnTabCreated(object sender, TabCreatedEventArgs e)
    {
        if (e.Tab == null)
        {
            return;
        }

        var tab     = e.Tab;
        var element = e.UIElement;

        switch (element.ElementName.ToLowerCSafe())
        {
        case "widgetproperties.variant":
        {
            bool isNewVariant = QueryHelper.GetBoolean("isnewvariant", false);
            int  variantId    = QueryHelper.GetInteger("variantid", 0);

            // Set the variant mode into the tab url
            if ((variantMode != VariantModeEnum.None) && !string.IsNullOrEmpty(tab.RedirectUrl))
            {
                tab.RedirectUrl = URLHelper.AddParameterToUrl(tab.RedirectUrl, "variantmode", VariantModeFunctions.GetVariantModeString(variantMode));
            }

            if ((variantId <= 0) || isNewVariant)
            {
                e.Tab = null;
                return;
            }
        }
        break;
        }
    }
    /// <summary>
    /// Tabs the elem_ on tab created.
    /// </summary>
    protected TabItem tabElem_OnTabCreated(UIElementInfo element, TabItem tab, int tabIndex)
    {
        // Show/hide context help for some tabs
        String script       = "SetTabsContext('');";
        String defaultParam = tab.OnClientClick;

        switch (element.ElementName.ToLowerCSafe())
        {
        case "widgetproperties.variant":
            script = "SetTabsContext('variants');";
            String varName = (variantMode == VariantModeEnum.MVT) ? "mvtvariant_edit" : "cpvariant_edit";
            defaultParam = "if (window.SetHelpTopic) { window.SetHelpTopic('helpTopic', '" + varName + "')}";

            bool isNewVariant = QueryHelper.GetBoolean("isnewvariant", false);
            int  variantId    = QueryHelper.GetInteger("variantid", 0);

            // Set the variant mode into the tab url
            if ((variantMode != VariantModeEnum.None) && !string.IsNullOrEmpty(tab.RedirectUrl))
            {
                tab.RedirectUrl = URLHelper.AddParameterToUrl(tab.RedirectUrl, "variantmode", VariantModeFunctions.GetVariantModeString(variantMode));
            }

            if ((variantId <= 0) || isNewVariant)
            {
                return(null);
            }
            break;
        }

        tab.OnClientClick = script + defaultParam;
        return(tab);
    }