X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/a5871ab5512d87a33e7e95451d26ee7d3e789742..70fd8f6118a3e8bf298dd9c48c310f3309b780c3:/modules/visualEditor.js?ds=sidebyside diff --git a/modules/visualEditor.js b/modules/visualEditor.js index 29506a5..08085de 100644 --- a/modules/visualEditor.js +++ b/modules/visualEditor.js @@ -1,7 +1,69 @@ rng.modules.visualEditor = function(sandbox) { + var transformations = rng.modules.visualEditor.transformations; + var view = { + node: $(sandbox.getTemplate('main')()), + setup: function() { + var node = this.node; + node.find('#rng-visualEditor-content').on('keyup', function() { + isDirty = true; + }); + + node.find('#rng-visualEditor-meta').on('keyup', function() { + isDirty = true; + }); + }, + getMetaData: function() { + var toret = {}; + this.node.find('#rng-visualEditor-meta table tr').each(function() { + var tr = $(this); + var key = $(tr.find('td')[0]).html(); + var value = $(tr.find('td input')[0]).val(); + toret[key] = value; + }); + console.log(toret); + return toret; + }, + setMetaData: function(metadata) { + var table = this.node.find('#rng-visualEditor-meta table'); + table.empty(); + _.each(_.keys(metadata), function(key) { + $(sandbox.getTemplate('metaItem')({key: key, value: metadata[key]})).appendTo(table); + }); + }, + setBody: function(HTMLTree) { + this.node.find('#rng-visualEditor-content').html(HTMLTree); + }, + getBody: function() { + return this.node.find('#rng-visualEditor-content').html(); + } + }; + view.setup(); + + var isDirty = false; + + return { start: function() { + sandbox.publish('ready'); + }, + getView: function() { + return view.node; + }, + setDocument: function(xml) { + var transformed = transformations.fromXML.getDocumentDescription(xml); + view.setBody(transformed.HTMLTree); + view.setMetaData(transformed.metadata); + isDirty = false; + }, + getDocument: function() { + return transformations.toXML.getXML({HTMLTree: view.getBody(), metadata: view.getMetaData()}); + }, + isDirty: function() { + return isDirty; + }, + setDirty: function(dirty) { + isDirty = dirty; } }