X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/5fbecb65c701a7680aae9258ff16df6a1e9f35f5..b41ddda14e70e0a8ee1705b8c8edcb7625553e5e:/modules/visualEditor.js diff --git a/modules/visualEditor.js b/modules/visualEditor.js index e53bfbf..d8b30b7 100644 --- a/modules/visualEditor.js +++ b/modules/visualEditor.js @@ -1,11 +1,66 @@ rng.modules.visualEditor = function(sandbox) { + var transformations = rng.modules.visualEditor.transformations; + var view = { + node: $(sandbox.getTemplate('main')()), + 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.find('#rng-visualEditor-content').html(); + } + }; + + var isDirty = false; + + + $('#rng-visualEditor-content', view).on('keyup', function() { + isDirty = true; + }); + + $('#rng-visualEditor-meta', view).on('keyup', function() { + isDirty = true; + }); + return { start: function() { sandbox.publish('ready'); }, getView: function() { - return $('

visual editor

'); + 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; } }