/// <summary>
    /// Raises the callback event.
    /// </summary>
    public void RaiseCallbackEvent(string eventArgument)
    {
        string[] argumentParts = eventArgument.Split(';');

        if (argumentParts.Length > 0)
        {
            string action = argumentParts[0];

            switch (action)
            {
            // Get edit page url (also consider custom document type urls)
            case "editurl":
            {
                int nodeId = ValidationHelper.GetInteger(argumentParts[1], 0);

                // Prepare url retriever settings
                UIPageURLSettings settings = new UIPageURLSettings();
                settings.AllowSplitview  = false;
                settings.NodeID          = nodeId;
                settings.AdditionalQuery = "dialog=1";
                settings.Mode            = "editform";
                settings.Action          = null;
                settings.Culture         = preferredCultureCode;

                // Get edit page url
                callbackResult = DocumentUIHelper.GetDocumentPageUrl(settings);
            }
            break;
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Register the scripts
        ScriptHelper.RegisterDialogScript(Page);
        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "defaultVariables", ScriptHelper.GetScript(@"var IsCMSDesk = true;"));
        ScriptHelper.RegisterScriptFile(Page, @"~/CMSModules/Content/CMSDesk/Content.js");

        var settings = new UIPageURLSettings
        {
            Mode               = ResultMode,
            Action             = Action,
            NodeID             = ResultNodeID,
            Culture            = LocalizationContext.PreferredCultureCode,
            IncludeLiveSiteURL = true
        };

        var urls = urlRetriever.GetRequestedUrl(settings).Split(new[] { ContentUrlRetriever.CALLBACK_SEPARATOR }, StringSplitOptions.RemoveEmptyEntries);

        // Ensure action URL
        contentview.Src = urls[0];

        if (urls.Length > 1)
        {
            // Set default live site URL in header link
            ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "SetDefaultLiveSiteURL", ScriptHelper.GetScript("SetLiveSiteURL('" + urls[1] + "');"));
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        string url = QueryHelper.GetString("splitUrl", null);

        if (!string.IsNullOrEmpty(url) && UIContext.DisplaySplitMode)
        {
            // Register script files
            ltlScript.Text += ScriptHelper.GetScriptTag("~/CMSModules/Content/CMSDesk/SplitView.js");

            // Decode URL
            url = HttpUtility.UrlDecode(url);
            docSplitView.NodeID = ValidationHelper.GetInteger(URLHelper.GetQueryValue(url, "nodeid"), 0);
            docSplitView.Culture = ValidationHelper.GetString(URLHelper.GetQueryValue(url, "culture"), null);

            // Update view mode (e.g. to remember edit tabs)
            PortalContext.UpdateViewMode(PortalContext.ViewMode);

            // Set frame1 URL
            docSplitView.Frame1Url = url;

            // Get the URL of the compare frame
            UIPageURLSettings settings = new UIPageURLSettings
                                               {
                                                   Mode = Mode,
                                                   NodeID = NodeID,
                                                   Culture = UIContext.SplitModeCultureCode,
                                                   SplitViewSourceURL = url,
                                                   TransformToCompareUrl = true
                                               };
            // Get URL
            docSplitView.Frame2Url = DocumentUIHelper.GetDocumentPageUrl(settings);

            StringBuilder script = new StringBuilder();
            script.Append(
        @"
        function InitSplitViewSyncScroll(frameElement, body, refreshSameCulture, unbind) {
          if (InitSyncScroll) {
        InitSyncScroll(frameElement, body, refreshSameCulture, unbind);
          }
        }
        function SplitModeRefreshFrame() {
          if (FSP_SplitModeRefreshFrame) {
        FSP_SplitModeRefreshFrame();
          }
        }

        var FSP_appPref = '", URLHelper.GetFullApplicationUrl(), @"';
        var FSP_cntPref = '", ScriptPrefix, @"';
        ");

            ScriptHelper.RegisterStartupScript(Page, typeof(string), "splitViewSync_" + Page.ClientID, script.ToString(), true);
        }
    }
示例#4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string url = QueryHelper.GetString("splitUrl", null);

        if (!string.IsNullOrEmpty(url) && UIContext.DisplaySplitMode)
        {
            // Register script files
            ltlScript.Text += ScriptHelper.GetScriptTag("~/CMSModules/Content/CMSDesk/SplitView.js");

            // Decode URL
            url = HttpUtility.UrlDecode(url);
            docSplitView.NodeID  = ValidationHelper.GetInteger(URLHelper.GetQueryValue(url, "nodeid"), 0);
            docSplitView.Culture = ValidationHelper.GetString(URLHelper.GetQueryValue(url, "culture"), null);

            // Update view mode (e.g. to remember edit tabs)
            PortalContext.UpdateViewMode(PortalContext.ViewMode);

            // Set frame1 URL
            docSplitView.Frame1Url = url;

            // Get the URL of the compare frame
            UIPageURLSettings settings = new UIPageURLSettings
            {
                Mode                  = Mode,
                NodeID                = NodeID,
                Culture               = UIContext.SplitModeCultureCode,
                SplitViewSourceURL    = url,
                TransformToCompareUrl = true
            };
            // Get URL
            docSplitView.Frame2Url = DocumentUIHelper.GetDocumentPageUrl(settings);

            StringBuilder script = new StringBuilder();
            script.Append(
                @"
function InitSplitViewSyncScroll(frameElement, body, refreshSameCulture, unbind) {
  if (InitSyncScroll) {
    InitSyncScroll(frameElement, body, refreshSameCulture, unbind);
  }
}
function SplitModeRefreshFrame() {
  if (FSP_SplitModeRefreshFrame) {
    FSP_SplitModeRefreshFrame();
  }
}

var FSP_appPref = '", URLHelper.GetFullApplicationUrl(), @"';
var FSP_cntPref = '", ScriptPrefix, @"';
");

            ScriptHelper.RegisterStartupScript(Page, typeof(string), "splitViewSync_" + Page.ClientID, script.ToString(), true);
        }
    }
示例#5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Register the scripts
        ScriptHelper.RegisterDialogScript(Page);
        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "defaultVariables", ScriptHelper.GetScript(@"var IsCMSDesk = true;"));
        ScriptHelper.RegisterScriptFile(Page, @"~/CMSModules/Content/CMSDesk/Content.js");

        UIPageURLSettings settings = new UIPageURLSettings
        {
            Mode    = ResultMode,
            Action  = Action,
            NodeID  = ResultNodeID,
            Culture = CurrentUser.PreferredCultureCode
        };

        // Ensure action URL
        contentview.Src = urlRetriever.GetRequestedUrl(settings);
    }
