/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnInit(EventArgs e) { base.OnInit(e); if (_workflowType != null) { _canEdit = UserCanEdit || _workflowType.IsAuthorized(Authorization.EDIT, CurrentPerson); _canView = _canEdit || (_workflowType.IsAuthorized(Authorization.VIEW, CurrentPerson) && _workflowType.IsAuthorized("ViewList", CurrentPerson)); gfWorkflows.ApplyFilterClick += gfWorkflows_ApplyFilterClick; gfWorkflows.DisplayFilterValue += gfWorkflows_DisplayFilterValue; // this event gets fired after block settings are updated. it's nice to repaint the screen if these settings would alter it this.BlockUpdated += Block_BlockUpdated; this.AddConfigurationUpdateTrigger(upnlSettings); _bbtnDelete.Text = "Delete"; _bbtnDelete.Click += new EventHandler(bbtnDelete_Click); _bbtnDelete.CssClass = "btn btn-xs btn-default btn-grid-custom-action pull-left"; gWorkflows.Actions.AddCustomActionControl(_bbtnDelete); gWorkflows.DataKeyNames = new string[] { "Id" }; gWorkflows.Actions.ShowAdd = _canEdit; gWorkflows.Actions.AddClick += gWorkflows_Add; gWorkflows.GridRebind += gWorkflows_GridRebind; gWorkflows.Actions.ShowAdd = true; gWorkflows.IsDeleteEnabled = _canEdit; if (!string.IsNullOrWhiteSpace(_workflowType.WorkTerm)) { gWorkflows.RowItemText = _workflowType.WorkTerm; lGridTitle.Text = _workflowType.WorkTerm.Pluralize(); } RockPage.PageTitle = _workflowType.Name; if (!string.IsNullOrWhiteSpace(_workflowType.IconCssClass)) { lHeadingIcon.Text = string.Format("<i class='{0}'></i>", _workflowType.IconCssClass); } } else { pnlWorkflowList.Visible = false; } }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnInit(EventArgs e) { base.OnInit(e); if (_workflowType != null && _workflowType.IsAuthorized(Authorization.EDIT, CurrentPerson)) { gfWorkflows.ApplyFilterClick += gfWorkflows_ApplyFilterClick; gfWorkflows.DisplayFilterValue += gfWorkflows_DisplayFilterValue; // this event gets fired after block settings are updated. it's nice to repaint the screen if these settings would alter it this.BlockUpdated += Block_BlockUpdated; this.AddConfigurationUpdateTrigger(upnlSettings); gWorkflows.DataKeyNames = new string[] { "Id" }; gWorkflows.Actions.ShowAdd = true; gWorkflows.Actions.AddClick += gWorkflows_Add; gWorkflows.GridRebind += gWorkflows_GridRebind; gWorkflows.Actions.ShowAdd = true; gWorkflows.IsDeleteEnabled = true; if (!string.IsNullOrWhiteSpace(_workflowType.WorkTerm)) { gWorkflows.RowItemText = _workflowType.WorkTerm; lGridTitle.Text = _workflowType.WorkTerm.Pluralize(); } RockPage.PageTitle = _workflowType.Name; if (!string.IsNullOrWhiteSpace(_workflowType.IconCssClass)) { lHeadingIcon.Text = string.Format("<i class='{0}'></i>", _workflowType.IconCssClass); } } else { pnlWorkflowList.Visible = false; } }
private bool HydrateObjects() { LoadWorkflowType(); // Set the note type if this is first request if (!Page.IsPostBack) { var noteType = new NoteTypeService(_rockContext).Get(Rock.SystemGuid.NoteType.WORKFLOW_NOTE.AsGuid()); ncWorkflowNotes.NoteTypeId = noteType.Id; } if (_workflowType == null) { ShowMessage(NotificationBoxType.Danger, "Configuration Error", "Workflow type was not configured or specified correctly."); return(false); } if (!_workflowType.IsAuthorized(Authorization.VIEW, CurrentPerson)) { ShowMessage(NotificationBoxType.Warning, "Sorry", "You are not authorized to view this type of workflow."); return(false); } // If operating against an existing workflow, get the workflow and load attributes if (!WorkflowId.HasValue) { WorkflowId = PageParameter("WorkflowId").AsIntegerOrNull(); if (!WorkflowId.HasValue) { Guid guid = PageParameter("WorkflowGuid").AsGuid(); if (!guid.IsEmpty()) { _workflow = _workflowService.Queryable() .Where(w => w.Guid.Equals(guid) && w.WorkflowTypeId == _workflowType.Id) .FirstOrDefault(); if (_workflow != null) { WorkflowId = _workflow.Id; } } } } if (WorkflowId.HasValue) { if (_workflow == null) { _workflow = _workflowService.Queryable() .Where(w => w.Id == WorkflowId.Value && w.WorkflowTypeId == _workflowType.Id) .FirstOrDefault(); } if (_workflow != null) { _workflow.LoadAttributes(); foreach (var activity in _workflow.Activities) { activity.LoadAttributes(); } } } // If an existing workflow was not specified, activate a new instance of workflow and start processing if (_workflow == null) { string workflowName = PageParameter("WorkflowName"); if (string.IsNullOrWhiteSpace(workflowName)) { workflowName = "New " + _workflowType.WorkTerm; } _workflow = Rock.Model.Workflow.Activate(_workflowType, workflowName); if (_workflow != null) { // If a PersonId or GroupId parameter was included, load the corresponding // object and pass that to the actions for processing object entity = null; int? personId = PageParameter("PersonId").AsIntegerOrNull(); if (personId.HasValue) { entity = new PersonService(_rockContext).Get(personId.Value); } else { int?groupId = PageParameter("GroupId").AsIntegerOrNull(); if (groupId.HasValue) { entity = new GroupService(_rockContext).Get(groupId.Value); } } // Loop through all the query string parameters and try to set any workflow // attributes that might have the same key foreach (string key in Request.QueryString.AllKeys) { _workflow.SetAttributeValue(key, Request.QueryString[key]); } List <string> errorMessages; if (_workflow.Process(_rockContext, entity, out errorMessages)) { // If the workflow type is persisted, save the workflow if (_workflow.IsPersisted || _workflowType.IsPersisted) { if (_workflow.Id == 0) { _workflowService.Add(_workflow); } _rockContext.WrapTransaction(() => { _rockContext.SaveChanges(); _workflow.SaveAttributeValues(_rockContext); foreach (var activity in _workflow.Activities) { activity.SaveAttributeValues(_rockContext); } }); WorkflowId = _workflow.Id; } } } } if (_workflow == null) { ShowMessage(NotificationBoxType.Danger, "Workflow Activation Error", "Workflow could not be activated."); return(false); } if (_workflow.IsActive) { if (ActionTypeId.HasValue) { foreach (var activity in _workflow.ActiveActivities) { _action = activity.Actions.Where(a => a.ActionTypeId == ActionTypeId.Value).FirstOrDefault(); if (_action != null) { _activity = activity; _activity.LoadAttributes(); _actionType = _action.ActionType; ActionTypeId = _actionType.Id; return(true); } } } var canEdit = IsUserAuthorized(Authorization.EDIT); // Find first active action form int personId = CurrentPerson != null ? CurrentPerson.Id : 0; foreach (var activity in _workflow.Activities .Where(a => a.IsActive && ( (!a.AssignedGroupId.HasValue && !a.AssignedPersonAliasId.HasValue) || (a.AssignedPersonAlias != null && a.AssignedPersonAlias.PersonId == personId) || (a.AssignedGroup != null && a.AssignedGroup.Members.Any(m => m.PersonId == personId)) ) ) .OrderBy(a => a.ActivityType.Order)) { if (canEdit || (activity.ActivityType.IsAuthorized(Authorization.VIEW, CurrentPerson))) { foreach (var action in activity.ActiveActions) { if (action.ActionType.WorkflowForm != null && action.IsCriteriaValid) { _activity = activity; _activity.LoadAttributes(); _action = action; _actionType = _action.ActionType; ActionTypeId = _actionType.Id; return(true); } } } } } ShowNotes(false); ShowMessage(NotificationBoxType.Warning, string.Empty, "The selected workflow is not in a state that requires you to enter information."); return(false); }