Пример #1
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)
            {
                // create dynamic controls
                var rockContext = new RockContext();
                var metricValue = new MetricValueService(rockContext).Get(hfMetricValueId.Value.AsInteger());
                if (metricValue == null)
                {
                    metricValue = new MetricValue {
                        MetricId = hfMetricId.Value.AsInteger()
                    };
                    metricValue.Metric = new MetricService(rockContext).Get(metricValue.MetricId);
                }

                CreateDynamicControls(metricValue, false, false);
            }

            if (!Page.IsPostBack)
            {
                int?metricValueId = PageParameter("MetricValueId").AsIntegerOrNull();

                // in case called with MetricId as the parent id parameter
                int?metricId = PageParameter("MetricId").AsIntegerOrNull();

                // in case called with MetricCategoryId as the parent id parameter
                int?           metricCategoryId = PageParameter("MetricCategoryId").AsIntegerOrNull();
                MetricCategory metricCategory   = null;
                if (metricCategoryId.HasValue)
                {
                    if (metricCategoryId.Value > 0)
                    {
                        // editing a metric, but get the metricId from the metricCategory
                        metricCategory = new MetricCategoryService(new RockContext()).Get(metricCategoryId.Value);
                        if (metricCategory != null)
                        {
                            metricId = metricCategory.MetricId;
                        }
                    }
                    else
                    {
                        // adding a new metric. Block will (hopefully) not be shown
                        metricId = 0;
                    }
                }

                hfMetricCategoryId.Value = metricCategoryId.ToString();

                if (metricValueId.HasValue)
                {
                    ShowDetail(metricValueId.Value, metricId);
                }
                else
                {
                    pnlDetails.Visible = false;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Sets the value.
        /// </summary>
        /// <param name="metricCategory">The metric category.</param>
        public void SetValue( MetricCategory metricCategory )
        {
            if ( metricCategory != null )
            {
                ItemId = metricCategory.Id.ToString();

                var parentCategoryIds = new List<string>();
                var parentCategory = metricCategory.Category;
                while ( parentCategory != null )
                {
                    if ( !parentCategoryIds.Contains( parentCategory.Id.ToString() ) )
                    {
                        parentCategoryIds.Insert( 0, parentCategory.Id.ToString() );
                    }
                    else
                    {
                        // infinite recursion
                        break;
                    }

                    parentCategory = parentCategory.ParentCategory;
                }

                InitialItemParentIds = parentCategoryIds.AsDelimited( "," );
                ItemName = metricCategory.Name;
            }
            else
            {
                ItemId = Constants.None.IdValue;
                ItemName = Constants.None.TextHtml;
            }
        }
Пример #3
0
        /// <summary>
        /// Sets the hidden field values.
        /// </summary>
        private void SetHiddenFieldValues()
        {
            var rockContext = new RockContext();

            // in case called normally
            int?metricId = PageParameter("MetricId").AsIntegerOrNull();

            // in case called from CategoryTreeView
            int?           metricCategoryId = PageParameter("MetricCategoryId").AsIntegerOrNull();
            MetricCategory metricCategory   = null;

            if (metricCategoryId.HasValue)
            {
                if (metricCategoryId.Value > 0)
                {
                    // editing a metric, but get the metricId from the metricCategory
                    metricCategory = new MetricCategoryService(rockContext).Get(metricCategoryId.Value);
                    if (metricCategory != null)
                    {
                        metricId = metricCategory.MetricId;
                    }
                }
                else
                {
                    // adding a new metric. Block will (hopefully) not be shown
                    metricId = 0;
                }
            }

            hfMetricId.Value         = metricId.ToString();
            hfMetricCategoryId.Value = metricCategoryId.ToString();
        }
Пример #4
0
        /// <summary>
        /// Sets the value.
        /// </summary>
        /// <param name="metricCategory">The metric category.</param>
        public void SetValue(MetricCategory metricCategory)
        {
            if (metricCategory != null)
            {
                ItemId = metricCategory.Id.ToString();

                var parentCategoryIds = new List <string>();
                var parentCategory    = metricCategory.Category;
                while (parentCategory != null)
                {
                    if (!parentCategoryIds.Contains(parentCategory.Id.ToString()))
                    {
                        parentCategoryIds.Insert(0, parentCategory.Id.ToString());
                    }
                    else
                    {
                        // infinite recursion
                        break;
                    }

                    parentCategory = parentCategory.ParentCategory;
                }

                ExpandedCategoryIds = parentCategoryIds.AsDelimited(",");
                ItemName            = metricCategory.Name;
            }
            else
            {
                ItemId   = Constants.None.IdValue;
                ItemName = Constants.None.TextHtml;
            }
        }
        /// <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)
            {
                // create dynamic controls
                FieldTypeCache fieldType = FieldTypeCache.Read(hfSingleValueFieldTypeId.Value.AsInteger());
                if (fieldType != null)
                {
                    var entityTypeEditControl = fieldType.Field.EditControl(new Dictionary <string, Rock.Field.ConfigurationValue>(), "entityTypeEditControl");
                    phEntityTypeEntityIdValue.Controls.Add(entityTypeEditControl);
                    if (entityTypeEditControl is IRockControl)
                    {
                        (entityTypeEditControl as IRockControl).Label = fieldType.Name;
                    }
                }
            }

            if (!Page.IsPostBack)
            {
                int?metricValueId = PageParameter("MetricValueId").AsIntegerOrNull();

                // in case called with MetricId as the parent id parameter
                int?metricId = PageParameter("MetricId").AsIntegerOrNull();

                // in case called with MetricCategoryId as the parent id parameter
                int?           metricCategoryId = PageParameter("MetricCategoryId").AsIntegerOrNull();
                MetricCategory metricCategory   = null;
                if (metricCategoryId.HasValue)
                {
                    if (metricCategoryId.Value > 0)
                    {
                        // editing a metric, but get the metricId from the metricCategory
                        metricCategory = new MetricCategoryService(new RockContext()).Get(metricCategoryId.Value);
                        if (metricCategory != null)
                        {
                            metricId = metricCategory.MetricId;
                        }
                    }
                    else
                    {
                        // adding a new metric. Block will (hopefully) not be shown
                        metricId = 0;
                    }
                }

                hfMetricCategoryId.Value = metricCategoryId.ToString();

                if (metricValueId.HasValue)
                {
                    ShowDetail(metricValueId.Value, metricId);
                }
                else
                {
                    pnlDetails.Visible = false;
                }
            }
        }
Пример #6
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)
            {
                // in case called normally
                int?metricId = PageParameter("MetricId").AsInteger(false);

                // in case called from CategoryTreeView
                int?           metricCategoryId = PageParameter("MetricCategoryId").AsInteger(false);
                MetricCategory metricCategory   = null;
                if (metricCategoryId.HasValue)
                {
                    if (metricCategoryId.Value > 0)
                    {
                        // editing a metric, but get the metricId from the metricCategory
                        metricCategory = new MetricCategoryService(new RockContext()).Get(metricCategoryId.Value);
                        if (metricCategory != null)
                        {
                            hfMetricCategoryId.Value = metricCategory.Id.ToString();
                            metricId = metricCategory.MetricId;
                        }
                    }
                    else
                    {
                        if (!metricId.HasValue)
                        {
                            // adding a new metric
                            metricId = 0;
                        }
                    }
                }

                int?parentCategoryId = PageParameter("ParentCategoryId").AsInteger(false);

                if (metricId.HasValue)
                {
                    if (parentCategoryId.HasValue)
                    {
                        ShowDetail("MetricId", metricId.Value, parentCategoryId);
                    }
                    else
                    {
                        ShowDetail("MetricId", metricId.Value);
                    }
                }
                else
                {
                    pnlDetails.Visible = false;
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Sets the hidden field values.
        /// </summary>
        private void SetHiddenFieldValues()
        {
            var rockContext = new RockContext();

            // in case called normally
            int?metricId = PageParameter("MetricId").AsIntegerOrNull();

            hfEntityTypeName.Value = string.Empty;

            // in case called from CategoryTreeView
            int?           metricCategoryId = PageParameter("MetricCategoryId").AsIntegerOrNull();
            MetricCategory metricCategory   = null;

            if (metricCategoryId.HasValue)
            {
                if (metricCategoryId.Value > 0)
                {
                    // editing a metric, but get the metricId from the metricCategory
                    metricCategory = new MetricCategoryService(rockContext).Get(metricCategoryId.Value);
                    if (metricCategory != null)
                    {
                        metricId = metricCategory.MetricId;
                        if (metricCategory.Metric != null && metricCategory.Metric.EntityType != null)
                        {
                            hfEntityTypeName.Value = metricCategory.Metric.EntityType.FriendlyName;
                        }
                    }
                }
                else
                {
                    // adding a new metric. Block will (hopefully) not be shown
                    metricId = 0;
                }
            }

            hfMetricId.Value         = metricId.ToString();
            hfMetricCategoryId.Value = metricCategoryId.ToString();

            gMetricValues.Actions.ShowAdd = false;
            gMetricValues.IsDeleteEnabled = false;

            if (metricId.HasValue && metricId.Value > 0)
            {
                var metric = new MetricService(new RockContext()).Get(metricId.Value);
                if (UserCanEdit || (metric != null && metric.IsAuthorized(Authorization.EDIT, CurrentPerson)))
                {
                    // Block Security and special attributes (RockPage takes care of View)
                    gMetricValues.Actions.ShowAdd = true;
                    gMetricValues.IsDeleteEnabled = true;
                }
            }
        }
Пример #8
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            MetricValueService metricValueService = new MetricValueService(new RockContext());
            SortProperty       sortProperty       = gMetricValues.SortProperty;
            var qry = metricValueService.Queryable();

            // in case called normally
            int?metricId = PageParameter("MetricId").AsInteger(false);

            // in case called from CategoryTreeView
            int?           metricCategoryId = PageParameter("MetricCategoryId").AsInteger(false);
            MetricCategory metricCategory   = null;

            if (metricCategoryId.HasValue)
            {
                if (metricCategoryId.Value > 0)
                {
                    // editing a metric, but get the metricId from the metricCategory
                    metricCategory = new MetricCategoryService(new RockContext()).Get(metricCategoryId.Value);
                    if (metricCategory != null)
                    {
                        metricId = metricCategory.MetricId;
                    }
                }
                else
                {
                    // adding a new metric. Block will (hopefully) not be shown
                    metricId = 0;
                }
            }

            hfMetricId.Value         = metricId.ToString();
            hfMetricCategoryId.Value = metricCategoryId.ToString();

            this.Visible = metricId.HasValue;

            qry = qry.Where(a => a.MetricId == metricId);

            if (sortProperty != null)
            {
                gMetricValues.DataSource = qry.Sort(sortProperty).ToList();
            }
            else
            {
                gMetricValues.DataSource = qry.OrderBy(s => s.Order).ThenBy(s => s.XValue).ThenBy(s => s.MetricValueDateTime).ThenBy(s => s.YValue).ToList();
            }

            gMetricValues.DataBind();
        }
Пример #9
0
        public static Guid?GetMetricCategoryFromFullName(string FullName, IQueryable <MetricTrac.Bll.MetricCategory> DataSource)
        {
            if (string.IsNullOrEmpty(FullName))
            {
                return(null);
            }
            MetricTrac.Bll.MetricCategory[] t = DataSource.ToArray();
            string[] MetricCategorys          = FullName.Split('>');

            Guid   MetricCategoryID = Guid.Empty;
            string MetricCategory;

            for (int i = 0; i < MetricCategorys.Length; i++)
            {
                MetricCategory = HttpUtility.HtmlEncode(MetricCategorys[i].Trim());

                MetricTrac.Bll.MetricCategory[] c;

                if (i == MetricCategorys.Length - 1)
                {
                    c = t.Where(mc => mc.Name.ToLower().StartsWith(MetricCategory.ToLower())).ToArray();
                }
                else
                {
                    c = t.Where(mc => mc.Name.ToLower() == MetricCategory.ToLower()).ToArray();
                }

                if (MetricCategoryID != Guid.Empty)
                {
                    c = c.Where(mc => mc.ParentId == MetricCategoryID).ToArray();
                }
                else
                {
                    c = c.Where(mc => mc.ParentId == null).ToArray();
                }

                if (c.Length > 0)
                {
                    MetricCategoryID = c[0].MetricCategoryID;
                }
                else
                {
                    return(MetricCategoryID);
                }
            }
            return(MetricCategoryID);
        }
Пример #10
0
        private void ProcessDescendents(IEnumerable <GroupType> descendentGroupTypes, Category rootCategory)
        {
            foreach (var groupType in descendentGroupTypes)
            {
                _seenGroupTypeIds.Add(groupType.Id);
                if (!groupType.Groups.Any() && !groupType.ChildGroupTypes.Any(g => g.Groups.Any()))
                {
                    continue;
                }
                {
                    var category = _categoryService.Queryable().FirstOrDefault(c => c.ForeignGuid == groupType.Guid) ??
                                   MakeGroupTypeCategory(groupType, rootCategory);
                    var groups = groupType.Groups.ToList();
                    foreach (var group in groups)
                    {
                        if (
                            !_metricService.Queryable()
                            .Any(
                                m =>
                                m.MetricCategories.Any(c => c.CategoryId == category.Id) &&
                                m.ForeignGuid != null && m.ForeignGuid == group.Guid))
                        {
                            var metric = MakeGroupMetric(group);
                            _metricService.Add(metric);
                            var metricCategory = new MetricCategory
                            {
                                CategoryId = category.Id,
                                Metric     = metric
                            };
                            _metricCategoryService.Add(metricCategory);
                        }
                    }
                    _rockContext.SaveChanges();

                    if (groupType.ChildGroupTypes != null)
                    {
                        ProcessDescendents(
                            groupType.ChildGroupTypes.Where(
                                g => g.GroupTypePurposeValueId == _checkInTemplateId && !_seenGroupTypeIds.Contains(g.Id))
                            .ToList(), category);
                    }
                }
            }
        }
        /// <summary>
        /// Sets the value.
        /// </summary>
        /// <param name="metricCategory">The metric category.</param>
        public void SetValue( MetricCategory metricCategory )
        {
            if ( metricCategory != null )
            {
                ItemId = metricCategory.Id.ToString();

                string parentCategoryIds = string.Empty;
                var parentCategory = metricCategory.Category;
                while ( parentCategory != null )
                {
                    parentCategoryIds = parentCategory.Id + "," + parentCategoryIds;
                    parentCategory = parentCategory.ParentCategory;
                }

                InitialItemParentIds = parentCategoryIds.TrimEnd( new[] { ',' } );
                ItemName = metricCategory.Name;
            }
            else
            {
                ItemId = Constants.None.IdValue;
                ItemName = Constants.None.TextHtml;
            }
        }
        /// <summary>
        /// Sets the value.
        /// </summary>
        /// <param name="metricCategory">The metric category.</param>
        public void SetValue(MetricCategory metricCategory)
        {
            if (metricCategory != null)
            {
                ItemId = metricCategory.Id.ToString();

                string parentCategoryIds = string.Empty;
                var    parentCategory    = metricCategory.Category;
                while (parentCategory != null)
                {
                    parentCategoryIds = parentCategory.Id + "," + parentCategoryIds;
                    parentCategory    = parentCategory.ParentCategory;
                }

                InitialItemParentIds = parentCategoryIds.TrimEnd(new[] { ',' });
                ItemName             = metricCategory.Name;
            }
            else
            {
                ItemId   = Constants.None.IdValue;
                ItemName = Constants.None.TextHtml;
            }
        }
Пример #13
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="itemKey">The item key.</param>
        /// <param name="itemKeyValue">The item key value.</param>
        /// <param name="parentCategoryId">The parent category id.</param>
        public void ShowDetail(string itemKey, int itemKeyValue, int?parentCategoryId)
        {
            pnlDetails.Visible = false;
            if (!itemKey.Equals("MetricId"))
            {
                return;
            }

            var    rockContext   = new RockContext();
            var    metricService = new MetricService(rockContext);
            Metric metric        = null;

            if (!itemKeyValue.Equals(0))
            {
                metric = metricService.Get(itemKeyValue);
            }
            else
            {
                metric = new Metric {
                    Id = 0, IsSystem = false
                };
                metric.MetricCategories = new List <MetricCategory>();
                if (parentCategoryId.HasValue)
                {
                    var metricCategory = new MetricCategory {
                        CategoryId = parentCategoryId.Value
                    };
                    metricCategory.Category = metricCategory.Category ?? new CategoryService(rockContext).Get(metricCategory.CategoryId);
                    metric.MetricCategories.Add(metricCategory);
                }
            }

            if (metric == null || !metric.IsAuthorized(Authorization.VIEW, CurrentPerson))
            {
                return;
            }

            pnlDetails.Visible = true;
            hfMetricId.Value   = metric.Id.ToString();

            // render UI based on Authorized and IsSystem
            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;

            if (metric.IsSystem)
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem(Metric.FriendlyTypeName);
            }

            btnSecurity.Visible  = metric.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson);
            btnSecurity.Title    = metric.Title;
            btnSecurity.EntityId = metric.Id;

            if (readOnly)
            {
                btnEdit.Visible   = false;
                btnDelete.Visible = false;
                ShowReadonlyDetails(metric);
            }
            else
            {
                btnEdit.Visible = true;
                string errorMessage = string.Empty;
                btnDelete.Visible = metricService.CanDelete(metric, out errorMessage);
                if (metric.Id > 0)
                {
                    ShowReadonlyDetails(metric);
                }
                else
                {
                    ShowEditDetails(metric);
                }
            }
        }
