Esempio n. 1
0
        /// <summary>
        /// Gets the edit value as the IEntity.Id
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <returns></returns>
        public int?GetEditValueAsEntityId(Control control, Dictionary <string, ConfigurationValue> configurationValues)
        {
            Guid guid     = GetEditValue(control, configurationValues).AsGuid();
            var  noteType = NoteTypeCache.Get(guid);

            return(noteType != null ? noteType.Id : (int?)null);
        }
Esempio n. 2
0
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            errorMessages = new List <string>();

            if (action != null && action.Activity != null &&
                action.Activity.Workflow != null && action.Activity.Workflow.Id > 0)
            {
                var text = GetAttributeValue(action, "Note").ResolveMergeFields(GetMergeFields(action));

                var note = new Note();
                note.IsSystem      = false;
                note.IsAlert       = GetAttributeValue(action, "IsAlert").AsBoolean();
                note.IsPrivateNote = false;
                note.EntityId      = action.Activity.Workflow.Id;
                note.Caption       = string.Empty;
                note.Text          = text;

                var noteType = NoteTypeCache.Get(GetAttributeValue(action, "NoteType").AsGuid());
                if (noteType != null)
                {
                    note.NoteTypeId = noteType.Id;
                }

                new NoteService(rockContext).Add(note);

                return(true);
            }
            else
            {
                errorMessages.Add("A Note can only be added to a persisted workflow with a valid ID.");
                return(false);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Method that will be called on an entity immediately after the item is saved by context
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="entry">The entry.</param>
        /// <param name="state">The state.</param>
        public override void PreSaveChanges(Data.DbContext dbContext, DbEntityEntry entry, EntityState state)
        {
            if (state == EntityState.Added)
            {
                var noteType = NoteTypeCache.Get(this.NoteTypeId);
                if (noteType?.AutoWatchAuthors == true)
                {
                    // if this is a new note, and AutoWatchAuthors, then add a NoteWatch so the author will get notified when there are any replies
                    var rockContext = dbContext as RockContext;
                    if (rockContext != null && this.CreatedByPersonAliasId.HasValue)
                    {
                        var noteWatchService = new NoteWatchService(rockContext);

                        // we don't know the Note.Id yet, so just assign the NoteWatch.Note and EF will populate the NoteWatch.NoteId automatically
                        var noteWatch = new NoteWatch
                        {
                            IsWatching           = true,
                            WatcherPersonAliasId = this.CreatedByPersonAliasId.Value,
                            Note = this
                        };

                        noteWatchService.Add(noteWatch);
                    }
                }
            }

            base.PreSaveChanges(dbContext, entry, state);
        }
Esempio n. 4
0
        /// <summary>
        /// Handles 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)
            {
                DisplayCategories();
                SetNoteType();
                lbStart.Focus();
                lbFlag.Visible = _enableCommunityFlagging;
            }

            if (NoteTypeId.HasValue)
            {
                var noteType = NoteTypeCache.Read(NoteTypeId.Value);
                if (noteType != null)
                {
                    notesComments.NoteTypes = new List <NoteTypeCache> {
                        noteType
                    };
                }
            }

            notesComments.EntityId = CurrentPrayerRequestId;

            if (lbNext.Visible)
            {
                lbNext.Focus();
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Returns the field's current value(s)
        /// </summary>
        /// <param name="parentControl">The parent control.</param>
        /// <param name="value">Information about the value</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param>
        /// <returns></returns>
        public override string FormatValue(Control parentControl, string value, Dictionary <string, ConfigurationValue> configurationValues, bool condensed)
        {
            string formattedValue = string.Empty;

            if (!string.IsNullOrWhiteSpace(value))
            {
                var names = new List <string>();

                foreach (string guidString in value.SplitDelimitedValues())
                {
                    Guid?guid = guidString.AsGuidOrNull();
                    if (guid.HasValue)
                    {
                        var noteType = NoteTypeCache.Get(guid.Value);
                        if (noteType != null)
                        {
                            names.Add(noteType.Name);
                        }
                    }
                }

                formattedValue = names.AsDelimited(", ");
            }

            // The parent is CategoryFieldType. CategoryFieldType's FormatValue expects a list of category guids, so we should not call the base FormatValue.
            return(formattedValue);
        }
Esempio n. 6
0
        /// <summary>
        /// Formats the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override string FormatSelection(Type entityType, string selection)
        {
            string result = "Person Note";

            string[] selectionValues = selection.Split('|');
            if (selectionValues.Length >= 2)
            {
                int noteTypeId       = selectionValues[0].AsInteger();
                var selectedNoteType = NoteTypeCache.Get(noteTypeId);
                if (selectedNoteType != null)
                {
                    result = $"Has a {selectedNoteType.Name} note";
                }
                else
                {
                    result = "Has a note";
                }

                var containingText = selectionValues[1];
                if (containingText.IsNotNullOrWhiteSpace())
                {
                    result += $" containing '{containingText}'";
                }
            }

            return(result);
        }
Esempio n. 7
0
        /// <summary>
        /// Returns the field's current value(s)
        /// </summary>
        /// <param name="parentControl">The parent control.</param>
        /// <param name="value">Information about the value</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param>
        /// <returns></returns>
        public override string FormatValue(Control parentControl, string value, Dictionary <string, ConfigurationValue> configurationValues, bool condensed)
        {
            string formattedValue = string.Empty;

            if (!string.IsNullOrWhiteSpace(value))
            {
                var names = new List <string>();

                foreach (string guidString in value.SplitDelimitedValues())
                {
                    Guid?guid = guidString.AsGuidOrNull();
                    if (guid.HasValue)
                    {
                        var noteType = NoteTypeCache.Get(guid.Value);
                        if (noteType != null)
                        {
                            names.Add(noteType.Name);
                        }
                    }
                }

                formattedValue = names.AsDelimited(", ");
            }

            return(base.FormatValue(parentControl, formattedValue, null, condensed));
        }
        private void UpdateCustomNotes(int personId)
        {
            RockContext   rockContext   = new RockContext();
            NoteService   noteService   = new NoteService(rockContext);
            PersonService personService = new PersonService(rockContext);
            var           person        = personService.Get(personId);

            mdCustomNotes.Title = Rock.RockDateTime.Today.ToString("MMM dd") + "Custom Notes for " + person.FullName;
            var noteType = NoteTypeCache.Get(GetAttributeValue("NoteType").AsGuid());

            var today    = Rock.RockDateTime.Today;
            var tomorrow = today.AddDays(1);

            var notes = noteService.Queryable()
                        .Where(n => n.NoteTypeId == noteType.Id)
                        .Where(n => n.EntityId == personId)
                        .Where(n => n.ForeignId == null)
                        .Where(n => n.CreatedDateTime >= today && n.CreatedDateTime < tomorrow)
                        .ToList();

            tbCustomNotes.Text = "";
            ltCustomNotes.Text = "";

            foreach (var note in notes)
            {
                ltCustomNotes.Text += "<b>" + note.CreatedDateTime.Value.ToString("hh:mm tt") + ":</b> " + note.Text + "<br>";
            }
        }
        /// <summary>
        /// Configures the note editor.
        /// </summary>
        /// <param name="personId">The person identifier.</param>
        private void ConfigureNoteEditor()
        {
            var noteTypes = NoteTypeCache.GetByEntity(EntityTypeCache.GetId <Rock.Model.Person>(), string.Empty, string.Empty, true);

            // If block is configured to only allow certain note types, limit notes to those types.
            var configuredNoteTypes = GetAttributeValue(AttributeKey.NoteTypes).SplitDelimitedValues().AsGuidList();

            if (configuredNoteTypes.Any())
            {
                noteTypes = noteTypes.Where(n => configuredNoteTypes.Contains(n.Guid)).ToList();
            }

            NoteOptions noteOptions = new NoteOptions(this.ViewState)
            {
                NoteTypes           = noteTypes.ToArray(),
                AddAlwaysVisible    = true,
                DisplayType         = NoteDisplayType.Full,
                ShowAlertCheckBox   = true,
                ShowPrivateCheckBox = true,
                UsePersonIcon       = true,
                ShowSecurityButton  = false,
                ShowCreateDateInput = false,
            };

            noteEditor.SetNoteOptions(noteOptions);
            noteEditor.NoteTypeId = noteTypes.FirstOrDefault()?.Id;
        }
Esempio n. 10
0
        public object GetStructuredContent(Guid itemGuid)
        {
            using (var rockContext = new RockContext())
            {
                var contentChannelItemService = new ContentChannelItemService(rockContext);
                var noteTypeId = NoteTypeCache.Get(SystemGuid.NoteType.CONTENT_CHANNEL_ITEM_STRUCTURED_CONTENT_USER_VALUE).Id;

                var item = contentChannelItemService.Get(itemGuid);
                Dictionary <string, string> userValues = null;

                if (item != null && RequestContext.CurrentPerson != null)
                {
                    var noteService = new NoteService(rockContext);
                    var note        = noteService.Queryable()
                                      .AsNoTracking()
                                      .Where(a => a.NoteTypeId == noteTypeId && a.EntityId == item.Id)
                                      .Where(a => a.CreatedByPersonAliasId.HasValue && a.CreatedByPersonAlias.PersonId == RequestContext.CurrentPerson.Id)
                                      .FirstOrDefault();

                    if (note != null)
                    {
                        userValues = note.Text.FromJsonOrNull <Dictionary <string, string> >();
                    }
                }

                return(new
                {
                    DocumentJson = item?.StructuredContent,
                    UserValues = userValues
                });
            }
        }
Esempio n. 11
0
            /// <summary>
            /// Creates a <see cref="NoteWatch"/> for the author of this <see cref="Note"/> when appropriate.
            /// </summary>
            private void CreateAutoWatchForAuthor()
            {
                if (State != EntityContextState.Added)
                {
                    return; // only create new watches for new notes.
                }

                var noteType = NoteTypeCache.Get(this.Entity.NoteTypeId);

                if (noteType == null)
                {
                    return; // Probably an error, but let's avoid creating another one.
                }

                if (noteType.AutoWatchAuthors != true)
                {
                    return; // Don't auto watch.
                }

                if (!this.Entity.CreatedByPersonAliasId.HasValue)
                {
                    return; // No author to add a watch for.
                }

                // add a NoteWatch so the author will get notified when there are any replies
                var noteWatch = new NoteWatch
                {
                    // we don't know the Note.Id yet, so just assign the NoteWatch.Note and EF will populate the NoteWatch.NoteId automatically
                    Note                 = this.Entity,
                    IsWatching           = true,
                    WatcherPersonAliasId = this.Entity.CreatedByPersonAliasId.Value
                };

                new NoteWatchService(RockContext).Add(noteWatch);
            }
Esempio n. 12
0
        /// <summary>
        /// Handles the Delete event of the rGrid 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 rGrid_Delete(object sender, RowEventArgs e)
        {
            using (var rockContext = new RockContext())
            {
                var service  = new NoteTypeService(rockContext);
                var noteType = service.Get(e.RowKeyId);
                if (noteType != null)
                {
                    string errorMessage = string.Empty;
                    if (service.CanDelete(noteType, out errorMessage))
                    {
                        int id = noteType.Id;

                        service.Delete(noteType);
                        rockContext.SaveChanges();

                        NoteTypeCache.Flush(id);
                        NoteTypeCache.FlushEntityNoteTypes();
                    }
                    else
                    {
                        nbMessage.Text    = errorMessage;
                        nbMessage.Visible = true;
                    }
                }
            }

            BindFilter();
            BindGrid();
        }
Esempio n. 13
0
        /// <summary>
        /// Handles 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)
            {
                DisplayCategories();
                SetNoteType();
                lbStart.Focus();
                cpCampus.SetValue(this.GetUserPreference(string.Format(CAMPUS_PREFERENCE, this.BlockId)).AsIntegerOrNull());
                lbFlag.Visible = _enableCommunityFlagging;
            }

            if (NoteTypeId.HasValue)
            {
                var noteType = NoteTypeCache.Get(NoteTypeId.Value);
                if (noteType != null)
                {
                    notesComments.NoteOptions.NoteTypes = new NoteTypeCache[] { noteType };
                }
            }

            notesComments.NoteOptions.EntityId = CurrentPrayerRequestId;

            if (lbNext.Visible)
            {
                lbNext.Focus();
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Sets the edit value from IEntity.Id value
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="id">The identifier.</param>
        public void SetEditValueFromEntityId(Control control, Dictionary <string, ConfigurationValue> configurationValues, int?id)
        {
            var    noteType  = NoteTypeCache.Get(id ?? 0);
            string guidValue = noteType != null?noteType.Guid.ToString() : string.Empty;

            SetEditValue(control, configurationValues, guidValue);
        }
Esempio n. 15
0
        /// <summary>
        /// Renders the notes.
        /// </summary>
        private void ShowNotes()
        {
            IEntity contextEntity;

            if (ContextTypesRequired.Count == 1)
            {
                contextEntity = this.ContextEntity(ContextTypesRequired.First().Name);
            }
            else
            {
                contextEntity = this.ContextEntity();
            }

            if (contextEntity != null)
            {
                upNotes.Visible = true;

                string noteTypeName = GetAttributeValue("NoteType");

                using (var rockContext = new RockContext())
                {
                    var noteTypes = NoteTypeCache.GetByEntity(contextEntity.TypeId, string.Empty, string.Empty, true);

                    // If block is configured to only allow certain note types, limit notes to those types.
                    var configuredNoteTypes = GetAttributeValue("NoteTypes").SplitDelimitedValues().AsGuidList();
                    if (configuredNoteTypes.Any())
                    {
                        noteTypes = noteTypes.Where(n => configuredNoteTypes.Contains(n.Guid)).ToList();
                    }

                    NoteOptions noteOptions = new NoteOptions(notesTimeline)
                    {
                        EntityId               = contextEntity.Id,
                        NoteTypes              = noteTypes.ToArray(),
                        NoteLabel              = GetAttributeValue("NoteTerm"),
                        DisplayType            = GetAttributeValue("DisplayType") == "Light" ? NoteDisplayType.Light : NoteDisplayType.Full,
                        ShowAlertCheckBox      = GetAttributeValue("ShowAlertCheckbox").AsBoolean(),
                        ShowPrivateCheckBox    = GetAttributeValue("ShowPrivateCheckbox").AsBoolean(),
                        ShowSecurityButton     = GetAttributeValue("ShowSecurityButton").AsBoolean(),
                        AddAlwaysVisible       = GetAttributeValue("AddAlwaysVisible").AsBoolean(),
                        ShowCreateDateInput    = GetAttributeValue("AllowBackdatedNotes").AsBoolean(),
                        NoteViewLavaTemplate   = GetAttributeValue("NoteViewLavaTemplate"),
                        DisplayNoteTypeHeading = GetAttributeValue("DisplayNoteTypeHeading").AsBoolean(),
                        UsePersonIcon          = GetAttributeValue("UsePersonIcon").AsBoolean(),
                        ExpandReplies          = GetAttributeValue("ExpandReplies").AsBoolean()
                    };

                    notesTimeline.NoteOptions         = noteOptions;
                    notesTimeline.Title               = GetAttributeValue("Heading");
                    notesTimeline.TitleIconCssClass   = GetAttributeValue("HeadingIcon");
                    notesTimeline.AllowAnonymousEntry = GetAttributeValue("Allow Anonymous").AsBoolean();
                    notesTimeline.SortDirection       = GetAttributeValue("DisplayOrder") == "Ascending" ? ListSortDirection.Ascending : ListSortDirection.Descending;
                }
            }
            else
            {
                upNotes.Visible = false;
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Gets the approvers.
        /// </summary>
        /// <param name="noteTypeId">The note type identifier.</param>
        /// <returns></returns>
        public List <Person> GetApprovers(int noteTypeId)
        {
            var rockContext        = this.Context as RockContext;
            var groupMemberService = new GroupMemberService(rockContext);

            var noteType             = NoteTypeCache.Get(noteTypeId);
            int?noteTypeEntityTypeId = EntityTypeCache.GetId <NoteType>();

            if (!noteTypeEntityTypeId.HasValue || noteType == null)
            {
                // shouldn't happen
                return(new List <Person>());
            }

            var authService = new AuthService(rockContext);

            var approvalAuths = authService.GetAuths(noteTypeEntityTypeId.Value, noteTypeId, Rock.Security.Authorization.APPROVE);

            // Get a list of all PersonIds that are allowed that are included in the Auths
            // Then, when we get a list of all the allowed people that are in the auth as a specific Person or part of a Role (Group), we'll run all those people thru NoteType.IsAuthorized
            // That way, we don't have to figure out all the logic of Allow/Deny based on Order, etc
            List <int> authPersonIdListAll  = new List <int>();
            var        approvalAuthsAllowed = approvalAuths.Where(a => a.AllowOrDeny == "A").ToList();

            foreach (var approvalAuth in approvalAuthsAllowed)
            {
                var personId = approvalAuth.PersonAlias?.PersonId;
                if (personId.HasValue)
                {
                    authPersonIdListAll.Add(personId.Value);
                }
                else if (approvalAuth.GroupId.HasValue)
                {
                    var groupPersonIdsQuery = groupMemberService.Queryable().Where(a => a.GroupId == approvalAuth.GroupId.Value && a.GroupMemberStatus == GroupMemberStatus.Active && a.Person.IsDeceased == false).Select(a => a.PersonId);
                    authPersonIdListAll.AddRange(groupPersonIdsQuery.ToList());
                }
                else if (approvalAuth.SpecialRole != SpecialRole.None)
                {
                    // Not Supported: Get people that belong to Special Roles like AllUsers, AllAuthenticatedUser, and AllUnAuthenicatedUsers doesn't really make sense, so ignore it
                }
            }

            authPersonIdListAll = authPersonIdListAll.Distinct().ToList();

            var authPersonsAll      = new PersonService(rockContext).Queryable().Where(a => authPersonIdListAll.Contains(a.Id)).ToList();
            var authorizedApprovers = new List <Person>();

            // now that we have a list of all people that have at least one Allow auth, run them thru noteType.IsAuthorized, to get rid of people that would have been excluded due to a Deny auth
            foreach (var authPerson in authPersonsAll)
            {
                if (noteType.IsAuthorized(Rock.Security.Authorization.APPROVE, authPerson))
                {
                    authorizedApprovers.Add(authPerson);
                }
            }

            return(authorizedApprovers);
        }
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summarysni>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            var noteTypeString = GetAttributeValue("NoteType");
            var noteType       = NoteTypeCache.Read(noteTypeString.AsGuid());

            if (noteType != null)
            {
                lEntityType.Text = "Note Type: " + noteType.Name;
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Loads the note type drop down.
        /// </summary>
        public void LoadNoteTypeDropDown(int?entityTypeId)
        {
            ddlNoteType.Items.Clear();
            ddlNoteType.Items.Add(new ListItem());
            if (entityTypeId.HasValue)
            {
                var entityNoteTypes = NoteTypeCache.GetByEntity(entityTypeId.Value, null, null, true);
                ddlNoteType.Items.AddRange(entityNoteTypes.Select(a => new ListItem(a.Name, a.Id.ToString())).ToArray());
            }

            ddlNoteType.Visible = entityTypeId.HasValue;
        }
Esempio n. 19
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)
        {
            int noteTypeId = 0;

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

            var      rockContext = new RockContext();
            var      service     = new NoteTypeService(rockContext);
            NoteType noteType    = null;

            if (noteTypeId != 0)
            {
                noteType = service.Get(noteTypeId);
            }

            if (noteType == null)
            {
                var orders = service.Queryable()
                             .Where(t => t.EntityTypeId == (entityTypePicker.SelectedEntityTypeId ?? 0))
                             .Select(t => t.Order)
                             .ToList();

                noteType       = new NoteType();
                noteType.Order = orders.Any() ? orders.Max(t => t) + 1 : 0;
                service.Add(noteType);
            }

            noteType.Name         = tbName.Text;
            noteType.EntityTypeId = entityTypePicker.SelectedEntityTypeId ?? 0;
            noteType.EntityTypeQualifierColumn = "";
            noteType.EntityTypeQualifierValue  = "";
            noteType.UserSelectable            = cbUserSelectable.Checked;
            noteType.CssClass     = tbCssClass.Text;
            noteType.IconCssClass = tbIconCssClass.Text;

            if (noteType.IsValid)
            {
                rockContext.SaveChanges();

                NoteTypeCache.Flush(noteType.Id);
                NoteTypeCache.FlushEntityNoteTypes();

                hfIdValue.Value = string.Empty;
                modalDetails.Hide();

                BindFilter();
                BindGrid();
            }
        }
        private List <FormElementItem> GetForm(NoteTypeCache noteType, int entityId)
        {
            var         form                  = new List <FormElementItem>();
            RockContext rockContext           = new RockContext();
            NoteService noteService           = new NoteService(rockContext);
            var         currentPersonAliasIds = CurrentPerson.Aliases.Select(a => a.Id);
            var         note                  = noteService.Queryable()
                                                .Where(n => n.NoteTypeId == noteType.Id && n.EntityId == entityId && currentPersonAliasIds.Contains(n.CreatedByPersonAliasId ?? 0))
                                                .FirstOrDefault();

            if (note == null)
            {
                note = new Rock.Model.Note
                {
                    NoteTypeId = noteType.Id,
                    EntityId   = entityId,
                    Text       = ""
                };
            }

            var hidden = new FormElementItem
            {
                Type  = FormElementType.Hidden,
                Key   = "entityId",
                Value = entityId.ToString()
            };

            form.Add(hidden);

            var editor = new FormElementItem
            {
                Label         = GetAttributeValue("NoteFieldLabel"),
                HeightRequest = GetAttributeValue("NoteFieldHeight").AsInteger(),
                Type          = FormElementType.Editor,
                Key           = "note",
                Value         = note.Text,
            };

            form.Add(editor);

            var button = new FormElementItem
            {
                Key   = "save",
                Type  = FormElementType.Button,
                Label = "Save"
            };

            form.Add(button);

            return(form);
        }
Esempio n. 21
0
        /// <summary>
        /// Gets the viewable note types.
        /// </summary>
        /// <returns></returns>
        private ICollection <NoteTypeCache> GetViewableNoteTypes()
        {
            var contextEntityType = EntityTypeCache.Get(ContextEntityType);

            if (contextEntityType == null)
            {
                return(new NoteTypeCache[0]);
            }

            return(NoteTypeCache.GetByEntity(contextEntityType.Id, string.Empty, string.Empty, true)
                   .Where(a => !NoteTypes.Any() || NoteTypes.Contains(a.Guid))
                   .Where(a => a.IsAuthorized(Authorization.VIEW, RequestContext.CurrentPerson))
                   .ToList());
        }
Esempio n. 22
0
        /// <summary>
        /// Handles the GridReorder event of the rGrid control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="GridReorderEventArgs"/> instance containing the event data.</param>
        protected void rGrid_GridReorder(object sender, GridReorderEventArgs e)
        {
            var rockContext = new RockContext();
            var noteTypes   = GetNoteTypes(rockContext).ToList();

            if (noteTypes != null)
            {
                new NoteTypeService(rockContext).Reorder(noteTypes, e.OldIndex, e.NewIndex);
                rockContext.SaveChanges();

                noteTypes.ForEach(t => NoteTypeCache.Flush(t.Id));
            }

            BindGrid();
        }
Esempio n. 23
0
        private List <NoteTypeCache> GetNoteTypes(string viewStateKey)
        {
            var noteTypes   = new List <NoteTypeCache>();
            var noteTypeIds = ViewState[viewStateKey] as List <int> ?? new List <int>();

            foreach (var noteTypeId in noteTypeIds)
            {
                var noteType = NoteTypeCache.Read(noteTypeId);
                if (noteType != null)
                {
                    noteTypes.Add(noteType);
                }
            }
            return(noteTypes);
        }
Esempio n. 24
0
        /// <summary>
        /// Returns the field's current value(s)
        /// </summary>
        /// <param name="parentControl">The parent control.</param>
        /// <param name="value">Information about the value</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param>
        /// <returns></returns>
        public override string FormatValue(Control parentControl, string value, Dictionary <string, ConfigurationValue> configurationValues, bool condensed)
        {
            string formattedValue = string.Empty;

            if (!string.IsNullOrWhiteSpace(value))
            {
                var noteType = NoteTypeCache.Get(value.AsGuid());
                if (noteType != null)
                {
                    formattedValue = noteType.Name;
                }
            }

            return(base.FormatValue(parentControl, formattedValue, null, condensed));
        }
        private List <NoteTypeCache> getNoteTypes()
        {
            var noteTypes = NoteTypeCache.GetByEntity(_entityTypeId, string.Empty, string.Empty, true);

            // If block is configured to only allow certain note types, limit notes to those types.
            var configuredPersonNoteTypes      = GetAttributeValue("PersonNoteTypes").SplitDelimitedValues().AsGuidList();
            var configuredGroupMemberNoteTypes = GetAttributeValue("GroupMemberNoteTypes").SplitDelimitedValues().AsGuidList();

            if (configuredPersonNoteTypes.Any() || configuredGroupMemberNoteTypes.Any())
            {
                noteTypes = noteTypes.Where(n => configuredPersonNoteTypes.Contains(n.Guid) || configuredGroupMemberNoteTypes.Contains(n.Guid)).ToList();
            }

            return(noteTypes);
        }
Esempio n. 26
0
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            errorMessages = new List <string>();

            var person = GetPersonAliasFromActionAttribute(AttributeKey.Person, rockContext, action, errorMessages);

            if (person != null)
            {
                var mergeFields = GetMergeFields(action);

                NoteService noteService = new NoteService(rockContext);

                Note note = new Note();
                note.EntityId       = person.Id;
                note.Caption        = GetAttributeValue(action, AttributeKey.Caption).ResolveMergeFields(mergeFields);
                note.IsAlert        = GetAttributeValue(action, AttributeKey.Alert).AsBoolean();
                note.IsPrivateNote  = false;
                note.Text           = GetAttributeValue(action, AttributeKey.Text).ResolveMergeFields(mergeFields);
                note.EditedDateTime = RockDateTime.Now;

                var noteType = NoteTypeCache.Get(GetAttributeValue(action, AttributeKey.NoteType).AsGuid());
                if (noteType != null)
                {
                    note.NoteTypeId = noteType.Id;
                }

                // get author
                var author = GetPersonAliasFromActionAttribute(AttributeKey.Author, rockContext, action, errorMessages);
                if (author != null)
                {
                    note.CreatedByPersonAliasId = author.PrimaryAlias.Id;
                }

                noteService.Add(note);
                rockContext.SaveChanges();

                return(true);
            }
            else
            {
                errorMessages.Add("No person was provided for the note.");
            }

            errorMessages.ForEach(m => action.AddLogEntry(m, true));

            return(true);
        }
Esempio n. 27
0
        protected void btnCustomNotes_Click(object sender, EventArgs e)
        {
            RockContext rockContext = new RockContext();
            NoteService noteService = new NoteService(rockContext);
            var         noteType    = NoteTypeCache.Get(GetAttributeValue("NoteType").AsGuid());

            Note note = new Note()
            {
                NoteTypeId = noteType.Id,
                Text       = tbCustomNotes.Text,
                EntityId   = hfCustomNotesPersonId.ValueAsInt()
            };

            noteService.Add(note);
            rockContext.SaveChanges();
            UpdateCustomNotes(hfCustomNotesPersonId.ValueAsInt());
        }
Esempio n. 28
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            var contextEntity = this.ContextEntity();

            if (contextEntity != null)
            {
                upNotes.Visible = true;

                string noteTypeName = GetAttributeValue("NoteType");

                using (var rockContext = new RockContext())
                {
                    var noteTypes = NoteTypeCache.GetByEntity(contextEntity.TypeId, string.Empty, string.Empty, true);

                    // If block is configured to only allow certain note types, limit notes to those types.
                    var configuredNoteTypes = GetAttributeValue("NoteTypes").SplitDelimitedValues().AsGuidList();
                    if (configuredNoteTypes.Any())
                    {
                        noteTypes = noteTypes.Where(n => configuredNoteTypes.Contains(n.Guid)).ToList();
                    }

                    notesTimeline.EntityId          = contextEntity.Id;
                    notesTimeline.NoteTypes         = noteTypes;
                    notesTimeline.Title             = GetAttributeValue("Heading");
                    notesTimeline.TitleIconCssClass = GetAttributeValue("HeadingIcon");
                    notesTimeline.Term                = GetAttributeValue("NoteTerm");
                    notesTimeline.DisplayType         = GetAttributeValue("DisplayType") == "Light" ? NoteDisplayType.Light : NoteDisplayType.Full;
                    notesTimeline.UsePersonIcon       = GetAttributeValue("UsePersonIcon").AsBoolean();
                    notesTimeline.ShowAlertCheckBox   = GetAttributeValue("ShowAlertCheckbox").AsBoolean();
                    notesTimeline.ShowPrivateCheckBox = GetAttributeValue("ShowPrivateCheckbox").AsBoolean();
                    notesTimeline.ShowSecurityButton  = GetAttributeValue("ShowSecurityButton").AsBoolean();
                    notesTimeline.AllowAnonymousEntry = GetAttributeValue("Allow Anonymous").AsBoolean();
                    notesTimeline.AddAlwaysVisible    = GetAttributeValue("AddAlwaysVisible").AsBoolean();
                    notesTimeline.SortDirection       = GetAttributeValue("DisplayOrder") == "Ascending" ? ListSortDirection.Ascending : ListSortDirection.Descending;
                    notesTimeline.ShowCreateDateInput = GetAttributeValue("AllowBackdatedNotes").AsBoolean();
                }
            }
            else
            {
                upNotes.Visible = false;
            }
        }
Esempio n. 29
0
        protected void mdEdit_SaveClick(object sender, EventArgs e)
        {
            RockContext rockContext  = new RockContext();
            NoteService noteService  = new NoteService(rockContext);
            var         keys         = (ddlMatrixItem.SelectedValue).SplitDelimitedValues();
            var         personId     = keys[0].AsInteger();
            var         matrixId     = keys[1].AsInteger();
            var         scheduleGuid = keys[2].AsGuid();

            AttributeMatrixItemService attributeMatrixItemService = new AttributeMatrixItemService(rockContext);
            var matrix = attributeMatrixItemService.Get(matrixId);

            matrix.LoadAttributes();
            var noteType = NoteTypeCache.Get(GetAttributeValue("NoteType").AsGuid());


            var noteId = hfNoteId.ValueAsInt();
            var note   = noteService.Get(noteId);

            if (note == null)
            {
                note = new Note
                {
                    NoteTypeId  = noteType.Id,
                    EntityId    = personId,
                    ForeignId   = matrixId,
                    ForeignGuid = scheduleGuid,
                    Caption     = "Medication Distributed"
                };
                noteService.Add(note);
            }

            note.Text = string.Format(
                "<span class=\"field-name\">{0}</span> was distributed at <span class=\"field-name\">{1}</span>",
                matrix.GetAttributeValue("Medication"),
                dtpDateTime.SelectedDateTime.Value);

            note.CreatedDateTime = dtpDateTime.SelectedDateTime.Value;

            rockContext.SaveChanges(true);

            mdEdit.Hide();
            ShowNotesModal(hfPersonId.ValueAsInt());
        }
Esempio n. 30
0
        public object SaveUserValues(Guid itemGuid, Dictionary <string, string> userValues)
        {
            if (RequestContext.CurrentPerson == null)
            {
                return(ActionStatusCode(System.Net.HttpStatusCode.Unauthorized));
            }

            using (var rockContext = new RockContext())
            {
                var contentChannelItemService = new ContentChannelItemService(rockContext);
                var noteService = new NoteService(rockContext);
                var noteTypeId  = NoteTypeCache.Get(SystemGuid.NoteType.CONTENT_CHANNEL_ITEM_STRUCTURED_CONTENT_USER_VALUE).Id;

                var item = contentChannelItemService.Get(itemGuid);

                if (item == null)
                {
                    return(ActionNotFound());
                }

                var note = noteService.Queryable()
                           .Where(a => a.NoteTypeId == noteTypeId && a.EntityId == item.Id)
                           .Where(a => a.CreatedByPersonAliasId.HasValue && a.CreatedByPersonAlias.PersonId == RequestContext.CurrentPerson.Id)
                           .FirstOrDefault();

                if (note == null)
                {
                    note = new Note
                    {
                        NoteTypeId = noteTypeId,
                        EntityId   = item.Id
                    };

                    noteService.Add(note);
                }

                note.Text = userValues.ToJson();

                rockContext.SaveChanges();
            }

            return(ActionOk());
        }