Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
        private void UpdateEditor(SnippetDescriptor descriptor, ElementEditorContext context) {
            var viewModel = new SnippetViewModel {
                Descriptor = descriptor
            };
            
            if (context.Updater != null) {
                foreach (var fieldDescriptor in descriptor.Fields) {
                    var name = fieldDescriptor.Name;
                    var result = context.ValueProvider.GetValue(name);

                    if (result == null)
                        continue;

                    context.Element.Data[name] = result.AttemptedValue;
                }
            }

            viewModel.FieldEditors = descriptor.Fields.Select(x => {
                var fieldEditorTemplateName = String.Format("Elements.Snippet.Field.{0}", x.Type ?? "Text");
                var fieldDescriptorViewModel = new SnippetFieldViewModel {
                    Descriptor = x,
                    Value = context.Element.Data.Get(x.Name)
                };
                var fieldEditor = context.ShapeFactory.EditorTemplate(TemplateName: fieldEditorTemplateName, Model: fieldDescriptorViewModel, Prefix: context.Prefix);

                return fieldEditor;
            }).ToList();

            var snippetEditorShape = context.ShapeFactory.EditorTemplate(TemplateName: "Elements.Snippet", Model: viewModel, Prefix: context.Prefix);
            snippetEditorShape.Metadata.Position = "Fields:0";
            
            context.EditorResult.Add(snippetEditorShape);
        }
        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.
            var forms     = FormNames.Reverse().Select(x => _formManager.Bind(_formManager.Build(x), context.ValueProvider)).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.
            var form = _formManager.Bind(_formManager.Build(formName), context.ValueProvider);

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

            return(form);
        }
        private void UpdateEditor(ElementEditorContext context) {
            var contentTypeName = (string)context.Element.Descriptor.StateBag["ContentTypeName"];
            var element = (PlaceableContentItem) context.Element;
            var elementViewModel = new PlaceableContentItemViewModel {
                ContentItemId = element.ContentItemId
            };

            if (context.Updater != null) {
                context.Updater.TryUpdateModel(elementViewModel, context.Prefix, null, null);
            }

            var contentItemId = elementViewModel.ContentItemId;
            var contentItem = contentItemId != null 
                ? _contentManager.Value.Get(contentItemId.Value, VersionOptions.Latest) 
                : _contentManager.Value.New(contentTypeName);

            dynamic contentEditorShape;

            if (context.Updater != null) {
                if (contentItem.Id == 0) {
                    _contentManager.Value.Create(contentItem, VersionOptions.Draft);
                }
                else {
                    var isDraftable = contentItem.TypeDefinition.Settings.GetModel<ContentTypeSettings>().Draftable;
                    var versionOptions = isDraftable ? VersionOptions.DraftRequired : VersionOptions.Latest;
                    contentItem = _contentManager.Value.Get(contentItem.Id, versionOptions);
                }

                element.ContentItemId = contentItem.Id;

                // If the placed content item has the CommonPart attached, set its Container property to the Content (if any).
                // This helps preventing widget types from appearing as orphans.
                var commonPart = contentItem.As<ICommonPart>();
                if (commonPart != null)
                    commonPart.Container = context.Content;

                contentItem.IsPlaceableContent(true);
                contentEditorShape = _contentManager.Value.UpdateEditor(contentItem, context.Updater);

                _contentManager.Value.Publish(contentItem);
            }
            else {
                contentEditorShape = _contentManager.Value.BuildEditor(contentItem);
            }

            var elementEditorShape = context.ShapeFactory.EditorTemplate(TemplateName: "Elements.PlaceableContentItem", Model: elementViewModel, Prefix: context.Prefix);
            
            elementEditorShape.Metadata.Position = "Properties:0";
            contentEditorShape.Metadata.Position = "Properties:0";
            context.EditorResult.Add(elementEditorShape);
            context.EditorResult.Add(contentEditorShape);
        }
Beispiel #7
0
        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;
                }
            }
        }
Beispiel #8
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 BuildEditorInternal(ElementEditorContext context, Func<IElementDriver, EditorResult> action) {
            var descriptor = context.Element.Descriptor;
            var drivers = _elementManager.GetDrivers(descriptor);

            foreach (var driver in drivers) {
                var editorResult = action(driver);

                if (editorResult == null)
                    continue;

                foreach (var editor in editorResult.Editors) {
                    editor.ElementDescriptor = descriptor;
                    editor.ElementData = context.Element.Data;
                    editor.Content = context.Content;

                    context.EditorResult.Add(editor);
                }
            }
        }
        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";
                    }
                }
            }
        }
 public virtual void BuildEditor(ElementEditorContext context)
 {
 }
 private void Editor(SnippetDescriptor descriptor, ElementEditorContext context) {
     UpdateEditor(descriptor, context);
 }
 public virtual void UpdateEditor(ElementEditorContext context)
 {
 }
        protected override EditorResult OnBuildEditor(TElement element, ElementEditorContext context)
        {
            var formShape = BuildForms(context);

            return(Editor(context, formShape));
        }
 void IElementEventHandler.BuildEditor(ElementEditorContext context) {}
 void IElementEventHandler.UpdateEditor(ElementEditorContext context) {}
 public override void UpdateEditor(ElementEditorContext context)
 {
     BuildEditorInternal(context, driver => driver.UpdateEditor(context));
 }
        private void Editor(ElementEditorContext context)
        {

        }
Beispiel #19
0
 public EditorResult BuildEditor(ElementEditorContext context)
 {
     return(OnBuildEditor((TElement)context.Element, context));
 }
 private void Editor(ElementEditorContext context) {
     UpdateEditor(context);
 }
Beispiel #21
0
 public EditorResult UpdateEditor(ElementEditorContext context)
 {
     return(OnUpdateEditor((TElement)context.Element, context));
 }
Beispiel #22
0
 protected virtual EditorResult OnBuildEditor(TElement element, ElementEditorContext context)
 {
     return(null);
 }
Beispiel #23
0
 protected virtual EditorResult OnUpdateEditor(TElement element, ElementEditorContext context)
 {
     return(OnBuildEditor(element, context));
 }