Пример #14
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="metricId">The metric identifier.</param>
        /// <param name="parentCategoryId">The parent category id.</param>
        public void ShowDetail(int metricId, int?parentCategoryId)
        {
            pnlDetails.Visible = false;

            var    rockContext   = new RockContext();
            var    metricService = new MetricService(rockContext);
            Metric metric        = null;

            if (!metricId.Equals(0))
            {
                metric = metricService.Get(metricId);
            }

            if (metric == null)
            {
                metric = new Metric {
                    Id = 0, IsSystem = false
                };
                metric.SourceValueTypeId = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.METRIC_SOURCE_VALUE_TYPE_MANUAL.AsGuid()).Id;
                metric.MetricCategories  = new List <MetricCategory>();
                if (parentCategoryId.HasValue)
                {
                    var metricCategory = new MetricCategory {
                        CategoryId = parentCategoryId.Value
                    };
                    metricCategory.Category = metricCategory.Category ?? new CategoryService(rockContext).Get(metricCategory.CategoryId);
                    metric.MetricCategories.Add(metricCategory);
                }
            }

            if (!metric.IsAuthorized(Authorization.VIEW, CurrentPerson))
            {
                return;
            }

            pnlDetails.Visible = true;
            hfMetricId.Value   = metric.Id.ToString();

            // render UI based on Authorized and IsSystem
            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;

            if (metric.IsSystem)
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem(Metric.FriendlyTypeName);
            }

            if (!UserCanEdit && !metric.IsAuthorized(Authorization.EDIT, CurrentPerson))
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.NotAuthorizedToEdit(Metric.FriendlyTypeName);
            }

            bool canAdministrate = UserCanAdministrate || metric.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson);

            if (canAdministrate)
            {
                btnSecurity.Visible  = true;
                btnSecurity.Title    = metric.Title;
                btnSecurity.EntityId = metric.Id;
            }
            else
            {
                btnSecurity.Visible = false;
            }

            if (readOnly)
            {
                btnEdit.Visible   = false;
                btnDelete.Visible = false;
                ShowReadonlyDetails(metric);
            }
            else
            {
                btnEdit.Visible = true;
                string errorMessage = string.Empty;
                btnDelete.Visible = metricService.CanDelete(metric, out errorMessage);
                if (metric.Id > 0)
                {
                    ShowReadonlyDetails(metric);
                }
                else
                {
                    ShowEditDetails(metric);
                }
            }
        }
