示例#1
0
        private void GetFormValues()
        {
            if (_workflow != null && _actionType != null)
            {
                var form = _actionType.WorkflowForm;

                var values = new Dictionary <int, string>();
                foreach (var formAttribute in form.FormAttributes.OrderBy(a => a.Order))
                {
                    if (formAttribute.IsVisible && !formAttribute.IsReadOnly)
                    {
                        var attribute = AttributeCache.Get(formAttribute.AttributeId);
                        var control   = phAttributes.FindControl(string.Format("attribute_field_{0}", formAttribute.AttributeId));

                        if (attribute != null && control != null)
                        {
                            Rock.Attribute.IHasAttributes item = null;
                            if (attribute.EntityTypeId == _workflow.TypeId)
                            {
                                item = _workflow;
                            }
                            else if (attribute.EntityTypeId == _activity.TypeId)
                            {
                                item = _activity;
                            }

                            if (item != null)
                            {
                                item.SetAttributeValue(attribute.Key, attribute.FieldType.Field.GetEditValue(attribute.GetControl(control), attribute.QualifierValues));
                            }
                        }
                    }
                }
            }
        }
示例#2
0
 private void LoadEditControls(int serviceId, bool setValues)
 {
     Rock.Attribute.IHasAttributes component = _container.Dictionary[serviceId].Value;
     Rock.Attribute.Helper.AddEditControls(component, phProperties, setValues, string.Empty, new List <string>()
     {
         "Order"
     });
 }
        private void LoadEditControls()
        {
            int serviceId = ( int )ViewState["serviceId"];

            Rock.Attribute.IHasAttributes component = _container.Dictionary[serviceId].Value;

            Rock.Attribute.Helper.AddEditControls(component, phProperties, true, new List <string>()
            {
                "Order"
            });
        }
        /// <summary>
        /// Handles the SaveClick event of the mdEditComponent control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void mdEditComponent_SaveClick(object sender, EventArgs e)
        {
            int serviceId = (int)ViewState["serviceId"];

            Rock.Attribute.IHasAttributes component = _container.Dictionary[serviceId].Value;

            Rock.Attribute.Helper.GetEditValues(phProperties, component);
            component.SaveAttributeValues();

            HideDialog();

            BindGrid();
        }
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            int serviceId = ( int )ViewState["serviceId"];

            Rock.Attribute.IHasAttributes component = _container.Dictionary[serviceId].Value;

            Rock.Attribute.Helper.GetEditValues(phProperties, component);
            Rock.Attribute.Helper.SaveAttributeValues(component, CurrentPersonId);

            BindGrid();

            SetEditMode(false);
        }
        /// <summary>
        /// Displays the edit attributes.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="displayedAttributeGuids">The displayed attribute guids.</param>
        /// <param name="phAttributes">The place holder attributes.</param>
        /// <param name="pnlAttributes">The PNL attributes.</param>
        /// <param name="setValue">a boolean that determines if the value should be preset.</param>
        private void DisplayEditAttributes(Rock.Attribute.IHasAttributes item, List <Guid> displayedAttributeGuids, PlaceHolder phAttributes, Panel pnlAttributes, bool setValue)
        {
            phAttributes.Controls.Clear();
            item.LoadAttributes();
            var excludedAttributeList = item.Attributes.Where(a => !displayedAttributeGuids.Contains(a.Value.Guid)).Select(a => a.Value.Key).ToList();

            if (item.Attributes != null && item.Attributes.Any() && displayedAttributeGuids.Any())
            {
                pnlAttributes.Visible = true;
                Helper.AddEditControls(item, phAttributes, setValue, BlockValidationGroup, excludedAttributeList, false, 2);
            }
            else
            {
                pnlAttributes.Visible = false;
            }
        }
