material 0.4.3 → 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 (166) 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 +127 -44
  5. package/src/control/button.new.js +190 -0
  6. package/src/control/dialog.js +174 -0
  7. package/src/control/{upload.js → file.js} +33 -8
  8. package/src/control/link.js +61 -0
  9. package/src/control/list.js +77 -0
  10. package/src/control/loading.js +128 -0
  11. package/src/control/module/addclass.js +16 -0
  12. package/src/control/module/attributes.js +3 -1
  13. package/src/control/search.js +98 -0
  14. package/src/control/select.js +80 -22
  15. package/src/control/selecter.js +246 -0
  16. package/src/control/switch.js +272 -0
  17. package/src/control/switcher.js +245 -0
  18. package/src/control/text.js +18 -3
  19. package/src/control/textfield.js +89 -15
  20. package/src/field/image.js +9 -3
  21. package/src/form/build.js +28 -4
  22. package/src/form/cancel.js +7 -3
  23. package/src/form/controller.js +90 -0
  24. package/src/form/create.js +11 -7
  25. package/src/form/data.js +82 -0
  26. package/src/form/delete.js +2 -1
  27. package/src/form/fetch.js +5 -3
  28. package/src/form/render.js +11 -9
  29. package/src/form/set.js +27 -12
  30. package/src/form/submit.js +11 -37
  31. package/src/form/update.js +35 -16
  32. package/src/layout.js +25 -21
  33. package/src/list/add.js +34 -0
  34. package/src/list/build.js +96 -12
  35. package/src/list/click.js +10 -5
  36. package/src/list/collection.js +187 -0
  37. package/src/list/create.js +21 -11
  38. package/src/list/display.js +78 -0
  39. package/src/list/empty.js +4 -1
  40. package/src/list/filter.js +114 -0
  41. package/src/list/load.js +2 -2
  42. package/src/list/remove.js +17 -4
  43. package/src/list/render.js +32 -9
  44. package/src/list/request.js +182 -0
  45. package/src/list/search.js +118 -35
  46. package/src/list/select.js +151 -30
  47. package/src/list/status.js +10 -3
  48. package/src/list/update.js +49 -8
  49. package/src/list/virtual.js +195 -127
  50. package/src/map/build.js +103 -0
  51. package/src/map/countries.js +114 -0
  52. package/src/map/display.js +135 -0
  53. package/src/map/focus.js +39 -0
  54. package/src/map/init.js +24 -0
  55. package/src/map/label.js +0 -0
  56. package/src/map/mode.js +44 -0
  57. package/src/map/mouse.js +65 -0
  58. package/src/map/select.js +68 -0
  59. package/src/map/set.js +71 -0
  60. package/src/map/viewport.js +46 -0
  61. package/src/map.js +71 -0
  62. package/src/module/attach.js +9 -2
  63. package/src/module/mediator.js +56 -0
  64. package/src/module/object.js +17 -1
  65. package/src/module/observer.js +1 -1
  66. package/src/module/passive.js +17 -0
  67. package/src/module/remove.js +74 -0
  68. package/src/module/scrollbar.js +48 -0
  69. package/src/module/smoothscroll.js +20 -0
  70. package/src/module/viewport.js +20 -0
  71. package/src/selector.js +239 -0
  72. package/src/skin/material/base/body.sass +3 -0
  73. package/src/skin/material/button/file.sass +1 -1
  74. package/src/skin/material/container/container.sass +1 -1
  75. package/src/skin/material/container/dialog.sass +57 -1
  76. package/src/skin/material/container/drawer.sass +3 -3
  77. package/src/skin/material/control/button.sass +125 -0
  78. package/src/skin/material/control/dialog.sass +0 -0
  79. package/src/skin/material/control/progress.sass +136 -0
  80. package/src/skin/material/control/search.sass +40 -0
  81. package/src/skin/material/control/selecter.sass +131 -0
  82. package/src/skin/material/control/selector.sass +38 -0
  83. package/src/skin/material/control/slider.sass +2 -2
  84. package/src/skin/material/control/switch.sass +146 -3
  85. package/src/skin/material/control/switcher.sass +41 -0
  86. package/src/skin/material/control/textfield.sass +2 -1
  87. package/src/skin/material/icon/cancel.svg +1 -0
  88. package/src/skin/material/material.sass +3 -0
  89. package/src/skin/material/view/list.sass +81 -188
  90. package/src/skin/material/view/listview.sass +187 -96
  91. package/src/skin/material/view/tabview.sass +6 -4
  92. package/src/skin/material.bak/base/body.sass +52 -0
  93. package/src/skin/material.bak/base/elevation.sass +50 -0
  94. package/src/skin/material.bak/base/grid.sass +63 -0
  95. package/src/skin/material.bak/base/typo.sass +107 -0
  96. package/src/skin/material.bak/button/action.sass +89 -0
  97. package/src/skin/material.bak/button/button.sass +183 -0
  98. package/src/skin/material.bak/button/file.sass +24 -0
  99. package/src/skin/material.bak/button/floating.sass +113 -0
  100. package/src/skin/material.bak/button/raised.sass +101 -0
  101. package/src/skin/material.bak/button/stroked.sass +71 -0
  102. package/src/skin/material.bak/component/component.sass +7 -0
  103. package/src/skin/material.bak/component/divider.sass +17 -0
  104. package/src/skin/material.bak/component/image.sass +6 -0
  105. package/src/skin/material.bak/component/label.sass +2 -0
  106. package/src/skin/material.bak/component/progress.sass +138 -0
  107. package/src/skin/material.bak/component/subheader.sass +3 -0
  108. package/src/skin/material.bak/component/text.sass +85 -0
  109. package/src/skin/material.bak/container/appbar.sass +167 -0
  110. package/src/skin/material.bak/container/banner.sass +38 -0
  111. package/src/skin/material.bak/container/card.sass +18 -0
  112. package/src/skin/material.bak/container/container.sass +1 -0
  113. package/src/skin/material.bak/container/dialog.sass +184 -0
  114. package/src/skin/material.bak/container/drawer.sass +159 -0
  115. package/src/skin/material.bak/container/drawernew.sass +159 -0
  116. package/src/skin/material.bak/container/menu.sass +58 -0
  117. package/src/skin/material.bak/container/snackbar.sass +18 -0
  118. package/src/skin/material.bak/container/tabs.sass +75 -0
  119. package/src/skin/material.bak/container/toolbar.sass +161 -0
  120. package/src/skin/material.bak/control/button.sass +125 -0
  121. package/src/skin/material.bak/control/checkbox.sass +105 -0
  122. package/src/skin/material.bak/control/dialog.sass +0 -0
  123. package/src/skin/material.bak/control/search.sass +40 -0
  124. package/src/skin/material.bak/control/selecter.sass +128 -0
  125. package/src/skin/material.bak/control/slider.sass +181 -0
  126. package/src/skin/material.bak/control/switch.sass +284 -0
  127. package/src/skin/material.bak/control/switcher.sass +35 -0
  128. package/src/skin/material.bak/control/textfield.sass +126 -0
  129. package/src/skin/material.bak/control/tooltip.sass +36 -0
  130. package/src/skin/material.bak/icon/back.svg +5 -0
  131. package/src/skin/material.bak/icon/cancel.svg +1 -0
  132. package/src/skin/material.bak/icon/checkbox.svg +4 -0
  133. package/src/skin/material.bak/icon/forward.svg +5 -0
  134. package/src/skin/material.bak/icon/menu.svg +4 -0
  135. package/src/skin/material.bak/icon/pin.svg +4 -0
  136. package/src/skin/material.bak/layout/layout.sass +69 -0
  137. package/src/skin/material.bak/layout/resizer.sass +69 -0
  138. package/src/skin/material.bak/material.css +2042 -0
  139. package/src/skin/material.bak/material.css.map +7 -0
  140. package/src/skin/material.bak/material.sass +65 -0
  141. package/src/skin/material.bak/module/ripple.sass +9 -0
  142. package/src/skin/material.bak/theme/default.sass +50 -0
  143. package/src/skin/material.bak/theme/ocean.sass +29 -0
  144. package/src/skin/material.bak/theme/theme.sass +3 -0
  145. package/src/skin/material.bak/view/calendar.sass +193 -0
  146. package/src/skin/material.bak/view/form.sass +15 -0
  147. package/src/skin/material.bak/view/grid.sass +116 -0
  148. package/src/skin/material.bak/view/list.sass +89 -0
  149. package/src/skin/material.bak/view/listview.sass +195 -0
  150. package/src/skin/material.bak/view/map.sass +6 -0
  151. package/src/skin/material.bak/view/page.sass +4 -0
  152. package/src/skin/material.bak/view/tabview-bak.sass +40 -0
  153. package/src/skin/material.bak/view/tabview.sass +55 -0
  154. package/src/skin/material.bak/view/tree.sass +73 -0
  155. package/src/skin/material.bak/view/view.sass +7 -0
  156. package/src/switch.js +1 -1
  157. package/src/tabs/setup.js +0 -0
  158. package/src/tabview.js +64 -14
  159. package/src/tooltip.js +23 -5
  160. package/src/view/build.js +13 -1
  161. package/src/view/display.js +63 -2
  162. package/src/form/clean.js +0 -6
  163. package/src/form/controls.js +0 -56
  164. package/src/form/mode.js +0 -8
  165. package/src/form/setup.js +0 -5
  166. package/src/list/fetch.js +0 -66
