-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable.js
67 lines (60 loc) · 1.47 KB
/
table.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
tableTag = "table";
trTag = "tr";
thTag = "th";
tdTag = "td";
inputTag = "input"
contenteditableAttr = "contenteditable";
missClass = "miss";
empty = "";
function Table(translator) {
this.translator = translator;
this.render = createTag(tableTag);
}
Table.prototype = {
constructor : Table,
makeHeader : function() {
var row = createTag(trTag);
this.translator.properties().foreach(function(value) {
var col = createTag(thTag, value);
row.appendChild(col);
});
this.render.appendChild(row);
},
makeContent : function() {
var self = this;
this.translator.data().foreach(function(m) {
var style = self.isMiss(m) ? missClass : empty;
var row = createTag(trTag, empty, style);
var prop = self.translator.properties();
self.translator.properties().foreach(function(value) {
var col = createTag(tdTag, m[value]);
col.setAttribute(contenteditableAttr, true);
col.addEventListener(inputTag, function() {
m[value] = col.innerHTML;
if (self.isMiss(m))
row.addClass(miss);
else
row.removeClass(miss);
}, false);
row.appendChild(col);
});
self.render.appendChild(row);
});
},
refresh : function() {
this.render.clearChildren();
this.makeHeader();
this.makeContent();
return this.render;
},
isMiss : function(m) {
var miss = !m.key;
this.translator.getSupportLang().foreach(function(lang) {
miss = miss || isUndef(m[lang]);
});
return miss;
},
render : function() {
return this.render;
}
}