Exemple #1
0
        /// <summary>
        /// Update the custom UI to reflect the current settings found in the entity.
        /// </summary>
        /// <param name="attributeEntity">The attribute entity.</param>
        public void ReadSettingsFromEntity(IHasAttributes attributeEntity)
        {
            SetupFormBindings();

            var fieldSettings = attributeEntity.GetAttributeValue(AttributeKeys.FieldSettings);

            if (fieldSettings.IsNotNullOrWhiteSpace())
            {
                this.FieldSettings = JsonConvert.DeserializeObject <List <ContentChannelItemList.FieldSetting> >(fieldSettings);
            }
            BindFieldGrid();

            ddlContentChannel.SelectedValue = attributeEntity.GetAttributeValue(AttributeKeys.ContentChannel);
            nbPageSize.Text                = attributeEntity.GetAttributeValue(AttributeKeys.PageSize);
            cbIncludeFollowing.Checked     = attributeEntity.GetAttributeValue(AttributeKeys.IncludeFollowing).AsBoolean();
            cbCheckItemSecurity.Checked    = attributeEntity.GetAttributeValue(AttributeKeys.CheckItemSecurity).AsBoolean();
            cbShowChildrenOfParent.Checked = attributeEntity.GetAttributeValue(AttributeKeys.ShowChildrenOfParent).AsBoolean();
            var pageCache = PageCache.Get(attributeEntity.GetAttributeValue(AttributeKeys.DetailPage).AsGuid());

            ppDetailPage.SetValue(pageCache != null ? ( int? )pageCache.Id : null);
            hfDataFilterId.Value          = attributeEntity.GetAttributeValue(AttributeKeys.FilterId);
            cbQueryParamFiltering.Checked = attributeEntity.GetAttributeValue(AttributeKeys.QueryParameterFiltering).AsBoolean();
            kvlOrder.Value = attributeEntity.GetAttributeValue(AttributeKeys.Order);

            LoadAttributeListForContentChannel();

            ConfigureChannelSpecificSettings();
        }
Exemple #2
0
        /// <inheritdoc/>
        public void ReadSettingsFromEntity(IHasAttributes attributeEntity)
        {
            // Set the value for the Group Type control.
            var groupTypeGuids = attributeEntity.GetAttributeValue(AttributeKey.GroupTypes)
                                 .SplitDelimitedValues()
                                 .AsGuidList();

            foreach (ListItem li in rlbGroupTypes.Items)
            {
                li.Selected = groupTypeGuids.Contains(li.Value.AsGuid());
            }

            GroupTypeLocations = attributeEntity.GetAttributeValue(AttributeKey.GroupTypesLocationType).FromJsonOrNull <Dictionary <int, int> >() ?? new Dictionary <int, int>();

            BindGroupTypeLocationGrid();
            UpdateAttributeFilterOptions();

            // Set the value for the Attribute Filters control.
            var attributeGuids = attributeEntity.GetAttributeValue(AttributeKey.AttributeFilters)
                                 .SplitDelimitedValues()
                                 .AsGuidList();

            foreach (ListItem li in cblAttributeFilters.Items)
            {
                li.Selected = attributeGuids.Contains(li.Value.AsGuid());
            }
        }
Exemple #3
0
        /// <summary>
        /// Gets the row value.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <param name="condensed">if set to <c>true</c> [condensed].</param>
        /// <param name="formatAsHtml">if set to <c>true</c> [format as HTML].</param>
        /// <returns></returns>
        private object GetRowValue(GridViewRow row, bool condensed, bool formatAsHtml)
        {
            // First try to get an IHasAttributes from the grid's object list
            IHasAttributes dataItem = GetAttributeObject(row);

            if (dataItem == null)
            {
                // If unsuccessful, check to see if row has attributes
                dataItem = row.DataItem as IHasAttributes;
            }

            if (dataItem != null)
            {
                if (dataItem.Attributes == null)
                {
                    dataItem.LoadAttributes();
                }

                AttributeCache attrib   = null;
                string         rawValue = string.Empty;

                bool exists = dataItem.Attributes.ContainsKey(this.DataField);
                if (exists)
                {
                    attrib   = dataItem.Attributes[this.DataField];
                    rawValue = dataItem.GetAttributeValue(this.DataField);
                }
                else
                {
                    if (AttributeId.HasValue)
                    {
                        attrib = dataItem.Attributes.Where(a => a.Value.Id == AttributeId.Value).Select(a => a.Value).FirstOrDefault();
                        if (attrib != null)
                        {
                            exists   = true;
                            rawValue = dataItem.GetAttributeValue(attrib.Key);
                        }
                    }
                }

                if (exists)
                {
                    if (formatAsHtml)
                    {
                        string resultHtml = attrib.FieldType.Field.FormatValueAsHtml(null, rawValue, attrib.QualifierValues, condensed);
                        return(new HtmlString(resultHtml ?? string.Empty));
                    }
                    else
                    {
                        string result = attrib.FieldType.Field.FormatValue(null, rawValue, attrib.QualifierValues, condensed);
                        return(result ?? string.Empty);
                    }
                }
            }

            return(null);
        }
