Exemple #1
0
        protected void rGrid_Delete(object sender, RowEventArgs e)
        {
            Rock.Core.Attribute attribute = _attributeService.Get(( int )rGrid.DataKeys[e.RowIndex]["id"]);
            if (attribute != null)
            {
                Rock.Web.Cache.Attribute.Flush(attribute.Id);

                _attributeService.Delete(attribute, CurrentPersonId);
                _attributeService.Save(attribute, CurrentPersonId);
            }

            BindGrid();
        }
Exemple #2
0
        protected void rGridAttribute_Delete(object sender, RowEventArgs e)
        {
            Rock.Core.Attribute attribute = attributeService.Get((int)rGridAttribute.DataKeys[e.RowIndex]["id"]);
            if (attribute != null)
            {
                Rock.Web.Cache.Attribute.Flush(attribute.Id);

                attributeService.Delete(attribute, CurrentPersonId);
                attributeService.Save(attribute, CurrentPersonId);
            }

            rGridAttribute_Bind(hfTypeId.Value);
        }
        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 ) );
                    }
                }
            }
        }
        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 );
                }
            }
        }
        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();
        }
        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();
        }