@@ -0,0 +1,245 @@
1
+ import emitter from '../module/emitter'
2
+
3
+ const defaults = {
4
+ class: 'switcher',
5
+ tag: 'div',
6
+ list: [],
7
+ first: false,
8
+ mode: 'unique',
9
+ allowEmpty: false
10
+ }
11
+
12
+ class Switcher {
13
+ /**
14
+ * Constructor
15
+ * @param {Object} options - Component options
16
+ * @return {Object} Class instance
17
+ */
18
+ constructor (options) {
19
+ this.options = Object.assign({}, defaults, options || {})
20
+ Object.assign(this, emitter)
21
+
22
+ this.build()
23
+ this.attach()
24
+
25
+ if (this.options.default) {
26
+ this.selectByName(this.options.default, true)
27
+ }
28
+
29
+ return this
30
+ }
31
+
32
+ build () {
33
+ this.root = document.createElement(this.options.tag)
34
+
35
+ if (this.options.class !== 'button') {
36
+ this.root.setAttribute('class', 'switcher ' + this.options.class)
37
+ } else {
38
+ this.root.classList.add('switcher')
39
+ }
40
+
41
+ if (this.options.label) {
42
+ this.label = document.createElement('label')
43
+ this.label.innerHTML = this.options.label
44
+ this.root.appendChild(this.label)
45
+ }
46
+
47
+ this.knob = document.createElement('span')
48
+ this.knob.classList.add('knob')
49
+ this.root.appendChild(this.knob)
50
+
51
+ if (this.options.size) {
52
+ this.root.classList.add(this.options.size + '-size')
53
+ }
54
+
55
+ this.buildList(this.options.list)
56
+
57
+ if (this.options.list) {
58
+ this.addOptions(this.options.list)
59
+ }
60
+
61
+ if (this.options.container) {
62
+ this.options.container.appendChild(this.root)
63
+ }
64
+ }
65
+
66
+ buildList (list) {
67
+ this.list = document.createElement('ul')
68
+ this.root.appendChild(this.list)
69
+ }
70
+
71
+ attach () {
72
+ this.root.addEventListener('click', (event) => {
73
+ if (!event.target.dataset.switcher) return
74
+ this.select(event.target)
75
+ })
76
+ }
77
+
78
+ select (option) {
79
+ if (this.options.mode === 'multiple') {
80
+ this.multiple(option)
81
+ } else {
82
+ this.unique(option)
83
+ }
84
+ }
85
+
86
+ preselect (item) {
87
+ // console.log('preselect', item)
88
+ if (item) {
89
+ item.classList.add('preselected')
90
+ } else {
91
+ var items = this.list.childNodes
92
+ for (var i = 0; i < items.length; i++) {
93
+ items[i].classList.remove('preselected')
94
+ }
95
+ }
96
+ }
97
+
98
+ selectByName (name) {
99
+ // console.log('selectByName', name)
100
+ var item = this.root.querySelector('[data-switcher="' + name + '"]')
101
+ // console.log('item', item)
102
+ if (item) {
103
+ this.select(item)
104
+ }
105
+ }
106
+
107
+ preSelectByName (name) {
108
+ // console.log('selectByName', name)
109
+ var item = this.root.querySelector('[data-switcher="' + name + '"]')
110
+ // console.log('item', item)
111
+ this.preselect(item)
112
+ }
113
+
114
+ unique (option) {
115
+ // console.log('option', option)
116
+ if (!option.classList.contains('selected')) {
117
+ var options = this.list.childNodes
118
+
119
+ for (var i = 0; i < options.length; i++) {
120
+ options[i].classList.remove('selected')
121
+ }
122
+
123
+ option.classList.add('selected')
124
+ this.selected = [option.dataset.switcher]
125
+ this.emit('change', this.selected[0])
126
+ } else {
127
+ if (this.options.allowEmpty) {
128
+ option.classList.remove('selected')
129
+ this.selected = []
130
+ this.emit('change', this.selected[0])
131
+ }
132
+ }
133
+ }
134
+
135
+ multiple (option) {
136
+ if (option.classList.contains('selected')) {
137
+ if (this.selected.length === 1) return
138
+ var i = this.selected.indexOf(option.dataset.switcher)
139
+ this.selected.splice(i, 1)
140
+ option.classList.remove('selected')
141
+ } else {
142
+ option.classList.add('selected')
143
+ this.selected.push(option.dataset.switcher)
144
+ }
145
+
146
+ this.emit('change', this.selected)
147
+ }
148
+
149
+ set (prop, value) {
150
+ switch (prop) {
151
+ case 'value':
152
+ this.setValue(value)
153
+ break
154
+ case 'options':
155
+ this.setOptions(value)
156
+ break
157
+ case 'option':
158
+ this.addOptions(value)
159
+ break
160
+ default:
161
+ this.setValue(prop)
162
+ }
163
+
164
+ return this
165
+ }
166
+
167
+ setValue (value) {
168
+ // console.log('value', value, this.options.list, this.root)
169
+ var list = this.options.list
170
+ if (this.options.mode === 'unique') {
171
+ for (var i = 0; i < list.length; i++) {
172
+ this.root.querySelector('[data-switcher="' + list[i] + '"]').classList.remove('selected')
173
+ if (list[i] == value) {
174
+ this.selected = [value]
175
+ this.root.querySelector('[data-switcher="' + list[i] + '"]').classList.add('selected')
176
+ }
177
+ }
178
+ } else {
179
+ value = value || []
180
+ this.selected = []
181
+ for (var i = 0; i < list.length; i++) {
182
+ this.root.querySelector('[data-switcher="' + list[i] + '"]').classList.remove('selected')
183
+ if (value.indexOf(list[i]) !== -1) {
184
+ this.selected.push(list[i])
185
+ this.root.querySelector('[data-switcher="' + list[i] + '"]').classList.add('selected')
186
+ }
187
+ }
188
+ }
189
+ }
190
+
191
+ addOptions (list) {
192
+ // console.log('setOptions', list, this.options.list)
193
+
194
+ if (!list) return
195
+
196
+ for (var i = 0; i < list.length; i++) {
197
+ this.addOption(list[i])
198
+ }
199
+ }
200
+
201
+ setOptions (list) {
202
+ // console.log('setOptions', list, this.options.list)
203
+
204
+ if (!list) return
205
+
206
+ if (this.options.list.length < 1) this.options.list = list
207
+
208
+ for (var i = 0; i < list.length; i++) {
209
+ this.addOption(list[i])
210
+ }
211
+ }
212
+
213
+ addOption (value) {
214
+ // console.log('addOption', value)
215
+ var item = document.createElement('li')
216
+ item.classList.add('item')
217
+ item.dataset.switcher = value
218
+ item.innerHTML = value
219
+ this.list.appendChild(item)
220
+ // this.options.list.push(list[i])
221
+ }
222
+
223
+ setLabel (value) {
224
+ // console.log('setLabel', value)
225
+ if (this.label) {
226
+ this.label.innerHTML = value
227
+ }
228
+ }
229
+
230
+ setText (value) {
231
+ // console.log('setText', value)
232
+ this.setLabel(value)
233
+ }
234
+
235
+ get () {
236
+ // console.log('get', this.selected)
237
+ if (this.options.mode === 'unique') {
238
+ return this.selected[0]
239
+ } else {
240
+ return this.selected
241
+ }
242
+ }
243
+ }
244
+
245
+ export default Switcher
@@ -1,4 +1,4 @@
1
- 'use strict'
1
+ import addClass from './module/addclass'
2
2
 