Пример #15
0
        /// <summary>
        /// Shows the settings.
        /// </summary>
        protected void ShowSettings()
        {
            flotChart.Visible    = false;
            pnlEditModel.Visible = true;

            var            rockContext           = new RockContext();
            var            metricCategoryService = new MetricCategoryService(rockContext);
            MetricCategory metricCategory        = null;

            if (this.MetricId.HasValue)
            {
                metricCategory = metricCategoryService.Queryable().Where(a => a.MetricId == this.MetricId).FirstOrDefault();
                mpMetricCategoryPicker.SetValue(metricCategory);
            }

            if (this.GetEntityFromContextEnabled)
            {
                rblSelectOrContext.SetValue("1");
            }
            else
            {
                rblSelectOrContext.SetValue("0");
            }

            cbCombineValues.Checked = this.CombineValues;

            rblSelectOrContext_SelectedIndexChanged(null, null);

            if (metricCategory != null)
            {
                var entityTypeEntityIds = (GetAttributeValue("MetricEntityTypeEntityIds") ?? string.Empty).Split(',').Select(a => a.Split('|')).Where(a => a.Length == 2).Select(a => new
                {
                    EntityTypeId = a[0].AsIntegerOrNull(),
                    EntityId     = a[1].AsIntegerOrNull()
                }).ToList();

                int position = 0;
                foreach (var metricPartition in metricCategory.Metric.MetricPartitions.OrderBy(a => a.Order))
                {
                    var     metricPartitionEntityType = EntityTypeCache.Get(metricPartition.EntityTypeId ?? 0);
                    var     controlId             = string.Format("metricPartition{0}_entityTypeEditControl", metricPartition.Id);
                    Control entityTypeEditControl = phMetricValuePartitions.FindControl(controlId);

                    if (entityTypeEntityIds.Count() > position)
                    {
                        var entry = entityTypeEntityIds[position];

                        if (metricPartitionEntityType != null && metricPartitionEntityType.SingleValueFieldType != null && metricPartitionEntityType.SingleValueFieldType.Field is IEntityFieldType)
                        {
                            if (entry != null && entry.EntityTypeId == metricPartitionEntityType.Id)
                            {
                                (metricPartitionEntityType.SingleValueFieldType.Field as IEntityFieldType).SetEditValueFromEntityId(entityTypeEditControl, new Dictionary <string, ConfigurationValue>(), entry.EntityId);
                            }
                        }
                    }

                    position++;
                }
            }

            drpSlidingDateRange.DelimitedValues = GetAttributeValue("SlidingDateRange");

            mdEdit.Show();
        }
