Exemple #1
0
    /// <summary>
    /// UniGrid action buttons event handler.
    /// </summary>
    protected void gridAttachments_OnAction(string actionName, object actionArgument)
    {
        if (Enabled && !HideActions)
        {
            // Check the permissions
            #region "Check permissions"

            if (CheckPermissions)
            {
                if (FormGUID != Guid.Empty)
                {
                    if (!RaiseOnCheckPermissions("Create", this))
                    {
                        if (!CMSContext.CurrentUser.IsAuthorizedToCreateNewDocument(NodeParentNodeID, NodeClassName))
                        {
                            lblError.Text = GetString("attach.actiondenied");
                            return;
                        }
                    }
                }
                else
                {
                    if (!RaiseOnCheckPermissions("Modify", this))
                    {
                        if (CMSContext.CurrentUser.IsAuthorizedPerDocument(Node, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied)
                        {
                            lblError.Text = GetString("attach.actiondenied");
                            return;
                        }
                    }
                }
            }

            #endregion

            Guid attachmentGuid = Guid.Empty;

            // Get action argument (Guid or int)
            if (ValidationHelper.IsGuid(actionArgument))
            {
                attachmentGuid = ValidationHelper.GetGuid(actionArgument, Guid.Empty);
            }

            // Process proper action
            switch (actionName.ToLower())
            {
            case "moveup":
                if (attachmentGuid != Guid.Empty)
                {
                    // Move attachment up
                    if (FormGUID == Guid.Empty)
                    {
                        // Ensure automatic check-in/ check-out
                        VersionManager vm = null;

                        // Check out the document
                        if (AutoCheck)
                        {
                            vm = new VersionManager(TreeProvider);
                            vm.CheckOut(Node, Node.IsPublished, true);
                        }

                        DocumentHelper.MoveAttachmentUp(attachmentGuid, Node);

                        // Check in the document
                        if (AutoCheck)
                        {
                            if (vm != null)
                            {
                                vm.CheckIn(Node, null, null);
                                VersionHistoryID = Node.DocumentCheckedOutVersionHistoryID;
                            }

                            // Ensure full page refresh
                            ScriptHelper.RegisterStartupScript(Page, typeof(Page), "moveUpRefresh", ScriptHelper.GetScript(String.Format("InitRefresh_{0}('', true, false, 'moveup');", ClientID)));
                        }

                        // Log synchronization task if not under workflow
                        if (!UsesWorkflow)
                        {
                            DocumentSynchronizationHelper.LogDocumentChange(Node, TaskTypeEnum.UpdateDocument, TreeProvider);
                        }
                    }
                    else
                    {
                        AttachmentManager.MoveAttachmentUp(attachmentGuid, 0);
                    }
                }
                break;

            case "movedown":
                if (attachmentGuid != Guid.Empty)
                {
                    // Move attachment down
                    if (FormGUID == Guid.Empty)
                    {
                        // Ensure automatic check-in/ check-out
                        VersionManager vm = null;

                        // Check out the document
                        if (AutoCheck)
                        {
                            vm = new VersionManager(TreeProvider);
                            vm.CheckOut(Node, Node.IsPublished, true);
                        }

                        DocumentHelper.MoveAttachmentDown(attachmentGuid, Node);

                        // Check in the document
                        if (AutoCheck)
                        {
                            if (vm != null)
                            {
                                vm.CheckIn(Node, null, null);
                                VersionHistoryID = Node.DocumentCheckedOutVersionHistoryID;
                            }

                            // Ensure full page refresh
                            ScriptHelper.RegisterStartupScript(Page, typeof(Page), "moveDownRefresh", ScriptHelper.GetScript(String.Format("InitRefresh_{0}('', true, false, 'movedown');", ClientID)));
                        }

                        // Log synchronization task if not under workflow
                        if (!UsesWorkflow)
                        {
                            DocumentSynchronizationHelper.LogDocumentChange(Node, TaskTypeEnum.UpdateDocument, TreeProvider);
                        }
                    }
                    else
                    {
                        AttachmentManager.MoveAttachmentDown(attachmentGuid, 0);
                    }
                }
                break;

            case "delete":
                if (attachmentGuid != Guid.Empty)
                {
                    // Delete attachment
                    if (FormGUID == Guid.Empty)
                    {
                        // Ensure automatic check-in/ check-out
                        VersionManager vm = null;

                        // Check out the document
                        if (AutoCheck)
                        {
                            vm = new VersionManager(TreeProvider);
                            vm.CheckOut(Node, Node.IsPublished, true);
                        }

                        DocumentHelper.DeleteAttachment(Node, attachmentGuid, TreeProvider);

                        // Check in the document
                        if (AutoCheck)
                        {
                            if (vm != null)
                            {
                                vm.CheckIn(Node, null, null);
                                VersionHistoryID = Node.DocumentCheckedOutVersionHistoryID;
                            }

                            // Ensure full page refresh
                            ScriptHelper.RegisterStartupScript(Page, typeof(Page), "deleteRefresh", ScriptHelper.GetScript(String.Format("InitRefresh_{0}('', true, false, 'delete');", ClientID)));
                        }

                        // Log synchronization task if not under workflow
                        if (!UsesWorkflow)
                        {
                            DocumentSynchronizationHelper.LogDocumentChange(Node, TaskTypeEnum.UpdateDocument, TreeProvider);
                        }
                    }
                    else
                    {
                        AttachmentManager.DeleteTemporaryAttachment(attachmentGuid, CMSContext.CurrentSiteName);
                    }

                    lblInfo.Text = GetString("attach.deleted");
                }
                break;
            }
        }
    }
Exemple #2
0
    /// <summary>
    /// UniGrid action buttons event handler.
    /// </summary>
    protected void GridAttachmentsOnAction(string actionName, object actionArgument)
    {
        if (Enabled && !HideActions)
        {
            // Check the permissions
            #region "Check permissions"

            if (CheckPermissions)
            {
                if (FormGUID != Guid.Empty)
                {
                    if (!RaiseOnCheckPermissions("Create", this))
                    {
                        if (!CMSContext.CurrentUser.IsAuthorizedToCreateNewDocument(NodeParentNodeID, NodeClassName))
                        {
                            lblError.Text = GetString("attach.actiondenied");
                            return;
                        }
                    }
                }
                else
                {
                    if (!RaiseOnCheckPermissions("Modify", this))
                    {
                        if (CMSContext.CurrentUser.IsAuthorizedPerDocument(Node, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied)
                        {
                            lblError.Text = GetString("attach.actiondenied");
                            return;
                        }
                    }
                }
            }

            #endregion

            Guid attachmentGuid = Guid.Empty;

            // Get action argument (Guid or int)
            if (ValidationHelper.IsGuid(actionArgument))
            {
                attachmentGuid = ValidationHelper.GetGuid(actionArgument, Guid.Empty);
            }

            // Process proper action
            switch (actionName.ToLower())
            {
            case "delete":
                if (!createTempAttachment)
                {
                    if (attachmentGuid != Guid.Empty)
                    {
                        // Delete attachment
                        if (FormGUID == Guid.Empty)
                        {
                            // Ensure automatic check-in/ check-out
                            VersionManager vm = null;

                            // Check out the document
                            if (AutoCheck)
                            {
                                vm = new VersionManager(TreeProvider);
                                vm.CheckOut(Node, Node.IsPublished, true);
                            }

                            // If the GUID column is set, use it to process additional actions for field attachments
                            if (GUIDColumnName != null)
                            {
                                DocumentHelper.DeleteAttachment(Node, GUIDColumnName, TreeProvider);
                            }
                            else
                            {
                                DocumentHelper.DeleteAttachment(Node, attachmentGuid, TreeProvider);
                            }
                            DocumentHelper.UpdateDocument(Node, TreeProvider);

                            // Ensure full page refresh
                            if (AutoCheck)
                            {
                                ScriptHelper.RegisterStartupScript(Page, typeof(Page), "deleteRefresh", ScriptHelper.GetScript("InitRefresh_" + ClientID + "('', true, true, '" + attachmentGuid + "', 'delete');"));
                            }
                            else
                            {
                                string script = "if (window.RefreshTree) { RefreshTree(" + ActualNode.NodeParentID + ", " + ActualNode.NodeID + "); }";
                                ScriptHelper.RegisterStartupScript(Page, typeof(Page), "refreshTree", ScriptHelper.GetScript(script));
                            }

                            // Check in the document
                            if (AutoCheck)
                            {
                                if (vm != null)
                                {
                                    vm.CheckIn(Node, null, null);
                                    VersionHistoryID = Node.DocumentCheckedOutVersionHistoryID;
                                }
                            }

                            // Log synchronization task if not under workflow
                            if (!UsesWorkflow)
                            {
                                DocumentSynchronizationHelper.LogDocumentChange(Node, TaskTypeEnum.UpdateDocument, TreeProvider);
                            }
                        }
                        else
                        {
                            AttachmentManager.DeleteTemporaryAttachment(attachmentGuid, CMSContext.CurrentSiteName);
                        }
                    }
                }

                LastAction = "delete";
                Value      = Guid.Empty;
                break;
            }

            // Force reload data
            ReloadData(true);
        }
    }