/// <summary>
        /// Handles the Add actions event.
        /// </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 gFilters_Add(object sender, EventArgs e)
        {
            var rockContext      = new RockContext();
            var attributeService = new AttributeService(rockContext);

            // Reset attribute editor fields.
            edtFilter.Name            = string.Empty;
            edtFilter.Key             = string.Empty;
            edtFilter.AbbreviatedName = "";

            Rock.Model.Attribute attribute = new Rock.Model.Attribute();

            // Set attribute fields to those from a new attribute to made sure the AttributeEditor / ViewState has no leftover values.
            edtFilter.AttributeGuid       = attribute.Guid;
            edtFilter.AttributeId         = attribute.Id;
            edtFilter.IsFieldTypeEditable = true;
            edtFilter.SetAttributeFieldType(FieldTypeCache.Get(Rock.SystemGuid.FieldType.TEXT).Id, null);

            edtFilter.ReservedKeyNames = AttributeCache.AllForEntityType(_blockTypeEntityId)
                                         .Where(a =>
                                                a.EntityTypeQualifierColumn == "Id" &&
                                                a.EntityTypeQualifierValue == _block.Id.ToString())
                                         .Select(a => a.Key)
                                         .Distinct()
                                         .ToList();

            mdFilter.Title = "Add Filter";
            mdFilter.Show();
        }
        private void LoadRockGroup(Group group)
        {
            _rockGroup   = group;
            _rockGroupId = _rockGroup.Id;

            var ebFieldType = FieldTypeCache.Get(rocks.kfs.Eventbrite.EBGuid.FieldType.EVENTBRITE_EVENT.AsGuid());

            if (ebFieldType != null)
            {
                _rockGroup.LoadAttributes(_rockContext);
                var attribute = _rockGroup.Attributes.Select(a => a.Value).FirstOrDefault(a => a.FieldTypeId == ebFieldType.Id);
                if (attribute != null)
                {
                    var attributeVal = _rockGroup.AttributeValues.Select(av => av.Value).FirstOrDefault(av => av.AttributeId == attribute.Id && av.Value != "");
                    if (attributeVal != null)
                    {
                        var splitVal = attributeVal.Value.SplitDelimitedValues("^");
                        if (splitVal.Length > 0)
                        {
                            _evntId = splitVal[0].AsLong();
                        }
                        if (splitVal.Length > 1)
                        {
                            _synced = splitVal[1];
                        }
                    }
                }
            }
        }
        public IQueryable <ContentChannelItem> GetFromPersonDataView(string guids)
        {
            RockContext rockContext = new RockContext();

            // Turn the comma separated list of guids into a list of strings.
            List <string> guidList = (guids ?? "").Split(',').ToList();

            // Get the Id of the Rock.Model.ContentChannelItem Entity.
            int contentChannelItemEntityTypeId = EntityTypeCache.Get("Rock.Model.ContentChannelItem").Id;

            // Get the Field Type (Attribute Type) Id of the Data View Field Type.
            int fieldTypeId = FieldTypeCache.Get(Rock.SystemGuid.FieldType.DATAVIEWS.AsGuid()).Id;

            // Get the list of attributes that are of the Rock.Model.ContentChannelItem entity type
            // and that are of the Data View field type.
            List <int> attributeIdList = new AttributeService(rockContext)
                                         .GetByEntityTypeId(contentChannelItemEntityTypeId)
                                         .Where(item => item.FieldTypeId == fieldTypeId)
                                         .Select(a => a.Id)
                                         .ToList();

            // I want a list of content channel items whose ids match up to attribute values that represent entity ids
            IQueryable <ContentChannelItem> contentChannelItemList = new ContentChannelItemService(rockContext)
                                                                     .Queryable()
                                                                     .WhereAttributeValue(rockContext, av => attributeIdList.Contains(av.AttributeId) && guidList.Contains(av.Value));

            // Return this list
            return(contentChannelItemList);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gs the defined type attributes_ show edit.
        /// </summary>
        /// <param name="attributeGuid">The attribute GUID.</param>
        protected void gDefinedTypeAttributes_ShowEdit(Guid attributeGuid)
        {
            pnlDetails.Visible = false;
            vsDetails.Enabled  = false;
            pnlDefinedTypeAttributes.Visible = true;

            Attribute attribute;

            if (attributeGuid.Equals(Guid.Empty))
            {
                attribute             = new Attribute();
                attribute.FieldTypeId = FieldTypeCache.Get(Rock.SystemGuid.FieldType.TEXT).Id;
                edtDefinedTypeAttributes.ActionTitle = ActionTitle.Add("attribute for defined type " + tbTypeName.Text);
            }
            else
            {
                AttributeService attributeService = new AttributeService(new RockContext());
                attribute = attributeService.Get(attributeGuid);
                edtDefinedTypeAttributes.ActionTitle = ActionTitle.Edit("attribute for defined type " + tbTypeName.Text);
            }

            edtDefinedTypeAttributes.ReservedKeyNames = new AttributeService(new RockContext())
                                                        .GetByEntityTypeId(new DefinedValue().TypeId, true).AsQueryable()
                                                        .Where(a =>
                                                               a.EntityTypeQualifierColumn.Equals("DefinedTypeId", StringComparison.OrdinalIgnoreCase) &&
                                                               a.EntityTypeQualifierValue.Equals(hfDefinedTypeId.Value) &&
                                                               !a.Guid.Equals(attributeGuid))
                                                        .Select(a => a.Key)
                                                        .Distinct()
                                                        .ToList();

            edtDefinedTypeAttributes.SetAttributeProperties(attribute, typeof(DefinedValue));

            this.HideSecondaryBlocks(true);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a <see cref="Rock.Field.FieldVisibilityRule"/>
        /// object from its view model representation.
        /// </summary>
        /// <param name="viewModel">The view model that represents the object.</param>
        /// <returns>The object created from the view model.</returns>
        internal static Rock.Field.FieldVisibilityRule FromViewModel(this FieldFilterRuleViewModel viewModel, List <FormFieldViewModel> formFields)
        {
            var rule = new Rock.Field.FieldVisibilityRule
            {
                Guid                    = viewModel.Guid,
                ComparisonType          = ( ComparisonType )viewModel.ComparisonType,
                ComparedToFormFieldGuid = viewModel.AttributeGuid,
                ComparedToValue         = viewModel.Value
            };

            if (rule.ComparedToFormFieldGuid.HasValue)
            {
                var comparisonValue = new Rock.Reporting.ComparisonValue
                {
                    ComparisonType = rule.ComparisonType,
                    Value          = rule.ComparedToValue
                };
                var field = formFields.Where(f => f.Guid == rule.ComparedToFormFieldGuid.Value).FirstOrDefault();

                if (field != null)
                {
                    var fieldType = FieldTypeCache.Get(field.FieldTypeGuid);

                    if (fieldType?.Field != null)
                    {
                        var privateConfigurationValues = fieldType.Field.GetPrivateConfigurationValues(field.ConfigurationValues);
                        var filterValues = fieldType.Field.GetPrivateFilterValue(comparisonValue, privateConfigurationValues).FromJsonOrNull <List <string> >();

                        if (filterValues != null && filterValues.Count == 2)
                        {
                            rule.ComparedToValue = filterValues[1];
                        }
                        else if (filterValues != null && filterValues.Count == 1)
                        {
                            rule.ComparedToValue = filterValues[0];
                        }
                    }
                }
                else
                {
                    var attribute = AttributeCache.Get(rule.ComparedToFormFieldGuid.Value);

                    if (attribute?.FieldType?.Field != null)
                    {
                        var filterValues = attribute.FieldType.Field.GetPrivateFilterValue(comparisonValue, attribute.ConfigurationValues).FromJsonOrNull <List <string> >();

                        if (filterValues != null && filterValues.Count == 2)
                        {
                            rule.ComparedToValue = filterValues[1];
                        }
                        else if (filterValues != null && filterValues.Count == 1)
                        {
                            rule.ComparedToValue = filterValues[0];
                        }
                    }
                }
            }

            return(rule);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets the attribute value.
        /// </summary>
        /// <param name="action">The action.</param>
        /// <param name="key">The key.</param>
        /// <param name="checkWorkflowAttributeValue">if set to <c>true</c> and the returned value is a guid, check to see if the workflow
        /// or activity contains an attribute with that guid. This is useful when using the WorkflowTextOrAttribute field types to get the
        /// actual value or workflow value.</param>
        /// <returns></returns>
        protected string GetAttributeValue(WorkflowAction action, string key, bool checkWorkflowAttributeValue)
        {
            string value = GetActionAttributeValue(action, key);

            if (checkWorkflowAttributeValue)
            {
                Guid?attributeGuid = value.AsGuidOrNull();
                if (attributeGuid.HasValue)
                {
                    var attribute = AttributeCache.Read(attributeGuid.Value);
                    if (attribute != null)
                    {
                        value = action.GetWorklowAttributeValue(attributeGuid.Value);
                        if (!string.IsNullOrWhiteSpace(value))
                        {
                            if (attribute.FieldTypeId == FieldTypeCache.Read(SystemGuid.FieldType.ENCRYPTED_TEXT.AsGuid()).Id)
                            {
                                value = Security.Encryption.DecryptString(value);
                            }
                            else if (attribute.FieldTypeId == FieldTypeCache.Read(SystemGuid.FieldType.SSN.AsGuid()).Id)
                            {
                                value = Rock.Field.Types.SSNFieldType.UnencryptAndClean(value);
                            }
                        }
                    }
                }
            }

            return(value);
        }
Ejemplo n.º 7
0
            private void PopulateFields(Dictionary <string, object> sourceProperties)
            {
                foreach (var field in FieldTypeCache.RetrieveAllFields(_targetType))
                {
                    var sourcePropertyValue = GetSourcePropertyValue(sourceProperties, field);
                    if (sourcePropertyValue == null)
                    {
                        continue;
                    }

                    var targetPropertyValue = FromJsonResult(
                        sourcePropertyValue,
                        field.FieldType,
                        _includeNonPublic);

                    try
                    {
                        field.SetValue(_target, targetPropertyValue);
                    }
                    catch
                    {
                        // ignored
                    }
                }
            }
Ejemplo n.º 8
0
        /// <summary>
        /// Binds the attributes grid.
        /// </summary>
        /// <param name="attributes">The attributes.</param>
        public void BindAttributesGrid(List <Rock.Model.Attribute> attributes)
        {
            if (attributes.Any())
            {
                _pwAttributes.Title = string.Format("Attributes ({0})", attributes.Count.ToString("N0"));
            }
            else
            {
                _pwAttributes.Title = "Attributes";
            }

            _gAttributes.DataSource = attributes
                                      .OrderBy(a => a.Order)
                                      .ThenBy(a => a.Name)
                                      .Select(a => new
            {
                a.Id,
                a.Guid,
                a.Name,
                a.Description,
                FieldType = FieldTypeCache.GetName(a.FieldTypeId),
                a.IsRequired
            })
                                      .ToList();
            _gAttributes.DataBind();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Gs the defined type attributes_ show edit.
        /// </summary>
        /// <param name="attributeGuid">The attribute GUID.</param>
        protected void gDefinedTypeAttributes_ShowEdit(Guid attributeGuid)
        {
            pnlDetails.Visible = false;
            vsDetails.Enabled  = false;
            pnlDefinedTypeAttributes.Visible = true;

            Attribute attribute;

            if (attributeGuid.Equals(Guid.Empty))
            {
                attribute             = new Attribute();
                attribute.FieldTypeId = FieldTypeCache.Read(Rock.SystemGuid.FieldType.TEXT).Id;
                edtDefinedTypeAttributes.ActionTitle = ActionTitle.Add("attribute for defined type " + tbTypeName.Text);
            }
            else
            {
                AttributeService attributeService = new AttributeService();
                attribute = attributeService.Get(attributeGuid);
                edtDefinedTypeAttributes.ActionTitle = ActionTitle.Edit("attribute for defined type " + tbTypeName.Text);
            }

            edtDefinedTypeAttributes.SetAttributeProperties(attribute, typeof(DefinedValue));

            this.HideSecondaryBlocks(true);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="itemKey">The item key.</param>
        /// <param name="itemKeyValue">The item key value.</param>
        public void ShowDetail(string itemKey, int itemKeyValue)
        {
            if (!itemKey.Equals("definedTypeId"))
            {
                return;
            }

            pnlDetails.Visible = true;
            DefinedType definedType = null;

            if (!itemKeyValue.Equals(0))
            {
                definedType = new DefinedTypeService().Get(itemKeyValue);
            }
            else
            {
                definedType = new DefinedType {
                    Id = 0
                };
                definedType.FieldTypeId = FieldTypeCache.Read(Rock.SystemGuid.FieldType.TEXT).Id;
            }

            hfDefinedTypeId.SetValue(definedType.Id);

            // render UI based on Authorized and IsSystem
            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if (!IsUserAuthorized("Edit"))
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(DefinedType.FriendlyTypeName);
            }

            if (definedType.IsSystem)
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem(DefinedType.FriendlyTypeName);
            }

            if (readOnly)
            {
                btnEdit.Visible = false;
                ShowReadonlyDetails(definedType);
            }
            else
            {
                btnEdit.Visible = true;
                if (definedType.Id > 0)
                {
                    ShowReadonlyDetails(definedType);
                }
                else
                {
                    ShowEditDetails(definedType);
                }
            }

            BindDefinedTypeAttributesGrid();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// gs the item attributes show edit.
        /// </summary>
        /// <param name="attributeGuid">The attribute unique identifier.</param>
        protected void gItemAttributes_ShowEdit(Guid attributeGuid)
        {
            Attribute attribute;

            if (attributeGuid.Equals(Guid.Empty))
            {
                attribute                     = new Attribute();
                attribute.FieldTypeId         = FieldTypeCache.Get(Rock.SystemGuid.FieldType.TEXT).Id;
                edtItemAttributes.ActionTitle = ActionTitle.Add(tbName.Text + " Item Attribute");
            }
            else
            {
                attribute = ItemAttributesState.First(a => a.Guid.Equals(attributeGuid));
                edtItemAttributes.ActionTitle = ActionTitle.Edit(tbName.Text + " Item Attribute");
            }


            List <string> reservedKeys = ItemAttributesState.Where(a => !a.Guid.Equals(attributeGuid)).Select(a => a.Key).ToList();

            reservedKeys.AddRange(ItemInheritedKey);
            edtItemAttributes.ReservedKeyNames = reservedKeys;

            edtItemAttributes.SetAttributeProperties(attribute, typeof(ContentChannelItem));

            edtItemAttributes.IsIndexingEnabledVisible = cbIndexChannel.Visible && cbIndexChannel.Checked;

            ShowDialog("ItemAttributes", true);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Sets the value.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        public static void SetValue(string key, string value)
        {
            var rockContext      = new Rock.Data.RockContext();
            var attributeService = new AttributeService(rockContext);
            var attribute        = attributeService.GetSystemSetting(key);

            if (attribute == null)
            {
                attribute             = new Rock.Model.Attribute();
                attribute.FieldTypeId = FieldTypeCache.Get(new Guid(SystemGuid.FieldType.TEXT)).Id;
                attribute.EntityTypeQualifierColumn = Rock.Model.Attribute.SYSTEM_SETTING_QUALIFIER;
                attribute.EntityTypeQualifierValue  = string.Empty;
                attribute.Key          = key;
                attribute.Name         = key.SplitCase();
                attribute.DefaultValue = value;
                attributeService.Add(attribute);
            }
            else
            {
                attribute.DefaultValue = value;
            }

            // NOTE: Service Layer will automatically update this Cache (see Attribute.cs UpdateCache)
            rockContext.SaveChanges();

            if (key == Rock.SystemKey.SystemSetting.START_DAY_OF_WEEK)
            {
                RockDateTime.FirstDayOfWeek = value.ConvertToEnumOrNull <DayOfWeek>() ?? RockDateTime.DefaultFirstDayOfWeek;
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Sets the entity field from field type attribute.
        /// </summary>
        /// <param name="entityField">The entity field.</param>
        /// <param name="fieldTypeAttribute">The field type attribute.</param>
        /// <returns></returns>
        private static bool SetEntityFieldFromFieldTypeAttribute(EntityField entityField, FieldTypeAttribute fieldTypeAttribute)
        {
            if (fieldTypeAttribute != null)
            {
                var fieldTypeCache = FieldTypeCache.Read(fieldTypeAttribute.FieldTypeGuid);
                if (fieldTypeCache != null && fieldTypeCache.Field != null)
                {
                    if (fieldTypeCache.Field.HasFilterControl())
                    {
                        if (entityField.Title.EndsWith(" Id"))
                        {
                            entityField.Title = entityField.Title.ReplaceLastOccurrence(" Id", string.Empty);
                        }

                        entityField.FieldType = fieldTypeCache;
                        if (fieldTypeAttribute.ConfigurationKey != null && fieldTypeAttribute.ConfigurationValue != null)
                        {
                            entityField.FieldConfig.Add(fieldTypeAttribute.ConfigurationKey, new ConfigurationValue(fieldTypeAttribute.ConfigurationValue));
                        }

                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Gs the group type attributes_ show edit.
        /// </summary>
        /// <param name="attributeGuid">The attribute GUID.</param>
        protected void gAttributes_ShowEdit(Guid attributeGuid)
        {
            Attribute attribute;

            if (attributeGuid.Equals(Guid.Empty))
            {
                attribute                 = new Attribute();
                attribute.FieldTypeId     = FieldTypeCache.Read(Rock.SystemGuid.FieldType.TEXT).Id;
                edtAttributes.ActionTitle = ActionTitle.Add("attribute for matrix attributes that use matrix template " + tbName.Text);
            }
            else
            {
                attribute = AttributesState.First(a => a.Guid.Equals(attributeGuid));
                edtAttributes.ActionTitle = ActionTitle.Edit("attribute for matrix attributes that use matrix template " + tbName.Text);
            }

            var reservedKeyNames = new List <string>();

            AttributesState.Where(a => !a.Guid.Equals(attributeGuid)).Select(a => a.Key).ToList().ForEach(a => reservedKeyNames.Add(a));
            edtAttributes.ReservedKeyNames = reservedKeyNames.ToList();

            edtAttributes.ExcludedFieldTypes = new FieldTypeCache[] { FieldTypeCache.Read <MatrixFieldType>() };
            edtAttributes.SetAttributeProperties(attribute, typeof(AttributeMatrixTemplate));

            dlgAttribute.Show();
        }
Ejemplo n.º 15
0
        /// <summary>
        /// gs the page attributes show edit.
        /// </summary>
        /// <param name="attributeGuid">The attribute unique identifier.</param>
        protected void gPageAttributes_ShowEdit(Guid attributeGuid)
        {
            Attribute attribute;

            if (attributeGuid.Equals(Guid.Empty))
            {
                attribute                     = new Attribute();
                attribute.FieldTypeId         = FieldTypeCache.Get(Rock.SystemGuid.FieldType.TEXT).Id;
                edtPageAttributes.ActionTitle = ActionTitle.Add("attribute for pages of site " + tbSiteName.Text);
            }
            else
            {
                attribute = PageAttributesState.First(a => a.Guid.Equals(attributeGuid));
                edtPageAttributes.ActionTitle = ActionTitle.Edit("attribute for pages of site " + tbSiteName.Text);
            }

            var reservedKeyNames = new List <string>();

            PageAttributesState.Where(a => !a.Guid.Equals(attributeGuid)).Select(a => a.Key).ToList().ForEach(a => reservedKeyNames.Add(a));
            edtPageAttributes.ReservedKeyNames = reservedKeyNames.ToList();

            edtPageAttributes.SetAttributeProperties(attribute, typeof(Rock.Model.Page));

            dlgPageAttribute.Show();
            HideSecondaryBlocks(true);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Creates the control(s) necessary for prompting user for a new value
        /// </summary>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="id"></param>
        /// <returns>
        /// The control
        /// </returns>
        public override Control EditControl(Dictionary <string, ConfigurationValue> configurationValues, string id)
        {
            var filteredFieldTypes = new List <string>();

            if (configurationValues != null &&
                configurationValues.ContainsKey(ATTRIBUTE_FIELD_TYPES_KEY))
            {
                filteredFieldTypes = configurationValues[ATTRIBUTE_FIELD_TYPES_KEY].Value
                                     .Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();
            }

            var editControl = new Rock.Web.UI.Controls.RockDropDownList {
                ID = id
            };

            editControl.Items.Add(new ListItem());

            var attributes = GetContextAttributes();

            if (attributes != null)
            {
                foreach (var attribute in attributes)
                {
                    var fieldType = FieldTypeCache.Get(attribute.Value.FieldTypeId);
                    if (!filteredFieldTypes.Any() || filteredFieldTypes.Contains(fieldType.Class, StringComparer.OrdinalIgnoreCase))
                    {
                        editControl.Items.Add(new ListItem(attribute.Value.Name, attribute.Key.ToString()));
                    }
                }
            }

            return(editControl);
        }
Ejemplo n.º 17
0
            private static Dictionary <Tuple <string, string>, MemberInfo> GetPropertiesCache(Type targetType)
            {
                if (TypeCache.TryGetValue(targetType, out var current))
                {
                    return(current);
                }

                var fields =
                    new List <MemberInfo>(PropertyTypeCache.RetrieveAllProperties(targetType).Where(p => p.CanRead));

                // If the target is a struct (value type) navigate the fields.
                if (targetType.IsValueType())
                {
                    fields.AddRange(FieldTypeCache.RetrieveAllFields(targetType));
                }

                var value = fields
                            .ToDictionary(
                    x => Tuple.Create(x.Name,
                                      x.GetCustomAttribute <JsonPropertyAttribute>()?.PropertyName ?? x.Name),
                    x => x);

                TypeCache.TryAdd(targetType, value);

                return(value);
            }
Ejemplo n.º 18
0
        /// <summary>
        /// Determines whether this instance can delete the specified item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="checkAttributeUsage">if set to <c>true</c> [check attribute usage].</param>
        /// <param name="errorMessage">The error message.</param>
        /// <returns>
        ///   <c>true</c> if this instance can delete the specified item; otherwise, <c>false</c>.
        /// </returns>
        public bool CanDelete(AttributeMatrixTemplate item, bool checkAttributeUsage, out string errorMessage)
        {
            if (!this.CanDelete(item, out errorMessage))
            {
                return(false);
            }
            else
            {
                if (checkAttributeUsage)
                {
                    // check if any MatrixAttributes are using this AttributeMatrixTemplate
                    var matrixFieldTypeId    = FieldTypeCache.Read <MatrixFieldType>().Id;
                    var qualifierKey         = MatrixFieldType.ATTRIBUTE_MATRIX_TEMPLATE;
                    var qualifierValue       = item.Id.ToString();
                    var usedAsMatrixTemplate = new AttributeService(new RockContext()).Queryable()
                                               .Where(a => a.FieldTypeId == matrixFieldTypeId)
                                               .Any(a => a.AttributeQualifiers.Any(q => q.Key == qualifierKey && q.Value == qualifierValue));
                    if (usedAsMatrixTemplate)
                    {
                        errorMessage = string.Format("This {0} is assigned to an {1}.", AttributeMatrixTemplate.FriendlyTypeName, Rock.Model.Attribute.FriendlyTypeName);
                        return(false);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Gs the marketing campaign ad attribute type_ show edit.
        /// </summary>
        /// <param name="attributeId">The attribute id.</param>
        protected void gItemAttributes_ShowEdit(Guid attributeGuid)
        {
            Attribute attribute;

            if (attributeGuid.Equals(Guid.Empty))
            {
                attribute                     = new Attribute();
                attribute.FieldTypeId         = FieldTypeCache.Read(Rock.SystemGuid.FieldType.TEXT).Id;
                edtItemAttributes.ActionTitle = ActionTitle.Add(tbName.Text + " Item Attribute");
            }
            else
            {
                attribute = ItemAttributesState.First(a => a.Guid.Equals(attributeGuid));
                edtItemAttributes.ActionTitle = ActionTitle.Edit(tbName.Text + " Item Attribute");
            }

            edtItemAttributes.ReservedKeyNames = ItemAttributesState.Where(a => !a.Guid.Equals(attributeGuid)).Select(a => a.Key).ToList();

            edtItemAttributes.SetAttributeProperties(attribute, typeof(ContentChannelItem));

            // always enable the display of the indexing option as the channel decides whether or not to index not the type
            edtItemAttributes.IsIndexingEnabledVisible = true;

            ShowDialog("ItemAttributes", true);
        }
Ejemplo n.º 20
0
            private static Dictionary <Tuple <string, string>, MemberInfo> GetPropertiesCache(Type targetType)
            {
                if (TypeCache.ContainsKey(targetType))
                {
                    return(TypeCache[targetType]);
                }

                var fields = new List <MemberInfo>();

                // If the target is a struct (value type) navigate the fields.
                if (targetType.IsValueType())
                {
                    fields.AddRange(FieldTypeCache.RetrieveAllFields(targetType));
                }

                // then incorporate the properties
                fields.AddRange(PropertyTypeCache.RetrieveAllProperties(targetType).Where(p => p.CanRead));

                TypeCache[targetType] = fields
                                        .ToDictionary(
                    x => new Tuple <string, string>(x.Name,
                                                    x.GetCustomAttribute <JsonPropertyAttribute>()?.PropertyName ?? x.Name),
                    x => x);

                return(TypeCache[targetType]);
            }
        /// <summary>
        /// Sets the form.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="workflowTypeAttributes">The workflow type attributes.</param>
        public void SetForm(WorkflowActionForm value, Dictionary <Guid, Rock.Model.Attribute> workflowTypeAttributes)
        {
            EnsureChildControls();

            if (value != null)
            {
                _hfFormGuid.Value = value.Guid.ToString();
                _ddlNotificationSystemEmail.SetValue(value.NotificationSystemEmailId);
                _cbIncludeActions.Checked = value.IncludeActionsInNotification;
                _ceHeaderText.Text        = value.Header;
                _ceFooterText.Text        = value.Footer;
                _falActions.Value         = value.Actions;
                _cbAllowNotes.Checked     = value.AllowNotes.HasValue && value.AllowNotes.Value;

                // Remove any existing rows (shouldn't be any)
                foreach (var attributeRow in Controls.OfType <WorkflowFormAttributeRow>())
                {
                    Controls.Remove(attributeRow);
                }

                foreach (var formAttribute in value.FormAttributes.OrderBy(a => a.Order))
                {
                    var row = new WorkflowFormAttributeRow();
                    row.AttributeGuid = formAttribute.Attribute.Guid;
                    row.AttributeName = formAttribute.Attribute.Name;
                    row.Guid          = formAttribute.Guid;
                    row.IsVisible     = formAttribute.IsVisible;
                    row.IsEditable    = !formAttribute.IsReadOnly;
                    row.IsRequired    = formAttribute.IsRequired;
                    row.HideLabel     = formAttribute.HideLabel;
                    row.PreHtml       = formAttribute.PreHtml;
                    row.PostHtml      = formAttribute.PostHtml;
                    Controls.Add(row);
                }

                _ddlActionAttribute.Items.Clear();
                _ddlActionAttribute.Items.Add(new ListItem());
                foreach (var attributeItem in workflowTypeAttributes)
                {
                    var fieldType = FieldTypeCache.Get(attributeItem.Value.FieldTypeId);
                    if (fieldType != null && fieldType.Field is Rock.Field.Types.TextFieldType)
                    {
                        var li = new ListItem(attributeItem.Value.Name, attributeItem.Key.ToString());
                        li.Selected = value.ActionAttributeGuid.HasValue && value.ActionAttributeGuid.Value.ToString() == li.Value;
                        _ddlActionAttribute.Items.Add(li);
                    }
                }
            }
            else
            {
                _hfFormGuid.Value = string.Empty;
                _ddlNotificationSystemEmail.SelectedIndex = 0;
                _cbIncludeActions.Checked = true;
                _ceHeaderText.Text        = string.Empty;
                _ceFooterText.Text        = string.Empty;
                _falActions.Value         = "Submit^^^Your information has been submitted successfully.";
                _ddlNotificationSystemEmail.SelectedIndex = 0;
                _cbAllowNotes.Checked = false;
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            errorMessages = new List <string>();

            if (action.Activity.Workflow.InitiatorPersonAliasId.HasValue)
            {
                var personAlias = new PersonAliasService(rockContext).Get(action.Activity.Workflow.InitiatorPersonAliasId.Value);
                if (personAlias != null)
                {
                    // Get the attribute to set
                    Guid guid = GetAttributeValue(action, "PersonAttribute").AsGuid();
                    if (!guid.IsEmpty())
                    {
                        var personAttribute = AttributeCache.Read(guid, rockContext);
                        if (personAttribute != null)
                        {
                            // If this is a person type attribute
                            if (personAttribute.FieldTypeId == FieldTypeCache.Read(SystemGuid.FieldType.PERSON.AsGuid(), rockContext).Id)
                            {
                                SetWorkflowAttributeValue(action, guid, personAlias.Guid.ToString());
                            }
                            else if (personAttribute.FieldTypeId == FieldTypeCache.Read(SystemGuid.FieldType.TEXT.AsGuid(), rockContext).Id)
                            {
                                SetWorkflowAttributeValue(action, guid, personAlias.Person.FullName);
                            }
                        }
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Saves a <see cref="Rock.Model.Person">Person's</see> user preference setting by key.
        /// </summary>
        /// <param name="person">The <see cref="Rock.Model.Person"/> who the preference value belongs to.</param>
        /// <param name="key">A <see cref="System.String"/> representing the key (name) of the preference setting.</param>
        /// <param name="value">The value.</param>
        public static void SaveUserPreference(Person person, string key, string value)
        {
            int?PersonEntityTypeId = Rock.Web.Cache.EntityTypeCache.Read(Person.USER_VALUE_ENTITY).Id;

            using (var rockContext = new RockContext())
            {
                var attributeService = new Model.AttributeService(rockContext);
                var attribute        = attributeService.Get(PersonEntityTypeId, string.Empty, string.Empty, key);

                if (attribute == null)
                {
                    var fieldTypeService = new Model.FieldTypeService(rockContext);
                    var fieldType        = FieldTypeCache.Read(Rock.SystemGuid.FieldType.TEXT.AsGuid());

                    attribute              = new Model.Attribute();
                    attribute.IsSystem     = false;
                    attribute.EntityTypeId = PersonEntityTypeId;
                    attribute.EntityTypeQualifierColumn = string.Empty;
                    attribute.EntityTypeQualifierValue  = string.Empty;
                    attribute.Key          = key;
                    attribute.Name         = key;
                    attribute.IconCssClass = string.Empty;
                    attribute.DefaultValue = string.Empty;
                    attribute.IsMultiValue = false;
                    attribute.IsRequired   = false;
                    attribute.Description  = string.Empty;
                    attribute.FieldTypeId  = fieldType.Id;
                    attribute.Order        = 0;

                    attributeService.Add(attribute);
                    rockContext.SaveChanges();
                }

                var attributeValueService = new Model.AttributeValueService(rockContext);
                var attributeValue        = attributeValueService.GetByAttributeIdAndEntityId(attribute.Id, person.Id);

                if (string.IsNullOrWhiteSpace(value))
                {
                    // Delete existing value if no existing value
                    if (attributeValue != null)
                    {
                        attributeValueService.Delete(attributeValue);
                    }
                }
                else
                {
                    if (attributeValue == null)
                    {
                        attributeValue             = new Model.AttributeValue();
                        attributeValue.AttributeId = attribute.Id;
                        attributeValue.EntityId    = person.Id;
                        attributeValueService.Add(attributeValue);
                    }
                    attributeValue.Value = value;
                }

                rockContext.SaveChanges();
            }
        }
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (Page.IsPostBack)
            {
                // create dynamic controls
                FieldTypeCache fieldType = FieldTypeCache.Read(hfSingleValueFieldTypeId.Value.AsInteger());
                if (fieldType != null)
                {
                    var entityTypeEditControl = fieldType.Field.EditControl(new Dictionary <string, Rock.Field.ConfigurationValue>(), "entityTypeEditControl");
                    phEntityTypeEntityIdValue.Controls.Add(entityTypeEditControl);
                    if (entityTypeEditControl is IRockControl)
                    {
                        (entityTypeEditControl as IRockControl).Label = fieldType.Name;
                    }
                }
            }

            if (!Page.IsPostBack)
            {
                int?metricValueId = PageParameter("MetricValueId").AsIntegerOrNull();

                // in case called with MetricId as the parent id parameter
                int?metricId = PageParameter("MetricId").AsIntegerOrNull();

                // in case called with MetricCategoryId as the parent id parameter
                int?           metricCategoryId = PageParameter("MetricCategoryId").AsIntegerOrNull();
                MetricCategory metricCategory   = null;
                if (metricCategoryId.HasValue)
                {
                    if (metricCategoryId.Value > 0)
                    {
                        // editing a metric, but get the metricId from the metricCategory
                        metricCategory = new MetricCategoryService(new RockContext()).Get(metricCategoryId.Value);
                        if (metricCategory != null)
                        {
                            metricId = metricCategory.MetricId;
                        }
                    }
                    else
                    {
                        // adding a new metric. Block will (hopefully) not be shown
                        metricId = 0;
                    }
                }

                hfMetricCategoryId.Value = metricCategoryId.ToString();

                if (metricValueId.HasValue)
                {
                    ShowDetail(metricValueId.Value, metricId);
                }
                else
                {
                    pnlDetails.Visible = false;
                }
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Shows the edit.
        /// </summary>
        /// <param name="attributeId">The attribute id.</param>
        protected void ShowEdit(int attributeId)
        {
            var attributeModel = new AttributeService().Get(attributeId);

            if (attributeModel == null)
            {
                lAttributeTitle.Text = ("Add Attribute").FormatAsHtmlTitle();

                attributeModel             = new Rock.Model.Attribute();
                attributeModel.FieldTypeId = FieldTypeCache.Read(Rock.SystemGuid.FieldType.TEXT).Id;

                if (!_configuredType)
                {
                    int entityTypeId = int.MinValue;
                    if (int.TryParse(rFilter.GetUserPreference("Entity Type"), out entityTypeId) && entityTypeId > 0)
                    {
                        attributeModel.EntityTypeId = entityTypeId;
                    }
                }

                List <int> selectedCategoryIds = cpCategoriesFilter.SelectedValuesAsInt().ToList();
                new CategoryService().Queryable().Where(c => selectedCategoryIds.Contains(c.Id)).ToList().ForEach(c =>
                                                                                                                  attributeModel.Categories.Add(c));
                edtAttribute.ActionTitle = Rock.Constants.ActionTitle.Add(Rock.Model.Attribute.FriendlyTypeName);
            }
            else
            {
                edtAttribute.ActionTitle = Rock.Constants.ActionTitle.Edit(Rock.Model.Attribute.FriendlyTypeName);
                lAttributeTitle.Text     = ("Edit " + attributeModel.Name).FormatAsHtmlTitle();
            }

            Type type = null;

            if (_entityTypeId.HasValue)
            {
                type = EntityTypeCache.Read(_entityTypeId.Value).GetEntityType();
            }
            edtAttribute.SetAttributeProperties(attributeModel, type);

            if (_configuredType)
            {
                ddlAttrEntityType.Visible    = false;
                tbAttrQualifierField.Visible = false;
                tbAttrQualifierValue.Visible = false;
            }
            else
            {
                ddlAttrEntityType.Visible    = true;
                tbAttrQualifierField.Visible = true;
                tbAttrQualifierValue.Visible = true;

                ddlAttrEntityType.SetValue(attributeModel.EntityTypeId.HasValue ? attributeModel.EntityTypeId.Value.ToString() : "0");
                tbAttrQualifierField.Text = attributeModel.EntityTypeQualifierColumn;
                tbAttrQualifierValue.Text = attributeModel.EntityTypeQualifierValue;
            }

            pnlList.Visible    = false;
            pnlDetails.Visible = true;
        }
Ejemplo n.º 26
0
 /// <summary>
 /// Sets the workflow RequestStatus attribute.
 /// </summary>
 /// <param name="workflow">The workflow.</param>
 /// <param name="rockContext">The rock context.</param>
 /// <param name="requestStatus">The request status.</param>
 private void UpdateWorkflowRequestStatus(Model.Workflow workflow, RockContext rockContext, string requestStatus)
 {
     if (SaveAttributeValue(workflow, "RequestStatus", requestStatus,
                            FieldTypeCache.Get(Rock.SystemGuid.FieldType.TEXT.AsGuid()), rockContext, null))
     {
         rockContext.SaveChanges();
     }
 }
Ejemplo n.º 27
0
        /// <summary>
        /// Displays the edit list.
        /// </summary>
        private void DisplayEditList()
        {
            lEditHeader.Text = GetAttributeValue("EditHeader");
            lEditFooter.Text = GetAttributeValue("EditFooter");

            if (_definedType != null)
            {
                using (var rockContext = new RockContext())
                {
                    var entityType  = EntityTypeCache.Get("Rock.Model.DefinedValue");
                    var definedType = new DefinedTypeService(rockContext).Get(_definedType.Id);
                    if (definedType != null && entityType != null)
                    {
                        var attributeService = new AttributeService(rockContext);
                        var attributes       = new AttributeService(rockContext)
                                               .GetByEntityTypeQualifier(entityType.Id, "DefinedTypeId", definedType.Id.ToString(), false)
                                               .ToList();

                        // Verify (and create if necessary) the "Is Link" attribute
                        if (!attributes.Any(a => a.Key == "IsLink"))
                        {
                            var fieldType = FieldTypeCache.Get(Rock.SystemGuid.FieldType.BOOLEAN);
                            if (entityType != null && fieldType != null)
                            {
                                var attribute = new Rock.Model.Attribute();
                                attributeService.Add(attribute);
                                attribute.EntityTypeId = entityType.Id;
                                attribute.EntityTypeQualifierColumn = "DefinedTypeId";
                                attribute.EntityTypeQualifierValue  = definedType.Id.ToString();
                                attribute.FieldTypeId  = fieldType.Id;
                                attribute.Name         = "Is Link";
                                attribute.Key          = "IsLink";
                                attribute.Description  = "Flag indicating if value is a link (vs Header)";
                                attribute.IsGridColumn = true;
                                attribute.DefaultValue = true.ToString();

                                var qualifier1 = new AttributeQualifier();
                                qualifier1.Key   = "truetext";
                                qualifier1.Value = "Yes";
                                attribute.AttributeQualifiers.Add(qualifier1);

                                var qualifier2 = new AttributeQualifier();
                                qualifier2.Key   = "falsetext";
                                qualifier2.Value = "No";
                                attribute.AttributeQualifiers.Add(qualifier2);

                                rockContext.SaveChanges();
                            }
                        }
                    }
                }

                BindGrid();

                pnlView.Visible = false;
                pnlEdit.Visible = true;
            }
        }
Ejemplo n.º 28
0
        /// <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)
        {
            EnsureChildControls();

            _ddlFieldType.DataSource = FieldTypeCache.All();
            _ddlFieldType.DataBind();

            base.OnInit(e);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Executes the specified workflow action.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            errorMessages = new List <string>();

            // Get the attribute's guid
            Guid guid = GetAttributeValue(action, "Attribute").AsGuid();

            if (!guid.IsEmpty())
            {
                // Get the attribute
                var attribute = AttributeCache.Get(guid, rockContext);
                if (attribute != null)
                {
                    if (attribute.FieldTypeId == FieldTypeCache.Get(SystemGuid.FieldType.PERSON.AsGuid(), rockContext).Id)
                    {
                        // If attribute type is a person, value should be person alias id
                        Guid?personAliasGuid = action.GetWorklowAttributeValue(guid).AsGuidOrNull();
                        if (personAliasGuid.HasValue)
                        {
                            var personAlias = new PersonAliasService(rockContext).Queryable("Person")
                                              .Where(a => a.Guid.Equals(personAliasGuid.Value))
                                              .FirstOrDefault();
                            if (personAlias != null)
                            {
                                action.Activity.AssignedPersonAlias   = personAlias;
                                action.Activity.AssignedPersonAliasId = personAlias.Id;
                                action.Activity.AssignedGroup         = null;
                                action.Activity.AssignedGroupId       = null;
                                action.AddLogEntry(string.Format("Assigned activity to '{0}' ({1})", personAlias.Person.FullName, personAlias.Person.Id));
                                return(true);
                            }
                        }
                    }

                    else if (attribute.FieldTypeId == FieldTypeCache.Get(SystemGuid.FieldType.GROUP.AsGuid(), rockContext).Id)
                    {
                        // If attribute type is a group, value should be group guid
                        Guid?groupGuid = action.GetWorklowAttributeValue(guid).AsGuidOrNull();
                        if (groupGuid.HasValue)
                        {
                            var group = new GroupService(rockContext).Get(groupGuid.Value);
                            if (group != null)
                            {
                                action.Activity.AssignedPersonAlias   = null;
                                action.Activity.AssignedPersonAliasId = null;
                                action.Activity.AssignedGroup         = group;
                                action.Activity.AssignedGroupId       = group.Id;
                                action.AddLogEntry(string.Format("Assigned activity to '{0}' group ({1})", group.Name, group.Id));
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Gets the list of view models that represent all the sections and fields
        /// of a form.
        /// </summary>
        /// <param name="actionForm">The <see cref="WorkflowActionForm"/> to be represented.</param>
        /// <returns>A collection of view models that represent that sections that will be edited.</returns>
        private static List <FormSectionViewModel> GetFormSectionViewModels(WorkflowActionForm actionForm)
        {
            var sectionViewModels = new List <FormSectionViewModel>();

            foreach (var workflowFormSection in actionForm.FormSections.OrderBy(s => s.Order))
            {
                // Create the basic section view model.
                var sectionViewModel = new FormSectionViewModel
                {
                    Guid                 = workflowFormSection.Guid,
                    Description          = workflowFormSection.Description,
                    Fields               = new List <FormFieldViewModel>(),
                    ShowHeadingSeparator = workflowFormSection.ShowHeadingSeparator,
                    Title                = workflowFormSection.Title,
                    Type                 = Rock.Blocks.WorkFlow.FormBuilder.Utility.GetDefinedValueGuid(workflowFormSection.SectionTypeValueId),
                    VisibilityRule       = workflowFormSection.SectionVisibilityRules?.ToViewModel()
                };

                // Get all the form attributes for this section.
                var formAttributes = actionForm.FormAttributes
                                     .Where(a => a.ActionFormSectionId == workflowFormSection.Id)
                                     .ToList();

                // Loop through each form attribute and make a view model out of it.
                foreach (var formAttribute in formAttributes.OrderBy(a => a.Order))
                {
                    var attribute = AttributeCache.Get(formAttribute.AttributeId);
                    var fieldType = FieldTypeCache.Get(attribute.FieldTypeId);

                    if (fieldType == null || fieldType.Field == null)
                    {
                        continue;
                    }

                    sectionViewModel.Fields.Add(new FormFieldViewModel
                    {
                        ConfigurationValues = fieldType.Field.GetPublicConfigurationValues(attribute.ConfigurationValues, Field.ConfigurationValueUsage.Configure, null),
                        DefaultValue        = fieldType.Field.GetPublicEditValue(attribute.DefaultValue, attribute.ConfigurationValues),
                        Description         = attribute.Description,
                        FieldTypeGuid       = fieldType.Guid,
                        Guid           = attribute.Guid,
                        IsHideLabel    = formAttribute.HideLabel,
                        IsRequired     = attribute.IsRequired,
                        IsShowOnGrid   = attribute.IsGridColumn,
                        Key            = attribute.Key,
                        Name           = attribute.Name,
                        Size           = formAttribute.ColumnSize ?? 12,
                        VisibilityRule = formAttribute.FieldVisibilityRules?.ToViewModel()
                    });
                }

                sectionViewModels.Add(sectionViewModel);
            }

            return(sectionViewModels);
        }