material 0.4.2 → 0.5.0

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.
Files changed (168) hide show
  1. package/dist/tracks.svg +10 -0
  2. package/package.json +1 -1
  3. package/src/appbar.js +1 -2
  4. package/src/control/button.js +263 -0
  5. package/src/control/button.new.js +190 -0
  6. package/src/control/datehour.js +65 -0
  7. package/src/control/dialog.js +174 -0
  8. package/src/control/file.js +123 -0
  9. package/src/control/image.js +92 -0
  10. package/src/control/link.js +61 -0
  11. package/src/control/list.js +77 -0
  12. package/src/control/loading.js +128 -0
  13. package/src/control/module/addclass.js +16 -0
  14. package/src/control/module/attributes.js +21 -0
  15. package/src/control/search.js +98 -0
  16. package/src/control/select.js +130 -0
  17. package/src/control/selecter.js +246 -0
  18. package/src/control/switch.js +272 -0
  19. package/src/control/switcher.js +245 -0
  20. package/src/control/text.js +66 -0
  21. package/src/control/textfield.js +177 -0
  22. package/src/field/image.js +9 -3
  23. package/src/form/build.js +60 -6
  24. package/src/form/cancel.js +7 -3
  25. package/src/form/controller.js +90 -0
  26. package/src/form/create.js +12 -6
  27. package/src/form/data.js +82 -0
  28. package/src/form/delete.js +2 -1
  29. package/src/form/fetch.js +30 -0
  30. package/src/form/render.js +14 -19
  31. package/src/form/set.js +27 -12
  32. package/src/form/submit.js +24 -49
  33. package/src/form/update.js +46 -0
  34. package/src/layout.js +26 -22
  35. package/src/list/add.js +34 -0
  36. package/src/list/build.js +100 -6
  37. package/src/list/click.js +10 -5
  38. package/src/list/collection.js +187 -0
  39. package/src/list/create.js +21 -11
  40. package/src/list/display.js +78 -0
  41. package/src/list/empty.js +4 -1
  42. package/src/list/filter.js +114 -0
  43. package/src/list/load.js +2 -2
  44. package/src/list/remove.js +17 -4
  45. package/src/list/render.js +32 -9
  46. package/src/list/request.js +182 -0
  47. package/src/list/search.js +118 -35
  48. package/src/list/select.js +151 -30
  49. package/src/list/status.js +10 -3
  50. package/src/list/update.js +49 -8
  51. package/src/list/virtual.js +195 -127
  52. package/src/map/build.js +103 -0
  53. package/src/map/countries.js +114 -0
  54. package/src/map/display.js +135 -0
  55. package/src/map/focus.js +39 -0
  56. package/src/map/init.js +24 -0
  57. package/src/map/label.js +0 -0
  58. package/src/map/mode.js +44 -0
  59. package/src/map/mouse.js +65 -0
  60. package/src/map/select.js +68 -0
  61. package/src/map/set.js +71 -0
  62. package/src/map/viewport.js +46 -0
  63. package/src/map.js +71 -0
  64. package/src/module/attach.js +15 -16
  65. package/src/module/extract.js +35 -28
  66. package/src/module/mediator.js +56 -0
  67. package/src/module/object.js +17 -1
  68. package/src/module/observer.js +1 -1
  69. package/src/module/passive.js +17 -0
  70. package/src/module/remove.js +74 -0
  71. package/src/module/scrollbar.js +48 -0
  72. package/src/module/smoothscroll.js +20 -0
  73. package/src/module/viewport.js +20 -0
  74. package/src/selector.js +239 -0
  75. package/src/skin/material/base/body.sass +3 -0
  76. package/src/skin/material/button/file.sass +1 -1
  77. package/src/skin/material/container/container.sass +1 -1
  78. package/src/skin/material/container/dialog.sass +57 -1
  79. package/src/skin/material/container/drawer.sass +3 -3
  80. package/src/skin/material/control/button.sass +125 -0
  81. package/src/skin/material/control/dialog.sass +0 -0
  82. package/src/skin/material/control/progress.sass +136 -0
  83. package/src/skin/material/control/search.sass +40 -0
  84. package/src/skin/material/control/selecter.sass +131 -0
  85. package/src/skin/material/control/selector.sass +38 -0
  86. package/src/skin/material/control/slider.sass +2 -2
  87. package/src/skin/material/control/switch.sass +146 -3
  88. package/src/skin/material/control/switcher.sass +41 -0
  89. package/src/skin/material/control/textfield.sass +2 -1
  90. package/src/skin/material/icon/cancel.svg +1 -0
  91. package/src/skin/material/material.sass +3 -0
  92. package/src/skin/material/view/list.sass +81 -188
  93. package/src/skin/material/view/listview.sass +187 -96
  94. package/src/skin/material/view/tabview.sass +7 -5
  95. package/src/skin/material.bak/base/body.sass +52 -0
  96. package/src/skin/material.bak/base/elevation.sass +50 -0
  97. package/src/skin/material.bak/base/grid.sass +63 -0
  98. package/src/skin/material.bak/base/typo.sass +107 -0
  99. package/src/skin/material.bak/button/action.sass +89 -0
  100. package/src/skin/material.bak/button/button.sass +183 -0
  101. package/src/skin/material.bak/button/file.sass +24 -0
  102. package/src/skin/material.bak/button/floating.sass +113 -0
  103. package/src/skin/material.bak/button/raised.sass +101 -0
  104. package/src/skin/material.bak/button/stroked.sass +71 -0
  105. package/src/skin/material.bak/component/component.sass +7 -0
  106. package/src/skin/material.bak/component/divider.sass +17 -0
  107. package/src/skin/material.bak/component/image.sass +6 -0
  108. package/src/skin/material.bak/component/label.sass +2 -0
  109. package/src/skin/material.bak/component/progress.sass +138 -0
  110. package/src/skin/material.bak/component/subheader.sass +3 -0
  111. package/src/skin/material.bak/component/text.sass +85 -0
  112. package/src/skin/material.bak/container/appbar.sass +167 -0
  113. package/src/skin/material.bak/container/banner.sass +38 -0
  114. package/src/skin/material.bak/container/card.sass +18 -0
  115. package/src/skin/material.bak/container/container.sass +1 -0
  116. package/src/skin/material.bak/container/dialog.sass +184 -0
  117. package/src/skin/material.bak/container/drawer.sass +159 -0
  118. package/src/skin/material.bak/container/drawernew.sass +159 -0
  119. package/src/skin/material.bak/container/menu.sass +58 -0
  120. package/src/skin/material.bak/container/snackbar.sass +18 -0
  121. package/src/skin/material.bak/container/tabs.sass +75 -0
  122. package/src/skin/material.bak/container/toolbar.sass +161 -0
  123. package/src/skin/material.bak/control/button.sass +125 -0
  124. package/src/skin/material.bak/control/checkbox.sass +105 -0
  125. package/src/skin/material.bak/control/dialog.sass +0 -0
  126. package/src/skin/material.bak/control/search.sass +40 -0
  127. package/src/skin/material.bak/control/selecter.sass +128 -0
  128. package/src/skin/material.bak/control/slider.sass +181 -0
  129. package/src/skin/material.bak/control/switch.sass +284 -0
  130. package/src/skin/material.bak/control/switcher.sass +35 -0
  131. package/src/skin/material.bak/control/textfield.sass +126 -0
  132. package/src/skin/material.bak/control/tooltip.sass +36 -0
  133. package/src/skin/material.bak/icon/back.svg +5 -0
  134. package/src/skin/material.bak/icon/cancel.svg +1 -0
  135. package/src/skin/material.bak/icon/checkbox.svg +4 -0
  136. package/src/skin/material.bak/icon/forward.svg +5 -0
  137. package/src/skin/material.bak/icon/menu.svg +4 -0
  138. package/src/skin/material.bak/icon/pin.svg +4 -0
  139. package/src/skin/material.bak/layout/layout.sass +69 -0
  140. package/src/skin/material.bak/layout/resizer.sass +69 -0
  141. package/src/skin/material.bak/material.css +2042 -0
  142. package/src/skin/material.bak/material.css.map +7 -0
  143. package/src/skin/material.bak/material.sass +65 -0
  144. package/src/skin/material.bak/module/ripple.sass +9 -0
  145. package/src/skin/material.bak/theme/default.sass +50 -0
  146. package/src/skin/material.bak/theme/ocean.sass +29 -0
  147. package/src/skin/material.bak/theme/theme.sass +3 -0
  148. package/src/skin/material.bak/view/calendar.sass +193 -0
  149. package/src/skin/material.bak/view/form.sass +15 -0
  150. package/src/skin/material.bak/view/grid.sass +116 -0
  151. package/src/skin/material.bak/view/list.sass +89 -0
  152. package/src/skin/material.bak/view/listview.sass +195 -0
  153. package/src/skin/material.bak/view/map.sass +6 -0
  154. package/src/skin/material.bak/view/page.sass +4 -0
  155. package/src/skin/material.bak/view/tabview-bak.sass +40 -0
  156. package/src/skin/material.bak/view/tabview.sass +55 -0
  157. package/src/skin/material.bak/view/tree.sass +73 -0
  158. package/src/skin/material.bak/view/view.sass +7 -0
  159. package/src/switch.js +1 -1
  160. package/src/tabs/setup.js +0 -0
  161. package/src/tabview.js +64 -14
  162. package/src/tooltip.js +23 -5
  163. package/src/view/build.js +15 -3
  164. package/src/view/display.js +79 -7
  165. package/src/form/clean.js +0 -6
  166. package/src/form/mode.js +0 -16
  167. package/src/form/setup.js +0 -30
  168. package/src/list/fetch.js +0 -66