示例#7
0
        private void CompleteFormAction(string formAction)
        {
            if (!string.IsNullOrWhiteSpace(formAction) &&
                _workflow != null &&
                _actionType != null &&
                _actionType.WorkflowForm != null &&
                _activity != null &&
                _action != null)
            {
                var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(this.RockPage, this.CurrentPerson);
                mergeFields.Add("Action", _action);
                mergeFields.Add("Activity", _activity);
                mergeFields.Add("Workflow", _workflow);

                Guid   activityTypeGuid = Guid.Empty;
                string responseText     = "Your information has been submitted successfully.";

                foreach (var action in _actionType.WorkflowForm.Actions.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    var actionDetails = action.Split(new char[] { '^' });
                    if (actionDetails.Length > 0 && actionDetails[0] == formAction)
                    {
                        if (actionDetails.Length > 2)
                        {
                            activityTypeGuid = actionDetails[2].AsGuid();
                        }

                        if (actionDetails.Length > 3 && !string.IsNullOrWhiteSpace(actionDetails[3]))
                        {
                            responseText = actionDetails[3].ResolveMergeFields(mergeFields);
                        }
                        break;
                    }
                }

                _action.MarkComplete();
                _action.FormAction = formAction;
                _action.AddLogEntry("Form Action Selected: " + _action.FormAction);

                if (_action.ActionTypeCache.IsActivityCompletedOnSuccess)
                {
                    _action.Activity.MarkComplete();
                }

                if (_actionType.WorkflowForm.ActionAttributeGuid.HasValue)
                {
                    var attribute = AttributeCache.Get(_actionType.WorkflowForm.ActionAttributeGuid.Value);
                    if (attribute != null)
                    {
                        Rock.Attribute.IHasAttributes item = null;
                        if (attribute.EntityTypeId == _workflow.TypeId)
                        {
                            item = _workflow;
                        }
                        else if (attribute.EntityTypeId == _activity.TypeId)
                        {
                            item = _activity;
                        }

                        if (item != null)
                        {
                            item.SetAttributeValue(attribute.Key, formAction);
                        }
                    }
                }

                if (!activityTypeGuid.IsEmpty())
                {
                    var activityType = _workflowType.ActivityTypes.Where(a => a.Guid.Equals(activityTypeGuid)).FirstOrDefault();
                    if (activityType != null)
                    {
                        WorkflowActivity.Activate(activityType, _workflow);
                    }
                }

                List <string> errorMessages;
                if (_workflowService.Process(_workflow, out errorMessages))
                {
                    Guid?previousActionGuid = null;

                    if (_action != null)
                    {
                        // Compare GUIDs since the IDs are DB generated and will be 0 if the workflow is not persisted.
                        previousActionGuid = _action.Guid;
                    }

                    ActionTypeId = null;
                    _action      = null;
                    _actionType  = null;
                    _activity    = null;
                    bool hydrateObjectsResult = HydrateObjects();

                    if (hydrateObjectsResult && _action != null && _action.Guid != previousActionGuid)
                    {
                        // The block reloads the page with the workflow IDs as a parameter. At this point the workflow must be persisted regardless of user settings in order for the workflow to work.
                        _workflowService.PersistImmediately(_action);

                        // If we are already being directed (presumably from the Redirect Action), don't redirect again.
                        if (!Response.IsRequestBeingRedirected)
                        {
                            var cb = CurrentPageReference;
                            cb.Parameters.AddOrReplace("WorkflowId", _workflow.Id.ToString());
                            foreach (var key in cb.QueryString.AllKeys.Where(k => !k.Equals("Command", StringComparison.OrdinalIgnoreCase)))
                            {
                                cb.Parameters.AddOrIgnore(key, cb.QueryString[key]);
                            }
                            cb.QueryString = new System.Collections.Specialized.NameValueCollection();
                            Response.Redirect(cb.BuildUrl(), false);
                            Context.ApplicationInstance.CompleteRequest();
                        }
                    }
                    else
                    {
                        if (lSummary.Text.IsNullOrWhiteSpace())
                        {
                            ShowMessage(NotificationBoxType.Success, string.Empty, responseText, (_action == null || _action.Guid != previousActionGuid));
                        }
                        else
                        {
                            pnlForm.Visible = false;
                        }
                    }
                }
                else
                {
                    ShowMessage(NotificationBoxType.Danger, "Workflow Processing Error(s):",
                                "<ul><li>" + errorMessages.AsDelimited("</li><li>", null, true) + "</li></ul>");
                }
                if (_workflow.Id != 0)
                {
                    WorkflowId = _workflow.Id;
                }
            }
        }
