public ActionResult Edit(int id, ElementDataViewModel model)
        {
            var blueprint       = _elementBlueprintService.GetBlueprint(id);
            var describeContext = DescribeElementsContext.Empty;
            var descriptor      = _elementManager.GetElementDescriptorByTypeName(describeContext, blueprint.BaseElementTypeName);
            var data            = ElementDataHelper.Deserialize(model.ElementData).Combine(Request.Form.ToDictionary());
            var element         = _elementManager.ActivateElement(descriptor, e => e.Data = data);
            var context         = CreateEditorContext(element, elementData: data);
            var editorResult    = _elementManager.UpdateEditor(context);
            var viewModel       = new EditElementBlueprintViewModel {
                EditorResult = editorResult,
                TypeName     = model.TypeName,
                DisplayText  = descriptor.DisplayText,
                Description  = descriptor.Description,
                ElementData  = element.Data.Serialize(),
                Tabs         = editorResult.CollectTabs().ToArray(),
                BaseElement  = element
            };

            if (!ModelState.IsValid)
            {
                _transactionManager.Cancel();
                return(View(viewModel));
            }

            blueprint.BaseElementState = data.Serialize();
            _signals.Trigger(Signals.ElementDescriptors);
            _notifier.Information(T("That blueprint has been saved."));
            return(RedirectToAction("Index"));
        }
示例#2
0
        public ViewResult Update(ElementDataViewModel model, string session)
        {
            var sessionState    = _objectStore.Get <ElementSessionState>(session);
            var contentId       = sessionState.ContentId;
            var contentType     = sessionState.ContentType;
            var describeContext = CreateDescribeContext(contentId, contentType);
            var descriptor      = _elementManager.GetElementDescriptorByTypeName(describeContext, model.TypeName);
            var elementData     = ElementDataHelper.Deserialize(sessionState.ElementData);
            var data            = Request.Form.ToDictionary();
            var element         = _elementManager.ActivateElement(descriptor, e => e.Data = data);
            var context         = CreateEditorContext(session, describeContext.Content, element, postedElementData: data, elementData: elementData, updater: this);
            var editorResult    = _elementManager.UpdateEditor(context);
            var viewModel       = new EditElementViewModel {
                Layout       = describeContext.Content.As <ILayoutAspect>(),
                EditorResult = editorResult,
                TypeName     = model.TypeName,
                DisplayText  = descriptor.DisplayText,
                ElementData  = element.Data.Serialize(),
                Tabs         = editorResult.CollectTabs().ToArray(),
                SessionKey   = session
            };

            if (!ModelState.IsValid)
            {
                _transactionManager.Cancel();
            }
            else
            {
                viewModel.ElementHtml        = RenderElement(element, describeContext);
                viewModel.Submitted          = true;
                viewModel.ElementEditorModel = _mapper.ToEditorModel(element, describeContext);
            }
            return(View("Edit", viewModel));
        }
示例#3
0
        protected override DriverResult Editor(ElementWrapperPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            return(ContentShape("Parts_ElementWrapper_Edit", () => {
                var describeContext = CreateDescribeContext(part);
                var descriptor = _elementManager.GetElementDescriptorByTypeName(describeContext, part.ElementTypeName);
                var data = ElementDataHelper.Deserialize(part.ElementData).Combine(_wca.GetContext().HttpContext.Request.Form.ToDictionary());
                var dataClosure = data;
                var element = _elementManager.ActivateElement(descriptor, e => e.Data = dataClosure);
                var context = CreateEditorContext(describeContext.Content, element, data, updater, shapeHelper);
                var editorResult = (EditorResult)(updater != null ? _elementManager.UpdateEditor(context) : _elementManager.BuildEditor(context));
                var viewModel = new ElementWrapperPartViewModel {
                    Tabs = editorResult.CollectTabs().ToArray(),
                    ElementTypeName = part.ElementTypeName,
                    ElementDisplayText = element.DisplayText,
                    ElementEditorResult = editorResult,
                    ElementEditors = editorResult.Editors,
                };

                data = context.ElementData;

                if (updater != null)
                {
                    part.ElementData = data.Serialize();
                }

                return shapeHelper.EditorTemplate(TemplateName: "Parts.ElementWrapper", Model: viewModel, Prefix: Prefix);
            }));
        }
        public ActionResult Edit(int id)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageLayouts, T("Not authorized to manage layouts.")))
            {
                return(new HttpUnauthorizedResult());
            }

            var blueprint       = _elementBlueprintService.GetBlueprint(id);
            var describeContext = DescribeElementsContext.Empty;
            var descriptor      = _elementManager.GetElementDescriptorByTypeName(describeContext, blueprint.BaseElementTypeName);
            var data            = ElementDataHelper.Deserialize(blueprint.BaseElementState);
            var element         = _elementManager.ActivateElement(descriptor, e => e.Data = data);
            var context         = CreateEditorContext(element, data);
            var editorResult    = _elementManager.BuildEditor(context);

            var viewModel = new EditElementBlueprintViewModel {
                EditorResult = editorResult,
                TypeName     = blueprint.BaseElementTypeName,
                DisplayText  = descriptor.DisplayText,
                Description  = descriptor.Description,
                ElementData  = element.Data.Serialize(),
                Tabs         = editorResult.CollectTabs().ToArray(),
                BaseElement  = element
            };

            return(View(viewModel));
        }
