Exemplo n.º 1
0
        /// <summary>
        /// Shows the edit value.
        /// </summary>
        /// <param name="attributeId">The attribute id.</param>
        /// <param name="setValues">if set to <c>true</c> [set values].</param>
        protected void ShowEditValue(int attributeId, bool setValues)
        {
            if (_displayValueEdit)
            {
                var attribute = Rock.Web.Cache.AttributeCache.Read(attributeId);

                hfIdValues.Value = attribute.Id.ToString();
                lCaption.Text    = attribute.Name;

                AttributeValueService attributeValueService = new AttributeValueService();
                var attributeValue = attributeValueService.GetByAttributeIdAndEntityId(attributeId, _entityId).FirstOrDefault();

                var fieldType = Rock.Web.Cache.FieldTypeCache.Read(attribute.FieldType.Id);

                Control editControl = fieldType.Field.EditControl(attribute.QualifierValues);
                editControl.ID           = string.Format("attribute_field_{0}", attribute.Id);
                editControl.ClientIDMode = ClientIDMode.AutoID;

                if (setValues && attributeValue != null)
                {
                    fieldType.Field.SetEditValue(editControl, attribute.QualifierValues, attributeValue.Value);
                }

                phEditControl.Controls.Clear();
                phEditControl.Controls.Add(editControl);

                modalDetails.Show();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Saves the attribute value.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        private void SaveAttributeValue(RockContext context, string key, string value)
        {
            var attributeSvc      = new AttributeService(context);
            var attribute         = attributeSvc.GetGlobalAttribute(key);
            var attributeValueSvc = new AttributeValueService(context);
            var attributeValue    = attributeValueSvc.GetByAttributeIdAndEntityId(attribute.Id, null);

            if (attributeValue == null && !String.IsNullOrWhiteSpace(value))
            {
                attributeValue             = new AttributeValue();
                attributeValue.AttributeId = attribute.Id;
                attributeValue.EntityId    = null;
                attributeValueSvc.Add(attributeValue);
            }

            if (attributeValue == null || value.Equals(attributeValue.Value))
            {
                return;
            }

            if (String.IsNullOrWhiteSpace(value))
            {
                attributeValueSvc.Delete(attributeValue);
            }
            else
            {
                attributeValue.Value = value;
            }

            context.SaveChanges();
        }
        protected override void OnLoad(EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                RockContext           rockContext      = new RockContext();
                AttributeValueService attributeService = new AttributeValueService(rockContext);
                var homePageAttributeCache             = GlobalAttributesCache.Read(rockContext).Attributes.Where(a => a.Key == "AvalancheHomePage").FirstOrDefault();
                var homePageAttribue = attributeService.GetByAttributeIdAndEntityId(homePageAttributeCache.Id, null);
                if (homePageAttribue != null)
                {
                    var homePageAttribueValue = homePageAttribue.Value;
                    ppHome.SetValue(homePageAttribueValue.AsInteger());
                }

                var menuPageAttributeCache = GlobalAttributesCache.Read(rockContext).Attributes.Where(a => a.Key == "AvalancheMenuPage").FirstOrDefault();
                var menuPageAttribute      = attributeService.GetByAttributeIdAndEntityId(menuPageAttributeCache.Id, null);
                if (menuPageAttribute != null)
                {
                    var menupageAttributeValue = menuPageAttribute.Value;
                    ppMenu.SetValue(menupageAttributeValue.AsInteger());
                }
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            RockContext           rockContext           = new RockContext();
            AttributeValueService attributeValueService = new AttributeValueService(rockContext);

            var homePageAttributeCache = GlobalAttributesCache.Read(rockContext).Attributes.Where(a => a.Key == "AvalancheHomePage").FirstOrDefault();
            var homePageAttribute      = attributeValueService.GetByAttributeIdAndEntityId(homePageAttributeCache.Id, null);

            if (homePageAttribute == null)
            {
                homePageAttribute = new AttributeValue()
                {
                    AttributeId = homePageAttributeCache.Id
                };
                attributeValueService.Add(homePageAttribute);
            }

            homePageAttribute.Value = ppHome.SelectedValue;


            var menuPageAttributeCache = GlobalAttributesCache.Read(rockContext).Attributes.Where(a => a.Key == "AvalancheMenuPage").FirstOrDefault();
            var menuPageAttribute      = attributeValueService.GetByAttributeIdAndEntityId(menuPageAttributeCache.Id, null);

            if (menuPageAttribute == null)
            {
                menuPageAttribute = new AttributeValue()
                {
                    AttributeId = menuPageAttributeCache.Id
                };
                attributeValueService.Add(menuPageAttribute);
            }
            menuPageAttribute.Value = ppMenu.SelectedValue;

            rockContext.SaveChanges();
            NavigateToParentPage();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Handles the SaveClick event of the mdAttributeValue 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 mdAttributeValue_SaveClick(object sender, EventArgs e)
        {
            if (_displayValueEdit)
            {
                // If page is not valid, exit and allow validators to display error messages.
                Page.Validate();

                if (!Page.IsValid)
                {
                    return;
                }

                int attributeId = 0;
                if (hfIdValues.Value != string.Empty && !int.TryParse(hfIdValues.Value, out attributeId))
                {
                    attributeId = 0;
                }

                if (attributeId != 0 && phEditControls.Controls.Count > 0)
                {
                    var attribute = Rock.Web.Cache.AttributeCache.Get(attributeId);

                    var rockContext           = new RockContext();
                    var attributeValueService = new AttributeValueService(rockContext);
                    var attributeValue        = attributeValueService.GetByAttributeIdAndEntityId(attributeId, _entityId);
                    if (attributeValue == null)
                    {
                        attributeValue = new AttributeValue
                        {
                            AttributeId = attributeId,
                            EntityId    = _entityId
                        };
                        attributeValueService.Add(attributeValue);
                    }

                    var fieldType = FieldTypeCache.Get(attribute.FieldType.Id);
                    attributeValue.Value = fieldType.Field.GetEditValue(attribute.GetControl(phEditControls.Controls[0]), attribute.QualifierValues);

                    rockContext.SaveChanges();
                }

                hfIdValues.Value = string.Empty;

                HideDialog();
            }

            BindGrid();
        }
        /// <summary>
        /// Adds/Updates any attributes that were defined in web.config 's rockConfig section
        /// This is usually used for Plugin Components that need to get any changed values from web.config before startup
        /// </summary>
        private static void UpdateAttributesFromRockConfig(RockContext rockContext)
        {
            var rockConfig = RockConfig.Config;

            if (rockConfig.AttributeValues.Count > 0)
            {
                foreach (AttributeValueConfig attributeValueConfig in rockConfig.AttributeValues)
                {
                    AttributeService      attributeService      = new AttributeService(rockContext);
                    AttributeValueService attributeValueService = new AttributeValueService(rockContext);
                    var attribute = attributeService.Get(
                        attributeValueConfig.EntityTypeId.AsInteger(),
                        attributeValueConfig.EntityTypeQualifierColumm,
                        attributeValueConfig.EntityTypeQualifierValue,
                        attributeValueConfig.AttributeKey);

                    if (attribute == null)
                    {
                        attribute              = new Rock.Model.Attribute();
                        attribute.FieldTypeId  = FieldTypeCache.Get(new Guid(Rock.SystemGuid.FieldType.TEXT)).Id;
                        attribute.EntityTypeId = attributeValueConfig.EntityTypeId.AsInteger();
                        attribute.EntityTypeQualifierColumn = attributeValueConfig.EntityTypeQualifierColumm;
                        attribute.EntityTypeQualifierValue  = attributeValueConfig.EntityTypeQualifierValue;
                        attribute.Key  = attributeValueConfig.AttributeKey;
                        attribute.Name = attributeValueConfig.AttributeKey.SplitCase();
                        attributeService.Add(attribute);
                        rockContext.SaveChanges();
                    }

                    var attributeValue = attributeValueService.GetByAttributeIdAndEntityId(attribute.Id, attributeValueConfig.EntityId.AsInteger());
                    if (attributeValue == null && !string.IsNullOrWhiteSpace(attributeValueConfig.Value))
                    {
                        attributeValue             = new Rock.Model.AttributeValue();
                        attributeValue.AttributeId = attribute.Id;
                        attributeValue.EntityId    = attributeValueConfig.EntityId.AsInteger();
                        attributeValueService.Add(attributeValue);
                    }

                    if (attributeValue.Value != attributeValueConfig.Value)
                    {
                        attributeValue.Value = attributeValueConfig.Value;
                        rockContext.SaveChanges();
                    }
                }
            }
        }
Exemplo n.º 7
0
        protected void ShowEdit(int attributeId, bool setValues)
        {
            AttributeService attributeService = new AttributeService();
            var attribute = attributeService.Get(attributeId);

            hfId.Value    = attribute.Id.ToString();
            lCaption.Text = attribute.Name;

            AttributeValueService attributeValueService = new AttributeValueService();
            var attributeValue = attributeValueService.GetByAttributeIdAndEntityId(attributeId, _entityId).FirstOrDefault();

            var fieldType = Rock.Web.Cache.FieldType.Read(attribute.FieldTypeId);

            phEditControl.Controls.Clear();
            phEditControl.Controls.Add(fieldType.Field.CreateControl((attributeValue != null ? attributeValue.Value : string.Empty), attribute.Required, setValues));

            modalDetails.Show();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Handles the SaveClick event of the mdAttributeValue 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 mdAttributeValue_SaveClick(object sender, EventArgs e)
        {
            if (_displayValueEdit)
            {
                int attributeId = 0;
                if (hfIdValues.Value != string.Empty && !int.TryParse(hfIdValues.Value, out attributeId))
                {
                    attributeId = 0;
                }

                if (attributeId != 0 && phEditControls.Controls.Count > 0)
                {
                    var attribute = Rock.Web.Cache.AttributeCache.Read(attributeId);

                    var rockContext = new RockContext();
                    AttributeValueService attributeValueService = new AttributeValueService(rockContext);
                    var attributeValue = attributeValueService.GetByAttributeIdAndEntityId(attributeId, _entityId);
                    if (attributeValue == null)
                    {
                        attributeValue             = new Rock.Model.AttributeValue();
                        attributeValue.AttributeId = attributeId;
                        attributeValue.EntityId    = _entityId;
                        attributeValueService.Add(attributeValue);
                    }

                    var fieldType = Rock.Web.Cache.FieldTypeCache.Read(attribute.FieldType.Id);
                    attributeValue.Value = fieldType.Field.GetEditValue(attribute.GetControl(phEditControls.Controls[0]), attribute.QualifierValues);

                    rockContext.SaveChanges();

                    Rock.Web.Cache.AttributeCache.Flush(attributeId);
                    if (!_entityTypeId.HasValue && _entityQualifierColumn == string.Empty && _entityQualifierValue == string.Empty && (!_entityId.HasValue || _entityId.Value == 0))
                    {
                        Rock.Web.Cache.GlobalAttributesCache.Flush();
                    }
                }

                hfIdValues.Value = string.Empty;

                HideDialog();
            }

            BindGrid();
        }
Exemplo n.º 9
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string attributeKey = GetAttributeValue("OAuthConfigAttributeKey");
            Dictionary <string, string> settings = GlobalAttributesCache.Value(attributeKey).AsDictionary();

            settings["OAuthAuthorizePath"]        = "/" + ddlAuthorizeRoute.SelectedValue;
            settings["OAuthLoginPath"]            = "/" + ddlLoginRoute.SelectedValue;
            settings["OAuthLogoutPath"]           = "/" + ddlLogoutRoute.SelectedValue;
            settings["OAuthTokenPath"]            = "/" + ddlTokenRoute.SelectedValue;
            settings["OAuthRequireSsl"]           = cbSSLRequired.Checked.ToString();
            settings["OAuthTokenLifespan"]        = tbTokenLifespan.Text;
            settings["OAuthRefreshTokenLifespan"] = tbRefreshTokenLifespan.Text;

            RockContext      context          = new RockContext();
            AttributeService attributeService = new AttributeService(context);

            Rock.Model.Attribute attribute = attributeService.Queryable().Where(a => a.Key == attributeKey).FirstOrDefault();
            if (attribute == null)
            {
                attribute             = new Rock.Model.Attribute();
                attribute.Name        = "OAuth Settings";
                attribute.Description = "Settings for the OAuth server plugin.";
                attribute.Key         = "OAuthSettings";
                FieldTypeService fieldTypeService = new FieldTypeService(context);
                attribute.FieldType = fieldTypeService.Get(Rock.SystemGuid.FieldType.KEY_VALUE_LIST.AsGuid());
                context.SaveChanges();
            }
            // Update the actual attribute value.
            AttributeValueService attributeValueService = new AttributeValueService(context);
            AttributeValue        attributeValue        = attributeValueService.GetByAttributeIdAndEntityId(attribute.Id, null);

            if (attributeValue == null)
            {
                attributeValue             = new AttributeValue();
                attributeValue.AttributeId = attribute.Id;
                attributeValueService.Add(attributeValue);
            }
            attributeValue.Value = string.Join("|", settings.Select(a => a.Key + "^" + a.Value).ToList());
            context.SaveChanges();

            // Flush the cache(s)
            AttributeCache.Flush(attribute.Id);
            GlobalAttributesCache.Flush();
        }
Exemplo n.º 10
0
        /// <summary>
        /// Handles the SaveClick event of the modalDetails 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 modalDetails_SaveClick(object sender, EventArgs e)
        {
            if (_displayValueEdit)
            {
                int attributeId = 0;
                if (hfIdValues.Value != string.Empty && !int.TryParse(hfIdValues.Value, out attributeId))
                {
                    attributeId = 0;
                }

                if (attributeId != 0 && fsEditControl.Controls.Count > 0)
                {
                    var attribute = Rock.Web.Cache.AttributeCache.Read(attributeId);

                    AttributeValueService attributeValueService = new AttributeValueService();
                    var attributeValue = attributeValueService.GetByAttributeIdAndEntityId(attributeId, _entityId).FirstOrDefault();
                    if (attributeValue == null)
                    {
                        attributeValue             = new Rock.Model.AttributeValue();
                        attributeValue.AttributeId = attributeId;
                        attributeValue.EntityId    = _entityId;
                        attributeValueService.Add(attributeValue, CurrentPersonId);
                    }

                    var fieldType = Rock.Web.Cache.FieldTypeCache.Read(attribute.FieldType.Id);
                    attributeValue.Value = fieldType.Field.GetEditValue(attribute.GetControl(fsEditControl.Controls[0]), attribute.QualifierValues);

                    attributeValueService.Save(attributeValue, CurrentPersonId);

                    Rock.Web.Cache.AttributeCache.Flush(attributeId);
                    if (!_entityTypeId.HasValue && _entityQualifierColumn == string.Empty && _entityQualifierValue == string.Empty && !_entityId.HasValue)
                    {
                        Rock.Web.Cache.GlobalAttributesCache.Flush();
                    }
                }

                hfIdValues.Value = string.Empty;

                modalDetails.Hide();
            }

            BindGrid();
        }
Exemplo n.º 11
0
        /// <summary>
        /// Sets the value of an existing <see cref="AttributeValue"/> and saves it to the database or creates a new database record if one doesn't already exist.
        /// </summary>
        /// <param name="attributeGuid">The parent <see cref="Rock.Model.Attribute"/> unique identifier.</param>
        /// <param name="entityId">The ID of the entity - if any - to which this <see cref="AttributeValue"/> belongs.</param>
        /// <param name="value">The value to be set.</param>
        /// <param name="previousValue">If a <see cref="AttributeValue"/> already exists in the database, it's current value will be returned, so you can set it back after the current tests complete.</param>
        /// <param name="newAttributeValueGuid">If a <see cref="AttributeValue"/> doesn't already exist in the database, the <see cref="Guid"/> of the newly-created record will be returned, so you can delete it after the current tests complete.</param>
        public static void SetAttributeValue(Guid attributeGuid, int?entityId, string value, out string previousValue, out Guid newAttributeValueGuid)
        {
            using (var rockContext = new RockContext())
            {
                previousValue         = null;
                newAttributeValueGuid = Guid.Empty;

                var attributeId = AttributeCache.GetId(attributeGuid);
                if (!attributeId.HasValue)
                {
                    return;
                }

                var attributeValueService = new AttributeValueService(rockContext);

                var attributeValue = attributeValueService.GetByAttributeIdAndEntityId(attributeId.Value, entityId);

                if (attributeValue == null)
                {
                    attributeValue = new AttributeValue
                    {
                        AttributeId = attributeId.Value,
                        EntityId    = entityId,
                        Value       = value
                    };

                    attributeValueService.Add(attributeValue);

                    // Remember this so we can delete this AttributeValue upon cleanup.
                    newAttributeValueGuid = attributeValue.Guid;
                }
                else
                {
                    // Remeber this so we can set it back upon cleanup.
                    previousValue        = attributeValue.Value;
                    attributeValue.Value = value;
                }

                rockContext.SaveChanges();
            }
        }
Exemplo n.º 12
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string attributeKey = GetAttributeValue("RoomscannerConfigAttributeKey");
            Dictionary <string, string> settings = GlobalAttributesCache.Value(attributeKey).AsDictionary();

            settings["AllowedGroupId"]      = tbAllowedGroupId.Text;
            settings["SubroomLocationType"] = tbSubroomLocationTypeId.Text;

            RockContext      context          = new RockContext();
            AttributeService attributeService = new AttributeService(context);

            Rock.Model.Attribute attribute = attributeService.Queryable().Where(a => a.Key == attributeKey).FirstOrDefault();
            if (attribute == null)
            {
                attribute             = new Rock.Model.Attribute();
                attribute.Name        = "RoomScanner Settings";
                attribute.Description = "Settings for the OAuth server plugin.";
                attribute.Key         = "RoomScannerSettings";
                FieldTypeService fieldTypeService = new FieldTypeService(context);
                attribute.FieldType = fieldTypeService.Get(Rock.SystemGuid.FieldType.KEY_VALUE_LIST.AsGuid());
                context.SaveChanges();
            }
            // Update the actual attribute value.
            AttributeValueService attributeValueService = new AttributeValueService(context);
            AttributeValue        attributeValue        = attributeValueService.GetByAttributeIdAndEntityId(attribute.Id, null);

            if (attributeValue == null)
            {
                attributeValue             = new AttributeValue();
                attributeValue.AttributeId = attribute.Id;
                attributeValueService.Add(attributeValue);
            }
            attributeValue.Value = string.Join("|", settings.Select(a => a.Key + "^" + a.Value).ToList());
            context.SaveChanges();

            // Flush the cache(s)
            AttributeCache.Remove(attribute.Id);
            GlobalAttributesCache.Clear();
        }
Exemplo n.º 13
0
        /// <summary>
        /// Haves the workflow action.
        /// </summary>
        /// <param name="guidValue">The guid value of the action.</param>
        /// <returns>True/False if the workflow contains the action</returns>
        private bool HaveWorkflowAction(string guidValue)
        {
            using (var rockContext = new RockContext())
            {
                BlockService          blockService          = new BlockService(rockContext);
                AttributeService      attributeService      = new AttributeService(rockContext);
                AttributeValueService attributeValueService = new AttributeValueService(rockContext);

                var block = blockService.Get(Rock.SystemGuid.Block.BIO.AsGuid());

                var attribute      = attributeService.Get(Rock.SystemGuid.Attribute.BIO_WORKFLOWACTION.AsGuid());
                var attributeValue = attributeValueService.GetByAttributeIdAndEntityId(attribute.Id, block.Id);
                if (attributeValue == null || string.IsNullOrWhiteSpace(attributeValue.Value))
                {
                    return(false);
                }

                var  workflowActionValues = attributeValue.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                Guid guid = guidValue.AsGuid();
                return(workflowActionValues.Any(w => w.AsGuid() == guid));
            }
        }
Exemplo n.º 14
0
        void rGrid_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Literal lValue = e.Row.FindControl("lValue") as Literal;

                if (lValue != null)
                {
                    int attributeId = ( int )rGrid.DataKeys[e.Row.RowIndex].Value;

                    var attribute = Rock.Web.Cache.AttributeCache.Read(attributeId);
                    var fieldType = Rock.Web.Cache.FieldTypeCache.Read(attribute.FieldTypeId);

                    AttributeValueService attributeValueService = new AttributeValueService();
                    var attributeValue = attributeValueService.GetByAttributeIdAndEntityId(attributeId, _entityId).FirstOrDefault();
                    if (attributeValue != null)
                    {
                        lValue.Text = fieldType.Field.FormatValue(lValue, attributeValue.Value, attribute.QualifierValues, true);
                    }
                }
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Gets the attribute value as a model that can be displayed on the
        /// user's device. This handles special block settings that change what
        /// value is available.
        /// </summary>
        /// <param name="rockContext">The rock database context.</param>
        /// <param name="attribute">The attribute whose value will be viewed.</param>
        /// <returns>A <see cref="PublicAttributeValueViewModel"/> that represents the attribute value.</returns>
        private string GetPublicAttributeValue(RockContext rockContext, AttributeCache attribute)
        {
            var entityId = GetEntityId();

            if (GetAttributeValue(AttributeKey.AllowSettingofValues).AsBooleanOrNull() ?? false)
            {
                AttributeValueService attributeValueService = new AttributeValueService(rockContext);
                var attributeValue = attributeValueService.GetByAttributeIdAndEntityId(attribute.Id, entityId);

                if (attributeValue != null && !attributeValue.Value.IsNullOrWhiteSpace())
                {
                    return(PublicAttributeHelper.GetPublicValueForView(attribute, attributeValue.Value));
                }
                else
                {
                    return(PublicAttributeHelper.GetPublicValueForView(attribute, attribute.DefaultValue));
                }
            }
            else
            {
                return(PublicAttributeHelper.GetPublicValueForView(attribute, attribute.DefaultValue));
            }
        }
Exemplo n.º 16
0
        public BlockActionResult SaveEditAttributeValue(Guid attributeGuid, string value)
        {
            if (GetAttributeValue(AttributeKey.AllowSettingofValues).AsBooleanOrNull() != true)
            {
                return(ActionBadRequest("Setting values is not enabled."));
            }

            var attribute = AttributeCache.Get(attributeGuid);

            if (attribute == null)
            {
                return(ActionBadRequest());
            }

            using (var rockContext = new RockContext())
            {
                var entityId = GetEntityId();
                var attributeValueService = new AttributeValueService(rockContext);
                var attributeValue        = attributeValueService.GetByAttributeIdAndEntityId(attribute.Id, entityId);

                if (attributeValue == null)
                {
                    attributeValue = new AttributeValue
                    {
                        AttributeId = attribute.Id,
                        EntityId    = entityId
                    };
                    attributeValueService.Add(attributeValue);
                }

                attributeValue.Value = PublicAttributeHelper.GetPrivateValue(attribute, value);

                rockContext.SaveChanges();

                return(ActionOk(GetAttributeRow(attribute, rockContext)));
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Handles the RowDataBound event of the rGrid control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="GridViewRowEventArgs" /> instance containing the event data.</param>
        protected void rGrid_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                int attributeId = (int)rGrid.DataKeys[e.Row.RowIndex].Value;

                var attribute = Rock.Web.Cache.AttributeCache.Read(attributeId);
                var fieldType = Rock.Web.Cache.FieldTypeCache.Read(attribute.FieldTypeId);

                if (_displayValueEdit)
                {
                    Literal lValue = e.Row.FindControl("lValue") as Literal;
                    if (lValue != null)
                    {
                        AttributeValueService attributeValueService = new AttributeValueService();
                        var attributeValue = attributeValueService.GetByAttributeIdAndEntityId(attributeId, _entityId).FirstOrDefault();
                        if (attributeValue != null && !string.IsNullOrWhiteSpace(attributeValue.Value))
                        {
                            lValue.Text = fieldType.Field.FormatValue(lValue, attributeValue.Value, attribute.QualifierValues, true);
                        }
                        else
                        {
                            lValue.Text = string.Format("<span class='muted'>{0}</span>", fieldType.Field.FormatValue(lValue, attribute.DefaultValue, attribute.QualifierValues, true));
                        }
                    }
                }
                else
                {
                    Literal lDefaultValue = e.Row.FindControl("lDefaultValue") as Literal;
                    if (lDefaultValue != null)
                    {
                        lDefaultValue.Text = fieldType.Field.FormatValue(lDefaultValue, attribute.DefaultValue, attribute.QualifierValues, true);
                    }
                }
            }
        }
Exemplo n.º 18
0
        void modalDetails_SaveClick(object sender, EventArgs e)
        {
            int attributeId = 0;

            if (hfId.Value != string.Empty && !Int32.TryParse(hfId.Value, out attributeId))
            {
                attributeId = 0;
            }

            if (attributeId != 0 && phEditControl.Controls.Count > 0)
            {
                AttributeService attributeService = new AttributeService();
                var attribute = attributeService.Get(attributeId);

                AttributeValueService attributeValueService = new AttributeValueService();
                var attributeValue = attributeValueService.GetByAttributeIdAndEntityId(attributeId, _entityId).FirstOrDefault();
                if (attributeValue == null)
                {
                    attributeValue             = new Rock.Core.AttributeValue();
                    attributeValue.AttributeId = attributeId;
                    attributeValue.EntityId    = _entityId;
                    attributeValueService.Add(attributeValue, CurrentPersonId);
                }

                var fieldType = Rock.Web.Cache.FieldType.Read(attribute.FieldTypeId);
                attributeValue.Value = fieldType.Field.ReadValue(phEditControl.Controls[0]);

                attributeValueService.Save(attributeValue, CurrentPersonId);

                Rock.Web.Cache.Attribute.Flush(attributeId);
            }

            modalDetails.Hide();

            BindGrid();
        }
Exemplo n.º 19
0
        /// <summary>
        /// Handles the RowDataBound event of the rGrid control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="GridViewRowEventArgs" /> instance containing the event data.</param>
        protected void rGrid_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                int attributeId = ( int )rGrid.DataKeys[e.Row.RowIndex].Value;

                var attribute = Rock.Web.Cache.AttributeCache.Get(attributeId);
                var fieldType = FieldTypeCache.Get(attribute.FieldTypeId);

                Literal lCategories = e.Row.FindControl("lCategories") as Literal;
                if (lCategories != null)
                {
                    lCategories.Text = attribute.Categories.Select(c => c.Name).ToList().AsDelimited(", ");
                }

                Literal lEntityQualifier = e.Row.FindControl("lEntityQualifier") as Literal;
                if (lEntityQualifier != null)
                {
                    if (attribute.EntityTypeId.HasValue)
                    {
                        string entityTypeName = EntityTypeCache.Get(attribute.EntityTypeId.Value).FriendlyName;
                        if (!string.IsNullOrWhiteSpace(attribute.EntityTypeQualifierColumn))
                        {
                            lEntityQualifier.Text = string.Format("{0} where [{1}] = '{2}'", entityTypeName, attribute.EntityTypeQualifierColumn, attribute.EntityTypeQualifierValue);
                        }
                        else
                        {
                            lEntityQualifier.Text = entityTypeName;
                        }
                    }
                    else
                    {
                        lEntityQualifier.Text = "Global Attribute";
                    }
                }

                if (_displayValueEdit)
                {
                    Literal lValue = e.Row.FindControl("lValue") as Literal;
                    if (lValue != null)
                    {
                        AttributeValueService attributeValueService = new AttributeValueService(new RockContext());
                        var attributeValue = attributeValueService.GetByAttributeIdAndEntityId(attributeId, _entityId);
                        if (attributeValue != null && !string.IsNullOrWhiteSpace(attributeValue.Value))
                        {
                            lValue.Text = fieldType.Field.FormatValue(lValue, attribute.EntityTypeId, _entityId, attributeValue.Value, attribute.QualifierValues, true).EncodeHtml();
                        }
                        else
                        {
                            lValue.Text = string.Format("<span class='text-muted'>{0}</span>", fieldType.Field.FormatValue(lValue, attribute.EntityTypeId, _entityId, attribute.DefaultValue, attribute.QualifierValues, true).EncodeHtml());
                        }
                    }
                }
                else
                {
                    Literal lDefaultValue = e.Row.FindControl("lDefaultValue") as Literal;
                    if (lDefaultValue != null)
                    {
                        lDefaultValue.Text = fieldType.Field.FormatValueAsHtml(lDefaultValue, attribute.EntityTypeId, _entityId, attribute.DefaultValue, attribute.QualifierValues, true);
                    }
                }

                if (attribute.IsActive == false)
                {
                    e.Row.AddCssClass("is-inactive");
                }
            }
        }
