public BlockActionResult StartEdit(Guid guid) { using (var rockContext = new RockContext()) { var template = new WorkflowFormBuilderTemplateService(rockContext).Get(guid); // Verify the template exists and the individual has the correct // permissions to make the edits. if (template == null || !template.IsAuthorized(Authorization.EDIT, RequestContext.CurrentPerson)) { return(ActionBadRequest("Invalid template.")); } return(ActionOk(GetTemplateEditViewModel(template, rockContext))); } }
/// <inheritdoc/> public override object GetObsidianBlockInitialization() { using (var rockContext = new RockContext()) { var templateId = RequestContext.GetPageParameter(PageParameterKey.FormTemplateId).AsIntegerOrNull(); // Build the basic view model information required to edit a // form template. var viewModel = new FormTemplateDetailConfiguration { Sources = GetOptionSources(rockContext), ParentUrl = this.GetParentPageUrl() }; // If we have a template specified in the query string then // load the information from it to populate the form. if (templateId.HasValue && templateId.Value != 0) { var template = new WorkflowFormBuilderTemplateService(rockContext).Get(templateId.Value); if (template != null && template.IsAuthorized(Authorization.VIEW, RequestContext.CurrentPerson)) { viewModel.TemplateGuid = template.Guid; viewModel.Template = GetTemplateDetailViewModel(template, rockContext); viewModel.IsEditable = template.IsAuthorized(Authorization.EDIT, RequestContext.CurrentPerson); } else { // null means "not found or some other error prevented viewing". viewModel.TemplateGuid = null; } } else { // Guid.Empty means "create a new template". viewModel.TemplateGuid = Guid.Empty; viewModel.IsEditable = true; } return(viewModel); } }
/// <summary> /// Handles the Delete event of the gFormTemplates control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param> protected void gFormTemplates_Delete(object sender, Rock.Web.UI.Controls.RowEventArgs e) { using (var rockContext = new RockContext()) { int templateId = ( int )e.RowKeyValue; var workflowService = new WorkflowService(rockContext); var hasTemplates = workflowService.Queryable().Any(wf => wf.WorkflowType.FormBuilderTemplateId == templateId); if (hasTemplates) { ShowAlert("This template has workflows assigned to it", ModalAlertType.Warning); } else { var formTemplateService = new WorkflowFormBuilderTemplateService(rockContext); var template = formTemplateService.Get(templateId); formTemplateService.Delete(template); rockContext.SaveChanges(); } } BindGrid(); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { var builderTemplateService = new WorkflowFormBuilderTemplateService(new RockContext()); var qry = builderTemplateService.Queryable().AsNoTracking(); var isActive = gfFormTemplates.GetUserPreference(UserPreferenceKeys.Active).AsBooleanOrNull(); // A null is active defaults to showing only active if (!isActive.HasValue) { isActive = true; } if (isActive.HasValue) { qry = qry.Where(w => w.IsActive == isActive.Value); } qry = qry.OrderBy(w => w.Name); gFormTemplates.SetLinqDataSource(qry); gFormTemplates.DataBind(); }
public BlockActionResult SaveTemplate(Guid guid, TemplateEditDetailViewModel template) { using (var rockContext = new RockContext()) { var isNew = false; var templateService = new WorkflowFormBuilderTemplateService(rockContext); WorkflowFormBuilderTemplate formTemplate; // If we are provided an empty guid (not null) then we treat that // to mean create a new template. if (guid == Guid.Empty) { formTemplate = new WorkflowFormBuilderTemplate(); templateService.Add(formTemplate); isNew = true; } else { formTemplate = templateService.Get(guid); } // Perform a check to see if we now have a valid template object // and that the user has permission to edit/create it. if (formTemplate == null || !formTemplate.IsAuthorized(Authorization.EDIT, RequestContext.CurrentPerson)) { return(ActionBadRequest("Invalid template.")); } // Store all the template details. formTemplate.Name = template.Name.Trim(); formTemplate.Description = template.Description?.Trim(); formTemplate.IsActive = template.IsActive; formTemplate.IsLoginRequired = template.IsLoginRequired; formTemplate.FormHeader = template.FormHeader?.Trim(); formTemplate.FormFooter = template.FormFooter?.Trim(); formTemplate.AllowPersonEntry = template.AllowPersonEntry; formTemplate.PersonEntrySettingsJson = template.PersonEntry?.FromViewModel().ToJson(); formTemplate.CompletionSettingsJson = template.CompletionAction?.FromViewModel().ToJson(); var confirmationEmail = template.ConfirmationEmail?.FromViewModel(rockContext); // Special check for template logic. We don't have attributes yet // so check if the confirmation e-mail uses the special values to // indicate which attribute to be used at runtime. If we find one // of those special values then translate it to the enum. if (confirmationEmail != null) { if (confirmationEmail.RecipientAttributeGuid == RecipientPersonGuid) { confirmationEmail.Destination = Rock.Workflow.FormBuilder.FormConfirmationEmailDestination.Person; confirmationEmail.RecipientAttributeGuid = null; } else if (confirmationEmail.RecipientAttributeGuid == RecipientSpouseGuid) { confirmationEmail.Destination = Rock.Workflow.FormBuilder.FormConfirmationEmailDestination.Spouse; confirmationEmail.RecipientAttributeGuid = null; } } formTemplate.ConfirmationEmailSettingsJson = confirmationEmail?.ToJson(); rockContext.SaveChanges(); if (isNew) { return(ActionContent(System.Net.HttpStatusCode.Created, this.GetCurrentPageUrl(new Dictionary <string, string> { ["FormTemplateId"] = formTemplate.Id.ToString() }))); } // Ensure navigation properties will work now. formTemplate = templateService.Get(formTemplate.Id); return(ActionOk(GetTemplateDetailViewModel(formTemplate, rockContext))); } }