Ejemplo n.º 1
0
        /// <summary>
        /// Copies from model.
        /// </summary>
        /// <param name="model">The model.</param>
        public virtual void CopyFromModel(Rock.Data.IEntity model)
        {
            this.Id   = model.Id;
            this.Guid = model.Guid;

            var secureModel = model as ISecured;

            if (secureModel != null)
            {
                this.TypeId           = secureModel.TypeId;
                this.TypeName         = secureModel.TypeName;
                this.SupportedActions = secureModel.SupportedActions;
            }

            var attributeModel = model as Rock.Attribute.IHasAttributes;

            if (attributeModel != null)
            {
                if (attributeModel.Attributes != null)
                {
                    this.Attributes = attributeModel.Attributes;
                }
                this.AttributeValues = attributeModel.AttributeValues;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Copies from model.
        /// </summary>
        /// <param name="model">The model.</param>
        public virtual void CopyFromModel(Rock.Data.IEntity model)
        {
            this.Id          = model.Id;
            this.Guid        = model.Guid;
            this.ForeignId   = model.ForeignId;
            this.ForeignGuid = model.ForeignGuid;
            this.ForeignKey  = model.ForeignKey;

            RockMemoryCache cache = RockMemoryCache.Default;

            cache.Set(model.Guid.ToString(), model.Id, new CacheItemPolicy());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handles the RowSelected event of the gReport control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Rock.Web.UI.Controls.RowEventArgs"/> instance containing the event data.</param>
        protected void gReport_RowSelected(object sender, Rock.Web.UI.Controls.RowEventArgs e)
        {
            Guid guid = Guid.Empty;

            if (TagEntityType != null && Guid.TryParse(e.RowKeyValue.ToString(), out guid))
            {
                object entity = InvokeServiceMethod("Get", new Type[] { typeof(Guid) }, new object[] { guid });
                if (entity != null)
                {
                    Rock.Data.IEntity model = entity as Rock.Data.IEntity;
                    if (model != null)
                    {
                        string routePath = string.Format("~/{0}/{1}", TagEntityType.FriendlyName.Replace(" ", ""), model.Id);
                        Response.Redirect(routePath, false);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <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)
            {
                // Get the context entity
                Rock.Data.IEntity contextEntity = this.ContextEntity();

                tagEntityTags.Visible = contextEntity != null;
                if (contextEntity != null)
                {
                    tagEntityTags.EntityTypeId          = EntityTypeCache.Read(contextEntity.GetType()).Id;
                    tagEntityTags.EntityGuid            = contextEntity.Guid;
                    tagEntityTags.EntityQualifierColumn = GetAttributeValue("EntityQualifierColumn");
                    tagEntityTags.EntityQualifierValue  = GetAttributeValue("EntityQualifierValue");
                    tagEntityTags.GetTagValues(CurrentPersonId);
                }
            }
        }
Ejemplo n.º 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string entityQualifierColumn = GetAttributeValue("EntityQualifierColumn");

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

            string entityQualifierValue = GetAttributeValue("EntityQualifierValue");

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

            var sb = new StringBuilder();

            // Get the context entity
            Rock.Data.IEntity contextEntity = this.ContextEntity();

            if (contextEntity != null)
            {
                var service = new TaggedItemService();
                foreach (dynamic item in service.Get(
                             contextEntity.TypeId, entityQualifierColumn, entityQualifierValue, CurrentPersonId, contextEntity.Guid)
                         .Select(i => new {
                    OwnerId = i.Tag.OwnerId,
                    Name = i.Tag.Name
                }))
                {
                    if (sb.Length > 0)
                    {
                        sb.Append(',');
                    }
                    sb.Append(item.Name);
                    if (CurrentPersonId.HasValue && item.OwnerId == CurrentPersonId.Value)
                    {
                        sb.Append("^personal");
                    }
                }

                phTags.Controls.Add(new LiteralControl(string.Format(
                                                           "<input name=\"person-tags\" id=\"person-tags\" value=\"{0}\" />", sb.ToString())));

                string script = string.Format(@"
    $(document).ready(function () {{
        $('ul.ui-autocomplete').css('width', '300px');
        $('#person-tags').tagsInput({{
            'autocomplete_url': function( request, response ) {{
                $.ajax({{
                    url: Rock.settings.get('baseUrl') + 'api/tags/availablenames/{0}/{1}/{2}{3}{4}',
                    dataType: 'json',
                    success: function(data, status, xhr){{ 
                        response($.map(data, function (item) {{
                            return {{
                                value: item.Name,
                                class: item.OwnerId == null || item.OwnerId == '' ? 'system' : 'personal'
                            }}
                        }}))
                    }},
                    error: function(xhr, status, error) {{
                        alert('availablenames status: ' + status + ' [' + error + ']: ' + xhr.reponseText);
                    }}
                }});
            }},
            autoCompleteAppendTo: 'div.tag-wrap',
            autoCompleteMessages: {{
              noResults: function () {{ }},
              results: function () {{ }}
            }},
            'height': 'auto',
            'width': '100%',
            'interactive': true,
            'defaultText': 'add tag',
            'removeWithBackspace': false,
            'onAddTag': verifyTag,
            'onRemoveTag': RemoveTag,
            'enableDelete': true
        }});
    }});

    function verifyTag(tagName) {{
        $.ajax({{
            type: 'GET',
            url: Rock.settings.get('baseUrl') + 'api/tags/{0}/{1}/' + tagName + '{3}{4}',
            statusCode: {{
                404: function () {{
                        var r = confirm(""A tag called '"" + tagName + ""' does not exist. Do you want to create a new personal tag?"");
                        if (r == true) {{
                            AddTag(tagName);
                        }}
                        else {{
                            // remove tag
                            $('#person-tags').removeTag(tagName);
                        }}
                    }},
                200: function (data, status, xhr) {{
                        AddTag(tagName);
                    }}
            }},
        }});
    }}

    function AddTag(tagName) {{
        $.ajax({{
            type: 'POST',
            url: Rock.settings.get('baseUrl') + 'api/taggeditems/{0}/{1}/{2}/' + tagName + '{3}{4}',
            error: function (xhr, status, error) {{
                alert('AddTag() status: ' + status + ' [' + error + ']: ' + xhr.responseText);
            }}
        }});
    }}

    function RemoveTag(tagName) {{
        $.ajax({{
            type: 'DELETE',
            url: Rock.settings.get('baseUrl') + 'api/taggeditems/{0}/{1}/{2}/' + tagName + '{3}{4}',
            error: function (xhr, status, error) {{
                alert('RemoveTag() status: ' + status + ' [' + error + ']: ' + xhr.responseText);
            }}
        }});
    }}

",
                                              contextEntity.TypeId, CurrentPersonId, contextEntity.Guid.ToString(),
                                              string.IsNullOrWhiteSpace(entityQualifierColumn) ? "" : "/" + entityQualifierColumn,
                                              string.IsNullOrWhiteSpace(entityQualifierValue) ? "" : "/" + entityQualifierValue);
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "tags-" + this.BlockId.ToString(), script, true);
            }
        }
Ejemplo n.º 6
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            string entityQualifierColumn = AttributeValue("EntityQualifierColumn");

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

            string entityQualifierValue = AttributeValue("EntityQualifierValue");

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

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

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

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

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

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

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

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

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

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

            Page.ClientScript.RegisterStartupScript(this.GetType(), "ConfirmDelete", script, true);
        }
Ejemplo n.º 7
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            string entityQualifierColumn = AttributeValue("EntityQualifierColumn");

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

            string entityQualifierValue = AttributeValue("EntityQualifierValue");

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

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

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

                // Should only be one.
                break;
            }

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

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

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

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

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

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

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

                    xDocument = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"), rootElement);
                }
            }
        }
