smartxml: Support for Node.object.describesParent property
[fnpeditor.git] / src / editor / modules / metadataEditor / metadataEditor.js
index 0eace02..70df62e 100644 (file)
@@ -7,6 +7,7 @@ define([
 ], function($, _, mainTemplate, itemTemplate, OpenSelectView) {
 
 'use strict';
 ], function($, _, mainTemplate, itemTemplate, OpenSelectView) {
 
 'use strict';
+/* globals gettext */
 
 return function(sandbox) {
 
 
 return function(sandbox) {
 
@@ -41,11 +42,15 @@ return function(sandbox) {
             
             this.node.find('.rng-module-metadataEditor-addBtn').click(function() {
                 adding = true;
             
             this.node.find('.rng-module-metadataEditor-addBtn').click(function() {
                 adding = true;
-                currentNode.getMetadata().add('','');
+                currentNode.document.transaction(function() {
+                    currentNode.getMetadata().add('','');
+                }, this, gettext('Add metadata row'));
             });
             
             this.metaTable.on('click', '.rng-visualEditor-metaRemoveBtn', function(e) {
             });
             
             this.metaTable.on('click', '.rng-visualEditor-metaRemoveBtn', function(e) {
-                $(e.target).closest('tr').data('row').remove();
+                currentNode.document.transaction(function() {
+                    $(e.target).closest('tr').data('row').remove();
+                }, this, gettext('Remove metadata row'));
             });
             
             this.metaTable.on('keydown', '[contenteditable]', function(e) {
             });
             
             this.metaTable.on('keydown', '[contenteditable]', function(e) {
@@ -70,13 +75,16 @@ return function(sandbox) {
                         row = editable.parents('tr').data('row'),
                         isKey = _.last(editable.attr('class').split('-')) === 'metaItemKey',
                         method = isKey ? 'setKey' : 'setValue';
                         row = editable.parents('tr').data('row'),
                         isKey = _.last(editable.attr('class').split('-')) === 'metaItemKey',
                         method = isKey ? 'setKey' : 'setValue';
-                    row[method](toSet);
+                    row.metadata.node.document.transaction(function() {
+                        row[method](toSet);
+                    }, this, gettext('Metadata edit'));
                 }
             }, 500));
         },
         clear: function() {
         },
         setMetadata: function(node) {
                 }
             }, 500));
         },
         clear: function() {
         },
         setMetadata: function(node) {
+            this.node.find('.rng-module-metadataEditor-addBtn').attr('disabled', !node);
             if(!node) {
                 this.metaTable.html('');
                 return;
             if(!node) {
                 this.metaTable.html('');
                 return;
@@ -113,6 +121,8 @@ return function(sandbox) {
             var valueSelectView = new OpenSelectView({
                 value: row.getValue(),
                 inputTemplate: _.template('<div class="openInput rng-module-metadataEditor-metaItemValue" contentEditable="true"><%= value %></div>')({value: row.getValue() || '' }),
             var valueSelectView = new OpenSelectView({
                 value: row.getValue(),
                 inputTemplate: _.template('<div class="openInput rng-module-metadataEditor-metaItemValue" contentEditable="true"><%= value %></div>')({value: row.getValue() || '' }),
+                maxHeight: '300px',
+                maxWidth: '100px',
                 setInput: function(inputDOM, value) {
                     if(inputDOM.text() !== value) {
                         inputDOM.text(value);
                 setInput: function(inputDOM, value) {
                     if(inputDOM.text() !== value) {
                         inputDOM.text(value);
@@ -181,7 +191,7 @@ return function(sandbox) {
                 if(event.type === 'metadataRemoved' && event.meta.node.sameNode(currentNode)) {
                     view.removeMetadataRow(event.meta.row);
                 }
                 if(event.type === 'metadataRemoved' && event.meta.node.sameNode(currentNode)) {
                     view.removeMetadataRow(event.meta.row);
                 }
-                if(event.type === 'nodeDetached' && event.meta.node.sameNode(currentNode)) {
+                if(event.type === 'nodeDetached' && event.meta.node.containsNode(currentNode)) {
                     view.setMetadata(null);
                 }
             });
                     view.setMetadata(null);
                 }
             });