Exemple #4
0
        /// <summary>
        /// Gets the mobile attribute values.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="attributes">The attributes.</param>
        /// <returns></returns>
        public static Dictionary <string, MobileAttributeValue> GetMobileAttributeValues(IHasAttributes entity, IEnumerable <AttributeCache> attributes)
        {
            var mobileAttributeValues = new Dictionary <string, MobileAttributeValue>();

            if (entity.Attributes == null)
            {
                entity.LoadAttributes();
            }

            foreach (var attribute in attributes)
            {
                var value          = entity.GetAttributeValue(attribute.Key);
                var formattedValue = entity.AttributeValues.ContainsKey(attribute.Key) ? entity.AttributeValues[attribute.Key].ValueFormatted : attribute.DefaultValueAsFormatted;

                var mobileAttributeValue = new MobileAttributeValue
                {
                    Value          = value,
                    FormattedValue = formattedValue
                };

                mobileAttributeValues.AddOrReplace(attribute.Key, mobileAttributeValue);
            }

            return(mobileAttributeValues);
        }
Exemple #5
0
            /// <summary>
            /// Update the custom UI to reflect the current settings found in the entity.
            /// </summary>
            /// <param name="attributeEntity">The attribute entity.</param>
            /// <param name="control">The control returned by GetCustomSettingsControl() method.</param>
            public override void ReadSettingsFromEntity(IHasAttributes attributeEntity, Control control)
            {
                var jfBuilder = ( JsonFieldsBuilder )control.Controls[0];

                jfBuilder.FieldSettings = attributeEntity.GetAttributeValue(AttributeKeys.AdditionalFields)
                                          .FromJsonOrNull <List <FieldSetting> >();
            }
Exemple #6
0
        /// <summary>
        /// Gets the row value.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <returns></returns>
        private object GetRowValue(GridViewRow row)
        {
            // First try to get an IHasAttributes from the grid's object list
            IHasAttributes dataItem = GetAttributeObject(row);

            if (dataItem == null)
            {
                // If unsuccessful, check to see if row has attributes
                dataItem = row.DataItem as IHasAttributes;
            }

            if (dataItem != null)
            {
                if (dataItem.Attributes == null)
                {
                    dataItem.LoadAttributes();
                }

                bool exists = dataItem.Attributes.ContainsKey(this.DataField);
                if (exists)
                {
                    var    attrib     = dataItem.Attributes[this.DataField];
                    string rawValue   = dataItem.GetAttributeValue(this.DataField);
                    string resultHtml = attrib.FieldType.Field.FormatValueAsHtml(null, rawValue, attrib.QualifierValues, Condensed);
                    return(new HtmlString(resultHtml ?? string.Empty));
                }
            }

            return(null);
        }
Exemple #7
0
        /// <summary>
        /// Gets the labels for an item (person, grouptype, group, location).
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="existingLabels">The existing labels.</param>
        /// <returns></returns>
        public virtual List <KioskLabel> GetLabels(IHasAttributes item, List <KioskLabel> existingLabels)
        {
            var labels = new List <KioskLabel>(existingLabels);

            if (item.Attributes == null)
            {
                item.LoadAttributes();
            }

            foreach (var attribute in item.Attributes.OrderBy(a => a.Value.Order))
            {
                if (attribute.Value.FieldType.Class == typeof(Rock.Field.Types.LabelFieldType).FullName)
                {
                    Guid?binaryFileGuid = item.GetAttributeValue(attribute.Key).AsGuidOrNull();
                    if (binaryFileGuid != null)
                    {
                        if (!labels.Any(l => l.Guid == binaryFileGuid.Value))
                        {
                            var labelCache = KioskLabel.Read(binaryFileGuid.Value);
                            labelCache.Order = attribute.Value.Order;
                            if (labelCache != null && (
                                    labelCache.LabelType == KioskLabelType.Family ||
                                    labelCache.LabelType == KioskLabelType.Person ||
                                    labelCache.LabelType == KioskLabelType.Location))
                            {
                                labels.Add(labelCache);
                            }
                        }
                    }
                }
            }

            return(labels);
        }
