Ejemplo n.º 1
0
        public override void Process(GetPageEditorNotificationsArgs arguments)
        {
            Assert.ArgumentNotNull((object)arguments, "arguments");
            var contextItem      = arguments.ContextItem;
            var database         = contextItem.Database;
            var workflowProvider = database.WorkflowProvider;

            if (workflowProvider == null)
            {
                return;
            }
            var workflow = workflowProvider.GetWorkflow(contextItem);

            if (workflow == null)
            {
                return;
            }
            WorkflowState state = workflow.GetState(contextItem);

            if (state == null)
            {
                return;
            }

            var repository = new WorxboxItemsRepository(workflow);

            var worxBoxIcon = "/~/icon/worxbox/32x32/worxbox.png";
            var displayIcon =
                $"<span><img src='{worxBoxIcon}'  style='vertical-align:middle; padding-right: 1px;'/></span>";

            using (new LanguageSwitcher(WebUtility.ClientLanguage))
            {
                string description        = GetDescription(workflow, state, database);
                string icon               = state.Icon;
                var    editorNotification = new PageEditorNotification(description, PageEditorNotificationType.Information)
                {
                    Icon = icon
                };
                var commands = WorkflowFilterer.FilterVisibleCommands(workflow.GetCommands(contextItem), contextItem);
                if (CanShowCommands(contextItem, commands))
                {
                    foreach (WorkflowCommand command in commands)
                    {
                        var notificationOption = new PageEditorNotificationOption(command.DisplayName, new WorkflowCommandBuilder(contextItem, workflow, command).ToString());
                        editorNotification.Options.Add(notificationOption);
                    }
                    editorNotification.Options.Add(new PageEditorNotificationOption("|", ""));
                    foreach (WorkflowCommand command in commands)
                    {
                        if (repository.IsWorxboxItem(state, new DataUri(contextItem.Uri)) &&
                            repository.GetWorkflowCommandIDs().Contains(ID.Parse(command.CommandID)))
                        {
                            var notificationOption = new PageEditorNotificationOption(displayIcon + command.DisplayName, new WorxBoxWorkflowCommandBuilder(contextItem, workflow, command).ToString());
                            editorNotification.Options.Add(notificationOption);
                        }
                    }
                }
                arguments.Notifications.Add(editorNotification);
            }
        }
 protected virtual void DisplayStates(IWorkflow workflow, XmlControl placeholder)
 {
     this._stateNames = null;
     foreach (WorkflowState state in workflow.GetStates())
     {
         if (WorkflowFilterer.FilterVisibleCommands(workflow.GetCommands(state.StateID)).Length > 0)
         {
             string    str2;
             DataUri[] items    = this.GetItems(state, workflow);
             string    str      = ShortID.Encode(workflow.WorkflowID) + "_" + ShortID.Encode(state.StateID);
             Section   section2 = new Section
             {
                 ID = str + "_section"
             };
             Section control = section2;
             control.Attributes["Width"] = "100%";
             placeholder.AddControl(control);
             int length = items.Length;
             if (length <= 0)
             {
                 str2 = Translate.Text("None");
             }
             else if (length == 1)
             {
                 str2 = string.Format("1 {0}", Translate.Text("item"));
             }
             else
             {
                 str2 = string.Format("{0} {1}", length, Translate.Text("items"));
             }
             str2           = string.Format("<span style=\"font-weight:normal\"> - ({0})</span>", str2);
             control.Header = state.DisplayName + str2;
             control.Icon   = state.Icon;
             if (Settings.ClientFeeds.Enabled)
             {
                 FeedUrlOptions options2 = new FeedUrlOptions("/sitecore/shell/~/feed/workflowstate.aspx")
                 {
                     UseUrlAuthentication = true
                 };
                 FeedUrlOptions options = options2;
                 options.Parameters["wf"] = workflow.WorkflowID;
                 options.Parameters["st"] = state.StateID;
                 control.FeedLink         = options.ToString();
             }
             control.Collapsed = length <= 0;
             Border child = new Border();
             control.Controls.Add(child);
             child.ID = str + "_content";
             this.DisplayState(workflow, state, items, child, 0, this.PageSize);
             this.CreateNavigator(control, str + "_navigator", length);
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>Executes the command in the specified context.</summary>
        /// <param name="context">The context.</param>
        public override void Execute(CommandContext context)
        {
            Assert.ArgumentNotNull((object)context, "context");
            string   name1    = context.Parameters["database"];
            string   path     = context.Parameters["id"];
            string   name2    = context.Parameters["language"];
            string   str      = context.Parameters["version"];
            Database database = Factory.GetDatabase(name1);

            if (database == null)
            {
                return;
            }
            Item obj = database.GetItem(path, Language.Parse(name2), Sitecore.Data.Version.Parse(str));

            if (obj == null)
            {
                return;
            }
            IWorkflow workflow = obj.Database.WorkflowProvider.GetWorkflow(obj);

            if (workflow == null)
            {
                return;
            }
            WorkflowCommand[] workflowCommandArray = WorkflowFilterer.FilterVisibleCommands(workflow.GetCommands(obj), obj);

            var repository = new WorxboxItemsRepository(workflow);

            if (workflowCommandArray == null || workflowCommandArray.Length == 0)
            {
                return;
            }
            Menu menu = new Menu();

            SheerResponse.DisableOutput();
            foreach (WorkflowCommand command in workflowCommandArray)
            {
                string @string = new WorkflowCommandBuilder(obj, workflow, command).ToString();
                menu.Add("C" + command.CommandID, command.DisplayName, command.Icon, string.Empty, @string, false, string.Empty, MenuItemType.Normal).Disabled =
                    !Context.User.IsAdministrator && !obj.Locking.HasLock();

                if (repository.IsWorxboxItem(obj.State.GetWorkflowState(), new DataUri(obj.Uri)) &&
                    repository.GetWorkflowCommandIDs().Contains(ID.Parse(command.CommandID)))
                {
                    @string = new WorxBoxWorkflowCommandBuilder(obj, workflow, command).ToString();
                    menu.Add("C" + command.CommandID, "WorxBox " + command.DisplayName, command.Icon, string.Empty, @string, false, string.Empty, MenuItemType.Normal).Disabled =
                        !Context.User.IsAdministrator && !obj.Locking.HasLock();
                }
            }
            SheerResponse.EnableOutput();
            SheerResponse.ShowContextMenu(Context.ClientPage.ClientRequest.Control, "right", (Control)menu);
        }
Ejemplo n.º 4
0
        /// <summary>Gets the icon.</summary>
        /// <param name="item">The item.</param>
        /// <returns>The icon.</returns>
        protected override GutterIconDescriptor GetIconDescriptor(Item item)
        {
            Assert.ArgumentNotNull((object)item, nameof(item));
            string str1 = item[FieldIDs.Workflow];
            string str2 = item[FieldIDs.WorkflowState];

            if (!Settings.Workflows.Enabled || !item.Access.CanWrite())
            {
                return((GutterIconDescriptor)null);
            }
            if (string.IsNullOrEmpty(str1) || string.IsNullOrEmpty(str2))
            {
                return((GutterIconDescriptor)null);
            }
            IWorkflowProvider workflowProvider = item.Database.WorkflowProvider;

            if (workflowProvider == null)
            {
                return((GutterIconDescriptor)null);
            }
            IWorkflow workflow = workflowProvider.GetWorkflow(item);

            if (workflow == null)
            {
                return((GutterIconDescriptor)null);
            }
            Sitecore.Workflows.WorkflowState state = workflow.GetState(item);
            if (state == null)
            {
                return((GutterIconDescriptor)null);
            }
            if (state.FinalState)
            {
                return((GutterIconDescriptor)null);
            }
            GutterIconDescriptor gutterIconDescriptor = new GutterIconDescriptor();

            gutterIconDescriptor.Icon    = state.Icon;
            gutterIconDescriptor.Tooltip = state.DisplayName;
            WorkflowCommand[] workflowCommandArray = WorkflowFilterer.FilterVisibleCommands(workflow.GetCommands(item), item);
            if (workflowCommandArray != null && workflowCommandArray.Length != 0)
            {
                //Modify the event subscribed to the gutterIconDescriptor to call custom command, found at ExtendedShowWorkflowCommands.cs
                gutterIconDescriptor.Click = "ss:extendedshowworkflowcommands(id=" + (object)item.ID + ",language=" + (object)item.Language + ",version=" + (object)item.Version + ",database=" + item.Database.Name + ")";
            }
            return(gutterIconDescriptor);
        }
Ejemplo n.º 5
0
        /// <summary>Executes the command in the specified context.</summary>
        /// <param name="context">The context.</param>
        public override void Execute(CommandContext context)
        {
            Assert.ArgumentNotNull((object)context, nameof(context));
            string   parameter1 = context.Parameters["database"];
            string   parameter2 = context.Parameters["id"];
            string   parameter3 = context.Parameters["language"];
            string   parameter4 = context.Parameters["version"];
            Database database   = Factory.GetDatabase(parameter1);

            if (database == null)
            {
                return;
            }
            Item obj = database.GetItem(parameter2, Language.Parse(parameter3), Sitecore.Data.Version.Parse(parameter4));

            if (obj == null)
            {
                return;
            }
            IWorkflow workflow = obj.Database.WorkflowProvider.GetWorkflow(obj);

            if (workflow == null)
            {
                return;
            }
            WorkflowCommand[] workflowCommandArray = WorkflowFilterer.FilterVisibleCommands(workflow.GetCommands(obj), obj);
            if (workflowCommandArray == null || workflowCommandArray.Length == 0)
            {
                return;
            }
            Menu menu = new Menu();

            SheerResponse.DisableOutput();
            foreach (WorkflowCommand command in workflowCommandArray)
            {
                string click = new WorkflowCommandBuilder(obj, workflow, command).ToString();
                //Add new logical condition to call canUserRunCommandsWithoutEdit() in Utilities class to check if user has permissions to execute
                //workflow commands without locking. The rest of the conditions are same as in default class
                menu.Add("C" + command.CommandID, command.DisplayName, command.Icon, string.Empty, click, false, string.Empty, MenuItemType.Normal).Disabled
                    = !Utilities.canUserRunCommandsWithoutLocking() && !Context.User.IsAdministrator && !obj.Locking.HasLock() && Settings.RequireLockBeforeEditing;
            }
            SheerResponse.EnableOutput();
            SheerResponse.ShowContextMenu(Context.ClientPage.ClientRequest.Control, "right", (Control)menu);
        }
 protected virtual void DisplayState(IWorkflow workflow, WorkflowState state, DataUri[] items, Control control, int offset, int pageSize)
 {
     if (items.Length > 0)
     {
         int length = offset + pageSize;
         if (length > items.Length)
         {
             length = items.Length;
         }
         for (int i = offset; i < length; i++)
         {
             DataUri uri  = items[i];
             Item    item = Context.ContentDatabase.Items[uri];
             if (item != null)
             {
                 this.CreateItem(workflow, item, control);
             }
         }
         Border child = new Border
         {
             Background = "#e9e9e9"
         };
         control.Controls.Add(child);
         child.Margin  = "0px 4px 0px 16px";
         child.Padding = "2px 8px 2px 8px";
         child.Border  = "1px solid #999999";
         foreach (WorkflowCommand command in WorkflowFilterer.FilterVisibleCommands(workflow.GetCommands(state.StateID)))
         {
             XmlControl webControl = Resource.GetWebControl("WorkboxCommand") as XmlControl;
             webControl["Header"]  = command.DisplayName + " " + Translate.Text("(selected)");
             webControl["Icon"]    = command.Icon;
             webControl["Command"] = "workflow:sendselected(command=" + command.CommandID + ",ws=" + state.StateID + ",wf=" + workflow.WorkflowID + ")";
             child.Controls.Add(webControl);
             webControl            = Resource.GetWebControl("WorkboxCommand") as XmlControl;
             webControl["Header"]  = command.DisplayName + " " + Translate.Text("(all)");
             webControl["Icon"]    = command.Icon;
             webControl["Command"] = "workflow:sendall(command=" + command.CommandID + ",ws=" + state.StateID + ",wf=" + workflow.WorkflowID + ")";
             child.Controls.Add(webControl);
         }
     }
 }
Ejemplo n.º 7
0
        /// <summary>Gets the commands.</summary>
        /// <param name="items">The items to get commands for.</param>
        /// <param name="workflow">The workflow.</param>
        /// <param name="commands">The commands.</param>
        private static void GetCommands(Item[] items, out IWorkflow workflow, out WorkflowCommand[] commands)
        {
            Assert.ArgumentNotNull((object)items, "items");
            Item obj = items[0];

            if (obj != null)
            {
                IWorkflowProvider workflowProvider = Context.ContentDatabase.WorkflowProvider;
                if (workflowProvider != null && workflowProvider.GetWorkflows().Length > 0)
                {
                    workflow = workflowProvider.GetWorkflow(obj);
                    if (workflow != null && workflow.GetState(obj) != null)
                    {
                        commands = WorkflowFilterer.FilterVisibleCommands(workflow.GetCommands(obj), obj);
                        return;
                    }
                }
            }
            workflow = (IWorkflow)null;
            commands = (WorkflowCommand[])null;
        }
        private void CreateItem(IWorkflow workflow, Item item, Control control)
        {
            XmlControl webControl = Resource.GetWebControl("WorkboxItem") as XmlControl;

            control.Controls.Add(webControl);
            StringBuilder builder  = new StringBuilder(" - (");
            Language      language = item.Language;

            builder.Append(language.CultureInfo.DisplayName);
            builder.Append(", ");
            builder.Append(Translate.Text("version"));
            builder.Append(' ');
            builder.Append(item.Version.ToString());
            builder.Append(")");
            Assert.IsNotNull(webControl, "workboxItem");
            webControl["Header"]           = item.DisplayName;
            webControl["Details"]          = builder.ToString();
            webControl["Icon"]             = item.Appearance.Icon;
            webControl["ShortDescription"] = item.Help.ToolTip;
            webControl["History"]          = this.GetHistory(workflow, item);
            webControl["HistoryMoreID"]    = Control.GetUniqueID("ctl");
            webControl["HistoryClick"]     = "workflow:showhistory(id=" + item.ID.ToString() + ",la=" + item.Language.Name + ",vs=" + item.Version.ToString() + ",wf=" + workflow.WorkflowID + ")";
            webControl["PreviewClick"]     = "Preview(\"" + item.ID.ToString() + "\", \"" + item.Language.ToString() + "\", \"" + item.Version.ToString() + "\")";
            webControl["Click"]            = "Open(\"" + item.ID.ToString() + "\", \"" + item.Language.ToString() + "\", \"" + item.Version.ToString() + "\")";
            webControl["DiffClick"]        = "Diff(\"" + item.ID.ToString() + "\", \"" + item.Language.ToString() + "\", \"" + item.Version.ToString() + "\")";
            webControl["Display"]          = "none";
            string uniqueID = Control.GetUniqueID(string.Empty);

            webControl["CheckID"]    = "check_" + uniqueID;
            webControl["HiddenID"]   = "hidden_" + uniqueID;
            webControl["CheckValue"] = string.Concat(new object[] { item.ID, ",", item.Language, ",", item.Version });
            foreach (WorkflowCommand command in WorkflowFilterer.FilterVisibleCommands(workflow.GetCommands(item)))
            {
                this.CreateCommand(workflow, command, item, webControl);
            }
        }