示例#5
0
        public ViewResult Edit(string session)
        {
            var sessionState    = _objectStore.Get <ElementSessionState>(session);
            var contentId       = sessionState.ContentId;
            var contentType     = sessionState.ContentType;
            var typeName        = sessionState.TypeName;
            var elementData     = ElementDataHelper.Deserialize(sessionState.ElementData);
            var describeContext = CreateDescribeContext(contentId, contentType);
            var descriptor      = _elementManager.GetElementDescriptorByTypeName(describeContext, typeName);
            var data            = elementData.Combine(ElementDataHelper.Deserialize(sessionState.ElementEditorData));
            var element         = _elementManager.ActivateElement(descriptor, e => e.Data = data);
            var context         = CreateEditorContext(session, describeContext.Content, element, postedElementData: data, elementData: elementData);
            var editorResult    = _elementManager.BuildEditor(context);

            var viewModel = new EditElementViewModel {
                Layout       = describeContext.Content.As <ILayoutAspect>(),
                EditorResult = editorResult,
                TypeName     = typeName,
                DisplayText  = descriptor.DisplayText,
                ElementData  = element.Data.Serialize(),
                Tabs         = editorResult.CollectTabs().ToArray(),
                SessionKey   = session,
                Submitted    = !descriptor.EnableEditorDialog,
            };

            return(View(viewModel));
        }
 protected virtual void ToElement(T element, JToken node)
 {
     element.Data        = ElementDataHelper.Deserialize((string)node["data"]);
     element.HtmlId      = (string)node["htmlId"];
     element.HtmlClass   = (string)node["htmlClass"];
     element.HtmlStyle   = (string)node["htmlStyle"];
     element.IsTemplated = (bool)(node["isTemplated"] ?? false);
 }
示例#7
0
        protected override void Exporting(ElementWrapperPart part, ExportContentContext context)
        {
            var describeContext = CreateDescribeContext(part);
            var descriptor      = _elementManager.GetElementDescriptorByTypeName(describeContext, part.ElementTypeName);
            var data            = ElementDataHelper.Deserialize(part.ElementData);
            var element         = _elementManager.ActivateElement(descriptor, e => e.Data = data);

            _elementManager.Exporting(new[] { element }, new ExportLayoutContext());
            var exportableData = _serializer.Serialize(element);

            context.Element(part.PartDefinition.Name).SetValue(exportableData);
        }
示例#8
0
        protected override DriverResult Display(ElementWrapperPart part, string displayType, dynamic shapeHelper)
        {
            return(ContentShape("Parts_ElementWrapper", () => {
                var describeContext = CreateDescribeContext(part);
                var descriptor = _elementManager.GetElementDescriptorByTypeName(describeContext, part.ElementTypeName);
                var data = ElementDataHelper.Deserialize(part.ElementData);
                var element = _elementManager.ActivateElement(descriptor, e => e.Data = data);
                var elementShape = _elementDisplay.DisplayElement(element, part, displayType);

                return shapeHelper.Parts_ElementWrapper(ElementShape: elementShape);
            }));
        }
        public virtual Element ToElement(IElementManager elementManager, DescribeElementsContext describeContext, JToken node)
        {
            var elementTypeName = (string)node["contentType"];
            var descriptor      = elementManager.GetElementDescriptorByTypeName(describeContext, elementTypeName);
            var element         = elementManager.ActivateElement(descriptor);

            element.Data        = ElementDataHelper.Deserialize((string)node["data"]);
            element.HtmlId      = (string)node["htmlId"];
            element.HtmlClass   = (string)node["htmlClass"];
            element.HtmlStyle   = (string)node["htmlStyle"];
            element.IsTemplated = (bool)(node["isTemplated"] ?? false);

            return(element);
        }