示例#8
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            string entityQualifierColumn = AttributeValue("EntityQualifierColumn");

            if (string.IsNullOrWhiteSpace(entityQualifierColumn))
            {
                entityQualifierColumn = PageParameter("EntityQualifierColumn");
            }

            string entityQualifierValue = AttributeValue("EntityQualifierValue");

            if (string.IsNullOrWhiteSpace(entityQualifierValue))
            {
                entityQualifierValue = PageParameter("EntityQualifierValue");
            }

            _category = AttributeValue("AttributeCategory");
            if (string.IsNullOrWhiteSpace(_category))
            {
                _category = PageParameter("AttributeCategory");
            }

            // Get the context entity
            int?contextEntityTypeId = null;

            Rock.Data.IEntity contextEntity = null;
            foreach (KeyValuePair <string, Rock.Data.IEntity> entry in ContextEntities)
            {
                contextEntityTypeId = entry.Value.TypeId;
                contextEntity       = entry.Value;
                // Should only be one.
                break;
            }

            if (contextEntityTypeId.HasValue && contextEntity != null)
            {
                ObjectCache cache    = MemoryCache.Default;
                string      cacheKey = string.Format("Attributes:{0}:{1}:{2}", contextEntityTypeId, entityQualifierColumn, entityQualifierValue);

                Dictionary <string, List <int> > cachedAttributes = cache[cacheKey] as Dictionary <string, List <int> >;
                if (cachedAttributes == null)
                {
                    cachedAttributes = new Dictionary <string, List <int> >();

                    AttributeService attributeService = new AttributeService();
                    foreach (var item in attributeService
                             .Get(contextEntityTypeId, entityQualifierColumn, entityQualifierValue)
                             .OrderBy(a => a.Category)
                             .ThenBy(a => a.Order)
                             .Select(a => new { a.Category, a.Id }))
                    {
                        if (!cachedAttributes.ContainsKey(item.Category))
                        {
                            cachedAttributes.Add(item.Category, new List <int>());
                        }
                        cachedAttributes[item.Category].Add(item.Id);
                    }

                    CacheItemPolicy cacheItemPolicy = null;
                    cache.Set(cacheKey, cachedAttributes, cacheItemPolicy);
                }

                Rock.Attribute.IHasAttributes model = contextEntity as Rock.Attribute.IHasAttributes;
                if (model != null)
                {
                    if (cachedAttributes.ContainsKey(_category))
                    {
                        foreach (var attributeId in cachedAttributes[_category])
                        {
                            var attribute = Rock.Web.Cache.AttributeCache.Read(attributeId);
                            if (attribute != null)
                            {
                                phAttributes.Controls.Add(/*(AttributeInstanceValues)*/ this.LoadControl("~/Blocks/Core/AttributeInstanceValues.ascx", model, attribute, CurrentPersonId));
                            }
                        }
                    }
                }
            }

            string script = @"
    Sys.Application.add_load(function () {
        $('div.context-attribute-values .delete').click(function(){
            return confirm('Are you sure?');
        });
    });
";

            Page.ClientScript.RegisterStartupScript(this.GetType(), "ConfirmDelete", script, true);
        }
示例#9
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            string entityQualifierColumn = AttributeValue("EntityQualifierColumn");

            if (string.IsNullOrWhiteSpace(entityQualifierColumn))
            {
                entityQualifierColumn = PageParameter("EntityQualifierColumn");
            }

            string entityQualifierValue = AttributeValue("EntityQualifierValue");

            if (string.IsNullOrWhiteSpace(entityQualifierValue))
            {
                entityQualifierValue = PageParameter("EntityQualifierValue");
            }

            // Get the context entity
            int?contextEntityTypeId = null;

            Rock.Data.IEntity contextEntity = null;
            foreach (KeyValuePair <string, Rock.Data.IEntity> entry in ContextEntities)
            {
                contextEntityTypeId = entry.Value.TypeId;
                contextEntity       = entry.Value;

                // Should only be one.
                break;
            }

            if (contextEntityTypeId.HasValue && contextEntity != null)
            {
                ObjectCache cache    = MemoryCache.Default;
                string      cacheKey = string.Format("Attributes:{0}:{1}:{2}", contextEntityTypeId, entityQualifierColumn, entityQualifierValue);

                Dictionary <string, List <int> > cachedAttributes = cache[cacheKey] as Dictionary <string, List <int> >;
                if (cachedAttributes == null)
                {
                    cachedAttributes = new Dictionary <string, List <int> >();

                    AttributeService attributeService = new AttributeService();
                    foreach (var item in attributeService
                             .Get(contextEntityTypeId, entityQualifierColumn, entityQualifierValue)
                             .OrderBy(a => a.Category)
                             .ThenBy(a => a.Order)
                             .Select(a => new { a.Category, a.Id }))
                    {
                        if (!cachedAttributes.ContainsKey(item.Category))
                        {
                            cachedAttributes.Add(item.Category, new List <int>());
                        }
                        cachedAttributes[item.Category].Add(item.Id);
                    }

                    CacheItemPolicy cacheItemPolicy = null;
                    cache.Set(cacheKey, cachedAttributes, cacheItemPolicy);
                }

                Rock.Attribute.IHasAttributes model = contextEntity as Rock.Attribute.IHasAttributes;
                if (model != null)
                {
                    var rootElement = new XElement("root");

                    foreach (string category in AttributeValue("AttributeCategories").SplitDelimitedValues(false))
                    {
                        if (cachedAttributes.ContainsKey(category))
                        {
                            var attributesElement = new XElement("attributes",
                                                                 new XAttribute("category-name", category)
                                                                 );
                            rootElement.Add(attributesElement);

                            foreach (var attributeId in cachedAttributes[category])
                            {
                                var attribute = Rock.Web.Cache.AttributeCache.Read(attributeId);
                                if (attribute != null)
                                {
                                    var values = model.AttributeValues[attribute.Key];
                                    if (values != null && values.Count > 0)
                                    {
                                        attributesElement.Add(new XElement("attribute",
                                                                           new XAttribute("name", attribute.Name),
                                                                           new XCData(attribute.FieldType.Field.FormatValue(null, values[0].Value, attribute.QualifierValues, false) ?? string.Empty)
                                                                           ));
                                    }
                                }
                            }
                        }
                    }

                    xDocument = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"), rootElement);
                }
            }
        }