示例#6
0
    /// <summary>
    /// Returns URL of modal dialog for creating new page.
    /// </summary>
    private string GetCreateNewPageDialogUrl()
    {
        var path = SettingsKeyInfoProvider.GetValue("CMSCampaignNewPageLocation", SiteContext.CurrentSiteName);
        var tree = new TreeProvider(MembershipContext.AuthenticatedUser);
        var node = tree.SelectSingleNode(SiteContext.CurrentSiteName, path, SiteContext.CurrentSite.DefaultVisitorCulture, true);

        if (node == null)
        {
            node = tree.SelectSingleNode(SiteContext.CurrentSiteName, "/", SiteContext.CurrentSite.DefaultVisitorCulture, true);
        }

        // General url settings
        var settings = new UIPageURLSettings
        {
            AllowSplitview  = false,
            NodeID          = node.NodeID,
            Culture         = node.DocumentCulture,
            Action          = "new",
            AdditionalQuery = "dialog=1&action=new&hidecontentonly=true"
        };

        return(DocumentUIHelper.GetDocumentPageUrl(settings));
    }
    /// <summary>
    /// Fires when a tab is created
    /// </summary>
    private void OnTabCreated(object sender, TabCreatedEventArgs e)
    {
        if (e.Tab == null)
        {
            return;
        }

        string mode = null;

        var element = e.UIElement;

        string elem = element.ElementName.ToLowerCSafe();

        // Hide other tabs for wireframe
        if (isWireframe && ((elem != "wireframe") && (elem != "editform")))
        {
            e.Tab = null;
            return;
        }

        switch (elem)
        {
            case "page":
                {
                    mode = "edit";
                }
                break;

            case "design":
                {
                    if (!showDesign)
                    {
                        e.Tab = null;
                        return;
                    }

                    mode = "design";
                }
                break;

            case "wireframe":
                {
                    if (!hasWireframe)
                    {
                        e.Tab = null;
                        return;
                    }

                    mode = "wireframe";
                }
                break;

            case "editform":
                // Keep edit form
                {
                    mode = "editform";
                }
                break;

            case "product":
                {
                    if (!showProductTab)
                    {
                        e.Tab = null;
                        return;
                    }

                    mode = "product";
                }
                break;

            case "masterpage":
                {
                    if (!showMasterPage)
                    {
                        e.Tab = null;
                        return;
                    }

                    mode = "masterpage";
                }
                break;

            case "properties":
                {
                    // Document properties
                    mode = "properties";
                }
                break;

            case "analytics":
                {
                    if (isWireframe)
                    {
                        e.Tab = null;
                        return;
                    }

                    mode = "analytics";
                }
                break;
        }

        if (Node != null)
        {
            var tab = e.Tab;

            var settings = new UIPageURLSettings
                {
                    Mode = mode,
                    Node = Node,
                    NodeID = Node.NodeID,
                    Culture = Node.DocumentCulture,
                    PreferredURL = tab.RedirectUrl
                };

            // Ensure correct URL
            tab.RedirectUrl = DocumentUIHelper.GetDocumentPageUrl(settings);
        }
    }
    protected void OnTabCreated(object sender, TabCreatedEventArgs e)
    {
        if (e.Tab == null)
        {
            return;
        }

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

        bool splitViewSupported = false;

        string lowerElementName = element.ElementName.ToLowerCSafe();

        switch (lowerElementName)
        {
            case "products.attachments":
            case "products.metadata":
            case "products.categories":
            case "products.workflow":
            case "products.versions":
                splitViewSupported = true;
                break;

            case "products.general":
                splitViewSupported = true;
                break;
        }

        switch (lowerElementName)
        {
            case "products.attachments":
            case "products.metadata":
            case "products.categories":
            case "products.workflow":
            case "products.versions":
            case "products.relatedproducts":
                // Check if editing product with its document
                if (NodeID <= 0)
                {
                    e.Tab = null;
                    return;
                }
                break;

            case "products.documents":
                if ((NodeID <= 0) && (ECommerceSettings.ProductsTree(SiteContext.CurrentSiteName) == ProductsTreeModeEnum.Sections))
                {
                    if (!MembershipContext.AuthenticatedUser.IsGlobalAdministrator || (sku == null) || !sku.IsGlobal)
                    {
                        e.Tab = null;
                        return;
                    }
                }
                break;

            case "products.preview":
                {
                    // Check if editing product with its document
                    if (NodeID <= 0)
                    {
                        e.Tab = null;
                        return;
                    }

                    var settings = new UIPageURLSettings
                    {
                        Mode = "preview",
                        NodeID = Node.NodeID,
                        Culture = Node.DocumentCulture,
                        Node = Node,
                        AllowViewValidate = false
                    };

                    tab.RedirectUrl = ProductUIHelper.GetProductPageUrl(settings);

                    tab.RedirectUrl = URLHelper.AddParameterToUrl(tab.RedirectUrl, "nodeid", NodeID.ToString());
                    tab.RedirectUrl = URLHelper.AddParameterToUrl(tab.RedirectUrl, "showdevicesselection", "0");
                }
                break;

            case "products.advanced":
                {
                    tab.Expand = (NodeID <= 0);

                    // Append product/node params to url
                    var url = tab.RedirectUrl;
                    url = URLHelper.AddParameterToUrl(url, "productid", ProductID.ToString());
                    if (Node != null)
                    {
                        url = URLHelper.AddParameterToUrl(url, "nodeid", Node.NodeID.ToString());
                        url = URLHelper.AddParameterToUrl(url, "culture", Node.DocumentCulture);
                    }

                    tab.RedirectUrl = url;
                }
                break;

            case "products.options":
                tab.RedirectUrl = URLHelper.AddParameterToUrl(tab.RedirectUrl, "productId", ProductID.ToString());
                break;
        }

        // Add SiteId parameter to each tab
        if (!string.IsNullOrEmpty(tab.RedirectUrl))
        {
            tab.RedirectUrl = URLHelper.AddParameterToUrl(tab.RedirectUrl, "siteId", siteId.ToString());
        }

        // Ensure split view mode
        if ((NodeID > 0) && splitViewSupported && UIContext.DisplaySplitMode)
        {
            tab.RedirectUrl = DocumentUIHelper.GetSplitViewUrl(tab.RedirectUrl);
        }

        // Make URL absolute
        tab.RedirectUrl = URLHelper.GetAbsoluteUrl(tab.RedirectUrl);
    }
