Class representing an area in an Umbraco Grid.
Inheritance: Skybrud.Umbraco.GridData.Json.GridJsonObject
Esempio n. 1
0
        /// <summary>
        /// Parses an area from the specified <paramref name="obj"/>.
        /// </summary>
        /// <param name="row">The parent row of the area.</param>
        /// <param name="obj">The instance of <see cref="JObject"/> to be parsed.</param>
        public static GridArea Parse(GridRow row, JObject obj)
        {
            // Some input validation
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            // Parse the array of allow blocks
            JArray allowed = obj.GetArray("allowed");

            // Parse basic properties
            GridArea area = new GridArea(obj)
            {
                Row      = row,
                Grid     = obj.GetInt32("grid"),
                AllowAll = obj.GetBoolean("allowAll"),
                Allowed  = allowed == null ? new string[0] : allowed.Select(x => (string)x).ToArray()
            };

            // Parse the controls
            area.Controls = obj.GetArray("controls", x => GridControl.Parse(area, x)) ?? new GridControl[0];

            // Update "PreviousArea" and "NextArea" properties
            for (int i = 1; i < area.Controls.Length; i++)
            {
                area.Controls[i - 1].NextControl = area.Controls[i];
                area.Controls[i].PreviousControl = area.Controls[i - 1];
            }

            // Return the row
            return(area);
        }
        /// <summary>
        /// Parses a control from the specified <paramref name="obj"/>.
        /// </summary>
        /// <param name="area">The parent area of the control.</param>
        /// <param name="obj">The instance of <see cref="JObject"/> to be parsed.</param>
        public static GridControl Parse(GridArea area, JObject obj)
        {
            // Set basic properties
            GridControl control = new GridControl(obj)
            {
                Area = area
            };

            Howdy.ReplaceEditorObjectFromConfig(control);

            // Parse the editor
            control.Editor = obj.GetObject("editor", x => GridEditor.Parse(control, x));

            // Parse the control value
            JToken value = obj.GetValue("value");

            foreach (IGridConverter converter in GridContext.Current.Converters)
            {
                try {
                    IGridControlValue converted;
                    if (!converter.ConvertControlValue(control, value, out converted))
                    {
                        continue;
                    }
                    control.Value = converted;
                    break;
                } catch (Exception ex) {
                    global::Umbraco.Core.Composing.Current.Logger.Error <GridControl>(ex, "Converter of type " + converter + " failed for ConvertControlValue()");
                }
            }

            return(control);
        }
        /// <summary>
        /// Parses a row from the specified <paramref name="obj"/>.
        /// </summary>
        /// <param name="section">The parent section of the row.</param>
        /// <param name="obj">The instance of <see cref="JObject"/> to be parsed.</param>
        public static GridRow Parse(GridSection section, JObject obj)
        {
            // Some input validation
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            // Parse basic properties
            GridRow row = new GridRow(obj)
            {
                Section = section,
                Id      = obj.GetString("id"),
                Alias   = obj.GetString("alias"),
                Label   = obj.GetString("label"),
                Name    = obj.GetString("name")
            };

            // Parse the areas
            row.Areas = obj.GetArray("areas", x => GridArea.Parse(row, x)) ?? new GridArea[0];

            // Update "PreviousArea" and "NextArea" properties
            for (int i = 1; i < row.Areas.Length; i++)
            {
                row.Areas[i - 1].NextArea = row.Areas[i];
                row.Areas[i].PreviousArea = row.Areas[i - 1];
            }

            // Return the row
            return(row);
        }
Esempio n. 4
0
        /// <summary>
        /// Parses a control from the specified <paramref name="obj"/>.
        /// </summary>
        /// <param name="area">The parent area of the control.</param>
        /// <param name="obj">The instance of <see cref="JObject"/> to be parsed.</param>
        public static GridControl Parse(GridArea area, JObject obj)
        {
            // Set basic properties
            GridControl control = new GridControl(obj)
            {
                Area = area
            };

            // As of Umbraco 7.3, information about the editor is no longer saved in the JSON, since these should be read from the configuration
            if (UmbracoVersion.Current.Major == 7 && UmbracoVersion.Current.Minor >= 3)
            {
                Howdy.ReplaceEditorObjectFromConfig(control);
            }

            // Parse the editor
            control.Editor = obj.GetObject("editor", x => GridEditor.Parse(control, x));

            // Parse the control value
            JToken value = obj.GetValue("value");

            foreach (IGridConverter converter in GridContext.Current.Converters)
            {
                try {
                    IGridControlValue converted;
                    if (!converter.ConvertControlValue(control, value, out converted))
                    {
                        continue;
                    }
                    control.Value = converted;
                    break;
                } catch (Exception ex) {
                    LogHelper.Error <GridControl>("Converter of type " + converter + " failed for ConvertControlValue()", ex);
                }
            }

            return(control);
        }
        /// <summary>
        /// Parses an area from the specified <code>obj</code>.
        /// </summary>
        /// <param name="row">The parent row of the area.</param>
        /// <param name="obj">The instance of <code>JObject</code> to be parsed.</param>
        public static GridArea Parse(GridRow row, JObject obj) {

            // Some input validation
            if (obj == null) throw new ArgumentNullException("obj");
            
            // Parse the array of allow blocks
            JArray allowed = obj.GetArray("allowed");
            
            // Parse basic properties
            GridArea area = new GridArea(obj) {
                Row = row,
                Grid = obj.GetInt32("grid"),
                AllowAll = obj.GetBoolean("allowAll"),
                Allowed = allowed == null ? new string[0] : allowed.Select(x => (string)x).ToArray(),
                Styles = obj.GetObject("styles", GridDictionary.Parse),
                Config = obj.GetObject("config", GridDictionary.Parse)
            };

            // Parse the controls
            area.Controls = obj.GetArray("controls", x => GridControl.Parse(area, x)) ?? new GridControl[0];
            
            // Update "PreviousArea" and "NextArea" properties
            for (int i = 1; i < area.Controls.Length; i++) {
                area.Controls[i - 1].NextControl = area.Controls[i];
                area.Controls[i].PreviousControl = area.Controls[i - 1];
            }
            
            // Return the row
            return area;
        
        }