From 1f3c5cc1a4afb9c55db8bb9f8bbb82d496b7b296 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Fri, 10 Apr 2015 17:38:48 +0200 Subject: [PATCH] Simplified URL encoding/decoding of layout editor data. This also fixes an issue with certain rendered HTML as part of he element editor model object. --- .../Orchard.Layouts/Scripts/LayoutDecoder.js | 26 +------------------ .../Views/EditorTemplates/LayoutEditor.cshtml | 5 ++-- .../Views/ElementEditor.cshtml | 4 +-- 3 files changed, 4 insertions(+), 31 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/LayoutDecoder.js b/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/LayoutDecoder.js index 4338cc231..620d84576 100644 --- a/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/LayoutDecoder.js +++ b/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/LayoutDecoder.js @@ -1,34 +1,10 @@ var LayoutEditor; (function ($, LayoutEditor) { - var decode = function(value) { + var decode = function (value) { return !!value ? decodeURIComponent(value.replace(/\+/g, "%20")) : null; }; - var decodeGraph = function (graph) { - - if (!!graph.html) { - graph.html = decode(graph.html); - } - - if (!!graph.data) { - var items = $.deserialize(graph.data); - - for (var i = 0; i < items.length; i++) { - items[i] = decode(items[i]); - } - - graph.data = $.param(items); - } - - if (!!graph.children) { - for (var i = 0; i < graph.children.length; i++) { - decodeGraph(graph.children[i]); - } - } - }; - LayoutEditor.decode = decode; - LayoutEditor.decodeLayoutGraph = decodeGraph; })(jQuery, LayoutEditor || (LayoutEditor = {})); \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Layouts/Views/EditorTemplates/LayoutEditor.cshtml b/src/Orchard.Web/Modules/Orchard.Layouts/Views/EditorTemplates/LayoutEditor.cshtml index fa9f76cc4..b81e2bb6f 100644 --- a/src/Orchard.Web/Modules/Orchard.Layouts/Views/EditorTemplates/LayoutEditor.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Layouts/Views/EditorTemplates/LayoutEditor.cshtml @@ -43,10 +43,9 @@ } }); (function() { - var editorConfig = @Html.Raw(Model.ConfigurationData); - var editorCanvasData = @Html.Raw(Model.Data); + var editorConfig = JSON.parse(LayoutEditor.decode("@Html.Raw(Url.Encode(Model.ConfigurationData))")); + var editorCanvasData = JSON.parse(LayoutEditor.decode("@Html.Raw(Url.Encode(Model.Data))")); - LayoutEditor.decodeLayoutGraph(editorCanvasData); window.layoutEditor = new LayoutEditor.Editor(editorConfig, editorCanvasData); })(jQuery); diff --git a/src/Orchard.Web/Modules/Orchard.Layouts/Views/ElementEditor.cshtml b/src/Orchard.Web/Modules/Orchard.Layouts/Views/ElementEditor.cshtml index aa80bdee5..4a1fab303 100644 --- a/src/Orchard.Web/Modules/Orchard.Layouts/Views/ElementEditor.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Layouts/Views/ElementEditor.cshtml @@ -43,11 +43,9 @@ html: LayoutEditor.decode("@Url.Encode(Model.ElementHtml)"), isTemplated: false }, - elementEditorModel: @Html.Raw(Model.ElementEditorModel.ToJson()) + elementEditorModel: LayoutEditor.decode("@Html.Raw(Url.Encode(Model.ElementEditorModel.ToJson()))") }; - LayoutEditor.decodeLayoutGraph(payload.element); - LayoutEditor.decodeLayoutGraph(payload.elementEditorModel); window.parent.currentDialog.trigger("command", payload); });