package/src/list/build.js CHANGED
@@ -1,21 +1,31 @@
1
- import observer from '../module/observer'
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.layout)
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
- this.root.classList.add(this.options.class)
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,25 +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
 
26
- observer.insert(this.root, () => {
27
- this.buildVirtual()
28
- })
36
+ // prepare loading
37
+ // this.ui.loading = new Loading()
38
+
39
+ if (this.options.container) {
40
+ this.options.container.appendChild(this.root)
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])
60
+ }
29
61
  },
30
62
 
31
63
  buildVirtual () {
64
+ // console.log('buildVirtual', this.options.class)
32
65
  var height = 80
66
+ this.size = this.options.list.size
67
+ this.stop = false
33
68
 
34
69
  if (this.options.item && this.options.item.height) {
35
70
  height = this.options.item.height
36
71
  }
37
72
 
38
73
  this.virtual = new Virtual({
74
+ view: this.options.name,
39
75
  container: this.ui.body,
40
76
  itemHeight: height,
77
+ size: this.size,
41
78
  render: (i) => {
42
79
  // console.log('render', this.data[i])
43
80
  return this.renderItem(this.data[i])
44
81
  }
45
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
46
140
  }
47
141
  }
package/src/list/click.js CHANGED
@@ -1,7 +1,8 @@
1
1
 
2
2
  export default {
3
3
  click (e) {
4
- // e.stopPropagation()
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
  }
@@ -0,0 +1,187 @@
1
+
2
+ import emitter from 'material/src/module/emitter'
3
+
4
+ const defaults = {
5
+ size: 25,
6
+ count: true
7
+ }
8
+
9
+ class Collection {
10
+ /**
11
+ * Constructor
12
+ * @param {Object} options - Component options
13
+ * @return {Object} Class instance
14
+ */
15
+ constructor (options) {
16
+ this.options = Object.assign({}, defaults, options || {})
17
+ Object.assign(this, emitter)
18
+
19
+ return this
20
+ }
21
+
22
+ get (page, size, more) {
23
+ 7
24
+ // console.log('fetch', page, size, more)
25
+ if (more !== true) {
26
+ this.page = 1
27
+ this.stop = false
28
+ }
29
+
30
+ this.data = this.data || []
31
+ var signal = null
32
+
33
+ if (this.abortController) {
34
+ // console.log('abort')
35
+ this.abortController.abort()
36
+ this.abortController = null
37
+ }
38
+
39
+ if (more !== true) {
40
+ this.abortController = new AbortController()
41
+ signal = this.abortController.signal
42
+ }
43
+
44
+ page = page || 1
45
+ size = size || this.options.list.size
46
+ // console.log('fetch')
47
+
48
+ if (page === 1) {
49
+ this.ui.body.scrolltop = 0
50
+ }
51
+
52
+ var route = this.buildRoute(page, size)
53
+
54
+ if (more !== true && this.options.count) {
55
+ this.fetchCount(route)
56
+ }
57
+
58
+ fetch(route, {signal}).then((resp) => {
59
+ return resp.json()
60
+ }).then((data) => {
61
+ if (this.options.debug) {
62
+ console.log('data', route, data.length, data)
63
+ }
64
+
65
+ data = data || []
66
+
67
+ if (data.error) {
68
+ console.log('error', data.error)
69
+ return
70
+ }
71
+
72
+ if (data.length < this.size && more) {
73
+ this.stop = true
74
+ }
75
+
76
+ if (more === true) {
77
+ var a = this.data.concat(data)
78
+ this.data = a
79
+ this.storeData(data, more)
80
+ this.virtual.add(this.data)
81
+ } else {
82
+ this.data = []
83
+ this.data = data
84
+ this.storeData(data)
85
+ this.render(data)
86
+ }
87
+
88
+ this.emit('fetched', data)
89
+ }).catch(function (e) {
90
+ // console.log('error', e.message)
91
+ })
92
+ }
93
+
94
+ fetchCount (route, signal) {
95
+ // console.log('fetchCount', route)
96
+ fetch(route + '&count=1', {signal}).then((resp) => {
97
+ return resp.json()
98
+ }).then((data) => {
99
+ // console.log('data', data.count)
100
+ this.count = data.count
101
+ this.statusDisplay('count', data.count)
102
+ }).catch(function (e) {
103
+ // console.log('error', e.message)
104
+ })
105
+ }
106
+
107
+ addParams (route, params) {
108
+ // console.log('addParams', route, params)
109
+
110
+ if (!route) {
111
+ console.log('error: no route specified!')
112
+
113
+ return
114
+ }
115
+
116
+ if (route.indexOf('?') > -1) {
117
+ // console.log('?', route, route.length, route[route.length - 1])
118
+ if (route[route.length - 1] === '&' || route[route.length - 1] === '?') {
119
+ route = route + params
120
+ } else {
121
+ route = route + '&' + params
122
+ }
123
+ } else {
124
+ // console.log('add ?')
125
+ route = route + '?' + params
126
+ }
127
+
128
+ return route
129
+ }
130
+
131
+ buildRoute (page, size, path) {
132
+ // console.log('buildroute', this.options.route, path)
133
+ path = path || 'list'
134
+
135
+ page = page || 1
136
+ size = size || this.options.list.size
137
+
138
+ var route = this.options.route
139
+
140
+ if (path) {
141
+ route = this.options.route[path]
142
+ }
143
+
144
+ if (this.routeAddOn) {
145
+ route = this.routeAddOn(route)
146
+ }
147
+
148
+ if (this.params) {
149
+ // console.log('params', route, this.params())
150
+ route = this.addParams(route, this.params())
151
+ }
152
+
153
+ if (this.ui.filter && this.ui.filter.root.classList.contains('selected')) {
154
+ route = this.addParams(route, this.getFilter())
155
+ }
156
+
157
+ if (this.options.pagination) {
158
+ route = this.addParams(route, 'page=' + page + '&size=' + size)
159
+ }
160
+
161
+ return route
162
+ }
163
+
164
+ storeData (list, more) {
165
+ // console.log('storeData', list.length, more)
166
+ if (more !== true) {
167
+ this.dataList = []
168
+ }
169
+
170
+ // console.log('storeData', this.dataStore)
171
+ this.dataStore = this.dataStore || {}
172
+ for (var i = 0; i < list.length; i++) {
173
+ this.dataList.push(list[i]this.dataId)
174
+ this.dataStore[list[i]this.dataId] = list[i]
175
+ }
176
+ }
177
+
178
+ set () {
179
+
180
+ }
181
+
182
+ setRoute (route) {
183
+ this.route = route
184
+ }
185
+ }
186
+
187
+ export default Collection
@@ -1,31 +1,41 @@
1
1
  export default {
2
2
  create () {
3
- console.log('create', this.mode, this.options.item.new)
3
+ // console.log('create', this.mode, this.options.item.new)
4
4
  // console.log('selected', this.info, this.item)
5
5
 
6
6
  if (this.mode === 'create') return
7
7
 
8
8
  this.mode = 'create'
9
9
 
10
- if (this.options.item) {
11
- this.newItem = this.renderItem(this.options.item.new, 'create')
10
+ if (this.options.virtual === true) {
11
+ this.data.unshift(this.options.item.new)
12
+ this.render(this.data)
13
+ } else {
14
+ if (this.options.item) {
15
+ this.newItem = this.renderItem(this.options.item.new, 'create')
16
+ }
12
17
  }
13
18
 
14
19
  this.emit('create', this.options.item.new)
15
20
  },
16
21
 
17
22
  created (data) {
18
- console.log('created', data)
19
- this.mode = null
20
- this.info = data
21
- this.ui.body.removeChild(this.newItem)
22
- this.item = this.renderItem(data, 'top')
23
+ // console.log('created', this.data.length, data)
24
+ if (this.options.virtual === true) {
25
+ this.data[0] = data
26
+ this.render(this.data)
27
+ } else {
28
+ this.mode = null
29
+ this.info = data
30
+ this.ui.body.removeChild(this.newItem)
31
+ this.item = this.renderItem(data, 'top')
32
+ }
23
33
  },
24
34
 
25
35
  createCancel () {
26
- console.log('createCancel', this.newItem)
27
- console.log('remove')
28
- console.log('prepare reselect', this.info, this.item)
36
+ // console.log('createCancel', this.newItem)
37
+ // console.log('remove')
38
+ // console.log('prepare reselect', this.info, this.item)
29
39
  this.ui.body.removeChild(this.newItem)
30
40
  this.mode = null
31
41
  if (this.item && this.info) {
@@ -0,0 +1,78 @@
1
+
2
+ export default {
3
+ toggle () {
4
+ this.visible ? this.hide() : this.show()
5
+
6
+ this.emit('toggle')
7
+ return this
8
+ },
9
+
10
+ show () {
11
+ // console.log('show', this.visible)
12
+
13
+ this.root.getBoundingClientRect()
14
+
15
+ this.root.classList.add('show')
16
+ this.visible = true
17
+
18
+ if (this.underlay) {
19
+ this.underlay.classList.add('show')
20
+ }
21
+
22
+ this.virtual.setOffset('onShow')
23
+
24
+ this.emit('show')
25
+ return this
26
+ },
27
+
28
+ hide () {
29
+ // console.log('hide', this.root.style.display)
30
+
31
+ if (!this.root) return
32
+
33
+ this.root.classList.remove('show')
34
+ this.visible = false
35
+
36
+ if (this.underlay) {
37
+ this.underlay.classList.remove('show')
38
+ }
39
+
40
+ this.emit('hide')
41
+ return this
42
+ },
43
+
44
+ destroy () {
45
+ // console.log('destroy', this.options.transition)
46
+ if (this.options.transition && this.root) {
47
+ this.root.classList.remove('show')
48
+
49
+ if (this.underlay) {
50
+ this.underlay.classList.remove('show')
51
+ }
52
+
53
+ setTimeout(() => {
54
+ this.removeChild()
55
+ }, this.options.transition)
56
+ } else {
57
+ this.removeChild()
58
+ }
59
+
60
+ this.emit('destroy')
61
+
62
+ return this
63
+ },
64
+
65
+ removeChild () {
66
+ if (this.root && this.root.parentNode) {
67
+ this.root.parentNode.removeChild(this.root)
68
+ this.root = null
69
+ }
70
+
71
+ if (this.underlay && this.underlay.parentNode) {
72
+ this.underlay.parentNode.removeChild(this.underlay)
73
+ }
74
+
75
+ this.emit('remove')
76
+ return this
77
+ }
78
+ }
package/src/list/empty.js CHANGED
@@ -1,6 +1,9 @@
1
1
  export default {
2
2
  empty () {
3
- console.log('empty')
3
+ // console.log('empty')
4
4
  this.ui.body.innerHTML = ''
5
+ this.data = []
6
+ this.dataList = []
7
+ this.dataStore = {}
5
8
  }
6
9
  }
@@ -0,0 +1,114 @@
1
+
2
+ export default {
3
+ initFilter () {
4
+ this.filter = this.extractFilter(this.ui)
5
+
6
+ for (var name in this.filter) {
7
+ if (this.filter.hasOwnProperty(name)) {
8
+ this.filter[name].on('change', () => {
9
+ this.request()
10
+ })
11
+ }
12
+ }
13
+
14
+ this.ui['filter-clear'].on('click', () => {
15
+ this.clearFilter()
16
+ })
17
+
18
+ this.ui['filter'].on('click', () => {
19
+ this.toggleFilter()
20
+ })
21
+ },
22
+
23
+ getFilter () {
24
+ // console.log('getFilter')
25
+ var filter = null
26
+ for (var name in this.filter) {
27
+ if (this.filter.hasOwnProperty(name)) {
28
+ // console.log('--', typeof this.filter[name].get(), this.filter[name].get())
29
+ if (this.filter[name].get() !== '' && this.filter[name].get() !== []) {
30
+ if (filter) {
31
+ filter = filter + '&' + name + '=' + this.filter[name].get()
32
+ } else {
33
+ filter = name + '=' + this.filter[name].get()
34
+ }
35
+ }
36
+ }
37
+ }
38
+
39
+ // console.log('filter', filter)
40
+
41
+ return filter
42
+ },
43
+
44
+ toggleFilter () {
45
+ // console.log('toggleFilter', this.ui['filter-input'])
46
+
47
+ if (this.ui['filter-input'].classList.contains('show')) {
48
+ this.hideFilter()
49
+ } else {
50
+ this.showFilter()
51
+ }
52
+ },
53
+
54
+ /**
55
+ * [showSearch description]
56
+ * @return {[type]} [description]
57
+ */
58
+ showFilter () {
59
+ if (this.hideSearch) {
60
+ this.hideSearch()
61
+ }
62
+
63
+ // console.log('showSearch')
64
+ this.ui['filter'].root.classList.add('selected')
65
+ this.ui['filter-input'].classList.add('show')
66
+
67
+ // this.ui['search-list'].classList.add('show')
68
+ // this.ui.body.classList.add('hide')
69
+ },
70
+
71
+ /**
72
+ * [hideSearch description]
73
+ * @return {[type]} [description]
74
+ */
75
+ hideFilter () {
76
+ // console.log('hideSearch')
77
+ this.ui['filter'].root.classList.remove('selected')
78
+ this.ui['filter-input'].classList.remove('show')
79
+ // this.ui['search-list'].classList.remove('show')
80
+ // this.ui.body.classList.remove('hide')
81
+ this.clearFilter()
82
+ this.request()
83
+ },
84
+
85
+ clearFilter () {
86
+ for (var name in this.filter) {
87
+ if (this.filter.hasOwnProperty(name)) {
88
+ this.filter[name].set('')
89
+ }
90
+ }
91
+
92
+ this.request()
93
+ },
94
+
95
+ extractFilter (object) {
96
+ // console.log('extractField', object)
97
+
98
+ var filter = {}
99
+
100
+ for (var property in object) {
101
+ if (object.hasOwnProperty(property)) {
102
+ var str = property.split(/\./)
103
+
104
+ if (str[0] === 'filter' && str[1] !== undefined) {
105
+ var name = property.substr(7, property.length)
106
+
107
+ filter[name] = object[property]
108
+ }
109
+ }
110
+ }
111
+
112
+ return filter
113
+ }
114
+ }
package/src/list/load.js CHANGED
@@ -1,8 +1,8 @@
1
1
 
2
2
  export default {
3
3
  load () {
4
- this.page = this.page || 2
4
+ this.page = this.page || 2
5
5
  this.page++
6
- this.fetch(this.page)
6
+ this.request(this.page)
7
7
  }
8
8
  }
@@ -1,9 +1,22 @@
1
1
  export default {
2
2
  remove (id) {
3
- // console.log('remove', id, this.ui.body)
3
+ // console.log('remove', id, this.dataList)
4
+ // console.log('datalist', this.dataList)
4
5
 
5
- var item = this.ui.body.querySelector('[data-id="' + id + '"]')
6
- // console.log('item', item)
7
- this.ui.body.removeChild(item)
6
+ if (!id) return
7
+
8
+ if (!this.dataStore[id]) {
9
+ // console.log('not in the list')
10
+ return
11
+ }
12
+
13
+ this.dataList.splice(this.dataList.indexOf(id), 1)
14
+
15
+ // remove id from the list
16
+ this.data = this.data.filter((info) => { return info[this.dataId] !== id })
17
+
18
+ // console.log('data', this.data)
19
+
20
+ this.virtual.update(this.data)
8
21
  }
9
22
  }