示例#9
0
    private TabItem tabModes_OnTabCreated(UIElementInfo element, TabItem tab, int tabIndex)
    {
        string mode = null;

        string elem = element.ElementName.ToLowerCSafe();

        // Hide other tabs for wireframe
        if (isWireframe && ((elem != "wireframe") && (elem != "editform")))
        {
            return(null);
        }

        switch (elem)
        {
        case "page":
        {
            pageTabIndex = tabIndex;
            mode         = "edit";
        }
        break;

        case "design":
        {
            // Check if the design mode is enabled
            if (!designEnabled)
            {
                return(null);
            }

            if (authorizedPerDesign)
            {
                designTabIndex = tabIndex;
            }
            else
            {
                if (!authorizedPerDesign)
                {
                    designPermissionRequired = true;
                }
                return(null);
            }
            mode = "design";
        }
        break;

        case "wireframe":
        {
            // Check if the wireframe mode is enabled
            if (!hasWireframe)
            {
                return(null);
            }

            wireframeTabIndex = tabIndex;
            mode = "wireframe";
        }
        break;

        case "editform":
            // Keep edit form
        {
            formTabIndex = tabIndex;
            mode         = "editform";
        }
        break;

        case "product":
        {
            // Check if the product tab is enabled
            if (showProductTab && LicenseHelper.IsFeatureAvailableInUI(FeatureEnum.Ecommerce, ModuleEntry.ECOMMERCE))
            {
                productTabIndex = tabIndex;
            }
            else
            {
                return(null);
            }
            mode = "product";
        }
        break;

        case "masterpage":
        {
            // Check if master page tab is enabled
            if (isMasterPage && authorizedPerDesign)
            {
                masterTabIndex = tabIndex;
            }
            else
            {
                if (!authorizedPerDesign)
                {
                    designPermissionRequired = true;
                }
                return(null);
            }

            mode = "masterpage";
        }
        break;

        case "properties":
        {
            // Document properties
            propertiesTabIndex = tabIndex;
            mode = "properties";
        }
        break;

        case "analytics":
        {
            // Analytics
            if (isWireframe)
            {
                return(null);
            }

            analyticsIndex = tabIndex;
            mode           = "analytics";
        }
        break;

        case "validation":
            return(null);
        }

        // Script for refresh 'display web part content' button
        string script = "SetTabsContext('" + elem + "');";

        UIPageURLSettings settings = new UIPageURLSettings
        {
            Mode         = mode,
            Node         = Node,
            NodeID       = Node.NodeID,
            Culture      = Node.DocumentCulture,
            PreferredURL = tab.RedirectUrl
        };

        // Ensure correct URL
        tab.RedirectUrl = GetDocumentPageUrl(settings);

        // Add script for refresh web part content button (displayed only when design mode)
        tab.OnClientClick = script + tab.OnClientClick;

        return(tab);
    }
    /// <summary>
    /// Raises the callback event.
    /// </summary>
    public void RaiseCallbackEvent(string eventArgument)
    {
        if ((eventArgument == null))
        {
            return;
        }

        string[] argumentParts = eventArgument.Split(';');

        if (argumentParts.Length > 0)
        {
            string action = argumentParts[0];

            switch (action)
            {
                // Get edit page url (also consider custom document type urls)
                case "editurl":
                    {
                        int nodeId = ValidationHelper.GetInteger(argumentParts[1], 0);

                        // Prepare url retriever settings
                        UIPageURLSettings settings = new UIPageURLSettings();
                        settings.AllowSplitview = false;
                        settings.NodeID = nodeId;
                        settings.AdditionalQuery = "dialog=1";
                        settings.Mode = "editform";
                        settings.Action = null;
                        settings.Culture = preferredCultureCode;

                        // Get edit page url
                        callbackResult = CMSDeskPage.GetUIPageURL(settings);
                    }
                    break;

                default:
                    break;
            }
        }
    }
    /// <summary>
    /// Registers script files for on-site editing
    /// </summary>
    /// <param name="pi">Current page info</param>
    private void RegisterEditScripts(PageInfo pi)
    {
        ScriptHelper.RegisterJQueryCookie(Page);
        StringBuilder script = new StringBuilder();

        // Edit toolbar scripts
        if (ViewMode == ViewModeEnum.EditLive)
        {
            // Dialog scripts
            ScriptHelper.RegisterDialogScript(Page);

            // General url settings
            UIPageURLSettings settings = new UIPageURLSettings();
            settings.AllowSplitview = false;
            settings.NodeID = pi.NodeID;
            settings.Culture = pi.DocumentCulture;
            settings.AdditionalQuery = "dialog=1";

            // Edit document
            settings.Mode = "editform";
            settings.Action = null;
            string editUrl = CMSDeskPage.GetUIPageURL(settings);
            settings.Mode = string.Empty;
            // Toolbar - Edit button script
            editUrl = URLHelper.RemoveParameterFromUrl(editUrl, "mode");
            string scriptEdit = GetModalDialogScript(editUrl, "editpage");
            // User contributions - Edit item script
            string scriptEditItem = GetModalDialogScript(AddItemUrlParameters(editUrl), "editpage");

            // Delete document
            settings.Action = "delete";
            string deleteUrl = CMSDeskPage.GetUIPageURL(settings);
            // Toolbar - Delete button script
            string scriptDelete = GetModalDialogScript(deleteUrl, "deletepage");
            // User contributions - Delete item script
            string scriptDeleteItem = GetModalDialogScript(AddItemUrlParameters(deleteUrl), "deletepage");

            // New document
            settings.Action = "new";
            settings.AdditionalQuery += "&reloadnewpage=1";
            string newUrl = CMSDeskPage.GetUIPageURL(settings);
            newUrl = AddNewItemUrlParameters(newUrl);
            // Toolbar - New button script
            string scriptNew = GetModalDialogScript(newUrl, "newpage");

            // Toolbar - Properties button script
            string scriptProperties = GetModalDialogScript(ResolveUrl("~/CMSModules/Content/CMSDesk/Properties/Properties_Frameset.aspx?mode=editlive&documentid=" + pi.DocumentID), "propertiespage");

            // Display items from current level by default
            int nodeId = pi.NodeParentID;
            // If current level is root display first level
            if (nodeId == 0)
            {
                isRootDocument = true;
                nodeId = pi.NodeID;
            }

            // In page not found mode display first level
            if (nodeId == 0)
            {
                TreeProvider tp = new TreeProvider(cui);
                TreeNode tn = tp.SelectSingleNode(CMSContext.CurrentSiteName, "/", TreeProvider.ALL_CULTURES);
                if (tn != null)
                {
                    nodeId = tn.NodeID;
                }
            }

            // Listing
            string listItemUrl = ResolveUrl("~/CMSModules/Content/CMSDesk/View/listing.aspx?dialog=1&wopenernodeid=" + pi.NodeID + "&nodeid=##id##");
            string scriptListItem = GetModalDialogScript(listItemUrl.Replace("##id##", nodeId.ToString()), "listingpage");

            // New culture
            string newCultureUrl = ResolveUrl("~/CMSModules/Content/CMSDesk/New/NewCultureVersion.aspx?nodeid=##id##&culture=##cult##&dialog=1");

            script.Append(@"
                var OEEditImagePath = '", GetImageUrl("CMSModules/CMS_PortalEngine/OnSiteEdit/webpart_edit.png"), @"';
                var OEConfigureImagePath = '", GetImageUrl("CMSModules/CMS_PortalEngine/OnSiteEdit/webpart_properties.png"), @"';
                var OEIsRTL = ", (isRTL ? "true" : "false"), @";
                var OECurrentNodeId = ", (CMSContext.CurrentPageInfo != null) ? CMSContext.CurrentPageInfo.NodeID : 0, @";
                var OEIsMobile = ", (CMSContext.CurrentDevice.IsMobile ? "true" : "false"), @";
                var OEHdnPostbackValue = null;

                function ConfigureWebPart(webPartZoneId, webPartId, aliasPath, instanceGuid, templateId, refreshOnCancel) {
                    modalDialog('", OnSiteEditHelper.WebPartPropertiesPageUrl, @"?aliaspath=' + aliasPath + '&zoneid=' + webPartZoneId + '&webpartid=' + webPartId + '&culture=' + ", preferredCultureCode, @" + '&instanceguid=' + instanceGuid + '&templateid=' + templateId + (!!refreshOnCancel ? '&refreshoncancel=true'  : ''), 'configurewebpart', 900, 638);
                }

                function NewDocument(parentId, classId, targetWindow)
                {
                    OEClearZIndex(OEActiveWebPart);

                    if (targetWindow == null) {
                        ", scriptNew, @";
                    }
                    else {
                        targetWindow.location.href = '", newUrl, @"';
                    }
                }

                function EditDocument(nodeId, targetWindow)
                {
                    OEClearZIndex(OEActiveWebPart);

                    // Edit item button in repeaters and datalists
                    var arg = 'editurl;' + nodeId;
                    ", Page.ClientScript.GetCallbackEventReference(this, "arg", "OECallbackHandler", null), @";

                }

                function OECallbackHandler(arg, context) {
                    ", GetModalDialogScript("arg", "editpage", false), @"
                }

                function DeleteDocument(nodeId)
                {
                    OEClearZIndex(OEActiveWebPart);
                    ", scriptDeleteItem, @"
                }

                function OnSiteToolbarAction(name)
                {
                    switch(name)
                    {
                        case 'edit':
                                ", scriptEdit, @"
                            break;

                        case 'properties':
                                ", scriptProperties, @"
                            break;

                        case 'new':
                                var parentId = OECurrentNodeId;
                                var classId = 0;
                                ", scriptNew, @"
                            break;

                        case 'delete':
                                ", scriptDelete, @"
                            break;

                        case 'list':
                                ", scriptListItem, @"
                            break;

                        default:
                            alert('Required action is not implemented.');
                    }
                }

                function SelectNode(nodeId, parentNodeId)
                {
                    var liu = '", listItemUrl, @"';
                    return liu.replace(/##id##/g, nodeId);
                }

                function NewDocumentCulture(nodeId, culture)
                {
                    var liu = '", newCultureUrl, @"';
                    liu = liu.replace(/##id##/g, nodeId);
                    liu = liu.replace(/##cult##/g, culture);
                    ", GetModalDialogScript("liu", "newculture", false), @"
                }

                function ToggleUpdateProgress(show) {
                    var loadingBg = jQuery('.OnSiteUPBg');
                    var loading = jQuery('#", updateProgress.ClientID, @"');

                    if (show) {
                        loading.css('display', 'inline');
                        loadingBg.show();
                    }
                    else {
                        loading.hide();
                        loadingBg.hide();
                    }
                }

                function OEEnsureHdnPostbackValue() {
                    if (OEHdnPostbackValue == null) {
                        OEHdnPostbackValue = document.getElementById('", hdnPostbackValue.ClientID, @"');
                    }
                }

                // Changes the device profile
                function ChangeDevice(device) {
                    OEEnsureHdnPostbackValue();
                    OEHdnPostbackValue.value = device;
                    ", ControlsHelper.GetPostBackEventReference(this, "changedeviceprofile"), @"
                } ");

            // Register jQuery
            ScriptHelper.RegisterJQueryDialog(Page);

            // Register OnSiteEdit script file
            ScriptHelper.RegisterScriptFile(Page, "DesignMode/OnSiteEdit.js");
            ScriptHelper.RegisterScriptFile(Page, "~/CMSScripts/jquery/jquery-url.js");
        }
        // Slider buttons scripts
        else if (ViewMode == ViewModeEnum.LiveSite)
        {
            bool sliderIsMinimized = ValidationHelper.GetBoolean(CookieHelper.GetValue(CookieName.OnSiteButtonMinimized), false);
            if (sliderIsMinimized)
            {
                // Renew the cookie
                CookieHelper.SetValue(CookieName.OnSiteButtonMinimized, "true", "/", DateTime.Now.AddDays(31), false);
            }

            script.Append(@"
                var OEIsMinimized = ", (sliderIsMinimized ? "true" : "false"), @";

                function OESlideSideToolbar() {
                    // Hide the slider button in CMSDesk
                    if (parent != this) {
                        return;
                    }

                    var toolbarEl = document.getElementById('", pnlSlider.ClientID, @"');
                    toolbarEl.style.display = ""block"";

                    if (!OEIsMinimized) {
                        // Show slider button
                        toolbarEl.style.top = ""0px"";
                        document.getElementById('", imgMinimize.ClientID, @"').style.display = ""inline"";
                        document.getElementById('", imgMaximize.ClientID, @"').style.display = ""none"";
                        jQuery.cookie('", CookieName.OnSiteButtonMinimized, @"', null, { path: '/' });
                    }
                    else {
                        // Hide slider button
                        var sliderButtonEl = document.getElementById('", pnlButton.ClientID, @"');
                        toolbarEl.style.top = ""-"" + (sliderButtonEl.offsetHeight + 1) + ""px"";
                        document.getElementById('", imgMinimize.ClientID, @"').style.display = ""none"";
                        document.getElementById('", imgMaximize.ClientID, @"').style.display = ""inline"";
                        jQuery.cookie('", CookieName.OnSiteButtonMinimized, @"', true, { path: '/', expires: 31 });
                    }

                    OEIsMinimized = !OEIsMinimized;
                }

                // Display slider button
                jQuery(document).ready(function() { OESlideSideToolbar(); });
                ");
        }

        script.Append(" function OnSiteEdit_ChangeEditMode(){", ControlsHelper.GetPostBackEventReference(this, "changeviewmode"), "} ");

        ControlsHelper.RegisterClientScriptBlock(this, Page, typeof(string), "OnSiteEditActions", ScriptHelper.GetScript(script.ToString()));
    }
示例#12
0
    /// <summary>
    /// Registers script files for on-site editing
    /// </summary>
    /// <param name="pi">Current page info</param>
    private void RegisterEditScripts(PageInfo pi)
    {
        ScriptHelper.RegisterJQueryCookie(Page);
        StringBuilder script = new StringBuilder();

        // Edit toolbar scripts
        if (ViewMode.IsEditLive())
        {
            // Dialog scripts
            ScriptHelper.RegisterDialogScript(Page);

            // General url settings
            UIPageURLSettings settings = new UIPageURLSettings();
            settings.AllowSplitview  = false;
            settings.NodeID          = pi.NodeID;
            settings.Culture         = pi.DocumentCulture;
            settings.AdditionalQuery = "dialog=1";

            // Edit document
            settings.Mode   = "editform";
            settings.Action = null;
            string editUrl = DocumentUIHelper.GetDocumentPageUrl(settings);
            settings.Mode = string.Empty;

            // Toolbar - Edit button script
            editUrl = URLHelper.RemoveParameterFromUrl(editUrl, "mode");
            string scriptEdit = GetModalDialogScript(editUrl, "editpage");

            // Delete document
            settings.Action = "delete";
            string deleteUrl = DocumentUIHelper.GetDocumentPageUrl(settings);
            // Toolbar - Delete button script
            string scriptDelete = GetModalDialogScript(deleteUrl, "deletepage");
            // User contributions - Delete item script
            string scriptDeleteItem = GetModalDialogScript(AddItemUrlParameters(deleteUrl), "deletepage");

            // New document
            settings.Action           = "new";
            settings.AdditionalQuery += "&reloadnewpage=1";
            string newUrl = DocumentUIHelper.GetDocumentPageUrl(settings);
            newUrl = AddNewItemUrlParameters(newUrl);
            // Include culture code
            newUrl = URLHelper.AddParameterToUrl(newUrl, "parentculture", preferredCultureCode);
            // Toolbar - New button script
            string scriptNew = GetModalDialogScript(newUrl, "newpage");

            // Toolbar - Properties button script
            string scriptProperties = GetModalDialogScript(ResolveUrl("~/CMSModules/Content/CMSDesk/Properties/Properties_Frameset.aspx?mode=editlive&documentid=" + pi.DocumentID), "propertiespage");

            // Display items from current level by default
            int nodeId = pi.NodeParentID;
            // If current level is root display first level
            if (nodeId == 0)
            {
                isRootDocument = true;
                nodeId         = pi.NodeID;
            }

            // In page not found mode display first level
            if (nodeId == 0)
            {
                TreeProvider tp = new TreeProvider(cui);
                TreeNode     tn = tp.SelectSingleNode(SiteContext.CurrentSiteName, "/", TreeProvider.ALL_CULTURES);
                if (tn != null)
                {
                    nodeId = tn.NodeID;
                }
            }

            // Listing
            string listItemUrl    = ResolveUrl("~/CMSModules/Content/CMSDesk/View/listing.aspx?dialog=1&wopenernodeid=" + pi.NodeID + "&nodeid=##id##");
            string scriptListItem = GetModalDialogScript(listItemUrl.Replace("##id##", nodeId.ToString()), "listingpage");

            // New culture
            string newCultureUrl = ResolveUrl("~/CMSModules/Content/CMSDesk/New/NewCultureVersion.aspx?nodeid=##id##&culture=##cult##&dialog=1");

            script.Append(@"
                var OEIsRTL = ", (isRTL ? "true" : "false"), @";
                var OECurrentNodeId = ", (DocumentContext.CurrentPageInfo != null) ? DocumentContext.CurrentPageInfo.NodeID : 0, @";
                var OEIsMobile = ", (DeviceContext.CurrentDevice.IsMobile ? "true" : "false"), @";
                var OEHdnPostbackValue = null;

                function NewDocument(parentId, classId, targetWindow)
                {
                    OEClearZIndex(OEActiveWebPart);

                    if (targetWindow == null) {
                        ", scriptNew, @";   
                    }
                    else {
                        targetWindow.location.href = '", newUrl, @"';
                    }
                }

                function EditDocument(nodeId, targetWindow)
                {
                    OEClearZIndex(OEActiveWebPart); 

                    // Edit item button in repeaters and datalists
                    var arg = 'editurl;' + nodeId;
                    ", Page.ClientScript.GetCallbackEventReference(this, "arg", "OECallbackHandler", null), @";
                   
                }

                function SaveDocumentWidgets() {
                    if (!CMSContentManager.contentModified()) {
                        return false;
                    }
                    if (window.CMSContentManager) { CMSContentManager.allowSubmit = true; }
                    ", ControlsHelper.GetPostBackEventReference(this, "savedocument"), @";
                }

                function OECallbackHandler(arg, context) {
                    ", GetModalDialogScript("arg", "editpage", false), @"
                }

                function DeleteDocument(nodeId)
                {
                    OEClearZIndex(OEActiveWebPart); 
                    ", scriptDeleteItem, @" 
                }

                function OnSiteToolbarAction(name)
                {
                    ", checkChanges, @"

                    switch(name)
                    {
                        case 'edit':
                                ", scriptEdit, @"
                            break;

                        case 'properties':
                                ", scriptProperties, @"
                            break;

                        case 'new':
                                var parentId = OECurrentNodeId;
                                var classId = 0;
                                ", scriptNew, @"
                            break;

                        case 'delete':
                                ", scriptDelete, @"
                            break;

                        case 'list':
                                ", scriptListItem, @"
                            break;

                        default:
                            alert('Required action is not implemented.');
                    }
                }

                function SelectNode(nodeId, parentNodeId)
                {
                    var liu = '", listItemUrl, @"';
                    return liu.replace(/##id##/g, nodeId);
                }

                function NewDocumentCulture(nodeId, culture)
                {
                    ", checkChanges, @"

                    var liu = '", newCultureUrl, @"';
                    liu = liu.replace(/##id##/g, nodeId);
                    liu = liu.replace(/##cult##/g, culture);
                    ", GetModalDialogScript("liu", "newculture", false), @"
                }

                function OEEnsureHdnPostbackValue() {
                    if (OEHdnPostbackValue == null) {
                        OEHdnPostbackValue = document.getElementById('", hdnPostbackValue.ClientID, @"');
                    }
                }

                // Changes the device profile
                function ChangeDevice(device) {
                    ", checkChanges, @"
                    OEEnsureHdnPostbackValue();
                    OEHdnPostbackValue.value = device;
                    ", ControlsHelper.GetPostBackEventReference(this, "changedeviceprofile"), @"
                } ");

            // Register jQuery
            ScriptHelper.RegisterJQueryDialog(Page);

            // Register OnSiteEdit script file
            ScriptHelper.RegisterScriptFile(Page, "DesignMode/OnSiteEdit.js");
            ScriptHelper.RegisterScriptFile(Page, "~/CMSScripts/jquery/jquery-url.js");
        }
        // Slider buttons scripts
        else if (ViewMode.IsLiveSite())
        {
            script.Append(@"

                function OESlideSideToolbar() {
                    // Hide the slider button in CMSDesk
                    if (parent != this) {
                        return;
                    }

                    var toolbarEl = document.getElementById('", pnlSlider.ClientID, @"');
                    toolbarEl.style.display = ""block"";
                    // Show slider button
                    toolbarEl.style.top = ""0px"";
                }

                // Display slider button
                jQuery(document).ready(function() { OESlideSideToolbar(); });
                ");
        }

        script.Append(" function OnSiteEdit_ChangeEditMode(){", ControlsHelper.GetPostBackEventReference(this, "changeviewmode"), "} ");

        ControlsHelper.RegisterClientScriptBlock(this, Page, typeof(string), "OnSiteEditActions", ScriptHelper.GetScript(script.ToString()));
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Register the scripts
        ScriptHelper.RegisterDialogScript(Page);
        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "defaultVariables", ScriptHelper.GetScript(@"var IsCMSDesk = true;"));
        ScriptHelper.RegisterScriptFile(Page, @"~/CMSModules/Content/CMSDesk/Content.js");

        UIPageURLSettings settings = new UIPageURLSettings
                                         {
                                             Mode = ResultMode,
                                             Action = Action,
                                             NodeID = ResultNodeID,
                                             Culture = CurrentUser.PreferredCultureCode
                                         };
        // Ensure action URL
        contentview.Src = urlRetriever.GetRequestedUrl(settings);
    }
    /// <summary>
    /// Fires when a tab is created
    /// </summary>
    private void OnTabCreated(object sender, TabCreatedEventArgs e)
    {
        if (e.Tab == null)
        {
            return;
        }

        string mode = null;

        var element = e.UIElement;

        string elem = element.ElementName.ToLowerCSafe();

        // Hide other tabs for wireframe
        if (isWireframe && ((elem != "wireframe") && (elem != "editform")))
        {
            e.Tab = null;
            return;
        }

        switch (elem)
        {
            case "page":
                {
                    mode = "edit";
                }
                break;

            case "design":
                {
                    // Check if the design mode is enabled
                    if (!designEnabled)
                    {
                        e.Tab = null;
                        return;
                    }

                    mode = "design";
                }
                break;

            case "wireframe":
                {
                    // Check if the wireframe mode is enabled
                    if (!hasWireframe)
                    {
                        e.Tab = null;
                        return;
                    }

                    mode = "wireframe";
                }
                break;

            case "editform":
                // Keep edit form
                {
                    mode = "editform";
                }
                break;

            case "product":
                {
                    // Check if the product tab is enabled
                    if (!showProductTab)
                    {
                        e.Tab = null;
                        return;
                    }

                    mode = "product";
                }
                break;

            case "masterpage":
                {
                    // Check if master page tab is enabled
                    if (!isMasterPage)
                    {
                        e.Tab = null;
                        return;
                    }

                    mode = "masterpage";
                }
                break;

            case "properties":
                {
                    // Document properties
                    mode = "properties";
                }
                break;

            case "analytics":
                {
                    // Analytics
                    if (isWireframe)
                    {
                        e.Tab = null;
                        return;
                    }

                    mode = "analytics";
                }
                break;
        }

        if (Node != null)
        {
            var tab = e.Tab;

            var settings = new UIPageURLSettings
                {
                    Mode = mode,
                    Node = Node,
                    NodeID = Node.NodeID,
                    Culture = Node.DocumentCulture,
                    PreferredURL = tab.RedirectUrl
                };

            // Ensure correct URL
            tab.RedirectUrl = DocumentUIHelper.GetDocumentPageUrl(settings);
        }
    }
    /// <summary>
    /// Registers script files for on-site editing
    /// </summary>
    /// <param name="pi">Current page info</param>
    private void RegisterEditScripts(PageInfo pi)
    {
        ScriptHelper.RegisterJQueryCookie(Page);
        StringBuilder script = new StringBuilder();

        // Edit toolbar scripts
        if (ViewMode == ViewModeEnum.EditLive)
        {
            // Dialog scripts
            ScriptHelper.RegisterDialogScript(Page);

            // General url settings
            UIPageURLSettings settings = new UIPageURLSettings();
            settings.AllowSplitview  = false;
            settings.NodeID          = pi.NodeID;
            settings.Culture         = pi.DocumentCulture;
            settings.AdditionalQuery = "dialog=1";

            // Edit document
            settings.Mode   = "editform";
            settings.Action = null;
            string editUrl = CMSDeskPage.GetUIPageURL(settings);
            settings.Mode = string.Empty;
            // Toolbar - Edit button script
            editUrl = URLHelper.RemoveParameterFromUrl(editUrl, "mode");
            string scriptEdit = GetModalDialogScript(editUrl, "editpage");
            // User contributions - Edit item script
            string scriptEditItem = GetModalDialogScript(AddItemUrlParameters(editUrl), "editpage");

            // Delete document
            settings.Action = "delete";
            string deleteUrl = CMSDeskPage.GetUIPageURL(settings);
            // Toolbar - Delete button script
            string scriptDelete = GetModalDialogScript(deleteUrl, "deletepage");
            // User contributions - Delete item script
            string scriptDeleteItem = GetModalDialogScript(AddItemUrlParameters(deleteUrl), "deletepage");

            // New document
            settings.Action           = "new";
            settings.AdditionalQuery += "&reloadnewpage=1";
            string newUrl = CMSDeskPage.GetUIPageURL(settings);
            newUrl = AddNewItemUrlParameters(newUrl);
            // Toolbar - New button script
            string scriptNew = GetModalDialogScript(newUrl, "newpage");

            // Toolbar - Properties button script
            string scriptProperties = GetModalDialogScript(ResolveUrl("~/CMSModules/Content/CMSDesk/Properties/Properties_Frameset.aspx?mode=editlive&documentid=" + pi.DocumentID), "propertiespage");

            // Display items from current level by default
            int nodeId = pi.NodeParentID;
            // If current level is root display first level
            if (nodeId == 0)
            {
                isRootDocument = true;
                nodeId         = pi.NodeID;
            }

            // In page not found mode display first level
            if (nodeId == 0)
            {
                TreeProvider tp = new TreeProvider(cui);
                TreeNode     tn = tp.SelectSingleNode(CMSContext.CurrentSiteName, "/", TreeProvider.ALL_CULTURES);
                if (tn != null)
                {
                    nodeId = tn.NodeID;
                }
            }

            // Listing
            string listItemUrl    = ResolveUrl("~/CMSModules/Content/CMSDesk/View/listing.aspx?dialog=1&wopenernodeid=" + pi.NodeID + "&nodeid=##id##");
            string scriptListItem = GetModalDialogScript(listItemUrl.Replace("##id##", nodeId.ToString()), "listingpage");

            // New culture
            string newCultureUrl = ResolveUrl("~/CMSModules/Content/CMSDesk/New/NewCultureVersion.aspx?nodeid=##id##&culture=##cult##&dialog=1");

            script.Append(@"
                var OEEditImagePath = '", GetImageUrl("CMSModules/CMS_PortalEngine/OnSiteEdit/webpart_edit.png"), @"';
                var OEConfigureImagePath = '", GetImageUrl("CMSModules/CMS_PortalEngine/OnSiteEdit/webpart_properties.png"), @"';
                var OEIsRTL = ", (isRTL ? "true" : "false"), @";
                var OECurrentNodeId = ", (CMSContext.CurrentPageInfo != null) ? CMSContext.CurrentPageInfo.NodeID : 0, @";
                var OEIsMobile = ", (CMSContext.CurrentDevice.IsMobile ? "true" : "false"), @";
                var OEHdnPostbackValue = null;

                function ConfigureWebPart(webPartZoneId, webPartId, aliasPath, instanceGuid, templateId, refreshOnCancel) {
                    modalDialog('", OnSiteEditHelper.WebPartPropertiesPageUrl, @"?aliaspath=' + aliasPath + '&zoneid=' + webPartZoneId + '&webpartid=' + webPartId + '&culture=' + ", preferredCultureCode, @" + '&instanceguid=' + instanceGuid + '&templateid=' + templateId + (!!refreshOnCancel ? '&refreshoncancel=true'  : ''), 'configurewebpart', 900, 638);
                }

                function NewDocument(parentId, classId, targetWindow)
                {
                    OEClearZIndex(OEActiveWebPart);

                    if (targetWindow == null) {
                        ", scriptNew, @";   
                    }
                    else {
                        targetWindow.location.href = '", newUrl, @"';
                    }
                }

                function EditDocument(nodeId, targetWindow)
                {
                    OEClearZIndex(OEActiveWebPart); 

                    // Edit item button in repeaters and datalists
                    var arg = 'editurl;' + nodeId;
                    ", Page.ClientScript.GetCallbackEventReference(this, "arg", "OECallbackHandler", null), @";
                   
                }

                function OECallbackHandler(arg, context) {
                    ", GetModalDialogScript("arg", "editpage", false), @"
                }

                function DeleteDocument(nodeId)
                {
                    OEClearZIndex(OEActiveWebPart); 
                    ", scriptDeleteItem, @" 
                }

                function OnSiteToolbarAction(name)
                { 
                    switch(name)
                    {
                        case 'edit':
                                ", scriptEdit, @"
                            break;

                        case 'properties':
                                ", scriptProperties, @"
                            break;

                        case 'new':
                                var parentId = OECurrentNodeId;
                                var classId = 0;
                                ", scriptNew, @"
                            break;

                        case 'delete':
                                ", scriptDelete, @"
                            break;

                        case 'list':
                                ", scriptListItem, @"
                            break;

                        default:
                            alert('Required action is not implemented.');
                    }
                }

                function SelectNode(nodeId, parentNodeId)
                {
                    var liu = '", listItemUrl, @"';
                    return liu.replace(/##id##/g, nodeId);
                }

                function NewDocumentCulture(nodeId, culture)
                {
                    var liu = '", newCultureUrl, @"';
                    liu = liu.replace(/##id##/g, nodeId);
                    liu = liu.replace(/##cult##/g, culture);
                    ", GetModalDialogScript("liu", "newculture", false), @"
                }

                function ToggleUpdateProgress(show) {
                    var loadingBg = jQuery('.OnSiteUPBg');
                    var loading = jQuery('#", updateProgress.ClientID, @"');
                
                    if (show) {
                        loading.css('display', 'inline');
                        loadingBg.show();
                    }
                    else {
                        loading.hide();
                        loadingBg.hide();
                    }
                }

                function OEEnsureHdnPostbackValue() {
                    if (OEHdnPostbackValue == null) {
                        OEHdnPostbackValue = document.getElementById('", hdnPostbackValue.ClientID, @"');
                    }
                }

                // Changes the device profile
                function ChangeDevice(device) {
                    OEEnsureHdnPostbackValue();
                    OEHdnPostbackValue.value = device;
                    ", ControlsHelper.GetPostBackEventReference(this, "changedeviceprofile"), @"
                } ");

            // Register jQuery
            ScriptHelper.RegisterJQueryDialog(Page);

            // Register OnSiteEdit script file
            ScriptHelper.RegisterScriptFile(Page, "DesignMode/OnSiteEdit.js");
            ScriptHelper.RegisterScriptFile(Page, "~/CMSScripts/jquery/jquery-url.js");
        }
        // Slider buttons scripts
        else if (ViewMode == ViewModeEnum.LiveSite)
        {
            bool sliderIsMinimized = ValidationHelper.GetBoolean(CookieHelper.GetValue(CookieName.OnSiteButtonMinimized), false);
            if (sliderIsMinimized)
            {
                // Renew the cookie
                CookieHelper.SetValue(CookieName.OnSiteButtonMinimized, "true", "/", DateTime.Now.AddDays(31), false);
            }

            script.Append(@"
                var OEIsMinimized = ", (sliderIsMinimized ? "true" : "false"), @";

                function OESlideSideToolbar() {
                    // Hide the slider button in CMSDesk
                    if (parent != this) {
                        return;
                    }

                    var toolbarEl = document.getElementById('", pnlSlider.ClientID, @"');
                    toolbarEl.style.display = ""block"";

                    if (!OEIsMinimized) {
                        // Show slider button
                        toolbarEl.style.top = ""0px"";
                        document.getElementById('", imgMinimize.ClientID, @"').style.display = ""inline"";
                        document.getElementById('", imgMaximize.ClientID, @"').style.display = ""none"";
                        jQuery.cookie('", CookieName.OnSiteButtonMinimized, @"', null, { path: '/' });
                    }
                    else {
                        // Hide slider button
                        var sliderButtonEl = document.getElementById('", pnlButton.ClientID, @"');
                        toolbarEl.style.top = ""-"" + (sliderButtonEl.offsetHeight + 1) + ""px"";
                        document.getElementById('", imgMinimize.ClientID, @"').style.display = ""none"";
                        document.getElementById('", imgMaximize.ClientID, @"').style.display = ""inline"";
                        jQuery.cookie('", CookieName.OnSiteButtonMinimized, @"', true, { path: '/', expires: 31 });
                    }

                    OEIsMinimized = !OEIsMinimized;
                }

                // Display slider button
                jQuery(document).ready(function() { OESlideSideToolbar(); });
                ");
        }

        script.Append(" function OnSiteEdit_ChangeEditMode(){", ControlsHelper.GetPostBackEventReference(this, "changeviewmode"), "} ");

        ControlsHelper.RegisterClientScriptBlock(this, Page, typeof(string), "OnSiteEditActions", ScriptHelper.GetScript(script.ToString()));
    }
    private TabItem tabModes_OnTabCreated(UIElementInfo element, TabItem tab, int tabIndex)
    {
        // Script for refresh 'display web part content' button
        string script = "SetTabsContext('');";
        string mode = null;

        string elem = element.ElementName.ToLowerCSafe();

        switch (elem)
        {
            case "wireframe":
                {
                    // Check if the wireframe mode is enabled
                    if (!hasWireframe)
                    {
                        return null;
                    }

                    wireframeTabIndex = tabIndex;
                    script = "SetTabsContext('wireframe');";
                    mode = "wireframe";
                }
                break;

            case "editform":
                // Keep edit form
                {
                    formTabIndex = tabIndex;
                    script = "SetTabsContext('editform');";
                    mode = "editform";
                }
                break;

            default:
                // Hide other tabs for wireframe
                if (isWireframe)
                {
                    return null;
                }
                break;
        }

        switch (elem)
        {
            case "page":
                {
                    pageTabIndex = tabIndex;
                    script = "SetTabsContext('page');";
                    mode = "edit";
                }
                break;

            case "design":
                {
                    // Check if the design mode is enabled
                    if (!designEnabled)
                    {
                        return null;
                    }

                    if (authorizedPerDesign)
                    {
                        designTabIndex = tabIndex;
                    }
                    else
                    {
                        if (!authorizedPerDesign)
                        {
                            designPermissionRequired = true;
                        }
                        return null;
                    }
                    script = "SetTabsContext('design');";
                    mode = "design";
                }
                break;

            case "product":
                {
                    // Check if the product tab is enabled
                    if (showProductTab && LicenseHelper.IsFeatureAvailableInUI(FeatureEnum.Ecommerce, ModuleEntry.ECOMMERCE))
                    {
                        productTabIndex = tabIndex;
                    }
                    else
                    {
                        return null;
                    }
                    script = "SetTabsContext('product');";
                    mode = "product";
                }
                break;

            case "masterpage":
                {
                    // Check if master page tab is enabled
                    if (isMasterPage && authorizedPerDesign)
                    {
                        masterTabIndex = tabIndex;
                    }
                    else
                    {
                        if (!authorizedPerDesign)
                        {
                            designPermissionRequired = true;
                        }
                        return null;
                    }

                    script = "SetTabsContext('masterpage');";
                    mode = "masterpage";
                }
                break;

            case "properties":
                {
                    // Document properties
                    propertiesTabIndex = tabIndex;
                    mode = "properties";
                }
                break;

            case "analytics":
                {
                    // Analytics
                    if (isWireframe)
                    {
                        return null;
                    }

                    analyticsIndex = tabIndex;
                    script = "SetTabsContext('analytics');";
                    mode = "analytics";
                }
                break;

            case "validation":
                return null;
        }

        UIPageURLSettings settings = new UIPageURLSettings
                                         {
                                             Mode = mode,
                                             Node = Node,
                                             NodeID = Node.NodeID,
                                             Culture = Node.DocumentCulture,
                                             PreferredURL = tab.RedirectUrl
                                         };

        // Ensure correct URL
        tab.RedirectUrl = GetDocumentPageUrl(settings);

        // Add script for refresh web part content button (displayed only when design mode)
        tab.OnClientClick = script + tab.OnClientClick;

        return tab;
    }
    protected TabItem Tabs_OnTabCreated(UIElementInfo element, TabItem tab, int tabIndex)
    {
        bool splitViewSupported = false;
        string lowerElementName = element.ElementName.ToLowerCSafe();
        UIPageURLSettings settings = null;
        switch (lowerElementName)
        {
            case "products.general":
            case "products.attachments":
            case "products.metadata":
            case "products.categories":
            case "products.workflow":
            case "products.versions":
                splitViewSupported = true;

                break;
        }

        switch (lowerElementName)
        {
            case "products.attachments":
            case "products.metadata":
            case "products.categories":
            case "products.workflow":
            case "products.versions":
            case "products.relatedproducts":
                // Check if editing product with its document
                if (NodeID <= 0)
                {
                    return null;
                }

                break;

            case "products.documents":
                if ((NodeID <= 0) && DisplayTreeInProducts)
                {
                    if (!CurrentUser.IsGlobalAdministrator || (sku == null) || !sku.IsGlobal)
                    {
                        return null;
                    }
                }

                break;

            case "products.preview":
                // Check if editing product with its document
                if (NodeID <= 0)
                {
                    return null;
                }

                settings = new UIPageURLSettings
                {
                    Mode = "preview",
                    NodeID = Node.NodeID,
                    Culture = Node.DocumentCulture,
                    Node = Node,
                    AllowViewValidate = false
                };
                tab.RedirectUrl = GetDocumentPageUrl(settings);
                tab.RedirectUrl = URLHelper.AddParameterToUrl(tab.RedirectUrl, "nodeid", NodeID.ToString());
                tab.OnClientClick += "SetTab('PreviewTab')";

                break;

            case "products.livesite":
                // Check if editing product with its document
                if (NodeID <= 0)
                {
                    return null;
                }

                settings = new UIPageURLSettings
                {
                    Mode = "livesite",
                    NodeID = Node.NodeID,
                    Culture = Node.DocumentCulture,
                    Node = Node,
                    AllowViewValidate = false
                };
                tab.RedirectUrl = GetDocumentPageUrl(settings);
                tab.RedirectUrl = URLHelper.AddParameterToUrl(tab.RedirectUrl, "nodeid", NodeID.ToString());
                tab.OnClientClick += "SetTab('LiveSiteTab')";

                break;

            case "products.customfields":
            case "productoptions.options.customfields":
                // Check if SKU has any custom fields
                FormInfo formInfo = FormHelper.GetFormInfo("ecommerce.sku", false);
                if (!formInfo.GetFormElements(true, false, true).Any())
                {
                    return null;
                }

                break;

            case "products.advanced":
                tab.Expand = (NodeID <= 0);

                break;
        }

        // Open advanced tab when one of its subtabs is selected
        bool openAdvanced = false;
        switch (selectedTab)
        {
            case "options":
            case "volumediscounts":
            case "workflow":
            case "versions":
            case "documents":
            case "relatedproducts":
                openAdvanced = true;
                break;
        }

        // Ensure tab preselection
        if (lowerElementName.StartsWithCSafe("products.") &&
            ((lowerElementName.Substring("products.".Length) == selectedTab) || (openAdvanced && (lowerElementName == "products.advanced"))))
        {
            CurrentMaster.Tabs.SelectedTab = tabIndex;
        }

        // Add SiteId parameter to each tab
        if (!string.IsNullOrEmpty(tab.RedirectUrl))
        {
            tab.RedirectUrl = URLHelper.AddParameterToUrl(tab.RedirectUrl, "siteId", SiteID.ToString());
        }

        // Ensure split view mode
        if ((NodeID > 0) && splitViewSupported && CMSContext.DisplaySplitMode)
        {
            tab.RedirectUrl = GetSplitViewUrl(tab.RedirectUrl);
        }

        // Make URL absolute
        tab.RedirectUrl = URLHelper.GetAbsoluteUrl(tab.RedirectUrl);

        return tab;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Register the scripts
        ScriptHelper.RegisterDialogScript(Page);
        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "defaultVariables", ScriptHelper.GetScript(@"var IsCMSDesk = true;"));
        ScriptHelper.RegisterScriptFile(Page, @"~/CMSModules/Content/CMSDesk/Content.js");

        var settings = new UIPageURLSettings
        {
            Mode = ResultMode,
            Action = Action,
            NodeID = ResultNodeID,
            Culture = LocalizationContext.PreferredCultureCode,
            IncludeLiveSiteURL = true
        };

        var urls = urlRetriever.GetRequestedUrl(settings).Split(new[] { ContentUrlRetriever.CALLBACK_SEPARATOR }, StringSplitOptions.RemoveEmptyEntries);

        // Ensure action URL
        contentview.Src = urls[0];

        if (urls.Length > 1)
        {
            // Set default live site URL in header link
            ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "SetDefaultLiveSiteURL", ScriptHelper.GetScript("SetLiveSiteURL('" + urls[1] + "');"));
        }
    }
    /// <summary>
    /// Registers script files for on-site editing
    /// </summary>
    /// <param name="pi">Current page info</param>
    private void RegisterEditScripts(PageInfo pi)
    {
        ScriptHelper.RegisterJQueryCookie(Page);
        StringBuilder script = new StringBuilder();

        // Edit toolbar scripts
        if (ViewMode.IsEditLive())
        {
            // Dialog scripts
            ScriptHelper.RegisterDialogScript(Page);

            // General url settings
            UIPageURLSettings settings = new UIPageURLSettings();
            settings.AllowSplitview = false;
            settings.NodeID = pi.NodeID;
            settings.Culture = pi.DocumentCulture;
            settings.AdditionalQuery = "dialog=1";

            // Edit document
            settings.Mode = "editform";
            settings.Action = null;
            string editUrl = DocumentUIHelper.GetDocumentPageUrl(settings);
            settings.Mode = string.Empty;

            // Toolbar - Edit button script
            editUrl = URLHelper.RemoveParameterFromUrl(editUrl, "mode");
            string scriptEdit = GetModalDialogScript(editUrl, "editpage");

            // Delete document
            settings.Action = "delete";
            string deleteUrl = DocumentUIHelper.GetDocumentPageUrl(settings);
            // Toolbar - Delete button script
            string scriptDelete = GetModalDialogScript(deleteUrl, "deletepage");
            // User contributions - Delete item script
            string scriptDeleteItem = GetModalDialogScript(AddItemUrlParameters(deleteUrl), "deletepage");

            // New document
            settings.Action = "new";
            settings.AdditionalQuery += "&reloadnewpage=1";
            string newUrl = DocumentUIHelper.GetDocumentPageUrl(settings);
            newUrl = AddNewItemUrlParameters(newUrl);
            // Include culture code
            newUrl = URLHelper.AddParameterToUrl(newUrl, "parentculture", preferredCultureCode);
            // Toolbar - New button script
            string scriptNew = GetModalDialogScript(newUrl, "newpage");

            // Toolbar - Properties button script
            string scriptProperties = GetModalDialogScript(ResolveUrl("~/CMSModules/Content/CMSDesk/Properties/Properties_Frameset.aspx?mode=editlive&documentid=" + pi.DocumentID), "propertiespage");

            // Display items from current level by default
            int nodeId = pi.NodeParentID;
            // If current level is root display first level
            if (nodeId == 0)
            {
                isRootDocument = true;
                nodeId = pi.NodeID;
            }

            // In page not found mode display first level
            if (nodeId == 0)
            {
                TreeProvider tp = new TreeProvider();
                TreeNode tn = tp.SelectSingleNode(SiteContext.CurrentSiteName, "/", TreeProvider.ALL_CULTURES);
                if (tn != null)
                {
                    nodeId = tn.NodeID;
                }
            }

            // Listing
            string listItemUrl = ResolveUrl("~/CMSModules/Content/CMSDesk/View/listing.aspx?dialog=1&wopenernodeid=" + pi.NodeID + "&nodeid=##id##");
            string scriptListItem = GetModalDialogScript(listItemUrl.Replace("##id##", nodeId.ToString()), "listingpage");

            // New culture
            string newCultureUrl = ResolveUrl("~/CMSModules/Content/CMSDesk/New/NewCultureVersion.aspx?nodeid=##id##&culture=##cult##&dialog=1");

            script.Append(@"
                var OEIsRTL = ", (isRTL ? "true" : "false"), @";
                var OECurrentNodeId = ", (DocumentContext.CurrentPageInfo != null) ? DocumentContext.CurrentPageInfo.NodeID : 0, @";
                var OEIsMobile = ", (DeviceContext.CurrentDevice.IsMobile ? "true" : "false"), @";
                var OEHdnPostbackValue = null;

                function NewDocument(parentId, classId, targetWindow)
                {
                    OEClearZIndex(OEActiveWebPart);

                    if (targetWindow == null) {
                        ", scriptNew, @";
                    }
                    else {
                        targetWindow.location.href = '", newUrl, @"';
                    }
                }

                function EditDocument(nodeId, targetWindow)
                {
                    OEClearZIndex(OEActiveWebPart);

                    // Edit item button in repeaters and datalists
                    var arg = 'editurl;' + nodeId;
                    ", Page.ClientScript.GetCallbackEventReference(this, "arg", "OECallbackHandler", null), @";

                }

                function SaveDocumentWidgets() {
                    if (!CMSContentManager.contentModified()) {
                        return false;
                    }
                    if (window.CMSContentManager) { CMSContentManager.allowSubmit = true; }
                    ", ControlsHelper.GetPostBackEventReference(this, "savedocument"), @";
                }

                function OECallbackHandler(arg, context) {
                    ", GetModalDialogScript("arg", "editpage", false), @"
                }

                function DeleteDocument(nodeId)
                {
                    OEClearZIndex(OEActiveWebPart);
                    ", scriptDeleteItem, @"
                }

                function OnSiteToolbarAction(name)
                {
                    ", checkChanges, @"

                    switch(name)
                    {
                        case 'edit':
                                ", scriptEdit, @"
                            break;

                        case 'properties':
                                ", scriptProperties, @"
                            break;

                        case 'new':
                                var parentId = OECurrentNodeId;
                                var classId = 0;
                                ", scriptNew, @"
                            break;

                        case 'delete':
                                ", scriptDelete, @"
                            break;

                        case 'list':
                                ", scriptListItem, @"
                            break;

                        default:
                            alert('Required action is not implemented.');
                    }
                }

                function SelectNode(nodeId, parentNodeId)
                {
                    var liu = '", listItemUrl, @"';
                    return liu.replace(/##id##/g, nodeId);
                }

                function NewDocumentCulture(nodeId, culture)
                {
                    ", checkChanges, @"

                    var liu = '", newCultureUrl, @"';
                    liu = liu.replace(/##id##/g, nodeId);
                    liu = liu.replace(/##cult##/g, culture);
                    ", GetModalDialogScript("liu", "newculture", false), @"
                }

                function OEEnsureHdnPostbackValue() {
                    if (OEHdnPostbackValue == null) {
                        OEHdnPostbackValue = document.getElementById('", hdnPostbackValue.ClientID, @"');
                    }
                }

                // Changes the device profile
                function ChangeDevice(device) {
                    ", checkChanges, @"
                    OEEnsureHdnPostbackValue();
                    OEHdnPostbackValue.value = device;
                    ", ControlsHelper.GetPostBackEventReference(this, "changedeviceprofile"), @"
                } ");

            ScriptHelper.RegisterJQueryDialog(Page);

            // Register OnSiteEdit script file
            ScriptHelper.RegisterScriptFile(Page, "DesignMode/OnSiteEdit.js");
            ScriptHelper.RegisterScriptFile(Page, "~/CMSScripts/jquery/jquery-url.js");
        }
        // Slider buttons scripts
        else if (ViewMode.IsLiveSite())
        {
            script.Append(@"

                function OESlideSideToolbar() {
                    // Hide the slider button in CMSDesk
                    if (parent != this) {
                        return;
                    }

                    var toolbarEl = document.getElementById('", pnlSlider.ClientID, @"');
                    toolbarEl.style.display = ""block"";
                    // Show slider button
                    toolbarEl.style.top = ""0px"";
                }

                // Display slider button
                $cmsj(document).ready(function() { OESlideSideToolbar(); });
                ");
        }

        script.Append(" function OnSiteEdit_ChangeEditMode(){", ControlsHelper.GetPostBackEventReference(this, "changeviewmode"), "} ");

        ControlsHelper.RegisterClientScriptBlock(this, Page, typeof(string), "OnSiteEditActions", ScriptHelper.GetScript(script.ToString()));
    }
示例#20
0
    protected void OnTabCreated(object sender, TabCreatedEventArgs e)
    {
        if (e.Tab == null)
        {
            return;
        }

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

        bool splitViewSupported = false;

        string lowerElementName = element.ElementName.ToLowerCSafe();

        switch (lowerElementName)
        {
        case "products.attachments":
        case "products.metadata":
        case "products.categories":
        case "products.workflow":
        case "products.versions":
            splitViewSupported = true;
            break;

        case "products.general":
            splitViewSupported = true;
            break;
        }

        switch (lowerElementName)
        {
        case "products.attachments":
        case "products.metadata":
        case "products.categories":
        case "products.workflow":
        case "products.versions":
        case "products.relatedproducts":
            // Check if editing product with its document
            if (NodeID <= 0)
            {
                e.Tab = null;
                return;
            }
            break;

        case "products.documents":
            if ((NodeID <= 0) && (ECommerceSettings.ProductsTree(SiteContext.CurrentSiteName) == ProductsTreeModeEnum.Sections))
            {
                if (!MembershipContext.AuthenticatedUser.IsGlobalAdministrator || (sku == null) || !sku.IsGlobal)
                {
                    e.Tab = null;
                    return;
                }
            }
            break;

        case "products.preview":
        {
            // Check if editing product with its document
            if (NodeID <= 0)
            {
                e.Tab = null;
                return;
            }

            var settings = new UIPageURLSettings
            {
                Mode              = "preview",
                NodeID            = Node.NodeID,
                Culture           = Node.DocumentCulture,
                Node              = Node,
                AllowViewValidate = false
            };

            tab.RedirectUrl = ProductUIHelper.GetProductPageUrl(settings);

            tab.RedirectUrl = URLHelper.AddParameterToUrl(tab.RedirectUrl, "nodeid", NodeID.ToString());
            tab.RedirectUrl = URLHelper.AddParameterToUrl(tab.RedirectUrl, "showdevicesselection", "0");
        }
        break;

        case "products.advanced":
        {
            tab.Expand = (NodeID <= 0);

            // Append product/node params to url
            var url = tab.RedirectUrl;
            url = URLHelper.AddParameterToUrl(url, "productid", ProductID.ToString());
            if (Node != null)
            {
                url = URLHelper.AddParameterToUrl(url, "nodeid", Node.NodeID.ToString());
                url = URLHelper.AddParameterToUrl(url, "culture", Node.DocumentCulture);
            }

            tab.RedirectUrl = url;
        }
        break;

        case "products.options":
            tab.RedirectUrl = URLHelper.AddParameterToUrl(tab.RedirectUrl, "productId", ProductID.ToString());
            break;
        }

        // Add SiteId parameter to each tab
        if (!string.IsNullOrEmpty(tab.RedirectUrl))
        {
            tab.RedirectUrl = URLHelper.AddParameterToUrl(tab.RedirectUrl, "siteId", siteId.ToString());
        }

        // Ensure split view mode
        if ((NodeID > 0) && splitViewSupported && UIContext.DisplaySplitMode)
        {
            tab.RedirectUrl = DocumentUIHelper.GetSplitViewUrl(tab.RedirectUrl);
        }

        // Make URL absolute
        tab.RedirectUrl = URLHelper.GetAbsoluteUrl(tab.RedirectUrl);
    }
    protected TabItem Tabs_OnTabCreated(UIElementInfo element, TabItem tab, int tabIndex)
    {
        bool              splitViewSupported = false;
        string            lowerElementName   = element.ElementName.ToLowerCSafe();
        UIPageURLSettings settings           = null;

        switch (lowerElementName)
        {
        case "products.general":
        case "products.attachments":
        case "products.metadata":
        case "products.categories":
        case "products.workflow":
        case "products.versions":
            splitViewSupported = true;

            break;
        }

        switch (lowerElementName)
        {
        case "products.attachments":
        case "products.metadata":
        case "products.categories":
        case "products.workflow":
        case "products.versions":
        case "products.relatedproducts":
            // Check if editing product with its document
            if (NodeID <= 0)
            {
                return(null);
            }

            break;

        case "products.documents":
            if ((NodeID <= 0) && DisplayTreeInProducts)
            {
                if (!CurrentUser.IsGlobalAdministrator || (sku == null) || !sku.IsGlobal)
                {
                    return(null);
                }
            }

            break;

        case "products.preview":
            // Check if editing product with its document
            if (NodeID <= 0)
            {
                return(null);
            }

            settings = new UIPageURLSettings
            {
                Mode              = "preview",
                NodeID            = Node.NodeID,
                Culture           = Node.DocumentCulture,
                Node              = Node,
                AllowViewValidate = false
            };
            tab.RedirectUrl    = GetDocumentPageUrl(settings);
            tab.RedirectUrl    = URLHelper.AddParameterToUrl(tab.RedirectUrl, "nodeid", NodeID.ToString());
            tab.OnClientClick += "SetTab('PreviewTab')";

            break;

        case "products.livesite":
            // Check if editing product with its document
            if (NodeID <= 0)
            {
                return(null);
            }

            settings = new UIPageURLSettings
            {
                Mode              = "livesite",
                NodeID            = Node.NodeID,
                Culture           = Node.DocumentCulture,
                Node              = Node,
                AllowViewValidate = false
            };
            tab.RedirectUrl    = GetDocumentPageUrl(settings);
            tab.RedirectUrl    = URLHelper.AddParameterToUrl(tab.RedirectUrl, "nodeid", NodeID.ToString());
            tab.OnClientClick += "SetTab('LiveSiteTab')";

            break;

        case "products.customfields":
        case "productoptions.options.customfields":
            // Check if SKU has any custom fields
            FormInfo formInfo = FormHelper.GetFormInfo("ecommerce.sku", false);
            if (!formInfo.GetFormElements(true, false, true).Any())
            {
                return(null);
            }

            break;

        case "products.advanced":
            tab.Expand = (NodeID <= 0);

            break;
        }

        // Open advanced tab when one of its subtabs is selected
        bool openAdvanced = false;

        switch (selectedTab)
        {
        case "options":
        case "volumediscounts":
        case "workflow":
        case "versions":
        case "documents":
        case "relatedproducts":
            openAdvanced = true;
            break;
        }

        // Ensure tab preselection
        if (lowerElementName.StartsWithCSafe("products.") &&
            ((lowerElementName.Substring("products.".Length) == selectedTab) || (openAdvanced && (lowerElementName == "products.advanced"))))
        {
            CurrentMaster.Tabs.SelectedTab = tabIndex;
        }

        // Add SiteId parameter to each tab
        if (!string.IsNullOrEmpty(tab.RedirectUrl))
        {
            tab.RedirectUrl = URLHelper.AddParameterToUrl(tab.RedirectUrl, "siteId", SiteID.ToString());
        }

        // Ensure split view mode
        if ((NodeID > 0) && splitViewSupported && CMSContext.DisplaySplitMode)
        {
            tab.RedirectUrl = GetSplitViewUrl(tab.RedirectUrl);
        }

        // Make URL absolute
        tab.RedirectUrl = URLHelper.GetAbsoluteUrl(tab.RedirectUrl);

        return(tab);
    }
示例#22
0
    /// <summary>
    /// Fires when a tab is created
    /// </summary>
    private void OnTabCreated(object sender, TabCreatedEventArgs e)
    {
        if (e.Tab == null)
        {
            return;
        }

        string mode = null;

        var element = e.UIElement;

        // Hides UI element if it is not relevant for edited node
        if (DocumentUIHelper.IsElementHiddenForNode(element, Node))
        {
            e.Tab = null;
            return;
        }

        switch (element.ElementName.ToLowerInvariant())
        {
        case "page":
        case "pagemvc":
        {
            mode = "edit";
        }
        break;

        case "design":
        {
            if (!showDesign)
            {
                e.Tab = null;
                return;
            }

            mode = "design";
        }
        break;

        case "editform":
            // Keep edit form
        {
            mode = "editform";
        }
        break;

        case "product":
        {
            if (!showProductTab)
            {
                e.Tab = null;
                return;
            }

            mode = "product";
        }
        break;

        case "masterpage":
        {
            if (!showMasterPage)
            {
                e.Tab = null;
                return;
            }

            mode = "masterpage";
        }
        break;

        case "properties":
        {
            // Document properties
            mode = "properties";
        }
        break;

        case "analytics":
        {
            mode = "analytics";
        }
        break;
        }

        if (Node != null)
        {
            var tab = e.Tab;

            var settings = new UIPageURLSettings
            {
                Mode         = mode,
                Node         = Node,
                NodeID       = Node.NodeID,
                Culture      = Node.DocumentCulture,
                PreferredURL = tab.RedirectUrl
            };

            tab.RedirectUrl = DocumentUIHelper.GetDocumentPageUrl(settings);
            tab.Text        = DocumentUIHelper.GetUIElementDisplayName(element, Node);
        }
    }
    /// <summary>
    /// Returns URL of modal dialog for creating new page.
    /// </summary>
    private string GetCreateNewPageDialogUrl()
    {
        var path = SettingsKeyInfoProvider.GetValue("CMSCampaignNewPageLocation", SiteContext.CurrentSiteName);
        var tree = new TreeProvider(MembershipContext.AuthenticatedUser);
        var node = tree.SelectSingleNode(SiteContext.CurrentSiteName, path, SiteContext.CurrentSite.DefaultVisitorCulture, true);

        if (node == null)
        {
            node = tree.SelectSingleNode(SiteContext.CurrentSiteName, "/", SiteContext.CurrentSite.DefaultVisitorCulture, true);
        }

        // General url settings
        var settings = new UIPageURLSettings
        {
            AllowSplitview = false,
            NodeID = node.NodeID,
            Culture = node.DocumentCulture,
            Action = "new",
            AdditionalQuery = "dialog=1&action=new&hidecontentonly=true"
        };

        return DocumentUIHelper.GetDocumentPageUrl(settings);
    }