X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/0add3b13ce4ef42557d9ca33342a159b80a4f42f..d4e89595e829f60443056ce65f5f275d10f882ed:/modules/visualEditor.js?ds=inline diff --git a/modules/visualEditor.js b/modules/visualEditor.js index b22aa7d..ce62c6a 100644 --- a/modules/visualEditor.js +++ b/modules/visualEditor.js @@ -1,33 +1,70 @@ rng.modules.visualEditor = function(sandbox) { + var transformations = rng.modules.visualEditor.transformations; - var view = $(sandbox.getTemplate('main')()); - var isDirty = false; - - var document2html = function(document) { - return document; - } + 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; + }); + + this.node.on('mouseover', '.rng', function(e) { $(e.target).addClass('rng-hover')}); + this.node.on('mouseout', '.rng', function(e) { $(e.target).removeClass('rng-hover')}); + this.node.on('click', '.rng', function(e) { + node.find('.rng').removeClass('rng-current'); + $(e.target).addClass('rng-current'); + }); + }, + 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 html2document = function() { - return $('#rng-visualEditor-content').text(); - } + var isDirty = false; - $('#rng-visualEditor-content', view).on('keyup', function() { - isDirty = true; - }); return { start: function() { sandbox.publish('ready'); }, getView: function() { - return view; + return view.node; }, - setDocument: function(document) { - $('#rng-visualEditor-content', view).html(document2html(document)); + setDocument: function(xml) { + var transformed = transformations.fromXML.getDocumentDescription(xml); + view.setBody(transformed.HTMLTree); + view.setMetaData(transformed.metadata); isDirty = false; }, getDocument: function() { - return html2document(); + return transformations.toXML.getXML({HTMLTree: view.getBody(), metadata: view.getMetaData()}); }, isDirty: function() { return isDirty;