示例#10
0
        public Element ParseNode(JToken node, Container parent, int index, DescribeElementsContext describeContext)
        {
            var elementTypeName = (string)node["typeName"];

            if (String.IsNullOrWhiteSpace(elementTypeName))
            {
                return(null);
            }

            var data              = (string)node["data"];
            var htmlId            = (string)node["htmlId"];
            var htmlClass         = (string)node["htmlClass"];
            var htmlStyle         = (string)node["htmlStyle"];
            var rule              = (string)node["rule"];
            var elementData       = ElementDataHelper.Deserialize(data);
            var exportableData    = ElementDataHelper.Deserialize((string)node["exportableData"]);
            var childNodes        = node["elements"];
            var elementDescriptor = _elementManager.GetElementDescriptorByTypeName(describeContext, elementTypeName);

            if (elementDescriptor == null)
            {
                return(null); // This happens if an element exists in a layout, but its type is no longer available due to its feature being disabled.
            }
            var element = _elementFactory.Activate(elementDescriptor, e => {
                e.Container      = parent;
                e.Index          = index;
                e.Data           = elementData;
                e.ExportableData = exportableData;
                e.HtmlId         = htmlId;
                e.HtmlClass      = htmlClass;
                e.HtmlStyle      = htmlStyle;
                e.Rule           = rule;
            });

            var container = element as Container;

            if (container != null)
            {
                container.Elements = childNodes != null
                    ? childNodes.Select((x, i) => ParseNode(x, container, i, describeContext)).Where(x => x != null).ToList()
                    : new List <Element>();
            }

            element.IsTemplated = node.Value <bool>("isTemplated");

            return(element);
        }
示例#11
0
        private void HandleSecondaryImportEvent(ElementWrapperPart part, ImportContentContext context, Action <DescribeElementsContext, Element> callback)
        {
            var root = context.Data.Element(part.PartDefinition.Name);

            if (root == null)
            {
                return;
            }

            var describeContext = CreateDescribeContext(part);
            // Deserialize element from the data set in previous Import events
            var descriptor = _elementManager.GetElementDescriptorByTypeName(describeContext, part.ElementTypeName);
            var data       = ElementDataHelper.Deserialize(part.ElementData);
            var element    = _elementManager.ActivateElement(descriptor, e => e.Data = data);

            callback(describeContext, element);
            part.ElementData = element.Data.Serialize();
        }