Exemplo n.º 20
0
        protected void ShowEdit( int attributeId, bool setValues )
        {
            AttributeService attributeService = new AttributeService();
            var attribute = attributeService.Get( attributeId );

            hfId.Value = attribute.Id.ToString();
            lCaption.Text = attribute.Name;

            AttributeValueService attributeValueService = new AttributeValueService();
            var attributeValue = attributeValueService.GetByAttributeIdAndEntityId( attributeId, _entityId ).FirstOrDefault();

            var fieldType = Rock.Web.Cache.FieldType.Read( attribute.FieldTypeId );

            phEditControl.Controls.Clear();
            phEditControl.Controls.Add(fieldType.Field.CreateControl((attributeValue != null ? attributeValue.Value : string.Empty), attribute.Required, setValues));

            modalDetails.Show();
        }
Exemplo n.º 21
0
        void modalDetails_SaveClick( object sender, EventArgs e )
        {
            int attributeId = 0;
            if ( hfId.Value != string.Empty && !Int32.TryParse( hfId.Value, out attributeId ) )
                attributeId = 0;

            if ( attributeId != 0 && phEditControl.Controls.Count > 0 )
            {
                AttributeService attributeService = new AttributeService();
                var attribute = attributeService.Get( attributeId );

                AttributeValueService attributeValueService = new AttributeValueService();
                var attributeValue = attributeValueService.GetByAttributeIdAndEntityId( attributeId, _entityId ).FirstOrDefault();
                if ( attributeValue == null )
                {
                    attributeValue = new Rock.Core.AttributeValue();
                    attributeValue.AttributeId = attributeId;
                    attributeValue.EntityId = _entityId;
                    attributeValueService.Add( attributeValue, CurrentPersonId );
                }

                var fieldType = Rock.Web.Cache.FieldType.Read( attribute.FieldTypeId );
                attributeValue.Value = fieldType.Field.ReadValue( phEditControl.Controls[0] );

                attributeValueService.Save(attributeValue, CurrentPersonId);

                Rock.Web.Cache.Attribute.Flush( attributeId );

            }

            modalDetails.Hide();

            BindGrid();
        }
