material 0.4.3 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/tracks.svg +10 -0
- package/package.json +4 -4
- package/src/appbar.js +1 -2
- package/src/control/button.js +127 -44
- package/src/control/button.new.js +190 -0
- package/src/control/dialog.js +174 -0
- package/src/control/{upload.js → file.js} +33 -8
- package/src/control/link.js +61 -0
- package/src/control/list.js +77 -0
- package/src/control/loading.js +128 -0
- package/src/control/module/addclass.js +16 -0
- package/src/control/module/attributes.js +3 -1
- package/src/control/search.js +98 -0
- package/src/control/select.js +80 -22
- package/src/control/selecter.js +246 -0
- package/src/control/switch.js +272 -0
- package/src/control/switcher.js +245 -0
- package/src/control/text.js +18 -3
- package/src/control/textfield.js +89 -15
- package/src/field/image.js +9 -3
- package/src/form/build.js +28 -4
- package/src/form/cancel.js +7 -3
- package/src/form/controller.js +90 -0
- package/src/form/create.js +11 -7
- package/src/form/data.js +82 -0
- package/src/form/delete.js +2 -1
- package/src/form/fetch.js +5 -3
- package/src/form/render.js +11 -9
- package/src/form/set.js +27 -12
- package/src/form/submit.js +11 -37
- package/src/form/update.js +35 -16
- package/src/layout.js +25 -21
- package/src/list/add.js +34 -0
- package/src/list/build.js +96 -12
- package/src/list/click.js +10 -5
- package/src/list/collection.js +187 -0
- package/src/list/create.js +21 -11
- package/src/list/display.js +78 -0
- package/src/list/empty.js +4 -1
- package/src/list/filter.js +114 -0
- package/src/list/load.js +2 -2
- package/src/list/remove.js +17 -4
- package/src/list/render.js +32 -9
- package/src/list/request.js +182 -0
- package/src/list/search.js +118 -35
- package/src/list/select.js +151 -30
- package/src/list/status.js +10 -3
- package/src/list/update.js +49 -8
- package/src/list/virtual.js +195 -127
- package/src/map/build.js +103 -0
- package/src/map/countries.js +114 -0
- package/src/map/display.js +135 -0
- package/src/map/focus.js +39 -0
- package/src/map/init.js +24 -0
- package/src/map/label.js +0 -0
- package/src/map/mode.js +44 -0
- package/src/map/mouse.js +65 -0
- package/src/map/select.js +68 -0
- package/src/map/set.js +71 -0
- package/src/map/viewport.js +46 -0
- package/src/map.js +71 -0
- package/src/module/attach.js +9 -2
- package/src/module/mediator.js +56 -0
- package/src/module/object.js +17 -1
- package/src/module/observer.js +1 -1
- package/src/module/passive.js +17 -0
- package/src/module/remove.js +74 -0
- package/src/module/scrollbar.js +48 -0
- package/src/module/smoothscroll.js +20 -0
- package/src/module/viewport.js +20 -0
- package/src/selector.js +239 -0
- package/src/skin/material/base/body.sass +3 -0
- package/src/skin/material/button/file.sass +1 -1
- package/src/skin/material/container/container.sass +1 -1
- package/src/skin/material/container/dialog.sass +57 -1
- package/src/skin/material/container/drawer.sass +3 -3
- package/src/skin/material/control/button.sass +125 -0
- package/src/skin/material/control/dialog.sass +0 -0
- package/src/skin/material/control/progress.sass +136 -0
- package/src/skin/material/control/search.sass +40 -0
- package/src/skin/material/control/selecter.sass +131 -0
- package/src/skin/material/control/selector.sass +38 -0
- package/src/skin/material/control/slider.sass +2 -2
- package/src/skin/material/control/switch.sass +146 -3
- package/src/skin/material/control/switcher.sass +41 -0
- package/src/skin/material/control/textfield.sass +2 -1
- package/src/skin/material/icon/cancel.svg +1 -0
- package/src/skin/material/material.sass +3 -0
- package/src/skin/material/view/list.sass +81 -188
- package/src/skin/material/view/listview.sass +187 -96
- package/src/skin/material/view/tabview.sass +6 -4
- package/src/skin/material.bak/base/body.sass +52 -0
- package/src/skin/material.bak/base/elevation.sass +50 -0
- package/src/skin/material.bak/base/grid.sass +63 -0
- package/src/skin/material.bak/base/typo.sass +107 -0
- package/src/skin/material.bak/button/action.sass +89 -0
- package/src/skin/material.bak/button/button.sass +183 -0
- package/src/skin/material.bak/button/file.sass +24 -0
- package/src/skin/material.bak/button/floating.sass +113 -0
- package/src/skin/material.bak/button/raised.sass +101 -0
- package/src/skin/material.bak/button/stroked.sass +71 -0
- package/src/skin/material.bak/component/component.sass +7 -0
- package/src/skin/material.bak/component/divider.sass +17 -0
- package/src/skin/material.bak/component/image.sass +6 -0
- package/src/skin/material.bak/component/label.sass +2 -0
- package/src/skin/material.bak/component/progress.sass +138 -0
- package/src/skin/material.bak/component/subheader.sass +3 -0
- package/src/skin/material.bak/component/text.sass +85 -0
- package/src/skin/material.bak/container/appbar.sass +167 -0
- package/src/skin/material.bak/container/banner.sass +38 -0
- package/src/skin/material.bak/container/card.sass +18 -0
- package/src/skin/material.bak/container/container.sass +1 -0
- package/src/skin/material.bak/container/dialog.sass +184 -0
- package/src/skin/material.bak/container/drawer.sass +159 -0
- package/src/skin/material.bak/container/drawernew.sass +159 -0
- package/src/skin/material.bak/container/menu.sass +58 -0
- package/src/skin/material.bak/container/snackbar.sass +18 -0
- package/src/skin/material.bak/container/tabs.sass +75 -0
- package/src/skin/material.bak/container/toolbar.sass +161 -0
- package/src/skin/material.bak/control/button.sass +125 -0
- package/src/skin/material.bak/control/checkbox.sass +105 -0
- package/src/skin/material.bak/control/dialog.sass +0 -0
- package/src/skin/material.bak/control/search.sass +40 -0
- package/src/skin/material.bak/control/selecter.sass +128 -0
- package/src/skin/material.bak/control/slider.sass +181 -0
- package/src/skin/material.bak/control/switch.sass +284 -0
- package/src/skin/material.bak/control/switcher.sass +35 -0
- package/src/skin/material.bak/control/textfield.sass +126 -0
- package/src/skin/material.bak/control/tooltip.sass +36 -0
- package/src/skin/material.bak/icon/back.svg +5 -0
- package/src/skin/material.bak/icon/cancel.svg +1 -0
- package/src/skin/material.bak/icon/checkbox.svg +4 -0
- package/src/skin/material.bak/icon/forward.svg +5 -0
- package/src/skin/material.bak/icon/menu.svg +4 -0
- package/src/skin/material.bak/icon/pin.svg +4 -0
- package/src/skin/material.bak/layout/layout.sass +69 -0
- package/src/skin/material.bak/layout/resizer.sass +69 -0
- package/src/skin/material.bak/material.css +2042 -0
- package/src/skin/material.bak/material.css.map +7 -0
- package/src/skin/material.bak/material.sass +65 -0
- package/src/skin/material.bak/module/ripple.sass +9 -0
- package/src/skin/material.bak/theme/default.sass +50 -0
- package/src/skin/material.bak/theme/ocean.sass +29 -0
- package/src/skin/material.bak/theme/theme.sass +3 -0
- package/src/skin/material.bak/view/calendar.sass +193 -0
- package/src/skin/material.bak/view/form.sass +15 -0
- package/src/skin/material.bak/view/grid.sass +116 -0
- package/src/skin/material.bak/view/list.sass +89 -0
- package/src/skin/material.bak/view/listview.sass +195 -0
- package/src/skin/material.bak/view/map.sass +6 -0
- package/src/skin/material.bak/view/page.sass +4 -0
- package/src/skin/material.bak/view/tabview-bak.sass +40 -0
- package/src/skin/material.bak/view/tabview.sass +55 -0
- package/src/skin/material.bak/view/tree.sass +73 -0
- package/src/skin/material.bak/view/view.sass +7 -0
- package/src/switch.js +1 -1
- package/src/tabs/setup.js +0 -0
- package/src/tabview.js +64 -14
- package/src/tooltip.js +23 -5
- package/src/view/build.js +13 -1
- package/src/view/display.js +63 -2
- package/src/form/clean.js +0 -6
- package/src/form/controls.js +0 -56
- package/src/form/mode.js +0 -8
- package/src/form/setup.js +0 -5
- package/src/list/fetch.js +0 -66
package/src/form/data.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { byString } from '../module/object'
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
|
|
5
|
+
initData () {
|
|
6
|
+
// console.log('submit', this.mode)
|
|
7
|
+
|
|
8
|
+
var data = new FormData()
|
|
9
|
+
|
|
10
|
+
if (this.mode !== 'create') {
|
|
11
|
+
this.appendSysinfo(data)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
this.appendFields(data)
|
|
15
|
+
this.appendFiles(data)
|
|
16
|
+
|
|
17
|
+
return data
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
appendSysinfo (data) {
|
|
21
|
+
var sys = this.options.sysinfo
|
|
22
|
+
for (var i = 0; i < sys.length; i++) {
|
|
23
|
+
// console.log('sys', sys[i], this.info[sys[i]])
|
|
24
|
+
var name = sys[i]
|
|
25
|
+
if (sys[i] === '_id') name = 'id'
|
|
26
|
+
|
|
27
|
+
data.append(name, this.info[sys[i]])
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return data
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
appendFields (data) {
|
|
34
|
+
for (var field in this.field) {
|
|
35
|
+
// console.log('field', field)
|
|
36
|
+
if (this.field.hasOwnProperty(field)) {
|
|
37
|
+
// console.log('check field', field)
|
|
38
|
+
var value = this.field[field].get()
|
|
39
|
+
if (value !== null) {
|
|
40
|
+
if (this.mode === 'update' && this.options.update && this.options.update.modifiedOnly) {
|
|
41
|
+
var modified = this.isModified(field, value)
|
|
42
|
+
if (modified) {
|
|
43
|
+
data.append(field, value)
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
data.append(field, value)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return data
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
appendFiles (data) {
|
|
56
|
+
// console.log('appendFiles', this.file)
|
|
57
|
+
for (var file in this.file) {
|
|
58
|
+
// console.log('this file', this.file, this.file[file].input)
|
|
59
|
+
// console.log('file', file, this.file[file])
|
|
60
|
+
if (this.file.hasOwnProperty(file) && this.file[file].input && this.file[file].input.value) {
|
|
61
|
+
data.append(file, this.file[file].input.files[0])
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return data
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
isModified (field, value) {
|
|
69
|
+
var initial = byString(this.info, field)
|
|
70
|
+
|
|
71
|
+
if (typeof initial === 'number') {
|
|
72
|
+
value = Number(value)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (initial !== value) {
|
|
76
|
+
// console.log('field', field, typeof value, value)
|
|
77
|
+
return true
|
|
78
|
+
} else {
|
|
79
|
+
return false
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
package/src/form/delete.js
CHANGED
|
@@ -18,7 +18,7 @@ export default {
|
|
|
18
18
|
// console.log('delete', this.info._id)
|
|
19
19
|
if (!this.info._id) return
|
|
20
20
|
this.setMode('delete')
|
|
21
|
-
fetch(this.options.
|
|
21
|
+
fetch(this.options.action, {
|
|
22
22
|
headers: {
|
|
23
23
|
'Accept': 'application/json',
|
|
24
24
|
'Content-Type': 'application/json'
|
|
@@ -32,6 +32,7 @@ export default {
|
|
|
32
32
|
return resp.json()
|
|
33
33
|
}).then((data) => {
|
|
34
34
|
// console.log('data', data)
|
|
35
|
+
this.form.reset()
|
|
35
36
|
this.emit('deleted', this.info._id)
|
|
36
37
|
})
|
|
37
38
|
}
|
package/src/form/fetch.js
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
export default {
|
|
2
2
|
fetch (option) {
|
|
3
|
+
// console.log('fetch', this.options.route, option.method)
|
|
3
4
|
fetch(this.options.route, {
|
|
4
5
|
method: option.method,
|
|
5
6
|
body: option.formData
|
|
6
7
|
}).then(r => r.json()).then(info => {
|
|
7
8
|
if (info.error) {
|
|
8
|
-
console.log('Error: ' + info.error)
|
|
9
|
+
// console.log('Error: ' + info.error)
|
|
9
10
|
if (this.error) {
|
|
10
11
|
this.error(info)
|
|
11
12
|
}
|
|
12
13
|
} else {
|
|
13
|
-
// console.log('
|
|
14
|
+
// console.log('updated', info, this.mode)
|
|
14
15
|
if (this.mode === 'create') {
|
|
15
16
|
this.emit('created', info)
|
|
16
|
-
this.mode =
|
|
17
|
+
this.mode = 'read'
|
|
17
18
|
} else {
|
|
18
19
|
this.info = info
|
|
19
20
|
this.emit('updated', info)
|
|
21
|
+
this.mode = 'read'
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
if (this.success) {
|
package/src/form/render.js
CHANGED
|
@@ -18,40 +18,42 @@ export default {
|
|
|
18
18
|
|
|
19
19
|
for (var field in this.field) {
|
|
20
20
|
if (this.field.hasOwnProperty(field)) {
|
|
21
|
-
// console.log('field type', field)
|
|
21
|
+
// console.log('field type', field, this.field[field])
|
|
22
22
|
if (this.field[field] &&
|
|
23
23
|
this.field[field].set) {
|
|
24
|
-
this.
|
|
24
|
+
var value = this.objectValueByDotKey(object, field)
|
|
25
|
+
// console.log('value', value)
|
|
26
|
+
this.field[field].set(value, true)
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
if (this.disableControls) {
|
|
30
|
-
this.disableControls()
|
|
31
|
-
}
|
|
32
|
-
|
|
33
31
|
this.emit('rendered')
|
|
34
32
|
|
|
35
|
-
// won't stay
|
|
33
|
+
// won't stay here
|
|
36
34
|
if (option === 'create' && this.field['name']) {
|
|
37
35
|
this.focusNameOnRender(this.field['name'])
|
|
38
36
|
}
|
|
39
37
|
},
|
|
40
38
|
|
|
41
39
|
objectValueByDotKey (object, dotkey) {
|
|
40
|
+
// console.log('objectValueByDotKey', object, dotkey)
|
|
42
41
|
var keys = dotkey.split(/\./)
|
|
43
42
|
|
|
44
43
|
var value = Object.assign({}, object)
|
|
45
44
|
|
|
46
45
|
for (var i = 0; i < keys.length; i++) {
|
|
47
|
-
value
|
|
46
|
+
if (value !== undefined) {
|
|
47
|
+
value = value[keys[i]]
|
|
48
|
+
}
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
return value
|
|
51
52
|
},
|
|
52
53
|
|
|
53
54
|
focusNameOnRender (field) {
|
|
54
|
-
|
|
55
|
+
// console.log('focusNameOnRender', field)
|
|
56
|
+
field.input.focus()
|
|
55
57
|
field.input.select()
|
|
56
58
|
}
|
|
57
59
|
}
|
package/src/form/set.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
export default {
|
|
2
2
|
set (id) {
|
|
3
|
-
// console.log('set',
|
|
3
|
+
// console.log('set', id)
|
|
4
4
|
if (!id) return
|
|
5
5
|
|
|
6
|
+
if (this.clean) {
|
|
7
|
+
this.clean()
|
|
8
|
+
}
|
|
9
|
+
|
|
6
10
|
this.emit('set', id)
|
|
7
11
|
|
|
8
12
|
this.setMode('read')
|
|
9
13
|
// this.render(info)
|
|
10
|
-
fetch(this.options.
|
|
14
|
+
fetch(this.options.action + id, {
|
|
11
15
|
headers: {
|
|
12
16
|
'Accept': 'application/json'
|
|
13
17
|
},
|
|
@@ -15,17 +19,28 @@ export default {
|
|
|
15
19
|
}).then((resp) => {
|
|
16
20
|
// console.log('resp', resp)
|
|
17
21
|
return resp.json()
|
|
18
|
-
}).then((
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
this.info = data
|
|
22
|
-
this.render(data)
|
|
23
|
-
|
|
24
|
-
if (this.ui.delete) {
|
|
25
|
-
this.ui.delete.enable()
|
|
22
|
+
}).then((info) => {
|
|
23
|
+
if (this.options.debug) {
|
|
24
|
+
console.log('info', info)
|
|
26
25
|
}
|
|
27
|
-
|
|
28
|
-
this.
|
|
26
|
+
this.info = info
|
|
27
|
+
this.render(info)
|
|
28
|
+
this.emit('setted', info)
|
|
29
29
|
})
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
setInfo (info) {
|
|
33
|
+
// console.log('set', id)
|
|
34
|
+
if (!info) return
|
|
35
|
+
|
|
36
|
+
// console.log('info', info)
|
|
37
|
+
this.info = info
|
|
38
|
+
this.render(info)
|
|
39
|
+
this.emit('setted', info)
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
updateInfo (info) {
|
|
43
|
+
Object.assign(this.info, info)
|
|
44
|
+
this.render(info)
|
|
30
45
|
}
|
|
31
46
|
}
|
package/src/form/submit.js
CHANGED
|
@@ -2,53 +2,29 @@ export default {
|
|
|
2
2
|
|
|
3
3
|
submit (ev) {
|
|
4
4
|
ev.preventDefault()
|
|
5
|
-
// console.log('submit', this.
|
|
6
|
-
// ev.preventDefault()
|
|
7
|
-
if (this.verify && !this.verify()) return
|
|
5
|
+
// console.log('submit', this.mode)
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
if (this.disableControls) {
|
|
11
|
-
this.disableControls()
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
var formData = new FormData()
|
|
15
|
-
|
|
16
|
-
if (this.info && this.info._id) {
|
|
17
|
-
formData.append('id', this.info._id)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (this.info && this.info.uuid) {
|
|
21
|
-
formData.append('id', this.info.uuid)
|
|
22
|
-
}
|
|
7
|
+
var data = this.initData()
|
|
23
8
|
|
|
24
|
-
//
|
|
9
|
+
// console.log('data', data)
|
|
25
10
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
11
|
+
if (this.update) {
|
|
12
|
+
this.update(data)
|
|
13
|
+
} else {
|
|
14
|
+
this.setMethod(data)
|
|
31
15
|
}
|
|
32
16
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
for (var file in this.file) {
|
|
36
|
-
// console.log('this file', this.file, this.file[file].input)
|
|
37
|
-
// console.log('file', file, this.file[file])
|
|
38
|
-
if (this.file.hasOwnProperty(file) && this.file[file].input && this.file[file].input.value) {
|
|
39
|
-
// console.log('---- append file', this.file[file].input.value)
|
|
40
|
-
formData.append(file, this.file[file].input.files[0])
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// console.log('formData', formData.keys())
|
|
17
|
+
return false
|
|
18
|
+
},
|
|
45
19
|
|
|
20
|
+
setMethod (formData) {
|
|
46
21
|
var method = 'PUT'
|
|
47
22
|
if (this.mode === 'create') {
|
|
48
23
|
method = 'POST'
|
|
49
24
|
}
|
|
50
25
|
|
|
51
26
|
if (this.fetch) {
|
|
27
|
+
// console.log('formData', formData.keys())
|
|
52
28
|
this.fetch({
|
|
53
29
|
method: method,
|
|
54
30
|
formData: formData
|
|
@@ -61,7 +37,5 @@ export default {
|
|
|
61
37
|
formData: formData
|
|
62
38
|
})
|
|
63
39
|
}
|
|
64
|
-
|
|
65
|
-
return false
|
|
66
40
|
}
|
|
67
41
|
}
|
package/src/form/update.js
CHANGED
|
@@ -1,26 +1,45 @@
|
|
|
1
|
-
const headers = {
|
|
2
|
-
'Accept': 'application/json',
|
|
3
|
-
'Content-Type': 'application/json'
|
|
4
|
-
}
|
|
5
|
-
|
|
6
1
|
export default {
|
|
7
|
-
update (data) {
|
|
8
|
-
// console.log('update', data)
|
|
9
|
-
|
|
2
|
+
update (data, options) {
|
|
3
|
+
// console.log('update', data, options)
|
|
4
|
+
// console.log('mode', this.mode)
|
|
5
|
+
options = options || {}
|
|
6
|
+
|
|
7
|
+
// console.log('mode', this.mode)
|
|
8
|
+
var method = options.method ||
|
|
9
|
+
this.options[this.mode].method ||
|
|
10
|
+
'put'
|
|
11
|
+
|
|
12
|
+
var action = options.action ||
|
|
13
|
+
this.options[this.mode].action ||
|
|
14
|
+
this.options.action
|
|
15
|
+
|
|
16
|
+
if (this.beforeCreate) {
|
|
17
|
+
this.beforeCreate(data)
|
|
18
|
+
}
|
|
10
19
|
|
|
11
|
-
fetch(
|
|
12
|
-
method:
|
|
13
|
-
|
|
14
|
-
body: JSON.stringify(data)
|
|
20
|
+
fetch(action, {
|
|
21
|
+
method: method,
|
|
22
|
+
body: data
|
|
15
23
|
}).then((resp) => {
|
|
24
|
+
// console.log('resp', resp)
|
|
16
25
|
return resp.json()
|
|
17
|
-
}).then(
|
|
18
|
-
// console.log('
|
|
26
|
+
}).then(info => {
|
|
27
|
+
// console.log('update', info)
|
|
19
28
|
if (info.error) {
|
|
20
|
-
|
|
29
|
+
// console.log('Error: ' + info.error)
|
|
30
|
+
if (this.error) {
|
|
31
|
+
this.error(info)
|
|
32
|
+
}
|
|
21
33
|
} else {
|
|
34
|
+
// console.log('info', this.mode, info)
|
|
35
|
+
if (this.mode === 'create') {
|
|
36
|
+
this.emit('created', info)
|
|
37
|
+
this.setMode('read')
|
|
38
|
+
} else {
|
|
39
|
+
this.emit('updated', info)
|
|
40
|
+
this.setMode('read')
|
|
41
|
+
}
|
|
22
42
|
this.info = info
|
|
23
|
-
this.emit('updated', this.info)
|
|
24
43
|
}
|
|
25
44
|
})
|
|
26
45
|
}
|
package/src/layout.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
|
|
1
2
|
import { is as isObject } from './module/object'
|
|
2
3
|
import css from './module/css'
|
|
3
|
-
import insert from './element/insert'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
*
|
|
@@ -13,8 +13,10 @@ class Layout {
|
|
|
13
13
|
* @return {?} [description]
|
|
14
14
|
*/
|
|
15
15
|
constructor (schema, container) {
|
|
16
|
+
this.components = []
|
|
16
17
|
this.component = this.create(schema, container)
|
|
17
|
-
|
|
18
|
+
|
|
19
|
+
// console.log('this', this)
|
|
18
20
|
|
|
19
21
|
return this
|
|
20
22
|
}
|
|
@@ -30,9 +32,6 @@ class Layout {
|
|
|
30
32
|
level = level || 0
|
|
31
33
|
level++
|
|
32
34
|
|
|
33
|
-
// console.log('level', level, schema)
|
|
34
|
-
// console.log('-------------')
|
|
35
|
-
|
|
36
35
|
structure = structure || {}
|
|
37
36
|
let component = null
|
|
38
37
|
|
|
@@ -43,7 +42,9 @@ class Layout {
|
|
|
43
42
|
|
|
44
43
|
if (schema[i] instanceof Object &&
|
|
45
44
|
typeof schema[i] === 'function') {
|
|
46
|
-
if (isObject(schema[i +
|
|
45
|
+
if (isObject(schema[i + 1])) {
|
|
46
|
+
options = schema[i + 1]
|
|
47
|
+
} else if (isObject(schema[i + 2])) {
|
|
47
48
|
options = schema[i + 2]
|
|
48
49
|
}
|
|
49
50
|
|
|
@@ -55,27 +56,30 @@ class Layout {
|
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
component = new schema[i](options)
|
|
59
|
+
var element = component.root || component
|
|
58
60
|
|
|
59
|
-
if (
|
|
60
|
-
structure
|
|
61
|
+
if (level === 1) {
|
|
62
|
+
structure.root = element
|
|
61
63
|
}
|
|
62
64
|
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
this.
|
|
65
|
+
if (name) {
|
|
66
|
+
structure[name] = component
|
|
67
|
+
this.components.push([name, component])
|
|
66
68
|
}
|
|
67
69
|
|
|
68
|
-
if (
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
// console.log('root', component.root)
|
|
73
|
-
structure.root = component.root
|
|
74
|
-
}
|
|
70
|
+
// if (component) {
|
|
71
|
+
// this.display(component.root, options)
|
|
72
|
+
// this.style(component, options)
|
|
73
|
+
// }
|
|
75
74
|
|
|
76
75
|
if (component && container) {
|
|
77
|
-
if (component.insert)
|
|
78
|
-
|
|
76
|
+
if (component.insert) {
|
|
77
|
+
component.insert(container)
|
|
78
|
+
} else {
|
|
79
|
+
var wrapper = container.root || container
|
|
80
|
+
|
|
81
|
+
wrapper.appendChild(element)
|
|
82
|
+
}
|
|
79
83
|
component._container = container
|
|
80
84
|
}
|
|
81
85
|
} else if (Array.isArray(schema[i])) {
|
|
@@ -162,7 +166,7 @@ class Layout {
|
|
|
162
166
|
}
|
|
163
167
|
}
|
|
164
168
|
|
|
165
|
-
console.log('--- field', field)
|
|
169
|
+
// console.log('--- field', field)
|
|
166
170
|
|
|
167
171
|
return field
|
|
168
172
|
}
|
package/src/list/add.js
CHANGED
|
@@ -1,4 +1,38 @@
|
|
|
1
1
|
|
|
2
2
|
export default {
|
|
3
|
+
add (info, context) {
|
|
4
|
+
// console.log('list add', info)
|
|
3
5
|
|
|
6
|
+
if (!this.dataStore) return
|
|
7
|
+
context = context || null
|
|
8
|
+
|
|
9
|
+
this.dataList = this.dataList || []
|
|
10
|
+
|
|
11
|
+
if (context === 'bottom') {
|
|
12
|
+
if (this.data) { this.data.push(info) }
|
|
13
|
+
if (this.dataList) { this.dataList.push(info[this.dataId]) }
|
|
14
|
+
} else {
|
|
15
|
+
if (this.data) {
|
|
16
|
+
this.data.unshift(info)
|
|
17
|
+
} else {
|
|
18
|
+
console.log('error no data')
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (this.dataList) { this.dataList.unshift(info[this.dataId]) }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
this.dataStore[info[this.dataId]] = info
|
|
25
|
+
// console.log('data', this.data.length, this.data)
|
|
26
|
+
|
|
27
|
+
if (window.getComputedStyle(this.root, null).display === 'none') {
|
|
28
|
+
this.virtual.items = this.data
|
|
29
|
+
} else {
|
|
30
|
+
this.virtual.update(this.data)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// this.ui.body.scrollTo(0, this.ui.body.scrollTop + 1)
|
|
34
|
+
// this.ui.body.scrollTo(0, this.ui.body.scrollTop - 1)
|
|
35
|
+
|
|
36
|
+
return info
|
|
37
|
+
}
|
|
4
38
|
}
|
package/src/list/build.js
CHANGED
|
@@ -1,21 +1,31 @@
|
|
|
1
|
-
import
|
|
1
|
+
import scrollbar from '../module/scrollbar'
|
|
2
2
|
import dataset from '../view/dataset'
|
|
3
3
|
|
|
4
4
|
import Layout from '../layout'
|
|
5
5
|
import Virtual from './virtual'
|
|
6
|
+
import Loading from '../control/loading'
|
|
6
7
|
|
|
7
8
|
export default {
|
|
8
9
|
build (data) {
|
|
9
|
-
// console.log('options', this.options.
|
|
10
|
+
// console.log('options', this.options.name)
|
|
11
|
+
|
|
12
|
+
this.dataId = this.options.dataId || '_id'
|
|
10
13
|
|
|
11
14
|
this.root = document.createElement('div')
|
|
12
15
|
this.root.classList.add('list')
|
|
13
|
-
|
|
16
|
+
|
|
17
|
+
if (this.options.class) {
|
|
18
|
+
this.addClass(this.options.class)
|
|
19
|
+
}
|
|
14
20
|
|
|
15
21
|
this.root.addEventListener('click', (e) => {
|
|
16
22
|
e.stopPropagation()
|
|
17
23
|
})
|
|
18
24
|
|
|
25
|
+
if (this.options.name) {
|
|
26
|
+
this.name = this.options.name
|
|
27
|
+
}
|
|
28
|
+
|
|
19
29
|
if (this.options.data) {
|
|
20
30
|
dataset(this.root, this.options.data)
|
|
21
31
|
}
|
|
@@ -23,35 +33,109 @@ export default {
|
|
|
23
33
|
this.layout = new Layout(this.options.layout.main, this.root)
|
|
24
34
|
this.ui = this.layout.component
|
|
25
35
|
|
|
36
|
+
// prepare loading
|
|
37
|
+
// this.ui.loading = new Loading()
|
|
38
|
+
|
|
26
39
|
if (this.options.container) {
|
|
27
40
|
this.options.container.appendChild(this.root)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
var scrollbarOffset = scrollbar()
|
|
44
|
+
|
|
45
|
+
// console.log('scrollbarOffset', scrollbarOffset)
|
|
46
|
+
if (this.ui && this.ui.body) {
|
|
47
|
+
// console.log('body padding', 11 - scrollbarOffset + 'px')
|
|
48
|
+
this.ui.body.style['marginRight'] = 11 - scrollbarOffset + 'px'
|
|
49
|
+
this.ui.body.classList.add('offset' + scrollbarOffset)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
this.buildVirtual()
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
addClass (c) {
|
|
56
|
+
var list = c.split(' ')
|
|
57
|
+
|
|
58
|
+
for (var i = 0; i < list.length; i++) {
|
|
59
|
+
this.root.classList.add(list[i])
|
|
37
60
|
}
|
|
38
61
|
},
|
|
39
62
|
|
|
40
63
|
buildVirtual () {
|
|
41
64
|
// console.log('buildVirtual', this.options.class)
|
|
42
65
|
var height = 80
|
|
66
|
+
this.size = this.options.list.size
|
|
67
|
+
this.stop = false
|
|
43
68
|
|
|
44
69
|
if (this.options.item && this.options.item.height) {
|
|
45
70
|
height = this.options.item.height
|
|
46
71
|
}
|
|
47
72
|
|
|
48
73
|
this.virtual = new Virtual({
|
|
74
|
+
view: this.options.name,
|
|
49
75
|
container: this.ui.body,
|
|
50
76
|
itemHeight: height,
|
|
77
|
+
size: this.size,
|
|
51
78
|
render: (i) => {
|
|
52
79
|
// console.log('render', this.data[i])
|
|
53
80
|
return this.renderItem(this.data[i])
|
|
54
81
|
}
|
|
55
82
|
})
|
|
83
|
+
|
|
84
|
+
// console.log('dynamic')
|
|
85
|
+
this.virtual.on('next', (total) => {
|
|
86
|
+
// console.log('next', total)
|
|
87
|
+
if (this.stop) return
|
|
88
|
+
|
|
89
|
+
// console.log('next', total, this.page, this.size)
|
|
90
|
+
this.page = this.page || 1
|
|
91
|
+
// console.log('slide', total, this.options.list.size)
|
|
92
|
+
// var page = Math.ceil(total / this.size) + 1
|
|
93
|
+
|
|
94
|
+
this.page++
|
|
95
|
+
|
|
96
|
+
if (this.mode === 'search') {
|
|
97
|
+
this.search(this.ui['search-input'].input.value, this.page, this.size, true)
|
|
98
|
+
} else {
|
|
99
|
+
// console.log('request', this.page, this.size, true)
|
|
100
|
+
this.request(this.page, this.size, true)
|
|
101
|
+
}
|
|
102
|
+
}).on('progress', (progress) => {
|
|
103
|
+
// console.log('progress', progress, this.count)
|
|
104
|
+
|
|
105
|
+
if (this.statusDisplay) {
|
|
106
|
+
var percent = parseInt(progress / this.count * 100)
|
|
107
|
+
this.statusDisplay('count', percent + '% | ' + progress + ' / ' + this.count)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
this.onProgress(progress)
|
|
111
|
+
})
|
|
112
|
+
// .on('size', (size) => {
|
|
113
|
+
// console.log('!!!!size', size)
|
|
114
|
+
// this.size = size
|
|
115
|
+
// })
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
onProgress (value) {
|
|
119
|
+
// console.log('progress', value, this._value)
|
|
120
|
+
|
|
121
|
+
if (this.ui.head) {
|
|
122
|
+
if (this.ui.body.scrollTop > 0 && this.ui.head) {
|
|
123
|
+
this.ui.head.classList.add('scrolled')
|
|
124
|
+
} else if (this.ui.head) {
|
|
125
|
+
this.ui.head.classList.remove('scrolled')
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (value > this._value) {
|
|
130
|
+
// console.log('scrolling down')
|
|
131
|
+
this.emit('scrolling', 'down')
|
|
132
|
+
} else if (value < this._value) {
|
|
133
|
+
// console.log('scrolling up')
|
|
134
|
+
this.emit('scrolling', 'up')
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
this._value = value
|
|
138
|
+
|
|
139
|
+
this.scrollTop = this.ui.body.scrollTop
|
|
56
140
|
}
|
|
57
141
|
}
|
package/src/list/click.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
export default {
|
|
3
3
|
click (e) {
|
|
4
|
-
// e.
|
|
4
|
+
// console.log('click', e.target)
|
|
5
|
+
e.stopPropagation()
|
|
5
6
|
|
|
6
7
|
if (e.target === e.currentTarget) {
|
|
7
8
|
return
|
|
@@ -21,15 +22,19 @@ export default {
|
|
|
21
22
|
i++
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
if (this.select) {
|
|
25
|
-
this.select(item)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
25
|
if (e.target.matches('BUTTON') && e.target.dataset.name && item.dataset.id) {
|
|
29
26
|
// console.log('button', e.target.dataset.name)
|
|
30
27
|
this.emit(e.target.dataset.name, item.dataset.id)
|
|
28
|
+
return this
|
|
31
29
|
}
|
|
32
30
|
|
|
31
|
+
if (this.select) {
|
|
32
|
+
this.select(item)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// console.log('item', item, e.target.dataset.name)
|
|
36
|
+
|
|
37
|
+
return this
|
|
33
38
|
// console.log(item)
|
|
34
39
|
}
|
|
35
40
|
}
|