示例#1
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, 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));
        }
示例#2
0
        public IEnumerable <Element> DetachTemplate(IEnumerable <Element> elements)
        {
            var canvas = (Canvas)elements.FirstOrDefault(x => x is Canvas) ?? _elementManager.ActivateElement <Canvas>();
            var nonTemplatedElements = ExtractNonTemplatedElements(elements).ToList();

            canvas.IsTemplated = false;
            canvas.Elements    = nonTemplatedElements;

            yield return(canvas);
        }
示例#3
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 object ToEditorModel(string layoutData, DescribeElementsContext describeContext)
        {
            var elements = _serializer.Deserialize(layoutData, describeContext);
            var canvas   = elements.FirstOrDefault(x => x is Canvas) ?? _elementManager.ActivateElement <Canvas>();

            return(ToEditorModel(canvas, describeContext));
        }
        private string GetConfigurationData(IContent content)
        {
            var elementCategories = GetCategories(content).ToArray();
            var config            = new {
                categories = elementCategories.Select(category => new {
                    name         = category.DisplayName.Text,
                    contentTypes = category.Elements.Where(x => !x.IsSystemElement).Select(descriptor => {
                        var element = _elementManager.ActivateElement(descriptor);
                        var map     = _mapper.GetMapFor(element);
                        return(new {
                            label = descriptor.DisplayText.Text,
                            id = descriptor.TypeName,
                            type = map.LayoutElementType,
                            typeClass = descriptor.DisplayText.Text.HtmlClassify(),
                            description = descriptor.Description.Text,
                            icon = descriptor.ToolboxIcon,
                            hasEditor = descriptor.EnableEditorDialog,

                            // If the element has no editor then the toolbox will add the element straight to to designer when being dragged & dropped,
                            // so we'll want to present the user with a prerendered element.
                            html = descriptor.EnableEditorDialog ? "" : RenderElement(element, new DescribeElementsContext {
                                Content = content
                            })
                        });
                    })
                })
            };

            return(JToken.FromObject(config).ToString(Formatting.None));
        }
示例#6
0
        public JsonResult CreateDirect(string typeName, int?contentId = null, string contentType = null)
        {
            var describeContext = CreateDescribeContext(contentId, contentType);
            var descriptor      = _elementManager.GetElementDescriptorByTypeName(describeContext, typeName);
            var element         = _elementManager.ActivateElement(descriptor);

            var dto = new {
                typeName  = typeName,
                typeLabel = descriptor.DisplayText.Text,
                typeClass = descriptor.DisplayText.Text.HtmlClassify(),
                data      = element.Data.Serialize(),
                html      = RenderElement(element, describeContext)
            };

            return(Json(dto));
        }
示例#7
0
        public Element ToElement(IElementManager elementManager, DescribeElementsContext describeContext, JToken node)
        {
            var descriptor = elementManager.GetElementDescriptorByType <T>(describeContext);
            var element    = elementManager.ActivateElement <T>(descriptor);

            ToElement(element, node);
            return(element);
        }
        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);
        }
        private string TokenValue(string elementTypeName, string value)
        {
            var describeContext   = DescribeElementsContext.Empty;
            var elementDescriptor = _elementManager.GetElementDescriptorByTypeName(describeContext, elementTypeName);

            if (elementDescriptor == null)
            {
                return("");
            }

            var element      = _elementManager.ActivateElement(elementDescriptor);
            var elementShape = _elementDisplay.DisplayElement(element, null);
            var elementHtml  = _shapeDisplay.Display(elementShape);

            return(elementHtml);
        }
示例#10
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 ActionResult Create(string id)
        {
            if (String.IsNullOrWhiteSpace(id))
            {
                return(RedirectToAction("Browse"));
            }

            var describeContext = DescribeElementsContext.Empty;
            var descriptor      = _elementManager.GetElementDescriptorByTypeName(describeContext, id);
            var baseElement     = _elementManager.ActivateElement(descriptor);
            var viewModel       = new CreateElementBlueprintViewModel {
                BaseElement = baseElement
            };

            return(View(viewModel));
        }
示例#12
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))));
            }
        }
        public ActionResult Create(string id)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageLayouts, T("Not authorized to manage layouts.")))
            {
                return(new HttpUnauthorizedResult());
            }

            if (String.IsNullOrWhiteSpace(id))
            {
                return(RedirectToAction("Browse"));
            }

            var describeContext = DescribeElementsContext.Empty;
            var descriptor      = _elementManager.GetElementDescriptorByTypeName(describeContext, id);
            var baseElement     = _elementManager.ActivateElement(descriptor);
            var viewModel       = new CreateElementBlueprintViewModel {
                BaseElement = baseElement
            };

            return(View(viewModel));
        }