Exemplo n.º 22
0
        void rGrid_RowDataBound( object sender, GridViewRowEventArgs e )
        {
            if ( e.Row.RowType == DataControlRowType.DataRow )
            {
                Literal lValue = e.Row.FindControl( "lValue" ) as Literal;

                if ( lValue != null )
                {
                    int attributeId = ( int )rGrid.DataKeys[e.Row.RowIndex].Value;

                    AttributeService attributeService = new AttributeService();
                    var attribute = attributeService.Get( attributeId );
                    var fieldType = Rock.Web.Cache.FieldType.Read( attribute.FieldTypeId );

                    AttributeValueService attributeValueService = new AttributeValueService();
                    var attributeValue = attributeValueService.GetByAttributeIdAndEntityId( attributeId, _entityId ).FirstOrDefault();
                    if ( attributeValue != null )
                        lValue.Text = fieldType.Field.FormatValue( lValue, attributeValue.Value, true );
                }
            }
        }
Exemplo n.º 23
0
        void rGrid_RowDataBound( object sender, GridViewRowEventArgs e )
        {
            if ( e.Row.RowType == DataControlRowType.DataRow )
            {
                Literal lValue = e.Row.FindControl( "lValue" ) as Literal;
                HtmlAnchor aEdit = e.Row.FindControl( "aEdit" ) as HtmlAnchor;

                if ( lValue != null && aEdit != null )
                {
                    int attributeId = ( int )rGrid.DataKeys[e.Row.RowIndex].Value;

                    AttributeService attributeService = new AttributeService();
                    var attribute = attributeService.Get( attributeId );
                    var fieldType = Rock.Web.Cache.FieldType.Read( attribute.FieldTypeId );

                    AttributeValueService attributeValueService = new AttributeValueService();

                    int? iEntityId = null;
                    if ( entityId != "null" )
                        try { iEntityId = Int32.Parse( entityId ); }
                        catch { }

                    var attributeValue = attributeValueService.GetByAttributeIdAndEntityId( attributeId, iEntityId );
                    if ( attributeValue != null )
                    {
                        string clientUpdateScript = fieldType.Field.ClientUpdateScript(
                            this.Page,
                            "0",
                            attributeValue.Value,
                            "attribute_value_" + BlockInstance.Id.ToString(),
                            hfAttributeValue.ClientID ) + "(\"" + attributeValue.Value.EscapeQuotes() + "\");";

                        lValue.Text = fieldType.Field.FormatValue( lValue, attributeValue.Value, true );
                        aEdit.Attributes.Add( "onclick", string.Format( "editValue({0}, {1}, '{2}', '{3}');",
                            attributeId, attributeValue.Id, attributeValue.Value.EscapeQuotes(), clientUpdateScript ) );
                    }
                    else
                    {
                        string clientUpdateScript = fieldType.Field.ClientUpdateScript(
                            this.Page,
                            "0",
                            string.Empty,
                            "attribute_value_" + BlockInstance.Id.ToString(),
                            hfAttributeValue.ClientID ) + "('');";

                        aEdit.Attributes.Add( "onclick", string.Format( "editValue({0}, 0, '', \"{1}\");",
                            attributeId, clientUpdateScript ) );
                    }
                }
            }
        }