wlxml: metadata wip - part of a new api approach
[fnpeditor.git] / src / wlxml / extensions / metadata / metadata.js
1 define(function(require) {
2     
3 'use strict';
4
5 var _ = require('libs/underscore'),
6     metadataKey = 'wlxml.metadata';
7
8 var Row = function(key, value) {
9     this.key = key;
10     this.value  = value;
11 };
12 _.extend(Row.prototype, {
13     setKey: function(key) {
14         this.key = key;
15     },
16     getKey: function() {
17         return this.key;
18     },
19     setValue: function(value) {
20         this.value = value;
21     },
22     getValue: function() {
23         return this.value;
24     }
25 });
26
27 // var Metadata = function(node) {
28 //     this._rows = [];
29 // }
30
31 // _.extend(Metadata.prototype, {
32 //     forEach: function(callback) {
33 //         this.
34 //     }
35 // })
36
37 var methods = {
38     getMetadata: function() {
39         return this.getData(metadataKey) || [];
40     }
41 };
42
43 var transformations = {
44     addMetadata: function(desc) {
45         var metadata = this.getData(metadataKey) || [],
46             row = new Row(desc.key, desc.value);
47         metadata.push(row);
48         this.setData(metadataKey, metadata);
49         return row;
50     }
51 };
52
53 return {
54     elementNode: {
55         methods: methods,
56         transformations: transformations,
57     }
58 };
59
60 });
61