Пример #16
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="metricId">The metric identifier.</param>
        /// <param name="parentCategoryId">The parent category id.</param>
        public void ShowDetail( int metricId, int? parentCategoryId )
        {
            pnlDetails.Visible = false;

            var rockContext = new RockContext();
            var metricService = new MetricService( rockContext );
            Metric metric = null;

            if ( !metricId.Equals( 0 ) )
            {
                metric = metricService.Get( metricId );
                pdAuditDetails.SetEntity( metric, ResolveRockUrl( "~" ) );
            }

            if ( metric == null )
            {
                // hide the panel drawer that show created and last modified dates
                pdAuditDetails.Visible = false;
                metric = new Metric { Id = 0, IsSystem = false };
                metric.SourceValueTypeId = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.METRIC_SOURCE_VALUE_TYPE_MANUAL.AsGuid() ).Id;
                metric.MetricCategories = new List<MetricCategory>();
                if ( parentCategoryId.HasValue )
                {
                    var metricCategory = new MetricCategory { CategoryId = parentCategoryId.Value };
                    metricCategory.Category = metricCategory.Category ?? new CategoryService( rockContext ).Get( metricCategory.CategoryId );
                    metric.MetricCategories.Add( metricCategory );
                }

                metric.MetricPartitions = new List<MetricPartition>();
            }

            if ( !metric.IsAuthorized( Authorization.VIEW, CurrentPerson ) )
            {
                return;
            }

            pnlDetails.Visible = true;
            hfMetricId.Value = metric.Id.ToString();

            // render UI based on Authorized and IsSystem
            bool readOnly = false;
            nbEditModeMessage.Text = string.Empty;

            if ( metric.IsSystem )
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem( Metric.FriendlyTypeName );
            }

            if ( !UserCanEdit && !metric.IsAuthorized( Authorization.EDIT, CurrentPerson ) )
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.NotAuthorizedToEdit( Metric.FriendlyTypeName );
            }

            bool canAdministrate = UserCanAdministrate || metric.IsAuthorized( Authorization.ADMINISTRATE, CurrentPerson );
            if ( canAdministrate )
            {
                btnSecurity.Visible = true;
                btnSecurity.Title = metric.Title;
                btnSecurity.EntityId = metric.Id;
            }
            else
            {
                btnSecurity.Visible = false;
            }

            if ( readOnly )
            {
                btnEdit.Visible = false;
                btnDelete.Visible = false;
                ShowReadonlyDetails( metric );
            }
            else
            {
                btnEdit.Visible = true;
                string errorMessage = string.Empty;
                btnDelete.Visible = metricService.CanDelete( metric, out errorMessage );
                if ( metric.Id > 0 )
                {
                    ShowReadonlyDetails( metric );
                }
                else
                {
                    ShowEditDetails( metric );
                }
            }
        }
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="itemKey">The item key.</param>
        /// <param name="itemKeyValue">The item key value.</param>
        /// <param name="parentCategoryId">The parent category id.</param>
        public void ShowDetail( string itemKey, int itemKeyValue, int? parentCategoryId )
        {
            pnlDetails.Visible = false;
            if ( !itemKey.Equals( "MetricId" ) )
            {
                return;
            }

            var rockContext = new RockContext();
            var metricService = new MetricService( rockContext );
            Metric metric = null;

            if ( !itemKeyValue.Equals( 0 ) )
            {
                metric = metricService.Get( itemKeyValue );
            }
            else
            {
                metric = new Metric { Id = 0, IsSystem = false };
                metric.MetricCategories = new List<MetricCategory>();
                if ( parentCategoryId.HasValue )
                {
                    var metricCategory = new MetricCategory { CategoryId = parentCategoryId.Value };
                    metricCategory.Category = metricCategory.Category ?? new CategoryService( rockContext ).Get( metricCategory.CategoryId );
                    metric.MetricCategories.Add( metricCategory );
                }
            }

            if ( metric == null || !metric.IsAuthorized( Authorization.VIEW, CurrentPerson ) )
            {
                return;
            }

            pnlDetails.Visible = true;
            hfMetricId.Value = metric.Id.ToString();

            // render UI based on Authorized and IsSystem
            bool readOnly = false;
            nbEditModeMessage.Text = string.Empty;

            if ( metric.IsSystem )
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem( Metric.FriendlyTypeName );
            }

            btnSecurity.Visible = metric.IsAuthorized( Authorization.ADMINISTRATE, CurrentPerson );
            btnSecurity.Title = metric.Title;
            btnSecurity.EntityId = metric.Id;

            if ( readOnly )
            {
                btnEdit.Visible = false;
                btnDelete.Visible = false;
                ShowReadonlyDetails( metric );
            }
            else
            {
                btnEdit.Visible = true;
                string errorMessage = string.Empty;
                btnDelete.Visible = metricService.CanDelete( metric, out errorMessage );
                if ( metric.Id > 0 )
                {
                    ShowReadonlyDetails( metric );
                }
                else
                {
                    ShowEditDetails( metric );
                }
            }
        }