2 'libs/jquery-1.9.1.min',
\r
3 'libs/underscore-min',
\r
5 'libs/text!./templates/main.html',
\r
6 'libs/text!./templates/item.html'
\r
7 ], function($, _, transformations, mainTemplate, itemTemplate) {
\r
11 return function(sandbox) {
\r
15 node: $(_.template(mainTemplate)()),
\r
17 var metaTable = this.metaTable = this.node.find('table');
\r
19 this.node.find('.rng-module-metadataEditor-addBtn').click(function() {
\r
20 var newRow = view._addMetaRow('', '');
\r
21 $(newRow.find('td div')[0]).focus();
\r
25 this.metaTable.on('click', '.rng-visualEditor-metaRemoveBtn', function(e) {
\r
26 $(e.target).closest('tr').remove();
\r
30 this.metaTable.on('keydown', '[contenteditable]', function(e) {
\r
31 console.log(e.which);
\r
32 if(e.which === 13) {
\r
33 if($(document.activeElement).hasClass('rng-module-metadataEditor-metaItemKey')) {
\r
34 metaTable.find('.rng-module-metadataEditor-metaItemValue').focus();
\r
36 var input = $('<input>');
\r
37 input.appendTo('body').focus()
\r
38 view.node.find('.rng-module-metadataEditor-addBtn').focus();
\r
46 getMetaData: function() {
\r
48 this.node.find('tr').each(function() {
\r
50 var inputs = $(this).find('td [contenteditable]');
\r
51 var key = $(inputs[0]).text();
\r
52 var value = $(inputs[1]).text();
\r
57 setMetadata: function(metadata) {
\r
59 this.metaTable.find('tr').remove();
\r
60 _.each(_.keys(metadata), function(key) {
\r
61 view._addMetaRow(key, metadata[key]);
\r
64 _addMetaRow: function(key, value) {
\r
65 var newRow = $(_.template(itemTemplate)({key: key || '', value: value || ''}));
\r
66 newRow.appendTo(this.metaTable);
\r
75 sandbox.publish('ready');
\r
77 setMetadata: function(xml) {
\r
78 view.setMetadata(transformations.getMetadata(xml));
\r
80 getMetadata: function() {
\r
81 return view.getMetadata();
\r
83 getView: function() {
\r