protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        // Check 'Manage servers' permission
        if (!CurrentUser.IsAuthorizedPerResource("cms.staging", "ManageDocumentsTasks"))
        {
            RedirectToAccessDenied("cms.staging", "ManageDocumentsTasks");
        }

        CurrentMaster.DisplaySiteSelectorPanel = true;

        // Check enabled servers
        var isCallback = RequestHelper.IsCallback();

        if (!isCallback && !ServerInfoProvider.IsEnabledServer(SiteContext.CurrentSiteID))
        {
            ShowInformation(GetString("ObjectStaging.NoEnabledServer"));
            CurrentMaster.PanelHeader.Visible = false;
            plcContent.Visible = false;
            pnlFooter.Visible  = false;
            return;
        }

        // Setup server dropdown
        selectorElem.DropDownList.AutoPostBack       = true;
        selectorElem.UniSelector.OnSelectionChanged += UniSelector_OnSelectionChanged;

        // Set server ID
        SelectedServerID = ValidationHelper.GetInteger(selectorElem.Value, QueryHelper.GetInteger("serverId", 0));

        // All servers
        if (SelectedServerID == UniSelector.US_ALL_RECORDS)
        {
            SelectedServerID   = 0;
            selectorElem.Value = UniSelector.US_ALL_RECORDS;
        }
        else
        {
            selectorElem.Value = SelectedServerID.ToString();
        }

        ltlScript.Text += ScriptHelper.GetScript("var currentServerId = " + SelectedServerID + ";");

        // Register script for pendingCallbacks repair
        ScriptHelper.FixPendingCallbacks(Page);

        HeaderActions.ActionPerformed += HeaderActions_ActionPerformed;

        if (!isCallback)
        {
            int nodeId = QueryHelper.GetInteger("stagingnodeid", 0);

            aliasPath = "/";

            // Get the document node
            if (nodeId > 0)
            {
                TreeProvider tree = new TreeProvider(CurrentUser);
                TreeNode     node = tree.SelectSingleNode(nodeId, TreeProvider.ALL_CULTURES);
                if (node != null)
                {
                    aliasPath = node.NodeAliasPath;
                }
            }

            // Setup title
            ucDisabledModule.TestSettingKeys = "CMSStagingLogChanges";
            ucDisabledModule.InfoText        = GetString("ContentStaging.TaskSeparator");
            ucDisabledModule.ParentPanel     = pnlNotLogged;

            // Check logging
            if (!ucDisabledModule.Check())
            {
                CurrentMaster.PanelHeader.Visible = false;
                plcContent.Visible = false;
                pnlFooter.Visible  = false;
                return;
            }

            // Create header actions
            HeaderActions.AddAction(new HeaderAction
            {
                Text      = GetString("Tasks.SyncCurrent"),
                EventName = SYNCHRONIZE_CURRENT
            });

            HeaderActions.AddAction(new HeaderAction
            {
                Text        = GetString("Tasks.SyncSubtree"),
                EventName   = SYNCHRONIZE_SUBTREE,
                ButtonStyle = ButtonStyle.Default
            });

            // Create header action
            HeaderActions.AddAction(new HeaderAction
            {
                Text        = GetString("Tasks.CompleteSync"),
                EventName   = SYNCHRONIZE_COMPLETE,
                ButtonStyle = ButtonStyle.Default
            });

            // Add CSS class to panels wrapper in order it could be stacked
            CurrentMaster.PanelHeader.AddCssClass("header-container-multiple-panels");

            if (!ControlsHelper.CausedPostBack(HeaderActions, btnSyncSelected, btnSyncAll))
            {
                // Check 'Manage servers' permission
                if (!CurrentUser.IsAuthorizedPerResource("cms.staging", "ManageDocumentsTasks"))
                {
                    RedirectToAccessDenied("cms.staging", "ManageDocumentsTasks");
                }

                // Register the dialog script
                ScriptHelper.RegisterDialogScript(this);

                ltlScript.Text +=
                    ScriptHelper.GetScript("function ConfirmDeleteTask(taskId) { return confirm(" +
                                           ScriptHelper.GetString(GetString("Tasks.ConfirmDelete")) + "); }");
                ltlScript.Text +=
                    ScriptHelper.GetScript("function CompleteSync(){" +
                                           Page.ClientScript.GetPostBackEventReference(btnSyncComplete, "") + "}");

                // Initialize grid
                tasksUniGrid.OnDataReload   += tasksUniGrid_OnDataReload;
                tasksUniGrid.ShowActionsMenu = true;
                tasksUniGrid.Columns         = "TaskID, TaskSiteID, TaskDocumentID, TaskNodeAliasPath, TaskTitle, TaskTime, TaskType, TaskObjectType, TaskObjectID, TaskRunning, (SELECT COUNT(*) FROM Staging_Synchronization WHERE SynchronizationTaskID = TaskID AND SynchronizationErrorMessage IS NOT NULL AND (SynchronizationServerID = @ServerID OR (@ServerID = 0 AND (@TaskSiteID = 0 OR SynchronizationServerID IN (SELECT ServerID FROM Staging_Server WHERE ServerSiteID = @TaskSiteID AND ServerEnabled=1))))) AS FailedCount";
                StagingTaskInfo ti = new StagingTaskInfo();
                tasksUniGrid.AllColumns = SqlHelper.MergeColumns(ti.ColumnNames);

                plcContent.Visible = true;

                // Initialize buttons
                btnSyncSelected.OnClientClick   = "return !" + tasksUniGrid.GetCheckSelectionScript();
                btnDeleteAll.OnClientClick      = "return confirm(" + ScriptHelper.GetString(GetString("Tasks.ConfirmDeleteAll")) + ");";
                btnDeleteSelected.OnClientClick = "return confirm(" + ScriptHelper.GetString(GetString("general.confirmdelete")) + ");";

                pnlLog.Visible     = false;
                TaskTypeCategories = TaskHelper.TASK_TYPE_CATEGORY_CONTENT + ";" + TaskHelper.TASK_TYPE_CATEGORY_GENERAL;
            }
        }


        var script = @"var currentNodeId = 0,