Exemple #8
0
        public static Dictionary <string, string> GetPublicAttributeValuesForEdit(this IHasAttributes entity, Person currentPerson, bool enforceSecurity = true)
        {
            if (entity == null || entity.Attributes == null)
            {
                return(new Dictionary <string, string>());
            }

            return(entity.Attributes
                   .Select(a => new
            {
                Value = entity.GetAttributeValue(a.Key),
                Attribute = a.Value
            })
                   .Where(av => !enforceSecurity || av.Attribute.IsAuthorized(Rock.Security.Authorization.VIEW, currentPerson))
                   .ToDictionary(av => av.Attribute.Key, av => PublicAttributeHelper.GetPublicEditValue(av.Attribute, av.Value)));
        }
Exemple #9
0
        /// <summary>
        /// Gets the row value.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <param name="condensed">if set to <c>true</c> [condensed].</param>
        /// <param name="formatAsHtml">if set to <c>true</c> [format as HTML].</param>
        /// <returns></returns>
        private object GetRowValue(GridViewRow row, bool condensed, bool formatAsHtml)
        {
            // First try to get an IHasAttributes from the grid's object list
            IHasAttributes dataItem = GetAttributeObject(row);

            if (dataItem == null)
            {
                // If unsuccessful, check to see if row has attributes
                dataItem = row.DataItem as IHasAttributes;
            }

            if (dataItem != null)
            {
                if (dataItem.Attributes == null)
                {
                    dataItem.LoadAttributes();
                }

                AttributeCache attrib   = null;
                string         rawValue = string.Empty;

                bool exists = dataItem.Attributes.ContainsKey(this.DataField);
                if (exists)
                {
                    attrib   = dataItem.Attributes[this.DataField];
                    rawValue = dataItem.GetAttributeValue(this.DataField);
                }
                else
                {
                    if (AttributeId.HasValue)
                    {
                        attrib = dataItem.Attributes.Where(a => a.Value.Id == AttributeId.Value).Select(a => a.Value).FirstOrDefault();
                        if (attrib != null)
                        {
                            exists   = true;
                            rawValue = dataItem.GetAttributeValue(attrib.Key);
                        }
                    }
                }

                if (exists)
                {
                    if (attrib?.FieldType?.Field is BooleanFieldType)
                    {
                        if (this.ItemStyle.HorizontalAlign != HorizontalAlign.Center)
                        {
                            this.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                        }

                        var boolValue = rawValue.AsBoolean();
                        return(boolValue ? "<i class=\"fa fa-check\"></i>" : string.Empty);
                    }

                    if (formatAsHtml)
                    {
                        string resultHtml = attrib.FieldType.Field.FormatValueAsHtml(null, attrib.EntityTypeId, dataItem.Id, rawValue, attrib.QualifierValues, condensed);
                        return(new HtmlString(resultHtml ?? string.Empty));
                    }
                    else
                    {
                        string result = attrib.FieldType.Field.FormatValue(null, attrib.EntityTypeId, dataItem.Id, rawValue, attrib.QualifierValues, condensed);
                        return(result ?? string.Empty);
                    }
                }
            }

            return(null);
        }
Exemple #10
0
 private string GetFileUrlOrNull(IHasAttributes item, string attributeKey)
 {
     return(_binaryFileService.Get(item.GetAttributeValue(attributeKey).AsGuid())?.Path);
 }