Ejemplo n.º 8
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            try
            {
                string entityType = GetAttributeValue("Entity");
                if (string.IsNullOrWhiteSpace(entityType))
                {
                    entityType = PageParameter("Entity");
                }

                if (string.IsNullOrWhiteSpace(GetAttributeValue("Entity")))
                {
                    throw new Exception("Entity is required");
                }

                _entityTypeId = Rock.Web.Cache.EntityTypeCache.Read(entityType).Id;

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

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

                _canConfigure = CurrentPage.IsAuthorized("Administrate", CurrentPerson);

                if (!Convert.ToBoolean(GetAttributeValue("GlobalTags")))
                {
                    Rock.Data.IEntity model = CurrentPage.GetCurrentContext("Rock.Model.Person");
                    if (model != null)
                    {
                        _ownerId = model.Id;
                    }
                    else
                    {
                        _ownerId = CurrentPersonId;
                    }
                }

                if (_canConfigure)
                {
                    rGrid.DataKeyNames    = new string[] { "id" };
                    rGrid.Actions.ShowAdd = true;

                    rGrid.Actions.AddClick += rGrid_Add;
                    rGrid.GridReorder      += rGrid_GridReorder;
                    rGrid.GridRebind       += rGrid_GridRebind;
                }
                else
                {
                    DisplayError("You are not authorized to configure these tags");
                }
            }
            catch (SystemException ex)
            {
                DisplayError(ex.Message);
            }
        }