X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/0214643f72c6aaa8e85eaba2ad27f2ca03ca6401..58f12279b796c932263a4cfad12c3f17695be02a:/modules/metadataEditor/metadataEditor.js?ds=inline diff --git a/modules/metadataEditor/metadataEditor.js b/modules/metadataEditor/metadataEditor.js index 5c3e4fc..79302bb 100644 --- a/modules/metadataEditor/metadataEditor.js +++ b/modules/metadataEditor/metadataEditor.js @@ -14,17 +14,18 @@ return function(sandbox) { var view = { node: $(_.template(mainTemplate)()), setup: function() { + var view = this; var metaTable = this.metaTable = this.node.find('table'); this.node.find('.rng-module-metadataEditor-addBtn').click(function() { var newRow = view._addMetaRow('', ''); $(newRow.find('td div')[0]).focus(); - //isDirty = true; + sandbox.publish('metadataChanged', view.getMetadata()); }); this.metaTable.on('click', '.rng-visualEditor-metaRemoveBtn', function(e) { $(e.target).closest('tr').remove(); - //isDirty = true; + sandbox.publish('metadataChanged', view.getMetadata()); }); this.metaTable.on('keydown', '[contenteditable]', function(e) { @@ -40,10 +41,16 @@ return function(sandbox) { } e.preventDefault(); } - }); + + + var onKeyUp = function(e) { + if(e.which !== 13) + sandbox.publish('metadataChanged', view.getMetadata()); + } + this.metaTable.on('keyup', '[contenteditable]', _.throttle(onKeyUp, 500)); }, - getMetaData: function() { + getMetadata: function() { var toret = {}; this.node.find('tr').each(function() { var tr = $(this); @@ -74,14 +81,32 @@ return function(sandbox) { start: function() { sandbox.publish('ready'); }, - setMetadata: function(xml) { + setDocument: function(xml) { view.setMetadata(transformations.getMetadata(xml)); + sandbox.publish('metadataSet'); }, getMetadata: function() { - return view.getMetadata(); + return transformations.getXML(view.getMetadata()); }, getView: function() { return view.node; + }, + attachMetadata: function(document) { + var toret = $('
'); + toret.append($(document)); + var meta = $('\n').append(transformations.getXML(view.getMetadata())); + + var metadata = toret.find('metadata'); + if(metadata.length === 0) { + var section = toret.find('section'); + section = section.length ? $(section[0]) : null; + if(section) { + section.prepend(meta) + } + } else { + metadata.replaceWith(meta); + } + return toret.html(); } };