예제 #1
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="metricValueId">The metric value identifier.</param>
        /// <param name="metricId">The metric identifier.</param>
        public void ShowDetail( int metricValueId, int? metricId )
        {
            pnlDetails.Visible = true;

            // Load depending on Add(0) or Edit
            MetricValue metricValue = null;
            if ( !metricValueId.Equals( 0 ) )
            {
                metricValue = new MetricValueService( new RockContext() ).Get( metricValueId );
                lActionTitle.Text = ActionTitle.Edit( MetricValue.FriendlyTypeName ).FormatAsHtmlTitle();
                pdAuditDetails.SetEntity( metricValue, ResolveRockUrl( "~" ) );
            }

            if ( metricValue == null && metricId.HasValue )
            {
                metricValue = new MetricValue { Id = 0, MetricId = metricId.Value };
                metricValue.Metric = metricValue.Metric ?? new MetricService( new RockContext() ).Get( metricValue.MetricId );
                lActionTitle.Text = ActionTitle.Add( MetricValue.FriendlyTypeName ).FormatAsHtmlTitle();
                // hide the panel drawer that show created and last modified dates
                pdAuditDetails.Visible = false;
            }

            hfMetricValueId.Value = metricValue.Id.ToString();

            LoadDropDowns();

            ddlMetricValueType.SelectedValue = metricValue.MetricValueType.ConvertToInt().ToString();
            tbXValue.Text = metricValue.XValue;
            tbYValue.Text = metricValue.YValue.ToString();
            hfMetricId.Value = metricValue.MetricId.ToString();
            tbNote.Text = metricValue.Note;
            dpMetricValueDateTime.SelectedDate = metricValue.MetricValueDateTime;

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

            nbEditModeMessage.Text = string.Empty;

            bool canEdit = UserCanEdit;
            if ( !canEdit && metricId.HasValue && metricId.Value > 0 )
            {
                var metric = new MetricService( new RockContext() ).Get( metricId.Value );
                if ( metric != null && metric.IsAuthorized( Authorization.EDIT, CurrentPerson ) )
                {
                    canEdit = true;
                }
            }

            if ( !canEdit )
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( MetricValue.FriendlyTypeName );
            }

            if ( readOnly )
            {
                lActionTitle.Text = ActionTitle.View( MetricValue.FriendlyTypeName );
                btnCancel.Text = "Close";
            }

            CreateDynamicControls( metricValue, true, readOnly );

            ddlMetricValueType.Enabled = !readOnly;
            tbXValue.ReadOnly = readOnly;
            tbYValue.ReadOnly = readOnly;
            tbNote.ReadOnly = readOnly;
            dpMetricValueDateTime.Enabled = !readOnly;

            btnSave.Visible = !readOnly;
        }
예제 #2
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="metricValueId">The metric value identifier.</param>
        /// <param name="metricId">The metric identifier.</param>
        public void ShowDetail( int metricValueId, int? metricId )
        {
            pnlDetails.Visible = true;

            // Load depending on Add(0) or Edit
            MetricValue metricValue = null;
            if ( !metricValueId.Equals( 0 ) )
            {
                metricValue = new MetricValueService( new RockContext() ).Get( metricValueId );
                lActionTitle.Text = ActionTitle.Edit( MetricValue.FriendlyTypeName ).FormatAsHtmlTitle();
            }

            if ( metricValue == null && metricId.HasValue )
            {
                metricValue = new MetricValue { Id = 0, MetricId = metricId.Value };
                metricValue.Metric = metricValue.Metric ?? new MetricService( new RockContext() ).Get( metricValue.MetricId );
                lActionTitle.Text = ActionTitle.Add( MetricValue.FriendlyTypeName ).FormatAsHtmlTitle();
            }

            hfMetricValueId.Value = metricValue.Id.ToString();

            LoadDropDowns();

            ddlMetricValueType.SelectedValue = metricValue.MetricValueType.ConvertToInt().ToString();
            tbXValue.Text = metricValue.XValue;
            tbYValue.Text = metricValue.YValue.ToString();
            hfMetricId.Value = metricValue.MetricId.ToString();
            tbNote.Text = metricValue.Note;
            dpMetricValueDateTime.SelectedDateTime = metricValue.MetricValueDateTime;

            var metricEntityType = EntityTypeCache.Read( metricValue.Metric.EntityTypeId ?? 0 );

            // Setup EntityType UI controls
            Control entityTypeEditControl = null;
            if ( metricEntityType != null && metricEntityType.SingleValueFieldType != null )
            {
                hfSingleValueFieldTypeId.Value = metricEntityType.SingleValueFieldType.Id.ToString();
                FieldTypeCache fieldType = FieldTypeCache.Read( hfSingleValueFieldTypeId.Value.AsInteger() );
                entityTypeEditControl = fieldType.Field.EditControl( new Dictionary<string, Rock.Field.ConfigurationValue>(), "entityTypeEditControl" );

                if ( entityTypeEditControl is IRockControl )
                {
                    ( entityTypeEditControl as IRockControl ).Label = fieldType.Name;
                }

                phEntityTypeEntityIdValue.Controls.Add( entityTypeEditControl );
                IEntityFieldType entityFieldType = metricEntityType.SingleValueFieldType.Field as IEntityFieldType;
                if ( entityFieldType != null )
                {
                    entityFieldType.SetEditValueFromEntityId( entityTypeEditControl, new Dictionary<string, ConfigurationValue>(), metricValue.EntityId );
                }
            }

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

            nbEditModeMessage.Text = string.Empty;

            bool canEdit = UserCanEdit;
            if ( !canEdit && metricId.HasValue && metricId.Value > 0 )
            {
                var metric = new MetricService( new RockContext() ).Get( metricId.Value );
                if ( metric != null && metric.IsAuthorized( Authorization.EDIT, CurrentPerson ) )
                {
                    canEdit = true;
                }
            }

            if ( !canEdit )
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( MetricValue.FriendlyTypeName );
            }

            if ( readOnly )
            {
                lActionTitle.Text = ActionTitle.View( MetricValue.FriendlyTypeName );
                btnCancel.Text = "Close";
            }

            ddlMetricValueType.Enabled = !readOnly;
            tbXValue.ReadOnly = readOnly;
            tbYValue.ReadOnly = readOnly;
            tbNote.ReadOnly = readOnly;
            dpMetricValueDateTime.Enabled = !readOnly;
            if ( entityTypeEditControl is WebControl )
            {
                ( entityTypeEditControl as WebControl ).Enabled = !readOnly;
            }

            btnSave.Visible = !readOnly;
        }
예제 #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();

            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;
                }
            }
        }