Exemple #11
0
        /// <summary>
        /// Builds the attribute fields.
        /// </summary>
        /// <param name="entity">The entity whose attribute values are going to be edited.</param>
        /// <param name="attributes">The attributes to be displayed.</param>
        /// <param name="postbackParameters">The postback parameters to request, key is node name and value is property path.</param>
        /// <param name="includeHeader">if set to <c>true</c> [include header].</param>
        /// <param name="person">If not null then security will be enforced for this person.</param>
        /// <returns>
        /// A XAML string that contains any attribute fields as well as the header text.
        /// </returns>
        public static string GetEditAttributesXaml(IHasAttributes entity, List <AttributeCache> attributes = null, Dictionary <string, string> postbackParameters = null, bool includeHeader = true, Person person = null)
        {
            if (entity.Attributes == null)
            {
                entity.LoadAttributes();
            }

            attributes = attributes ?? entity.Attributes.Values.ToList();

            if (!attributes.Any())
            {
                return(string.Empty);
            }

            var sb = new StringBuilder();

            sb.AppendLine("<StackLayout Spacing=\"0\">");

            if (includeHeader)
            {
                sb.AppendLine("<Label Text=\"Attributes\" StyleClass=\"h1\" />");
                sb.AppendLine("<BoxView Color=\"#888\" HeightRequest=\"1\" Margin=\"0 0 12 0\" />");
            }

            foreach (var attribute in attributes)
            {
                var label = attribute.AbbreviatedName.IsNotNullOrWhiteSpace() ? attribute.AbbreviatedName : attribute.Name;

                if (person != null && !attribute.IsAuthorized(Authorization.EDIT, person))
                {
                    if (person == null || attribute.IsAuthorized(Authorization.VIEW, person))
                    {
                        sb.AppendLine(GetReadOnlyFieldXaml(label, ""));
                    }
                }
                else
                {
                    var fieldName           = $"attribute_{attribute.Id}";
                    var configurationValues = attribute.QualifierValues
                                              .ToDictionary(a => a.Key, a => a.Value.Value)
                                              .ToJson();

                    sb.AppendLine(GetSingleFieldXaml($"<Rock:AttributeValueEditor x:Name=\"{fieldName}\" Label=\"{label}\" IsRequired=\"{attribute.IsRequired}\" FieldType=\"{attribute.FieldType.Class}\" ConfigurationValues=\"{{}}{configurationValues.EncodeXml( true )}\" Value=\"{entity.GetAttributeValue( attribute.Key ).EncodeXml( true )}\" />"));
                    postbackParameters.Add(fieldName, "Value");
                }
            }

            sb.AppendLine("</StackLayout>");

            return(sb.ToString());
        }
        protected void SaveDetails()
        {
            var      checkValue = false;
            CheckBox check      = ( CheckBox )fsAttributes.FindControl("SimpleCheckBox");

            if (check != null && check.Checked)
            {
                checkValue = true;
            }

            IHasAttributes entity = ContextEntity() as IHasAttributes;

            var rockContext          = new RockContext();
            var sourceAttributeKey   = GetAttributeValue("SourceEntityAttributeKey");
            var sourceAttributeValue = entity.GetAttributeValue(sourceAttributeKey);
            var attributeService     = new AttributeService(rockContext);
            var targetAttribute      = attributeService.GetByGuids(new List <Guid>()
            {
                sourceAttributeValue.AsGuid()
            }).ToList().FirstOrDefault();

            int personEntityTypeId = EntityTypeCache.Get(typeof(Person)).Id;

            var changes = new History.HistoryChangeList();

            var attribute = AttributeCache.Get(targetAttribute);

            if (CurrentPerson != null)
            {
                Control attributeControl = fsAttributes.FindControl(string.Format("attribute_field_{0}", attribute.Id));
                if (GetAttributeValue("CheckboxMode").AsBoolean(false) || attributeControl != null)
                {
                    string originalValue = CurrentPerson.GetAttributeValue(attribute.Key);
                    string newValue      = string.Empty;

                    if (GetAttributeValue("CheckboxMode").AsBoolean(false))
                    {
                        var valueMode = GetAttributeValue("CheckboxAttributeValueMode");
                        if (valueMode == "Date")
                        {
                            if (checkValue)
                            {
                                newValue = RockDateTime.Now.ToString();
                            }
                            else
                            {
                                newValue = string.Empty;
                            }
                        }
                        else if (valueMode == "Boolean")
                        {
                            if (checkValue)
                            {
                                newValue = "True";
                            }
                            else
                            {
                                newValue = "False";
                            }
                        }
                    }
                    else
                    {
                        newValue = attribute.FieldType.Field.GetEditValue(attributeControl, attribute.QualifierValues);
                    }

                    Rock.Attribute.Helper.SaveAttributeValue(CurrentPerson, attribute, newValue, rockContext);

                    // Check for changes to write to history
                    if ((originalValue ?? string.Empty).Trim() != (newValue ?? string.Empty).Trim())
                    {
                        string formattedOriginalValue = string.Empty;
                        if (!string.IsNullOrWhiteSpace(originalValue))
                        {
                            formattedOriginalValue = attribute.FieldType.Field.FormatValue(null, originalValue, attribute.QualifierValues, false);
                        }

                        string formattedNewValue = string.Empty;
                        if (!string.IsNullOrWhiteSpace(newValue))
                        {
                            formattedNewValue = attribute.FieldType.Field.FormatValue(null, newValue, attribute.QualifierValues, false);
                        }

                        History.EvaluateChange(changes, attribute.Name, formattedOriginalValue, formattedNewValue, attribute.FieldType.Field.IsSensitive());
                    }
                }
            }

            if (changes.Any())
            {
                HistoryService.SaveChanges(rockContext, typeof(Person), Rock.SystemGuid.Category.HISTORY_PERSON_DEMOGRAPHIC_CHANGES.AsGuid(),
                                           CurrentPerson.Id, changes);
            }

            string linkedPage = GetAttributeValue("RedirectPage");

            if (string.IsNullOrWhiteSpace(linkedPage))
            {
                ShowDetails();
            }
            else
            {
                var pageParams = new Dictionary <string, string>();
                pageParams.Add("av", "updated");
                var pageReference = new Rock.Web.PageReference(linkedPage, pageParams);
                Response.Redirect(pageReference.BuildUrl(), false);
            }
        }
        /// <summary>
        /// Shows the read-only attribute values.
        /// </summary>
        protected void ShowDetails()
        {
            var loadAttributeValue = GetAttributeValue("LoadAttributeValue").AsBoolean(false);

            ltTitle.Text = GetAttributeValue("PanelHeading");
            btnSave.Text = GetAttributeValue("SaveButtonText");

            IHasAttributes entity = ContextEntity() as IHasAttributes;

            if (entity != null && CurrentPerson != null)
            {
                var rockContext = new RockContext();

                if (entity.Attributes == null)
                {
                    entity.LoadAttributes();
                }

                if (CurrentPerson.Attributes == null)
                {
                    CurrentPerson.LoadAttributes();
                }

                var sourceAttributeKey   = GetAttributeValue("SourceEntityAttributeKey");
                var sourceAttributeValue = entity.GetAttributeValue(sourceAttributeKey);
                var attributeService     = new AttributeService(rockContext);
                var targetAttribute      = attributeService.GetByGuids(new List <Guid>()
                {
                    sourceAttributeValue.AsGuid()
                }).ToList().FirstOrDefault();

                fsAttributes.Controls.Clear();

                string validationGroup = string.Format("vgAttributeValues_{0}", this.BlockId);
                btnSave.ValidationGroup = validationGroup;

                var    attribute      = AttributeCache.Get(targetAttribute);
                string attributeValue = CurrentPerson.GetAttributeValue(attribute.Key);
                string formattedValue = string.Empty;

                if (GetAttributeValue("CheckboxMode").AsBoolean(false))
                {
                    var      checkboxText = GetAttributeValue("CheckboxText");
                    CheckBox checkbox     = new CheckBox();
                    checkbox.ID   = "SimpleCheckBox";
                    checkbox.Text = String.IsNullOrWhiteSpace(checkboxText) ? attribute.Name : checkboxText;

                    if (GetAttributeValue("InstantSave").AsBoolean(false))
                    {
                        checkbox.AutoPostBack = true;

                        checkbox.CheckedChanged += new EventHandler(this.Check_Change);
                        btnSave.Visible          = false;
                    }

                    if (loadAttributeValue && !string.IsNullOrWhiteSpace(attributeValue) && attributeValue.AsBoolean(true))
                    {
                        checkbox.Checked = true;
                    }

                    fsAttributes.Controls.Add(checkbox);
                }
                else
                {
                    attribute.AddControl(fsAttributes.Controls, attributeValue, validationGroup, loadAttributeValue, true);
                }

                pnlDetails.Visible = true;
            }
        }