예제 #1
0
        public ViewResult Create(string id, string session, int?contentId = null, string contentType = null)
        {
            var sessionState = new ElementSessionState {
                TypeName    = id,
                ElementData = null,
                ContentId   = contentId,
                ContentType = contentType
            };

            _objectStore.Set(session, sessionState);

            var describeContext = CreateDescribeContext(contentId, contentType);
            var descriptor      = _elementManager.GetElementDescriptorByTypeName(describeContext, id);
            var element         = _elementManager.ActivateElement(descriptor);
            var context         = CreateEditorContext(session, describeContext.Content, element);
            var editorResult    = _elementManager.BuildEditor(context);
            var viewModel       = new EditElementViewModel {
                SessionKey   = session,
                Layout       = describeContext.Content.As <ILayoutAspect>(),
                EditorResult = editorResult,
                TypeName     = id,
                DisplayText  = descriptor.DisplayText,
                ElementData  = element.Data.Serialize(),
                Submitted    = !descriptor.EnableEditorDialog,
                ElementHtml  = RenderElement(element, describeContext),
                Tabs         = editorResult.CollectTabs().ToArray()
            };

            return(View(viewModel));
        }
        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));
        }
예제 #3
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));
        }
        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));
        }
예제 #5
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);
            }));
        }