예제 #1
0
        /// <summary>Renders the panel.</summary>
        /// <param name="output">The output.</param>
        /// <param name="ribbon">The ribbon.</param>
        /// <param name="button">The button.</param>
        /// <param name="context">The context.</param>
        public override void Render(HtmlTextWriter output, Ribbon ribbon, Item button, CommandContext context)
        {
            Assert.ArgumentNotNull((object)output, "output");
            Assert.ArgumentNotNull((object)ribbon, "ribbon");
            Assert.ArgumentNotNull((object)button, "button");
            Assert.ArgumentNotNull((object)context, "context");
            if (context.Items.Length < 1)
            {
                return;
            }
            Item obj = context.Items[0];

            if (!this.HasField(obj, FieldIDs.Workflow) || !Settings.Workflows.Enabled)
            {
                return;
            }
            IWorkflow workflow;

            WorkflowCommand[] commands;
            GetCommands(context.Items, out workflow, out commands);
            bool flag1 = this.IsCommandEnabled("item:checkout", obj);
            bool flag2 = CanShowCommands(obj, commands);
            bool flag3 = this.IsCommandEnabled("item:checkin", obj);

            this.RenderText(output, GetText(context.Items));
            if (workflow == null && !flag1 && (!flag2 && !flag3))
            {
                return;
            }



            Context.ClientPage.ClientResponse.DisableOutput();
            ribbon.BeginSmallButtons(output);
            if (flag1)
            {
                this.RenderSmallButton(output, ribbon, string.Empty, Translate.Text("Edit"), "Office/24x24/edit_in_workflow.png", Translate.Text("Start editing this item."), "item:checkout", this.Enabled, false);
            }
            if (flag3)
            {
                Item checkInItem = this.GetCheckInItem();
                if (checkInItem != null)
                {
                    this.RenderSmallButton(output, ribbon, string.Empty, checkInItem["Phrase"], checkInItem.Appearance.Icon, Translate.Text("Check this item in."), "item:checkin(id=" + (object)obj.ID + ",language=" + obj.Language.Name + ",version=" + (object)obj.Version + ")", (this.Enabled ? 1 : 0) != 0, 0 != 0);
                }
            }
            if (workflow != null)
            {
                this.RenderSmallButton(output, ribbon, Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("B"), Translate.Text("History"), "Office/16x16/history.png", Translate.Text("Show the workflow history."), "item:workflowhistory", this.Enabled, false);
            }
            if (flag2)
            {
                var repository = new WorxboxItemsRepository(workflow);

                foreach (WorkflowCommand command in commands)
                {
                    this.RenderSmallButton(output, ribbon, string.Empty, command.DisplayName, command.Icon, command.DisplayName,
                                           new WorkflowCommandBuilder(obj, workflow, command).ToString(),
                                           this.Enabled,
                                           false);

                    if (repository.IsWorxboxItem(obj.State.GetWorkflowState(), new DataUri(obj.Uri)) &&
                        repository.GetWorkflowCommandIDs().Contains(ID.Parse(command.CommandID)))
                    {
                        this.RenderSmallButton(output, ribbon, string.Empty, "WorxBox " + command.DisplayName, command.Icon, command.DisplayName,
                                               new WorxBoxWorkflowCommandBuilder(obj, workflow, command).ToString(),
                                               this.Enabled,
                                               false);
                    }
                }
            }
            ribbon.EndSmallButtons(output);
            Context.ClientPage.ClientResponse.EnableOutput();
        }
        /// <summary>Renders the panel.</summary>
        /// <param name="output">The output.</param>
        /// <param name="ribbon">The ribbon.</param>
        /// <param name="button">The button.</param>
        /// <param name="context">The context.</param>
        public override void Render(HtmlTextWriter output, Ribbon ribbon, Item button, CommandContext context)
        {
            Assert.ArgumentNotNull((object)output, nameof(output));
            Assert.ArgumentNotNull((object)ribbon, nameof(ribbon));
            Assert.ArgumentNotNull((object)button, nameof(button));
            Assert.ArgumentNotNull((object)context, nameof(context));
            if (context.Items.Length < 1)
            {
                return;
            }
            Item obj = context.Items[0];

            if (!this.HasField(obj, FieldIDs.Workflow) || !Settings.Workflows.Enabled)
            {
                return;
            }
            IWorkflow workflow;

            WorkflowCommand[] commands;
            ExtendedWorkflowPanel.GetCommands(context.Items, out workflow, out commands);
            bool flag1 = this.IsCommandEnabled("item:checkout", obj);
            bool flag2 = ExtendedWorkflowPanel.CanShowCommands(obj, commands);
            bool flag3 = this.IsCommandEnabled("item:checkin", obj);
            //Add call to Utilities.canUserRunCommandsWithoutLocking() to validate user against custom criteria. If method returns true, this flag4 will be set
            //to true and the workflow commands will be clickable even if item is not locked by user
            bool flag4 = Context.User.IsAdministrator || obj.Locking.HasLock() || !Settings.RequireLockBeforeEditing ||
                         Utilities.canUserRunCommandsWithoutLocking();

            this.RenderText(output, ExtendedWorkflowPanel.GetText(context.Items));
            if (!(workflow != null | flag1 | flag2 | flag3))
            {
                return;
            }
            Context.ClientPage.ClientResponse.DisableOutput();
            ribbon.BeginSmallButtons(output);
            if (flag1)
            {
                this.RenderSmallButton(output, ribbon, string.Empty, Translate.Text("Edit"), "Office/24x24/edit_in_workflow.png", Translate.Text("Start editing this item."), "item:checkout", this.Enabled, false);
            }
            if (flag3)
            {
                Item checkInItem = this.GetCheckInItem();
                if (checkInItem != null)
                {
                    this.RenderSmallButton(output, ribbon, string.Empty, checkInItem["Header"], checkInItem["Icon"], Translate.Text("Check this item in."), "item:checkin", this.Enabled, false);
                }
            }
            if (workflow != null)
            {
                this.RenderSmallButton(output, ribbon, Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("B"), Translate.Text("History"), "Office/16x16/history.png", Translate.Text("Show the workflow history."), "item:workflowhistory", this.Enabled, false);
            }
            if (flag2)
            {
                foreach (WorkflowCommand command in commands)
                {
                    this.RenderSmallButton(output, ribbon, string.Empty, command.DisplayName, command.Icon, command.DisplayName, new WorkflowCommandBuilder(obj, workflow, command).ToString(), this.Enabled & flag4, false);
                }
            }
            ribbon.EndSmallButtons(output);
            Context.ClientPage.ClientResponse.EnableOutput();
        }