Exemplo n.º 1
0
        /// <summary>
        /// Handles the Delete event of the gReport control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
        protected void gReport_Delete(object sender, RowEventArgs e)
        {
            int id = int.MinValue;

            if (TagId.HasValue && int.TryParse(e.RowKeyValue.ToString(), out id))
            {
                object obj = InvokeServiceMethod("Get", new Type[] { typeof(int) }, new object[] { id });
                if (obj != null)
                {
                    Rock.Data.IEntity entity = obj as Rock.Data.IEntity;
                    if (entity != null)
                    {
                        var rockContext = new RockContext();
                        var service     = new TaggedItemService(rockContext);
                        var taggedItem  = service.Get(TagId.Value, entity.Guid);
                        if (taggedItem != null)
                        {
                            string errorMessage;
                            if (!service.CanDelete(taggedItem, out errorMessage))
                            {
                                mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                                return;
                            }

                            service.Delete(taggedItem);
                            rockContext.SaveChanges();
                        }
                    }
                }
            }

            BindGrid();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Copies from model.
        /// </summary>
        /// <param name="model">The model.</param>
        public override void CopyFromModel(Rock.Data.IEntity model)
        {
            base.CopyFromModel(model);

            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)
                {
                    attributeModel.LoadAttributes();
                }

                this.Attributes      = attributeModel.Attributes;
                this.AttributeValues = attributeModel.AttributeValues;
            }
        }
Exemplo n.º 3
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;

            RockMemoryCache cache = RockMemoryCache.Default;

            cache.Set(model.Guid.ToString(), new Lazy <int>(() => AsLazy(model.Id)), new CacheItemPolicy());
        }
Exemplo n.º 4
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());
        }
Exemplo 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(new RockContext());
                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}/' + request.term + '/{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);
            }
        }
Exemplo n.º 6
0
 public virtual void CopyFromModel(Rock.Data.IEntity model)
 {
     this.SetFromEntity(model);
 }