-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrows.js
More file actions
94 lines (78 loc) · 2.53 KB
/
rows.js
File metadata and controls
94 lines (78 loc) · 2.53 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
var ViewList = require('view-list')
var extend = require('extend')
var inherits = require('inherits')
var fields = require('data-fields')
function RowsView (options) {
if (!(this instanceof RowsView)) return new RowsView(options)
var rowHeight = options.rowHeight || 30
var height = window.innerHeight - rowHeight
ViewList.call(this, options)
extend(this, {
className: 'data-list-rows readonly',
rowHeight: rowHeight,
eachrow: function rows (row) {
var self = this
if (!row) return
if (!row.key) row.key = row.id
if (!row.value) row.value = row.properties || {}
var properties = Object.keys(row.value)
var elements = properties.map(element)
function element (key) {
var prop = self.properties[key]
var type = prop.type[0]
if (type === 'undefined') type = 'string'
function onfocus (e) {
self.send('focus', e, row, key, row.value[key])
}
function onblur (e) {
self.send('blur', e, row, key, row.value[key])
}
function onclick (e) {
self.send('click', e, row, key, row.value[key])
}
function oninput (e) {
row.value[key] = e.target.value
self.send('input', e, row, key, row.value[key])
}
var value = row.value[key]
var propertyOptions = {
value: value,
id: 'cell-' + row.key + '-' + key,
attributes: {
'data-type': 'string', // todo: use property type from options.properties
'data-key': key,
rows: 1
},
onfocus: onfocus,
onblur: onblur,
onclick: onclick,
oninput: oninput
}
if (self.readonly) {
propertyOptions.attributes.readonly = true
}
var h = self.html
var field = fields[type]()
return field.render(h, propertyOptions, value)
}
var rowOptions = { attributes: { 'data-key': row.key } }
if (row.active) {
rowOptions.className = 'active'
rowOptions.attributes['data-active'] = 'true'
}
return self.html('li.data-list-row', rowOptions, [
self.html('.data-list-row-items', elements)
])
},
readonly: true,
properties: {},
height: height
}, options)
}
module.exports = RowsView
inherits(RowsView, ViewList)
RowsView.prototype.render = function rowsview_render (state) {
this.properties = state.properties
var view = ViewList.prototype.render.call(this, state.data)
return this.afterRender(view)
}