selectDocuments = false;

function ChangeServer(value) {
    currentServerId = value;
}

function SelectNode(serverId, nodeId) {
    currentServerId = serverId;
    currentNodeId = nodeId;
    document.location = 'Tasks.aspx?serverId=' + currentServerId + '&stagingnodeid=' + nodeId;
}

function SelectDocNode(serverId, nodeId) {
    currentNodeId = nodeId;
    document.location = 'DocumentsList.aspx?serverId=' + currentServerId + '&stagingnodeid=' + nodeId;
}";

        ScriptHelper.RegisterClientScriptBlock(Page, typeof(string), ClientID + "HandlingTasks", ScriptHelper.GetScript(script));
    }
Пример #2
0
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        // Check 'Manage objects tasks' permission
        if (!CurrentUser.IsAuthorizedPerResource("cms.staging", "ManageObjectsTasks"))
        {
            RedirectToAccessDenied("cms.staging", "ManageObjectsTasks");
        }

        CurrentMaster.DisplaySiteSelectorPanel = true;

        // Check enabled servers
        var isCallback = RequestHelper.IsCallback();

        if (!isCallback && !ServerInfoProvider.IsEnabledServer(SiteContext.CurrentSiteID))
        {
            ShowInformation(GetString("ObjectStaging.NoEnabledServer"));
            CurrentMaster.PanelHeader.Visible = false;
            plcContent.Visible = false;
            pnlFooter.Visible  = false;
            return;
        }

        // Register script for pendingCallbacks repair
        ScriptHelper.FixPendingCallbacks(Page);

        // Setup server dropdown
        selectorElem.DropDownList.AutoPostBack       = true;
        selectorElem.UniSelector.OnSelectionChanged += UniSelector_OnSelectionChanged;

        // Set server ID
        SelectedServerID = ValidationHelper.GetInteger(selectorElem.Value, QueryHelper.GetInteger("serverId", 0));

        // All servers
        if (SelectedServerID == UniSelector.US_ALL_RECORDS)
        {
            SelectedServerID   = 0;
            selectorElem.Value = UniSelector.US_ALL_RECORDS;
        }
        else
        {
            selectorElem.Value = SelectedServerID.ToString();
        }

        ltlScript.Text += ScriptHelper.GetScript("var currentServerId = " + SelectedServerID + ";");

        HeaderActions.ActionPerformed += HeaderActions_ActionPerformed;

        if (!isCallback)
        {
            // Check 'Manage object tasks' permission
            if (!CurrentUser.IsAuthorizedPerResource("cms.staging", "ManageObjectsTasks"))
            {
                RedirectToAccessDenied("cms.staging", "ManageObjectsTasks");
            }

            synchronizedSiteId = QueryHelper.GetInteger("siteid", 0);
            CurrentSiteID      = SiteContext.CurrentSiteID;

            ucDisabledModule.TestSettingKeys = "CMSStagingLogObjectChanges";
            ucDisabledModule.ParentPanel     = pnlNotLogged;

            if (synchronizedSiteId == -1)
            {
                ucDisabledModule.InfoText         = GetString("objectstaging.globalandsitenotlogged");
                ucDisabledModule.KeyScope         = DisabledModuleScope.CurrentSiteAndGlobal;
                ucDisabledModule.GlobalButtonText = GetString("objectstaging.enableglobalandsiteobjects");
            }
            else if (synchronizedSiteId == 0)
            {
                ucDisabledModule.InfoText         = GetString("objectstaging.globalnotlogged");
                ucDisabledModule.KeyScope         = DisabledModuleScope.Global;
                ucDisabledModule.GlobalButtonText = GetString("objectstaging.enableglobalobjects");
            }
            else
            {
                ucDisabledModule.InfoText       = GetString("ObjectStaging.SiteNotLogged");
                ucDisabledModule.KeyScope       = DisabledModuleScope.Site;
                ucDisabledModule.SiteButtonText = GetString("objectstaging.enablesiteobjects");
            }

            // Check logging
            if (!ucDisabledModule.Check())
            {
                CurrentMaster.PanelHeader.Visible = false;
                plcContent.Visible = false;
                return;
            }

            // Get object type
            objectType = QueryHelper.GetString("objecttype", string.Empty);

            // Create "synchronize current" header action for tree root, nodes or objects with database representation
            if (String.IsNullOrEmpty(objectType) || objectType.StartsWith("##", StringComparison.Ordinal) || (ModuleManager.GetReadOnlyObject(objectType) != null))
            {
                HeaderActions.AddAction(new HeaderAction
                {
                    Text      = GetString("ObjectTasks.SyncCurrent"),
                    EventName = SYNCHRONIZE_CURRENT
                });
            }

            // Add CSS class to panels wrapper in order it could be stacked
            CurrentMaster.PanelHeader.AddCssClass("header-container-multiple-panels");

            // Setup title
            ctlAsyncLog.TitleText = GetString("Synchronization.Title");

            // Get the selected types
            ObjectTypeTreeNode selectedNode = StagingTaskInfoProvider.ObjectTree.FindNode(objectType, (synchronizedSiteId > 0));
            objectType = (selectedNode != null) ? selectedNode.GetObjectTypes(true) : string.Empty;
            if (!ControlsHelper.CausedPostBack(HeaderActions, btnSyncSelected, btnSyncAll))
            {
                // Register the dialog script
                ScriptHelper.RegisterDialogScript(this);

                plcContent.Visible = true;

                // Initialize buttons
                btnDeleteAll.OnClientClick      = "return confirm(" + ScriptHelper.GetString(GetString("Tasks.ConfirmDeleteAll")) + ");";
                btnDeleteSelected.OnClientClick = "return confirm(" + ScriptHelper.GetString(GetString("general.confirmdelete")) + ");";
                btnSyncSelected.OnClientClick   = "return !" + gridTasks.GetCheckSelectionScript();

                // Initialize grid
                gridTasks.ZeroRowsText    = GetString("Tasks.NoTasks");
                gridTasks.OnDataReload   += gridTasks_OnDataReload;
                gridTasks.ShowActionsMenu = true;
                gridTasks.Columns         = "TaskID, TaskSiteID, TaskDocumentID, TaskNodeAliasPath, TaskTitle, TaskTime, TaskType, TaskObjectType, TaskObjectID, TaskRunning, (SELECT COUNT(*) FROM Staging_Synchronization WHERE SynchronizationTaskID = TaskID AND SynchronizationErrorMessage IS NOT NULL AND (SynchronizationServerID = @ServerID OR (@ServerID = 0 AND (@TaskSiteID = 0 OR SynchronizationServerID IN (SELECT ServerID FROM Staging_Server WHERE ServerSiteID = @TaskSiteID AND ServerEnabled=1))))) AS FailedCount";
                StagingTaskInfo ti = new StagingTaskInfo();
                gridTasks.AllColumns = SqlHelper.MergeColumns(ti.ColumnNames);

                pnlLog.Visible     = false;
                TaskTypeCategories = TaskHelper.TASK_TYPE_CATEGORY_GENERAL + ";" + TaskHelper.TASK_TYPE_CATEGORY_OBJECTS + ";" + TaskHelper.TASK_TYPE_CATEGORY_DATA;
            }
        }
    }