Layout editor improvements.

- Implemented Removed element event.
- Fixed model validation in Element editor dialog.
- Extended support for placeable content.
This commit is contained in:
Sipke Schoorstra
2015-10-03 00:28:48 +02:00
parent 39a6e10c76
commit 8535644b99
6 changed files with 23 additions and 17 deletions

View File

@@ -218,13 +218,15 @@ namespace Orchard.Layouts.Controllers {
IUpdateModel updater = null) {
postedElementData = postedElementData ?? new ElementDataDictionary();
var valueProviderCollection = (ValueProviderCollection) ValueProvider;
valueProviderCollection.Add(postedElementData.ToValueProvider(_cultureAccessor.CurrentCulture));
var context = new ElementEditorContext {
Session = session,
Content = content,
Element = element,
Updater = updater,
ElementData = elementData ?? new ElementDataDictionary(),
ValueProvider = postedElementData.ToValueProvider(_cultureAccessor.CurrentCulture),
ValueProvider = valueProviderCollection,
ShapeFactory = _shapeFactory
};
ValueProvider = context.ValueProvider;

View File

@@ -104,12 +104,12 @@ namespace Orchard.Layouts.Drivers {
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).Single();
var recycleBin = (RecycleBin)_mapper.ToLayoutModel(viewModel.LayoutEditor.RecycleBin, describeContext).SingleOrDefault();
var context = new LayoutSavingContext {
Content = part,
Updater = updater,
Elements = elementInstances,
RemovedElements = recycleBin.Elements
RemovedElements = recycleBin != null ? recycleBin.Elements : Enumerable.Empty<Element>()
};
_elementManager.Saving(context);

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.ContentManagement.FieldStorage.InfosetStorage;
using Orchard.ContentManagement.MetaData.Models;
using Orchard.Core.Contents.Settings;
using Orchard.Environment;
@@ -135,9 +134,11 @@ namespace Orchard.Layouts.Providers {
}
private IEnumerable<ContentTypeDefinition> GetPlaceableContentTypeDefinitions() {
// Select all types that have either "Placeable" set ot true or the "Widget" or "Element" stereotype.
var contentTypeDefinitionsQuery =
from contentTypeDefinition in _contentManager.Value.GetContentTypeDefinitions()
where contentTypeDefinition.Settings.GetModel<ContentTypeLayoutSettings>().Placeable
let stereotype = contentTypeDefinition.Settings.ContainsKey("Stereotype") ? contentTypeDefinition.Settings["Stereotype"] : default(string)
where contentTypeDefinition.Settings.GetModel<ContentTypeLayoutSettings>().Placeable || stereotype == "Widget" || stereotype == "Element"
select contentTypeDefinition;
return contentTypeDefinitionsQuery.ToList();

View File

@@ -4,7 +4,6 @@
this.element = element;
this.element.data("layout-designer-host", this);
this.editor = window.layoutEditor;
this.isFormSubmitting = false;
this.settings = {
antiForgeryToken: self.element.data("anti-forgery-token"),
editorDialogTitleFormat: self.element.data("editor-dialog-title-format"),
@@ -88,12 +87,11 @@
});
};
var monitorForm = function() {
var layoutDesigner = self.element;
var form = layoutDesigner.closest("form");
var monitorForm = function () {
var form = $(".zone-content form:first");
form.on("submit", function (e) {
self.isFormSubmitting = true;
form.attr("isSubmitting", true);
serializeLayout();
});
};
@@ -115,7 +113,10 @@
});
$(window).on("beforeunload", function () {
if (!self.isFormSubmitting && self.editor.isDirty())
var form = $(".zone-content form:first");
var isFormSubmitting = form.attr("isSubmitting");
if (!isFormSubmitting && self.editor.isDirty())
return "You have unsaved changes.";
return undefined;
@@ -130,7 +131,7 @@
window.Orchard.Layouts.LayoutEditorHost = window.Orchard.Layouts.LayoutEditorHost || {};
$(function () {
var host = new LayoutDesignerHost($(".layout-designer"));
window.layoutDesignerHost = new LayoutDesignerHost($(".layout-designer"));
$(".layout-designer").each(function (e) {
var designer = $(this);
var dialog = designer.find(".layout-editor-help-dialog");

View File

@@ -174,10 +174,11 @@
break;
case "save": {
var frameDoc = self.frame.getDocument();
var form = frameDoc.find("#layout-content form:first");
form.submit();
var form = frameDoc.find(".zone-content form:first");
form.attr("isSubmitting", true);
form.trigger("submit");
}
break;
break;
}
});
};

View File

@@ -75,7 +75,8 @@ header, footer, aside, nav, article { display: block; }
}
.zone-content .edit-widget .primary .widget-props,
.zone-content .edit-widget .secondary {
.zone-content .edit-widget .secondary,
.zone-content .edit-item .edit-item-secondary {
display: none;
}