示例#12
0
        public override void Execute(RecipeExecutionContext context)
        {
            var blueprintEntries = context.RecipeStep.Step.Elements().Select(xmlBlueprint => {
                var typeName = xmlBlueprint.Attribute("ElementTypeName").Value;
                Logger.Information("Importing custom element '{0}'.", typeName);

                try {
                    var blueprint = GetOrCreateElement(typeName);
                    blueprint.BaseElementTypeName = xmlBlueprint.Attribute("BaseElementTypeName").Value;
                    blueprint.ElementDisplayName  = xmlBlueprint.Attribute("ElementDisplayName").Value;
                    blueprint.ElementDescription  = xmlBlueprint.Attribute("ElementDescription").Value;
                    blueprint.ElementCategory     = xmlBlueprint.Attribute("ElementCategory").Value;
                    blueprint.BaseElementState    = xmlBlueprint.Element("BaseElementState").Value;

                    var describeContext        = DescribeElementsContext.Empty;
                    var descriptor             = _elementManager.GetElementDescriptorByTypeName(describeContext, blueprint.BaseElementTypeName);
                    var baseElement            = _elementManager.ActivateElement(descriptor);
                    baseElement.Data           = ElementDataHelper.Deserialize(blueprint.BaseElementState);
                    baseElement.ExportableData = ElementDataHelper.Deserialize(xmlBlueprint.Attribute("BaseExportableData").Value);

                    return(new { Blueprint = blueprint, BaseElement = baseElement });
                }
                catch (Exception ex) {
                    Logger.Error(ex, "Error while importing custom element '{0}'.", typeName);
                    throw;
                }
            }).ToList();


            var baseElements         = blueprintEntries.Select(e => e.BaseElement).ToList();
            var importContentSession = new ImportContentSession(_orchardServices.ContentManager);
            var importLayoutContext  = new ImportLayoutContext {
                Session = new ImportContentSessionWrapper(importContentSession)
            };

            _elementManager.Importing(baseElements, importLayoutContext);
            _elementManager.Imported(baseElements, importLayoutContext);
            _elementManager.ImportCompleted(baseElements, importLayoutContext);

            foreach (var blueprintEntry in blueprintEntries)
            {
                blueprintEntry.Blueprint.BaseElementState = blueprintEntry.BaseElement.Data.Serialize();
            }
        }
        public ViewResult Edit(int id)
        {
            var blueprint       = _elementBlueprintService.GetBlueprint(id);
            var describeContext = DescribeElementsContext.Empty;
            var descriptor      = _elementManager.GetElementDescriptorByTypeName(describeContext, blueprint.BaseElementTypeName);
            var data            = ElementDataHelper.Deserialize(blueprint.BaseElementState);
            var element         = _elementManager.ActivateElement(descriptor, e => e.Data = data);
            var context         = CreateEditorContext(element, data);
            var editorResult    = _elementManager.BuildEditor(context);

            var viewModel = new EditElementBlueprintViewModel {
                EditorResult = editorResult,
                TypeName     = blueprint.BaseElementTypeName,
                DisplayText  = descriptor.DisplayText,
                Description  = descriptor.Description,
                ElementData  = element.Data.Serialize(),
                Tabs         = editorResult.CollectTabs().ToArray(),
                BaseElement  = element
            };

            return(View(viewModel));
        }
示例#14
0
        public override void Build(BuildContext context)
        {
            var blueprints = _repository.Table.OrderBy(x => x.ElementTypeName).ToList();

            if (!blueprints.Any())
            {
                return;
            }

            var blueprintEntries = blueprints.Select(blueprint => {
                var describeContext = DescribeElementsContext.Empty;
                var descriptor      = _elementManager.GetElementDescriptorByTypeName(describeContext, blueprint.BaseElementTypeName);
                var baseElement     = _elementManager.ActivateElement(descriptor);
                baseElement.Data    = ElementDataHelper.Deserialize(blueprint.BaseElementState);
                return(new { Blueprint = blueprint, BaseElement = baseElement });
            }).ToList();

            var baseElements        = blueprintEntries.Select(e => e.BaseElement).ToList();
            var exportLayoutContext = new ExportLayoutContext();

            _elementManager.Exporting(baseElements, exportLayoutContext);
            _elementManager.Exported(baseElements, exportLayoutContext);

            var root = new XElement("CustomElements");

            context.RecipeDocument.Element("Orchard").Add(root);

            foreach (var blueprintEntry in blueprintEntries)
            {
                root.Add(new XElement("Element",
                                      new XAttribute("ElementTypeName", blueprintEntry.Blueprint.ElementTypeName),
                                      new XAttribute("BaseElementTypeName", blueprintEntry.Blueprint.BaseElementTypeName),
                                      new XAttribute("ElementDisplayName", blueprintEntry.Blueprint.ElementDisplayName),
                                      new XAttribute("ElementDescription", blueprintEntry.Blueprint.ElementDescription ?? ""),
                                      new XAttribute("ElementCategory", blueprintEntry.Blueprint.ElementCategory ?? ""),
                                      new XAttribute("BaseExportableData", blueprintEntry.BaseElement.ExportableData.Serialize()),
                                      new XElement("BaseElementState", new XCData(blueprintEntry.Blueprint.BaseElementState))));
            }
        }
        private void CreatingDisplay(ElementCreatingDisplayShapeContext context, ElementBlueprint blueprint)
        {
            var bluePrintState = ElementDataHelper.Deserialize(blueprint.BaseElementState);

            context.Element.Data = bluePrintState;
        }