3
3
  const defaults = {
4
4
  class: 'text',
@@ -14,6 +14,8 @@ class Text {
14
14
  constructor (options) {
15
15
  this.options = Object.assign({}, defaults, options || {})
16
16
 
17
+ // console.log('options', this.options)
18
+
17
19
  this.build()
18
20
 
19
21
  return this
@@ -25,7 +27,11 @@ class Text {
25
27
  */
26
28
  build () {
27
29
  this.root = document.createElement(this.options.tag)
28
- this.root.classList.add(this.options.class)
30
+ addClass(this.root, this.options.class)
31
+
32
+ if (this.options.class !== 'text') {
33
+ this.root.classList.add('text')
34
+ }
29
35
 
30
36
  if (this.options.text) {
31
37
  this.set(this.options.text)
@@ -40,12 +46,21 @@ class Text {
40
46
 
41
47
  set (text) {
42
48
  // console.log('set', text)
43
- this.root.innerHTML = text
49
+ if (text === undefined) return
50
+
51
+ var label = this.options.label || ''
52
+
53
+ this.root.innerHTML = label + text
44
54
 
45
55
  if (this.options.spaceAfter) {
46
56
  this.root.innerHTML = this.root.innerHTML + ' '
47
57
  }
48
58
  }
59
+
60
+ setText (text) {
61
+ // console.log('setText', text)
62
+ this.root.innerHTML = text
63
+ }
49
64
  }
50
65
 
51
66
  export default Text
@@ -6,10 +6,12 @@ import attributes from './module/attributes'
6
6
 
7
7
  const defaults = {
8
8
  class: 'textfield',
9
- tag: 'div',
10
- attributes: ['type', 'name', 'autocomplete', 'required', 'disabled'],
9
+ attributes: ['type', 'name', 'title', 'maxlength', 'pattern', 'min', 'max', 'placeholder', 'readonly', 'autocomplete', 'required', 'disabled'],
11
10
  events: [
12
- ['input.keyup', 'onKeyup']
11
+ ['input.input', 'onInput'],
12
+ ['input.focus', 'onFocus'],
13
+ ['input.blur', 'onBlur'],
14
+ ['input.click', 'onClick']
13
15
  ]
14
16
  }
15
17
 
@@ -38,10 +40,12 @@ class Text {
38
40
  * @return {Object} This class instance
39
41
  */
40
42
  build () {
41
- this.root = document.createElement(this.options.tag)
43
+ var tag = this.options.tag || 'div'
44
+
45
+ this.root = document.createElement(tag)
42
46
  this.root.classList.add('textfield')
43
47
 
44
- if (this.options.class !== 'upload') {
48
+ if (this.options.class !== 'textfield') {
45
49
  this.root.classList.add(this.options.class)
46
50
  }
47
51
 
@@ -65,14 +69,20 @@ class Text {
65
69
 
66
70
  buildLabel () {
67
71
  if (this.options.label) {
68
- this.label = document.createElement('span')
72
+ this.label = document.createElement('label')
73
+ this.label.classList.add('label')
69
74
  this.label.innerHTML = this.options.label
70
75
  this.root.appendChild(this.label)
71
76
  }
72
77
  }
73
78
 
74
79
  buildInput () {
75
- this.input = document.createElement('input')
80
+ let tag = 'input'
81
+ if (this.options.type === 'multiline') {
82
+ tag = 'textarea'
83
+ }
84
+ this.input = document.createElement(tag)
85
+ this.input.classList.add('input')
76
86
  this.root.appendChild(this.input)
77
87
 
78
88
  attributes(this.input, this.options)
@@ -82,17 +92,81 @@ class Text {
82
92
  }
83
93
  }
84
94
 
85
- onKeyup (ev) {
86
- // console.log('change', this.value, this.input.value)
87
- if (this.value !== this.input.value) {
88
- this.emit('change', ev)
95
+ onInput (ev) {
96
+ console.log('onInput', this.value, this.input.value)
97
+
98
+ this.emit('change', ev)
99
+ }
100
+
101
+ onFocus (ev) {
102
+ this.root.classList.add('focused')
103
+ this.emit('focus', ev)
104
+ }
105
+
106
+ onBlur (ev) {
107
+ this.root.classList.remove('focused')
108
+ this.emit('blur', ev)
109
+ }
110
+
111
+ onClick (ev) {
112
+ console.log('click')
113
+ this.emit('click', ev)
114
+ }
115
+
116
+ /**
117
+ * Setter
118
+ * @param {string} prop
119
+ * @param {string} value
120
+ * @return {Object} The class instance
121
+ */
122
+ set (prop, value) {
123
+ // console.log('set', this.root, prop, value)
124
+ switch (prop) {
125
+ case 'value':
126
+ this.setValue(value)
127
+ break
128
+ case 'label':
129
+ this.setLabel(value)
130
+ break
131
+ default:
132
+ // console.log('prop', prop)
133
+ this.setValue(prop)
89
134
  }
135
+
136
+ return this
137
+ }
138
+
139
+ setValue (value) {
140
+ // console.log('set', typeof value, value)
141
+ if (value && value !== 'undefined') {
142
+ this.value = value
143
+ this.input.value = value
144
+ } else {
145
+ this.input.value = ''
146
+ }
147
+ }
148
+
149
+ setLabel (value) {
150
+ // console.log('setLabel', value)
151
+ if (this.label) {
152
+ this.label.innerHTML = value
153
+ }
154
+ }
155
+
156
+ setText (value) {
157
+ this.setLabel(value)
158
+
159
+ if (this.options.placeholder) {
160
+ this.input.placeholder = value
161
+ }
162
+ }
163
+
164
+ hide () {
165
+ this.root.classList.add('hide')
90
166
  }
91
167
 
92
- set (value) {
93
- // console.log('set', value)
94
- this.value = value
95
- this.input.value = value
168
+ show () {
169
+ this.root.classList.remove('hide')
96
170
  }
97
171
 
98
172
  get () {
@@ -20,12 +20,16 @@ const defaults = {
20
20
  * });
21
21
  */
22
22
  class Image {
23
+ static isImage () {
24
+ return true
25
+ }
23
26
  /**
24
27
  * Constructor
25
28
  * @param {Object} options - Component options
26
29
  * @return {Object} Class instance
27
30
  */
28
31
  constructor (options) {
32
+ // console.log('options', options)
29
33
  this.options = Object.assign({}, defaults, options || {})
30
34
 
31
35
  this.build()
@@ -48,8 +52,10 @@ class Image {
48
52
  return this
49
53
  }
50
54
 
51
- set (src) {
52
- // console.log('set', src)
55
+ set (src, asset) {
56
+ console.log('set', src, asset)
57
+
58
+ asset = asset || {}
53
59
 
54
60
  if (!src) return
55
61
 
@@ -70,7 +76,7 @@ class Image {
70
76
  url = url + format
71
77
  }
72
78
 
73
- this.root.style.backgroundImage = 'url(' + url + src.filename + ')'
79
+ this.root.style.backgroundImage = 'url(' + asset.url + src.path + 'thumb/' + src.filename + ')'
74
80
  }
75
81
 
76
82
  sanitize (formats) {
package/src/form/build.js CHANGED
@@ -12,6 +12,10 @@ export default {
12
12
  this.root.classList.add(this.options.class)
13
13
  }
14
14
 
15
+ if (this.options.form) {
16
+ this.root.classList.add(this.options.form)
17
+ }
18
+
15
19
  if (this.options.data) {
16
20
  dataset(this.root, this.options.data)
17
21
  }
@@ -33,12 +37,12 @@ export default {
33
37
  this.form.setAttribute('method', form.method)
34
38
  }
35
39
 
36
- if (form && form.autocomplete) {
37
- this.form.setAttribute('autocomplete', form.autocomplete)
40
+ if (this.options.autocomplete) {
41
+ this.form.setAttribute('autocomplete', this.options.autocomplete)
38
42
  }
39
43
 
40
- if (form && form.action) {
41
- this.form.setAttribute('action', form.action)
44
+ if (this.options.action) {
45
+ this.form.setAttribute('action', this.options.action)
42
46
  }
43
47
  },
44
48
 
@@ -48,6 +52,8 @@ export default {
48
52
  this.layout = new Layout(this.options.layout, this.form)
49
53
  this.ui = this.layout.component
50
54
 
55
+ // console.log('ui', this.ui)
56
+
51
57
  this.extractInfo(this.ui)
52
58
  this.extractFile(this.ui)
53
59
  // console.log('file', this.file)
@@ -55,6 +61,11 @@ export default {
55
61
  if (this.disableControl) {
56
62
  this.disableControl()
57
63
  }
64
+
65
+ if (this.language) {
66
+ // console.log('translate')
67
+ this.translate()
68
+ }
58
69
  },
59
70
 
60
71
  extractFile (object) {
@@ -90,5 +101,18 @@ export default {
90
101
  }
91
102
  }
92
103
  }
104
+ },
105
+
106
+ clean () {
107
+ // console.log('clean', this.info)
108
+ for (var member in this.info) {
109
+ delete this.info[member]
110
+ }
111
+
112
+ this.form.reset()
113
+
114
+ // console.log('cleaned', this.info)
115
+
116
+ this.emit('cleaned')
93
117
  }
94
118
  }
@@ -1,13 +1,17 @@
1
1
  export default {
2
- cancel () {
3
- console.log('cancel', this.info, this.mode)
2
+ cancel (ev) {
3
+ // console.log('cancel', this.info, this.mode)
4
+ ev.preventDefault()
4
5
 
5
6
  this.render(this.info)
6
7
 
7
8
  if (this.mode === 'create') {
8
- console.log('cancel create')
9
9
  this.mode = null
10
10
  this.emit('cancel', 'create')
11
11
  }
12
+
13
+ this.setMode('read')
14
+
15
+ return false
12
16
  }
13
17
  }
@@ -0,0 +1,90 @@
1
+
2
+ export default {
3
+
4
+ initController () {
5
+ // console.log('initController', this.field)
6
+
7
+ this.disableControls()
8
+
9
+ for (var field in this.field) {
10
+ if (this.field.hasOwnProperty(field)) {
11
+ this.bindControl(this.field[field])
12
+ }
13
+ }
14
+
15
+ for (var file in this.file) {
16
+ if (this.file.hasOwnProperty(file)) {
17
+ this.bindControl(this.file[file])
18
+ }
19
+ }
20
+ },
21
+
22
+ setMode (mode) {
23
+ // console.log('setMode', mode)
24
+ this.mode = mode
25
+
26
+ this.updateClassMode(mode)
27
+
28
+ this.emit('mode', mode)
29
+ },
30
+
31
+ updateClassMode (mode) {
32
+ var modes = ['read', 'create', 'update']
33
+
34
+ for (var i = 0; i < modes.length; i++) {
35
+ this.form.classList.remove(modes[i] + '-mode')
36
+ }
37
+
38
+ this.form.classList.add(mode + '-mode')
39
+ },
40
+
41
+ changeMode (mode) {
42
+ console.log('changeMode', mode)
43
+
44
+ if (mode === 'update' && this.enableControls) {
45
+ this.enableControls()
46
+ } else if (mode === 'update' && this.disableControls) {
47
+ this.disableControls()
48
+ } else if (mode === 'read' && this.disableControls) {
49
+ this.disableControls()
50
+ }
51
+ },
52
+
53
+ bindControl (control) {
54
+ // console.log('bindControl')
55
+ if (control && control.on) {
56
+ control.on('change', () => {
57
+ // console.log('change', control, this.mode)
58
+ if (this.mode === 'read') {
59
+ this.setMode('update')
60
+ }
61
+ })
62
+ }
63
+ },
64
+
65
+ enableControls () {
66
+ // console.log('enableControls')
67
+ var controls = this.options.controls || ['submit', 'cancel']
68
+
69
+ if (controls === null) return
70
+
71
+ for (var i = 0; i < controls.length; i++) {
72
+ if (this.ui[controls[i]] && this.ui[controls[i]].enable) {
73
+ this.ui[controls[i]].enable()
74
+ }
75
+ }
76
+ },
77
+
78
+ disableControls () {
79
+ // console.log('disableControls')
80
+ var controls = this.options.controls || ['submit', 'cancel']
81
+
82
+ if (controls === null) return
83
+
84
+ for (var i = 0; i < controls.length; i++) {
85
+ if (this.ui[controls[i]] && this.ui[controls[i]].disable) {
86
+ this.ui[controls[i]].disable()
87
+ }
88
+ }
89
+ }
90
+ }
@@ -1,15 +1,19 @@
1
1
 
2
2
  export default {
3
3
 
4
- create (info) {
5
- console.log('create', info, this.info)
6
- this.form.style.display = 'flex'
4
+ create () {
5
+ console.log('create', this.options.create.info)
7
6
 
7
+ this.clean()
8
+
9
+ var info = this.options.create.info || { name: 'New Item' }
10
+
11
+ console.log('info', info)
12
+
13
+ this.render(info, 'create')
8
14
  this.setMode('create')
9
- this.render(this.options.create, 'create')
15
+ this.enableControls()
10
16
 
11
- if (this.controls) {
12
- this.enableControls()
13
- }
17
+ this.emit('new')
14
18
  }
15
19
  }