示例#1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        const string CONTENT_CMSDESK_FOLDER = "~/CMSModules/Content/CMSDesk/";

        // Register script files
        ScriptHelper.RegisterScriptFile(this, CONTENT_CMSDESK_FOLDER + "EditTabs.js");

        bool   checkCulture       = false;
        bool   splitViewSupported = false;
        string action             = QueryHelper.GetString("action", "edit").ToLowerCSafe();

        switch (action)
        {
        // New dialog / new page form
        case "new":
            int classId = QueryHelper.GetInteger("classid", 0);
            if (classId <= 0)
            {
                // Get by class name if specified
                string className = QueryHelper.GetString("classname", string.Empty);
                if (className != string.Empty)
                {
                    classInfo = DataClassInfoProvider.GetDataClassInfo(className);
                    if (classInfo != null)
                    {
                        classId = classInfo.ClassID;
                    }
                }
            }

            const string EC_PRODUCTS_FOLDER = "~/CMSModules/Ecommerce/Pages/Tools/Products/";

            if (classId > 0)
            {
                viewpage = ResolveUrl(CONTENT_CMSDESK_FOLDER + "Edit/Edit.aspx");

                // Check if document type is allowed under parent node
                if (parentNodeID > 0)
                {
                    // Get the node
                    TreeNode = Tree.SelectSingleNode(parentNodeID, TreeProvider.ALL_CULTURES);
                    if (TreeNode != null)
                    {
                        if (!DocumentHelper.IsDocumentTypeAllowed(TreeNode, classId))
                        {
                            viewpage = CONTENT_CMSDESK_FOLDER + "NotAllowed.aspx?action=child";
                        }
                    }
                }

                // Use product page when product type is selected
                classInfo = classInfo ?? DataClassInfoProvider.GetDataClassInfo(classId);
                if ((classInfo != null) && (classInfo.ClassIsProduct))
                {
                    viewpage = ResolveUrl(EC_PRODUCTS_FOLDER + "Product_New.aspx");
                }
            }
            else
            {
                if (parentNodeID > 0)
                {
                    viewpage = EC_PRODUCTS_FOLDER + "New_ProductOrSection.aspx";
                }
                else
                {
                    viewpage = EC_PRODUCTS_FOLDER + "Product_New.aspx?parentNodeId=0";
                }
            }
            break;

        case "delete":
            // Delete dialog
            viewpage = CONTENT_CMSDESK_FOLDER + "Delete.aspx";
            break;

        default:
            // Edit mode
            viewpage           = CONTENT_CMSDESK_FOLDER + "Edit/edit.aspx?mode=editform";
            splitViewSupported = true;

            // Ensure class info
            if ((classInfo == null) && (Node != null))
            {
                classInfo = DataClassInfoProvider.GetDataClassInfo(Node.NodeClassName);
            }

            // Check explicit editing page url
            if ((classInfo != null) && !string.IsNullOrEmpty(classInfo.ClassEditingPageURL))
            {
                viewpage = URLHelper.AppendQuery(ResolveUrl(classInfo.ClassEditingPageURL), RequestContext.CurrentQueryString);
            }

            checkCulture = true;
            break;
        }

        // If culture version should be checked, check
        if (checkCulture)
        {
            // Check (and ensure) the proper content culture
            if (!CheckPreferredCulture())
            {
                RefreshParentWindow();
            }

            // Check split mode
            bool isSplitMode = PortalUIHelper.DisplaySplitMode;
            bool combineWithDefaultCulture = !isSplitMode && SiteInfoProvider.CombineWithDefaultCulture(SiteContext.CurrentSiteName);

            var nodeId = QueryHelper.GetInteger("nodeid", 0);
            TreeNode = Tree.SelectSingleNode(nodeId, CultureCode, combineWithDefaultCulture);
            if (TreeNode == null)
            {
                // Document does not exist -> redirect to new culture version creation dialog
                viewpage = ProductUIHelper.GetNewCultureVersionPageUrl();
            }
        }

        // Apply the additional transformations to the view page URL
        viewpage = URLHelper.AppendQuery(viewpage, RequestContext.CurrentQueryString);
        viewpage = URLHelper.RemoveParameterFromUrl(viewpage, "mode");
        viewpage = URLHelper.AddParameterToUrl(viewpage, "mode", "productssection");
        viewpage = ResolveUrl(viewpage);
        viewpage = URLHelper.AddParameterToUrl(viewpage, "hash", QueryHelper.GetHash(viewpage));

        // Split mode enabled
        if (splitViewSupported && PortalUIHelper.DisplaySplitMode && (TreeNode != null) && (action == "edit" || action == "preview" || (TreeNode.IsPublished && action == "livesite")))
        {
            viewpage = DocumentUIHelper.GetSplitViewUrl(viewpage);
        }

        URLHelper.Redirect(UrlResolver.ResolveUrl(viewpage));
    }
    /// <summary>
    /// Initializes the extender
    /// </summary>
    public override void OnInit()
    {
        base.OnInit();
        var  breadcrumbName      = "";
        bool generateBreadcrumbs = true;


        // Ensure selection of general tab in case EditForm is requested
        var tabName = QueryHelper.GetString("tabName", "");

        if (tabName.EqualsCSafe("EditForm", true))
        {
            Control.SelectedTabName = "Products.General";
        }

        var page = (CMSPage)Control.Page;

        if (ProductID <= 0)
        {
            // Setup the document manager
            var manager = page.DocumentManager;
            manager.RedirectForNonExistingDocument = false;
            manager.Tree.CombineWithDefaultCulture = false;

            var node = manager.Node;
            if (node == null)
            {
                // Redirect to create new culture version
                URLHelper.ResponseRedirect(ProductUIHelper.GetNewCultureVersionPageUrl(), false);
                CMSHttpContext.Current.ApplicationInstance.CompleteRequest();
                return;
            }

            Node           = node;
            breadcrumbName = Node.Site.Generalized.ObjectDisplayName;
        }

        // Get product name and option category ID
        if (ProductID > 0)
        {
            sku = SKUInfoProvider.GetSKUInfo(ProductID);
            if (sku != null)
            {
                breadcrumbName   = ResHelper.LocalizeString(sku.SKUName);
                optionCategoryId = sku.SKUOptionCategoryID;
                siteId           = sku.SKUSiteID;

                // Check if edited object belongs to configured site
                if ((siteId != SiteContext.CurrentSiteID) && ((siteId != 0) || !AllowGlobalObjects))
                {
                    page.EditedObject = null;
                }

                var dialogMode = QueryHelper.GetBoolean("dialog", false);

                int hideBreadcrumbs = QueryHelper.GetInteger("hidebreadcrumbs", 0);

                // Show breadcrumbs if not dialog mode or dialog mode is in product option UI
                if ((hideBreadcrumbs != 0) || dialogMode)
                {
                    generateBreadcrumbs = false;
                }
            }
        }

        if (generateBreadcrumbs)
        {
            ProductUIHelper.EnsureProductBreadcrumbs(page.PageBreadcrumbs, breadcrumbName, (ProductID <= 0), ProductListInTree);
        }

        Control.Page.Load += Page_Load;

        Control.ElementName = (optionCategoryId > 0) ? "ProductOptions.Options" : "Products.Properties";
    }