var view = {\r
node: $(_.template(mainTemplate)()),\r
setup: function() {\r
+ var view = this;\r
var metaTable = this.metaTable = this.node.find('table');\r
\r
this.node.find('.rng-module-metadataEditor-addBtn').click(function() {\r
var newRow = view._addMetaRow('', '');\r
$(newRow.find('td div')[0]).focus();\r
- //isDirty = true;\r
+ sandbox.publish('metadataChanged', view.getMetadata());\r
});\r
\r
this.metaTable.on('click', '.rng-visualEditor-metaRemoveBtn', function(e) {\r
$(e.target).closest('tr').remove();\r
- //isDirty = true;\r
+ sandbox.publish('metadataChanged', view.getMetadata());\r
});\r
\r
this.metaTable.on('keydown', '[contenteditable]', function(e) {\r
}\r
e.preventDefault();\r
}\r
- \r
});\r
+ \r
+ \r
+ var onKeyUp = function(e) {\r
+ if(e.which !== 13)\r
+ sandbox.publish('metadataChanged', view.getMetadata());\r
+ }\r
+ this.metaTable.on('keyup', '[contenteditable]', _.throttle(onKeyUp, 500));\r
},\r
- getMetaData: function() {\r
+ getMetadata: function() {\r
var toret = {};\r
this.node.find('tr').each(function() {\r
var tr = $(this);\r
start: function() {\r
sandbox.publish('ready');\r
},\r
- setMetadata: function(xml) {\r
+ setDocument: function(xml) {\r
view.setMetadata(transformations.getMetadata(xml));\r
+ sandbox.publish('metadataSet');\r
},\r
getMetadata: function() {\r
- return view.getMetadata();\r
+ return transformations.getXML(view.getMetadata());\r
},\r
getView: function() {\r
return view.node;\r
+ },\r
+ attachMetadata: function(document) {\r
+ var toret = $('<div>');\r
+ toret.append($(document));\r
+ var meta = $('<metadata></metadata>\n').append(transformations.getXML(view.getMetadata()));\r
+ \r
+ var metadata = toret.find('metadata');\r
+ if(metadata.length === 0) {\r
+ var section = toret.find('section');\r
+ section = section.length ? $(section[0]) : null;\r
+ if(section) {\r
+ section.prepend(meta)\r
+ }\r
+ } else {\r
+ metadata.replaceWith(meta);\r
+ }\r
+ return toret.html();\r
}\r
\r
};\r