X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/16c90b3616f1645aab9fe284fd3b89641dfb42f2..091b7b516be2b5c2053e2a9103f8a910efbad68a:/src/wlxml/extensions/metadata/metadata.js diff --git a/src/wlxml/extensions/metadata/metadata.js b/src/wlxml/extensions/metadata/metadata.js index 54b3f96..899306d 100644 --- a/src/wlxml/extensions/metadata/metadata.js +++ b/src/wlxml/extensions/metadata/metadata.js @@ -8,8 +8,8 @@ var _ = require('libs/underscore'), var Row = function(key, value, metadata) { - this.key = key; - this.value = value; + this.key = key || ''; + this.value = value || ''; this.metadata = metadata; }; @@ -17,6 +17,9 @@ _.extend(Row.prototype, { ChangeProperty: smartxmlTransformations.createContextTransformation({ impl: function(t, rowIndex, propName, value) { var row = this.getMetadata().at(rowIndex); + if(row.getValue() === value) { + return; + } t.rowIndex = rowIndex; t.propName = propName; t.oldValue = row[propName]; @@ -85,13 +88,23 @@ _.extend(Metadata.prototype, { this.triggerChangeEvent('metadataRemoved', {row: t.row}); }, undo: function(t) { - var metadata = this.getMetadata(); - metadata._rows.splice(t.rowIdx, 0, new Row(t.row.getKey(), t.row.getValue(), metadata)); + var metadata = this.getMetadata(), + row = new Row(t.row.getKey(), t.row.getValue(), metadata); + metadata._rows.splice(t.rowIdx, 0, row); + this.triggerChangeEvent('metadataAdded', {row: row}); } }), - forEach: function(callback) { - return this._rows.forEach(callback); + _iter: function(method, callback, key) { + return this._rows + .filter(function(row) { return !key || row.getKey() === key; }) + [method](function(row) { return callback(row); }); + }, + forEach: function(callback, key) { + return this._iter('forEach', callback, key); + }, + some: function(callback, key) { + return this._iter('some', callback, key); }, add: function(rowDesc, options) { var row;