X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/0214643f72c6aaa8e85eaba2ad27f2ca03ca6401..8e6255bf612a7d33e1f1c97dd293db6f34949ef9:/modules/metadataEditor/metadataEditor.js?ds=sidebyside 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 = $('