protected dynamic BuildForms(ElementEditorContext context)
        {
            // TODO: Fix Forms API so that it works with prefixes. Right now only binding implements prefix, but building a form ignores the specified prefix.

            // If not a post-back, we need to bind the form with the element's data values. Otherwise, bind the form with the posted values.
            var valueProvider = context.Updater == null
                ? context.Element.Data.ToValueProvider(_cultureAccessor.CurrentCulture)
                : context.ValueProvider;

            var forms = FormNames.Reverse().Select(x => {
                var shape = _formManager.Bind(_formManager.Build(x), valueProvider);

                if (context.Updater != null)
                {
                    // Update the element's data dictionary with the posted values.
                    Action <object> process = s => UpdateElementProperty(s, context);
                    FormNodesProcessor.ProcessForm(shape, process);
                }

                return(shape);
            }).ToArray();
            var formShape = context.ShapeFactory.ElementEditor__Forms(Forms: forms);

            return(formShape);
        }
        protected dynamic BuildForm(ElementEditorContext context, string formName, string position = null)
        {
            // TODO: Fix Forms API so that it works with prefixes. Right now only binding implements prefix, but building a form ignores the specified prefix.

            // If not a post-back, we need to bind the form with the element's data values. Otherwise, bind the form with the posted values.
            var valueProvider = context.Updater == null
                ? context.Element.Data.ToValueProvider(_cultureAccessor.CurrentCulture)
                : context.ValueProvider;

            var form = _formManager.Bind(_formManager.Build(formName), valueProvider);

            if (context.Updater != null)
            {
                // Update the element's data dictionary with the posted values.
                Action <object> process = s => UpdateElementProperty(s, context);
                FormNodesProcessor.ProcessForm(form, process);
            }

            if (!String.IsNullOrWhiteSpace(position))
            {
                form.Metadata.Position = position;
            }

            return(form);
        }
Example #3
0
        protected EditorResult Editor(ElementEditorContext context, params dynamic[] editorShapes)
        {
            foreach (var editorShape in editorShapes)
            {
                if (String.IsNullOrWhiteSpace(editorShape.Metadata.Position))
                {
                    editorShape.Metadata.Position = "Properties:0";
                }
            }

            var result = new EditorResult {
                Editors = editorShapes.ToList()
            };

            return(result);
        }
        private void UpdateElementProperty(dynamic formElementShape, ElementEditorContext context)
        {
            var name = (string)formElementShape.Name;

            if (name != null)
            {
                var value = context.ValueProvider.GetValue(context.Prefix + name);
                if (value != null)
                {
                    context.Element.Data[name] = value.AttemptedValue;
                }
                else if (formElementShape.Metadata.Type == "Checkbox")
                {
                    var shapeValue = formElementShape.Value as string;
                    if (shapeValue != null && shapeValue.ToLower() == "true")
                    {
                        context.Element.Data[name] = "false";
                    }
                }
            }
        }
        protected override EditorResult OnBuildEditor(TElement element, ElementEditorContext context)
        {
            var formShape = BuildForms(context);

            return(Editor(context, formShape));
        }
Example #6
0
 protected virtual EditorResult OnUpdateEditor(TElement element, ElementEditorContext context)
 {
     return(OnBuildEditor(element, context));
 }
Example #7
0
 protected virtual EditorResult OnBuildEditor(TElement element, ElementEditorContext context)
 {
     return(null);
 }
Example #8
0
 public EditorResult UpdateEditor(ElementEditorContext context)
 {
     return(OnUpdateEditor((TElement)context.Element, context));
 }
Example #9
0
 public EditorResult BuildEditor(ElementEditorContext context)
 {
     return(OnBuildEditor((TElement)context.Element, context));
 }