/// <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); _rockContext = new RockContext(); int groupId = PageParameter("GroupId").AsInteger(); _group = new GroupService(_rockContext) .Queryable("GroupLocations").AsNoTracking() .FirstOrDefault(g => g.Id == groupId); if (_group != null && (_group.IsAuthorized(Authorization.VIEW, CurrentPerson) || LineQuery.IsGroupInPersonsLine(_group, CurrentPerson))) { _group.LoadAttributes(_rockContext); _canView = true; rFilter.ApplyFilterClick += rFilter_ApplyFilterClick; gOccurrences.DataKeyNames = new string[] { "Date", "ScheduleId", "LocationId" }; gOccurrences.Actions.AddClick += gOccurrences_Add; gOccurrences.GridRebind += gOccurrences_GridRebind; gOccurrences.RowDataBound += gOccurrences_RowDataBound; // make sure they have Auth to edit the block OR edit to the Group bool canEditBlock = IsUserAuthorized(Authorization.EDIT) || _group.IsAuthorized(Authorization.EDIT, this.CurrentPerson); gOccurrences.Actions.ShowAdd = canEditBlock && GetAttributeValue("AllowAdd").AsBoolean(); gOccurrences.IsDeleteEnabled = canEditBlock; } _allowCampusFilter = GetAttributeValue("AllowCampusFilter").AsBoolean(); bddlCampus.Visible = _allowCampusFilter; if (_allowCampusFilter) { bddlCampus.DataSource = CampusCache.All(); bddlCampus.DataBind(); bddlCampus.Items.Insert(0, new ListItem("All Campuses", "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); RegisterScript(); _rockContext = new RockContext(); int groupId = PageParameter("GroupId").AsInteger(); _group = new GroupService(_rockContext) .Queryable("GroupType,Schedule").AsNoTracking() .FirstOrDefault(g => g.Id == groupId); if (_group != null && CurrentPerson != null && (_group.IsAuthorized(Authorization.EDIT, CurrentPerson) || LineQuery.IsGroupInPersonsLine(_group, CurrentPerson))) { lHeading.Text = " Attendance: " + _group.Name; _canEdit = true; } _allowAdd = GetAttributeValue("AllowAdd").AsBoolean(); _allowCampusFilter = GetAttributeValue("AllowCampusFilter").AsBoolean(); bddlCampus.Visible = _allowCampusFilter; if (_allowCampusFilter) { bddlCampus.DataSource = CampusCache.All(); bddlCampus.DataBind(); bddlCampus.Items.Insert(0, new ListItem("All Campuses", "0")); } }
//// //// Group Methods /// <summary> /// Displays the view group using a lava template /// </summary> private void DisplayViewGroup() { if (_groupId > 0) { RockContext rockContext = new RockContext(); GroupService groupService = new GroupService(rockContext); bool enableDebug = GetAttributeValue("EnableDebug").AsBoolean(); var qry = groupService .Queryable("GroupLocations,Members,Members.Person,Members.Person.PhoneNumbers,GroupType") .Where(g => g.Id == _groupId); if (!enableDebug) { qry = qry.AsNoTracking(); } var group = qry.FirstOrDefault(); // order group members by name if (group != null) { group.Members = group.Members.OrderBy(m => m.Person.LastName).ThenBy(m => m.Person.FirstName).ToList(); } var mergeFields = LavaHelper.GetCommonMergeFields(RockPage, CurrentPerson); mergeFields.Add("Group", group); // add linked pages Dictionary <string, object> linkedPages = new Dictionary <string, object>(); linkedPages.Add("PersonDetailPage", LinkedPageRoute("PersonDetailPage")); linkedPages.Add("RosterPage", LinkedPageRoute("RosterPage")); linkedPages.Add("AttendancePage", LinkedPageRoute("AttendancePage")); linkedPages.Add("CommunicationPage", LinkedPageRoute("CommunicationPage")); mergeFields.Add("LinkedPages", linkedPages); // add collection of allowed security actions Dictionary <string, object> securityActions = new Dictionary <string, object>(); securityActions.Add("View", group != null && group.IsAuthorized(Authorization.VIEW, CurrentPerson)); securityActions.Add("Edit", group != null && (group.IsAuthorized(Authorization.EDIT, CurrentPerson) || LineQuery.IsGroupInPersonsLine(group, CurrentPerson))); securityActions.Add("Administrate", group != null && group.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson)); mergeFields.Add("AllowedActions", securityActions); mergeFields.Add("Groups", string.Join(",", LineQuery.GetCellGroupsInLine(CurrentPerson, new RockContext(), false).Select(g => g.Name).ToList())); mergeFields.Add("LinePermission", LineQuery.IsGroupInPersonsLine(group, CurrentPerson)); Dictionary <string, object> currentPageProperties = new Dictionary <string, object>(); currentPageProperties.Add("Id", RockPage.PageId); currentPageProperties.Add("Path", Request.Path); mergeFields.Add("CurrentPage", currentPageProperties); string template = GetAttributeValue("LavaTemplate"); // show debug info if (enableDebug && IsUserAuthorized(Authorization.EDIT)) { string postbackCommands = @"<h5>Available Postback Commands</h5> <ul> <li><strong>EditGroup:</strong> Shows a panel for modifing group info. Expects a group id. <code>{{ Group.Id | Postback:'EditGroup' }}</code></li> <li><strong>AddGroupMember:</strong> Shows a panel for adding group info. Does not require input. <code>{{ '' | Postback:'AddGroupMember' }}</code></li> <li><strong>EditGroupMember:</strong> Shows a panel for modifing group info. Expects a group member id. <code>{{ member.Id | Postback:'EditGroupMember' }}</code></li> <li><strong>DeleteGroupMember:</strong> Deletes a group member. Expects a group member id. <code>{{ member.Id | Postback:'DeleteGroupMember' }}</code></li> <li><strong>SendCommunication:</strong> Sends a communication to all group members on behalf of the Current User. This will redirect them to the communication page where they can author their email. <code>{{ '' | Postback:'SendCommunication' }}</code></li> </ul>"; lDebug.Visible = true; lDebug.Text = mergeFields.lavaDebugInfo(null, string.Empty, postbackCommands); } lContent.Text = template.ResolveMergeFields(mergeFields).ResolveClientIds(upnlContent.ClientID); } else { lContent.Text = "<div class='alert alert-warning'>No group was available from the querystring.</div>"; } }
/// <summary> /// Displays the edit group panel. /// </summary> private void DisplayEditGroup() { IsEditingGroup = true; if (_groupId != -1) { RockContext rockContext = new RockContext(); GroupService groupService = new GroupService(rockContext); var qry = groupService .Queryable("GroupLocations,GroupType,Schedule") .Where(g => g.Id == _groupId); var group = qry.FirstOrDefault(); if (group.IsAuthorized(Authorization.EDIT, CurrentPerson) || LineQuery.IsGroupInPersonsLine(group, CurrentPerson)) { tbName.Text = group.Name; tbDescription.Text = group.Description; cbIsActive.Checked = group.IsActive; timeWeekly.Visible = GetAttributeValue("ShowTimeField").AsBoolean(); if ((group.GroupType.AllowedScheduleTypes & ScheduleType.Weekly) == ScheduleType.Weekly) { pnlSchedule.Visible = group.Schedule == null || group.Schedule.ScheduleType == ScheduleType.Weekly; if (group.Schedule != null) { dowWeekly.SelectedDayOfWeek = group.Schedule.WeeklyDayOfWeek; timeWeekly.SelectedTime = group.Schedule.WeeklyTimeOfDay; } else { dowWeekly.SelectedDayOfWeek = null; timeWeekly.SelectedTime = null; } } else { pnlSchedule.Visible = false; } group.LoadAttributes(); phAttributes.Controls.Clear(); Helper.AddEditControls(group, phAttributes, true, BlockValidationGroup); // enable editing location pnlGroupEditLocations.Visible = GetAttributeValue("EnableLocationEdit").AsBoolean(); if (GetAttributeValue("EnableLocationEdit").AsBoolean()) { ConfigureGroupLocationControls(group); // set location tabs rptLocationTypes.DataSource = _tabs; rptLocationTypes.DataBind(); } } else { lContent.Text = "<div class='alert alert-warning'>You do not have permission to edit this group.</div>"; } } else { lContent.Text = "<div class='alert alert-warning'>No group was available from the querystring.</div>"; } }
/// <summary> /// Handles the Click event of the btnSaveGroup 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 btnSaveGroup_Click(object sender, EventArgs e) { var rockContext = new RockContext(); GroupService groupService = new GroupService(rockContext); Group group = groupService.Get(_groupId); if (group != null && (group.IsAuthorized(Authorization.EDIT, CurrentPerson) || LineQuery.IsGroupInPersonsLine(group, CurrentPerson))) { group.Name = tbName.Text; group.Description = tbDescription.Text; group.IsActive = cbIsActive.Checked; if (pnlSchedule.Visible) { if (group.Schedule == null) { group.Schedule = new Schedule(); group.Schedule.iCalendarContent = null; } group.Schedule.WeeklyDayOfWeek = dowWeekly.SelectedDayOfWeek; group.Schedule.WeeklyTimeOfDay = timeWeekly.SelectedTime; } // set attributes group.LoadAttributes(rockContext); Helper.GetEditValues(phAttributes, group); // configure locations if (GetAttributeValue("EnableLocationEdit").AsBoolean()) { // get selected location Location location = null; int? memberPersonAliasId = null; if (LocationTypeTab.Equals(MEMBER_LOCATION_TAB_TITLE)) { if (ddlMember.SelectedValue != null) { var ids = ddlMember.SelectedValue.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); if (ids.Length == 2) { var dbLocation = new LocationService(rockContext).Get(int.Parse(ids[0])); if (dbLocation != null) { location = dbLocation; } memberPersonAliasId = new PersonAliasService(rockContext).GetPrimaryAliasId(int.Parse(ids[1])); } } } else { if (locpGroupLocation.Location != null) { location = new LocationService(rockContext).Get(locpGroupLocation.Location.Id); } } if (location != null) { GroupLocation groupLocation = group.GroupLocations.FirstOrDefault(); if (groupLocation == null) { groupLocation = new GroupLocation(); group.GroupLocations.Add(groupLocation); } groupLocation.GroupMemberPersonAliasId = memberPersonAliasId; groupLocation.Location = location; groupLocation.LocationId = groupLocation.Location.Id; groupLocation.GroupLocationTypeValueId = ddlLocationType.SelectedValueAsId(); } } rockContext.SaveChanges(); group.SaveAttributeValues(rockContext); } IsEditingGroup = false; // reload the group info pnlGroupEdit.Visible = false; pnlGroupView.Visible = true; DisplayViewGroup(); }