Exemplo n.º 1
0
        protected override DriverResult Editor(LayoutPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            return(ContentShape("Parts_Layout_Edit", () => {
                if (part.Id == 0 && String.IsNullOrWhiteSpace(part.LayoutData))
                {
                    var settings = part.TypePartDefinition.Settings.GetModel <LayoutTypePartSettings>();

                    // If the default layout setting is left empty, use the one from the service
                    if (String.IsNullOrWhiteSpace(settings.DefaultLayoutData))
                    {
                        var defaultData = _serializer.Serialize(_layoutManager.CreateDefaultLayout());
                        part.LayoutData = defaultData;
                    }
                    else
                    {
                        part.LayoutData = settings.DefaultLayoutData;
                    }
                }

                var viewModel = new LayoutPartViewModel {
                    LayoutEditor = _layoutEditorFactory.Create(part)
                };

                if (updater != null)
                {
                    updater.TryUpdateModel(viewModel, Prefix, null, new[] { "Part", "Templates" });
                    var describeContext = new DescribeElementsContext {
                        Content = part
                    };
                    var elementInstances = _mapper.ToLayoutModel(viewModel.LayoutEditor.Data, describeContext).ToArray();
                    var recycleBin = (RecycleBin)_mapper.ToLayoutModel(viewModel.LayoutEditor.RecycleBin, describeContext).SingleOrDefault();
                    var context = new LayoutSavingContext {
                        Content = part,
                        Updater = updater,
                        Elements = elementInstances,
                        RemovedElements = recycleBin != null ? recycleBin.Elements : Enumerable.Empty <Element>()
                    };

                    _elementManager.Saving(context);
                    _elementManager.Removing(context);

                    part.LayoutData = _serializer.Serialize(elementInstances);
                    part.TemplateId = viewModel.LayoutEditor.TemplateId;
                    part.SessionKey = viewModel.LayoutEditor.SessionKey;
                    viewModel.LayoutEditor.Data = _mapper.ToEditorModel(part.LayoutData, new DescribeElementsContext {
                        Content = part
                    }).ToJson();
                }

                return shapeHelper.EditorTemplate(TemplateName: "Parts.Layout", Model: viewModel, Prefix: Prefix);
            }));
        }
Exemplo n.º 2
0
        public override IEnumerable <TemplateViewModel> TypePartEditor(ContentTypePartDefinition definition)
        {
            if (definition.PartDefinition.Name != "LayoutPart")
            {
                yield break;
            }

            var model = definition.Settings.GetModel <LayoutTypePartSettings>();

            if (String.IsNullOrWhiteSpace(model.DefaultLayoutData))
            {
                var defaultData = _serializer.Serialize(_layoutManager.CreateDefaultLayout());
                model.DefaultLayoutData = defaultData;
            }

            yield return(DefinitionTemplate(model));
        }