using System; using System.Collections.Generic; using System.Linq; using CMS.UIControls; using CMS.UIControls.UniMenuConfig; using CMS.UIControls.Workflows; using CMS.SettingsProvider; using CMS.WorkflowEngine; using CMS.GlobalHelper; public partial class CMSModules_Workflows_Controls_WorkflowDesignerToolbar : UniGraphToolbar { #region "Private variables" private List mStepItems = new List(); private StepTypeUniMenuItems mInjector = null; #endregion #region "Properties" /// /// Factory for uniMenu items. /// protected StepTypeUniMenuItems Factory { get { if (mInjector == null) { mInjector = new StepTypeUniMenuItems(JsGraphObject, Page); } return mInjector; } } /// /// Steps user should be able to add to graph from toolbar. /// public List StepItems { get { if (mStepItems.Count == 0 && Visible) { InitStepItems(); } return mStepItems; } set { mStepItems = value; } } /// /// Groups of uniMenu. /// public override List ToolbarGroups { get { return toolbar.Groups; } set { toolbar.Groups = value; } } /// /// In this control visibility has same function as stopping processing. Only values are inversed. /// public override bool StopProcessing { get { return !Visible; } set { Visible = !value; } } /// /// Property of workflow info object. /// public WorkflowInfo Workflow { get; set; } #endregion #region "Event handlers" protected override void OnLoad(EventArgs e) { if (!Visible) { return; } InitResources(); SetBaseNodeItems(); AddActionGroup(editToolbar.Search); RegisterInitScript(); base.OnLoad(e); } #endregion #region "Methods" /// /// Initializes default set of menu items in steps group. /// private void InitStepItems() { StepItems = new List() { {WorkflowStepTypeEnum.Standard}, {WorkflowStepTypeEnum.Condition}, {WorkflowStepTypeEnum.Multichoice}, {WorkflowStepTypeEnum.MultichoiceFirstWin}, {WorkflowStepTypeEnum.Userchoice}, {WorkflowStepTypeEnum.Wait} }; if (Workflow.IsDocumentWorkflow) { StepItems.Add(WorkflowStepTypeEnum.DocumentPublished); StepItems.Add(WorkflowStepTypeEnum.DocumentArchived); } else if (Workflow.IsAutomation) { StepItems.Add(WorkflowStepTypeEnum.Finished); } } /// /// Registers script initializing toolbar. /// private void RegisterInitScript() { string script = string.Format("graphControlHandler.initToolbar('{0}');", pnlAjax.ClientID); ScriptHelper.RegisterStartupScript(Page, typeof(string), ClientID, script, true); } /// /// Initializes default paths to controls. /// private void InitResources() { NodesControlPath = "~/CMSAdminControls/UI/UniMenu/UniGraphToolbar/NodesGroup.ascx"; //NodesGroupResourceString = "workflowToolbar.stepsGroup"; editToolbar.JsGraphObject = JsGraphObject; } /// /// Sets menu items in nodes group based on workflow step types. /// private void SetBaseNodeItems() { NodeItems = Factory.GetSettingsObject(StepItems); NodeItems = FilterList(NodeItems, editToolbar.Search); } /// /// Adds group for actions. /// /// Pattern to be used to filter actions private void AddActionGroup(string where) { string condition = "ActionEnabled = 1"; // Allowed objects condition = SqlHelperClass.AddWhereCondition(condition, "ActionAllowedObjects IS NULL OR ActionAllowedObjects LIKE N'%" + SqlHelperClass.GetSafeQueryString(Workflow.WorkflowAllowedObjects) + "%'"); // Workflow type condition = SqlHelperClass.AddWhereCondition(condition, Workflow.IsAutomation ? "ActionWorkflowType = " + (int)Workflow.WorkflowType : "ActionWorkflowType = " + (int)Workflow.WorkflowType + " OR ActionWorkflowType IS NULL"); InfoDataSet actions = WorkflowActionInfoProvider.GetWorkflowActions(condition, "ActionDisplayName", "ActionID, ActionThumbnailGUID, ActionDisplayName, ActionDescription, ActionIconGUID"); List nodesMenuItems = Factory.GetSettingsObjectBy(actions); nodesMenuItems = FilterList(nodesMenuItems, where); nodesMenuItems = nodesMenuItems.OrderBy(i => i.Text).ToList(); if (nodesMenuItems.Count > 0) { KeyValuePair nodesValue = new KeyValuePair("NodesMenuItems", nodesMenuItems); AppendGroup(NodesControlPath, nodesValue, ""); } } /// /// Filters unimenu items in list by specified name. /// /// List to be filtered /// Name to be filtered by /// Filtered list private List FilterList(List list, string pattern) { if (!string.IsNullOrEmpty(pattern)) { return list.Where(n => n.Text.ToLowerCSafe().Contains(pattern.ToLowerCSafe()) || n.Tooltip.ToLowerCSafe().Contains(pattern.ToLowerCSafe())).ToList(); } return list; } #endregion }