@base-framework/base 2.6.1 → 2.6.2

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 (248) hide show
  1. package/README.md +1 -0
  2. package/dist/base.js +1 -0
  3. package/package.json +9 -4
  4. package/.jshintrc +0 -3
  5. package/base.js +0 -41
  6. package/base.min.js +0 -1
  7. package/core.js +0 -1
  8. package/data-tracker.js +0 -351
  9. package/es5/base.js +0 -2968
  10. package/es5/modules/ajax.js +0 -663
  11. package/es5/modules/animation.js +0 -188
  12. package/es5/modules/animations.js +0 -1080
  13. package/es5/modules/atom.js +0 -65
  14. package/es5/modules/component.js +0 -1310
  15. package/es5/modules/data-binder.js +0 -1131
  16. package/es5/modules/data.js +0 -1808
  17. package/es5/modules/date.js +0 -525
  18. package/es5/modules/form-validator.js +0 -324
  19. package/es5/modules/history.js +0 -126
  20. package/es5/modules/html-builder.js +0 -461
  21. package/es5/modules/layout.js +0 -1679
  22. package/es5/modules/mouse.js +0 -124
  23. package/es5/modules/nav-link.js +0 -123
  24. package/es5/modules/olderversions/animations-ease.js +0 -1095
  25. package/es5/modules/olderversions/animations-update.js +0 -1048
  26. package/es5/modules/olderversions/base-animations.js +0 -636
  27. package/es5/modules/olderversions/base-component-class.js +0 -100
  28. package/es5/modules/olderversions/base-data-binder-1.js +0 -407
  29. package/es5/modules/olderversions/base-data-binder-class.js +0 -358
  30. package/es5/modules/olderversions/base-layout-parser-class.js +0 -172
  31. package/es5/modules/olderversions/base-mode-1.js +0 -777
  32. package/es5/modules/olderversions/base-model-class.js +0 -585
  33. package/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
  34. package/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
  35. package/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
  36. package/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
  37. package/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
  38. package/es5/modules/olderversions/data-tracker.js +0 -187
  39. package/es5/modules/olderversions/event-update.js +0 -666
  40. package/es5/modules/olderversions/nav-link.js +0 -119
  41. package/es5/modules/olderversions/router-with-templates-1.js +0 -785
  42. package/es5/modules/olderversions/router-with-templates.js +0 -701
  43. package/es5/modules/prototypes/ajax.js +0 -657
  44. package/es5/modules/prototypes/atom.js +0 -65
  45. package/es5/modules/prototypes/component.js +0 -972
  46. package/es5/modules/prototypes/data-binder.js +0 -1089
  47. package/es5/modules/prototypes/data.js +0 -1290
  48. package/es5/modules/prototypes/html-builder.js +0 -414
  49. package/es5/modules/prototypes/layout.js +0 -879
  50. package/es5/modules/router.js +0 -1680
  51. package/es5/modules/state.js +0 -274
  52. package/es6/.jshintrc +0 -3
  53. package/es6/base.js +0 -41
  54. package/es6/core.js +0 -1
  55. package/es6/data-tracker.js +0 -351
  56. package/es6/events.js +0 -602
  57. package/es6/legacy/es5/base.js +0 -2968
  58. package/es6/legacy/es5/modules/ajax.js +0 -663
  59. package/es6/legacy/es5/modules/animation.js +0 -188
  60. package/es6/legacy/es5/modules/animations.js +0 -1080
  61. package/es6/legacy/es5/modules/atom.js +0 -65
  62. package/es6/legacy/es5/modules/component.js +0 -1310
  63. package/es6/legacy/es5/modules/data-binder.js +0 -1131
  64. package/es6/legacy/es5/modules/data.js +0 -1808
  65. package/es6/legacy/es5/modules/date.js +0 -525
  66. package/es6/legacy/es5/modules/form-validator.js +0 -324
  67. package/es6/legacy/es5/modules/history.js +0 -126
  68. package/es6/legacy/es5/modules/html-builder.js +0 -461
  69. package/es6/legacy/es5/modules/layout.js +0 -1679
  70. package/es6/legacy/es5/modules/mouse.js +0 -124
  71. package/es6/legacy/es5/modules/nav-link.js +0 -123
  72. package/es6/legacy/es5/modules/olderversions/animations-ease.js +0 -1095
  73. package/es6/legacy/es5/modules/olderversions/animations-update.js +0 -1048
  74. package/es6/legacy/es5/modules/olderversions/base-animations.js +0 -636
  75. package/es6/legacy/es5/modules/olderversions/base-component-class.js +0 -100
  76. package/es6/legacy/es5/modules/olderversions/base-data-binder-1.js +0 -407
  77. package/es6/legacy/es5/modules/olderversions/base-data-binder-class.js +0 -358
  78. package/es6/legacy/es5/modules/olderversions/base-layout-parser-class.js +0 -172
  79. package/es6/legacy/es5/modules/olderversions/base-mode-1.js +0 -777
  80. package/es6/legacy/es5/modules/olderversions/base-model-class.js +0 -585
  81. package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
  82. package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
  83. package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
  84. package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
  85. package/es6/legacy/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
  86. package/es6/legacy/es5/modules/olderversions/data-tracker.js +0 -187
  87. package/es6/legacy/es5/modules/olderversions/event-update.js +0 -666
  88. package/es6/legacy/es5/modules/olderversions/nav-link.js +0 -119
  89. package/es6/legacy/es5/modules/olderversions/router-with-templates-1.js +0 -785
  90. package/es6/legacy/es5/modules/olderversions/router-with-templates.js +0 -701
  91. package/es6/legacy/es5/modules/prototypes/ajax.js +0 -657
  92. package/es6/legacy/es5/modules/prototypes/atom.js +0 -65
  93. package/es6/legacy/es5/modules/prototypes/component.js +0 -972
  94. package/es6/legacy/es5/modules/prototypes/data-binder.js +0 -1089
  95. package/es6/legacy/es5/modules/prototypes/data.js +0 -1290
  96. package/es6/legacy/es5/modules/prototypes/html-builder.js +0 -414
  97. package/es6/legacy/es5/modules/prototypes/layout.js +0 -879
  98. package/es6/legacy/es5/modules/router.js +0 -1680
  99. package/es6/legacy/es5/modules/state.js +0 -274
  100. package/es6/main.js +0 -1331
  101. package/es6/modules/ajax/ajax.js +0 -514
  102. package/es6/modules/animation/animation.js +0 -236
  103. package/es6/modules/animations/animation-controller.js +0 -231
  104. package/es6/modules/animations/animation.js +0 -64
  105. package/es6/modules/animations/attr-movement.js +0 -66
  106. package/es6/modules/animations/css-movement.js +0 -170
  107. package/es6/modules/animations/movement.js +0 -131
  108. package/es6/modules/animations/value.js +0 -187
  109. package/es6/modules/atom/atom.js +0 -54
  110. package/es6/modules/component/component.js +0 -230
  111. package/es6/modules/component/event-helper.js +0 -119
  112. package/es6/modules/component/jot.js +0 -144
  113. package/es6/modules/component/state-helper.js +0 -262
  114. package/es6/modules/component/unit.js +0 -551
  115. package/es6/modules/data/attrs.js +0 -40
  116. package/es6/modules/data/basic-data.js +0 -500
  117. package/es6/modules/data/data-utils.js +0 -29
  118. package/es6/modules/data/data.js +0 -3
  119. package/es6/modules/data/deep-data.js +0 -541
  120. package/es6/modules/data/model-service.js +0 -528
  121. package/es6/modules/data/model.js +0 -133
  122. package/es6/modules/data/simple-data.js +0 -33
  123. package/es6/modules/data-binder/connection-tracker.js +0 -113
  124. package/es6/modules/data-binder/connection.js +0 -16
  125. package/es6/modules/data-binder/data-binder.js +0 -352
  126. package/es6/modules/data-binder/data-pub-sub.js +0 -141
  127. package/es6/modules/data-binder/data-source.js +0 -56
  128. package/es6/modules/data-binder/element-source.js +0 -219
  129. package/es6/modules/data-binder/one-way-connection.js +0 -46
  130. package/es6/modules/data-binder/one-way-source.js +0 -43
  131. package/es6/modules/data-binder/source.js +0 -36
  132. package/es6/modules/data-binder/two-way-connection.js +0 -75
  133. package/es6/modules/data-binder/two-way-source.js +0 -41
  134. package/es6/modules/date/date.js +0 -544
  135. package/es6/modules/history/history.js +0 -89
  136. package/es6/modules/html-builder/html-builder.js +0 -434
  137. package/es6/modules/import/import.js +0 -390
  138. package/es6/modules/layout/layout-builder.js +0 -1269
  139. package/es6/modules/layout/layout-parser.js +0 -134
  140. package/es6/modules/layout/watcher-helper.js +0 -282
  141. package/es6/modules/mouse/mouse.js +0 -114
  142. package/es6/modules/router/component-helper.js +0 -163
  143. package/es6/modules/router/history-controller.js +0 -216
  144. package/es6/modules/router/nav-link.js +0 -124
  145. package/es6/modules/router/route.js +0 -401
  146. package/es6/modules/router/router.js +0 -789
  147. package/es6/modules/router/utils.js +0 -31
  148. package/es6/modules/state/state-target.js +0 -91
  149. package/es6/modules/state/state.js +0 -171
  150. package/es6/package-lock.json +0 -13
  151. package/es6/package.json +0 -28
  152. package/es6/shared/objects.js +0 -99
  153. package/events.js +0 -602
  154. package/legacy/es5/base.js +0 -2968
  155. package/legacy/es5/modules/ajax.js +0 -663
  156. package/legacy/es5/modules/animation.js +0 -188
  157. package/legacy/es5/modules/animations.js +0 -1080
  158. package/legacy/es5/modules/atom.js +0 -65
  159. package/legacy/es5/modules/component.js +0 -1310
  160. package/legacy/es5/modules/data-binder.js +0 -1131
  161. package/legacy/es5/modules/data.js +0 -1808
  162. package/legacy/es5/modules/date.js +0 -525
  163. package/legacy/es5/modules/form-validator.js +0 -324
  164. package/legacy/es5/modules/history.js +0 -126
  165. package/legacy/es5/modules/html-builder.js +0 -461
  166. package/legacy/es5/modules/layout.js +0 -1679
  167. package/legacy/es5/modules/mouse.js +0 -124
  168. package/legacy/es5/modules/nav-link.js +0 -123
  169. package/legacy/es5/modules/olderversions/animations-ease.js +0 -1095
  170. package/legacy/es5/modules/olderversions/animations-update.js +0 -1048
  171. package/legacy/es5/modules/olderversions/base-animations.js +0 -636
  172. package/legacy/es5/modules/olderversions/base-component-class.js +0 -100
  173. package/legacy/es5/modules/olderversions/base-data-binder-1.js +0 -407
  174. package/legacy/es5/modules/olderversions/base-data-binder-class.js +0 -358
  175. package/legacy/es5/modules/olderversions/base-layout-parser-class.js +0 -172
  176. package/legacy/es5/modules/olderversions/base-mode-1.js +0 -777
  177. package/legacy/es5/modules/olderversions/base-model-class.js +0 -585
  178. package/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
  179. package/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
  180. package/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
  181. package/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
  182. package/legacy/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
  183. package/legacy/es5/modules/olderversions/data-tracker.js +0 -187
  184. package/legacy/es5/modules/olderversions/event-update.js +0 -666
  185. package/legacy/es5/modules/olderversions/nav-link.js +0 -119
  186. package/legacy/es5/modules/olderversions/router-with-templates-1.js +0 -785
  187. package/legacy/es5/modules/olderversions/router-with-templates.js +0 -701
  188. package/legacy/es5/modules/prototypes/ajax.js +0 -657
  189. package/legacy/es5/modules/prototypes/atom.js +0 -65
  190. package/legacy/es5/modules/prototypes/component.js +0 -972
  191. package/legacy/es5/modules/prototypes/data-binder.js +0 -1089
  192. package/legacy/es5/modules/prototypes/data.js +0 -1290
  193. package/legacy/es5/modules/prototypes/html-builder.js +0 -414
  194. package/legacy/es5/modules/prototypes/layout.js +0 -879
  195. package/legacy/es5/modules/router.js +0 -1680
  196. package/legacy/es5/modules/state.js +0 -274
  197. package/main.js +0 -1331
  198. package/modules/ajax/ajax.js +0 -514
  199. package/modules/animation/animation.js +0 -236
  200. package/modules/animations/animation-controller.js +0 -231
  201. package/modules/animations/animation.js +0 -64
  202. package/modules/animations/attr-movement.js +0 -66
  203. package/modules/animations/css-movement.js +0 -170
  204. package/modules/animations/movement.js +0 -131
  205. package/modules/animations/value.js +0 -187
  206. package/modules/atom/atom.js +0 -54
  207. package/modules/component/component.js +0 -230
  208. package/modules/component/event-helper.js +0 -119
  209. package/modules/component/jot.js +0 -144
  210. package/modules/component/state-helper.js +0 -262
  211. package/modules/component/unit.js +0 -551
  212. package/modules/data/attrs.js +0 -40
  213. package/modules/data/basic-data.js +0 -500
  214. package/modules/data/data-utils.js +0 -29
  215. package/modules/data/data.js +0 -3
  216. package/modules/data/deep-data.js +0 -541
  217. package/modules/data/model-service.js +0 -528
  218. package/modules/data/model.js +0 -133
  219. package/modules/data/simple-data.js +0 -33
  220. package/modules/data-binder/connection-tracker.js +0 -113
  221. package/modules/data-binder/connection.js +0 -16
  222. package/modules/data-binder/data-binder.js +0 -352
  223. package/modules/data-binder/data-pub-sub.js +0 -141
  224. package/modules/data-binder/data-source.js +0 -56
  225. package/modules/data-binder/element-source.js +0 -219
  226. package/modules/data-binder/one-way-connection.js +0 -46
  227. package/modules/data-binder/one-way-source.js +0 -43
  228. package/modules/data-binder/source.js +0 -36
  229. package/modules/data-binder/two-way-connection.js +0 -75
  230. package/modules/data-binder/two-way-source.js +0 -41
  231. package/modules/date/date.js +0 -544
  232. package/modules/history/history.js +0 -89
  233. package/modules/html-builder/html-builder.js +0 -434
  234. package/modules/import/import.js +0 -390
  235. package/modules/layout/layout-builder.js +0 -1269
  236. package/modules/layout/layout-parser.js +0 -134
  237. package/modules/layout/watcher-helper.js +0 -282
  238. package/modules/mouse/mouse.js +0 -114
  239. package/modules/router/component-helper.js +0 -163
  240. package/modules/router/history-controller.js +0 -216
  241. package/modules/router/nav-link.js +0 -124
  242. package/modules/router/route.js +0 -401
  243. package/modules/router/router.js +0 -789
  244. package/modules/router/utils.js +0 -31
  245. package/modules/state/state-target.js +0 -91
  246. package/modules/state/state.js +0 -171
  247. package/shared/objects.js +0 -99
  248. package/update +0 -16
@@ -1,528 +0,0 @@
1
- import {ajax} from '../ajax/ajax.js';
2
- import {base} from '../../core.js';
3
-
4
- /**
5
- * ModelService
6
- *
7
- * This will create a new model service.
8
- * @class
9
- */
10
- export class ModelService
11
- {
12
- /**
13
- * @constructor
14
- * @param {object} model
15
- */
16
- constructor(model)
17
- {
18
- /**
19
- * @member {object} model
20
- */
21
- this.model = model;
22
-
23
- /**
24
- * @member {string} objectType The return type.
25
- */
26
- this.objectType = this.objectType || 'item';
27
-
28
- this.url = '';
29
- this.validateCallBack = null;
30
- this.init();
31
- }
32
-
33
- init()
34
- {
35
- let model = this.model;
36
- if(model && model.url)
37
- {
38
- this.url = model.url;
39
- }
40
- }
41
-
42
- /**
43
- * This will check if the model is valid.
44
- *
45
- * @return {boolean}
46
- */
47
- isValid()
48
- {
49
- let result = this.validate();
50
- if(result !== false)
51
- {
52
- let callBack = this.validateCallBack;
53
- if(typeof callBack === 'function')
54
- {
55
- callBack(result);
56
- }
57
- }
58
- return result;
59
- }
60
-
61
- /**
62
- * This should be overriden to validate the model
63
- * before submitting.
64
- *
65
- * @return {boolean}
66
- */
67
- validate()
68
- {
69
- return true;
70
- }
71
-
72
- /**
73
- * This can be overriden to add default params
74
- * with each request.
75
- *
76
- * @protected
77
- * @return {string}
78
- */
79
- getDefaultParams()
80
- {
81
- return '';
82
- }
83
-
84
- /**
85
- * This will setup the request params.
86
- *
87
- * @protected
88
- * @param {(string|object)} params
89
- * @return {(string|object)}
90
- */
91
- setupParams(params)
92
- {
93
- let defaults = this.getDefaultParams();
94
- params = this.addParams(params, defaults);
95
- return params;
96
- }
97
-
98
- /**
99
- * This will convert an object to a string.
100
- *
101
- * @protected
102
- * @param {object} object
103
- * @return {string}
104
- */
105
- objectToString(object)
106
- {
107
- const params = [];
108
- for (var prop in object)
109
- {
110
- if(object.hasOwnProperty(prop))
111
- {
112
- params.push(prop + '=' + object[prop]);
113
- }
114
- }
115
- return params.join('&');
116
- }
117
-
118
- /**
119
- * This will add the params.
120
- *
121
- * @protected
122
- * @param {*} params
123
- * @param {*} addingParams
124
- * @return {(string|object)}
125
- */
126
- addParams(params, addingParams)
127
- {
128
- params = params || {};
129
- if(typeof params === 'string')
130
- {
131
- params = base.parseQueryString(params, false);
132
- }
133
-
134
- if(!addingParams)
135
- {
136
- return (!this._isFormData(params))? this.objectToString(params) : params;
137
- }
138
-
139
- if(typeof addingParams === 'string')
140
- {
141
- addingParams = base.parseQueryString(addingParams, false);
142
- }
143
-
144
- if(this._isFormData(params))
145
- {
146
- for(var key in addingParams)
147
- {
148
- if(addingParams.hasOwnProperty(key))
149
- {
150
- params.append(key, addingParams[key]);
151
- }
152
- }
153
- }
154
- else
155
- {
156
- params = Object.assign(params, addingParams);
157
- params = this.objectToString(params);
158
- }
159
-
160
- return params;
161
- }
162
-
163
- /**
164
- * This will get the model by id.
165
- *
166
- * @param {string} [instanceParams]
167
- * @param {function} [callBack]
168
- * @return {object}
169
- */
170
- get(instanceParams, callBack)
171
- {
172
- let id = this.model.get('id'),
173
- params = 'op=get' +
174
- '&id=' + id;
175
-
176
- let model = this.model;
177
- return this._get('', params, instanceParams, callBack, (response) =>
178
- {
179
- if(response)
180
- {
181
- /* this will update the model with the get request
182
- response */
183
- let object = this.getObject(response);
184
- if(object)
185
- {
186
- model.set(object);
187
- }
188
- }
189
- });
190
- }
191
-
192
- /**
193
- * This will get the object from the response.
194
- *
195
- * @protected
196
- * @param {object} response
197
- * @return {object}
198
- */
199
- getObject(response)
200
- {
201
- /* this will update the model with the get request
202
- response */
203
- let object = response[this.objectType] || response;
204
- return object || false;
205
- }
206
-
207
- /**
208
- * This will return a string with the model data json encoded.
209
- *
210
- * @protected
211
- * @return {string}
212
- */
213
- setupObjectData()
214
- {
215
- let item = this.model.get();
216
- return this.objectType + '=' + base.prepareJsonUrl(item);
217
- }
218
-
219
- /**
220
- * This will add or update the model.
221
- *
222
- * @param {string} [instanceParams]
223
- * @param {function} [callBack]
224
- * @return {object}
225
- */
226
- setup(instanceParams, callBack)
227
- {
228
- if(!this.isValid())
229
- {
230
- return false;
231
- }
232
-
233
- let params = 'op=setup' +
234
- '&' + this.setupObjectData();
235
-
236
- /* this will add the instance params with the
237
- method params */
238
- params = this.addParams(params, instanceParams, instanceParams);
239
-
240
- return this._put('', params, callBack);
241
- }
242
-
243
- /**
244
- * This will add the model.
245
- *
246
- * @param {string} [instanceParams]
247
- * @param {function} [callBack]
248
- * @return {object}
249
- */
250
- add(instanceParams, callBack)
251
- {
252
- if(!this.isValid())
253
- {
254
- return false;
255
- }
256
-
257
- let params = 'op=add' +
258
- '&' + this.setupObjectData();
259
-
260
- return this._post('', params, instanceParams, callBack);
261
- }
262
-
263
- /**
264
- * This will update the model.
265
- *
266
- * @param {string} [instanceParams]
267
- * @param {function} [callBack]
268
- * @return {object}
269
- */
270
- update(instanceParams, callBack)
271
- {
272
- if(!this.isValid())
273
- {
274
- return false;
275
- }
276
-
277
- let params = 'op=update' +
278
- '&' + this.setupObjectData();
279
-
280
- return this._patch('', params, instanceParams, callBack);
281
- }
282
-
283
- /**
284
- * This will delete the model.
285
- *
286
- * @param {string} [instanceParams]
287
- * @param {function} [callBack]
288
- * @return {object}
289
- */
290
- delete(instanceParams, callBack)
291
- {
292
- let id = this.model.get('id'),
293
- params = 'op=delete' +
294
- '&id=' + id;
295
-
296
- return this._delete('', params, instanceParams, callBack);
297
- }
298
-
299
- /**
300
- * This will list rows of the model.
301
- *
302
- * @param {string} [instanceParams]
303
- * @param {function} [callBack]
304
- * @param {int} start
305
- * @param {int} count
306
- * @param {string} filter
307
- * @return {object}
308
- */
309
- all(instanceParams, callBack, start, count, filter)
310
- {
311
- filter = filter || '';
312
- start = !isNaN(start)? start : 0;
313
- count = !isNaN(count)? count : 50;
314
-
315
- let params = 'op=all' +
316
- '&option=' + filter +
317
- '&start=' + start +
318
- '&stop=' + count;
319
-
320
- return this._get('', params, instanceParams, callBack);
321
- }
322
-
323
- getUrl(url)
324
- {
325
- let baseUrl = this.url;
326
- if(!url)
327
- {
328
- return baseUrl;
329
- }
330
-
331
- if(url[0] === '?')
332
- {
333
- return baseUrl + url;
334
- }
335
-
336
- return baseUrl += '/' + url;
337
- }
338
-
339
- /**
340
- * This will make an ajax request.
341
- *
342
- * @param {string} url
343
- * @param {string} method
344
- * @param {(string|object)} params
345
- * @param {function} callBack
346
- * @param {function} [requestCallBack]
347
- * @param {object}
348
- */
349
- setupRequest(url, method, params, callBack, requestCallBack)
350
- {
351
- let settings = {
352
- url: this.getUrl(url),
353
- method,
354
- params,
355
- completed: (response, xhr) =>
356
- {
357
- if(typeof requestCallBack === 'function')
358
- {
359
- requestCallBack(response);
360
- }
361
-
362
- this.getResponse(response, callBack, xhr);
363
- }
364
- };
365
-
366
- let overrideHeader = this._isFormData(params);
367
- if(overrideHeader)
368
- {
369
- settings.headers = {};
370
- }
371
-
372
- return ajax(settings);
373
- }
374
-
375
- _isFormData(data)
376
- {
377
- return data instanceof FormData;
378
- }
379
-
380
- /**
381
- * This will make an ajax request.
382
- *
383
- * @param {(string|object)} params
384
- * @param {string} instanceParams
385
- * @param {function} callBack
386
- * @param {function} [requestCallBack]
387
- * @param {object}
388
- */
389
- request(params, instanceParams, callBack, requestCallBack)
390
- {
391
- return this._request('', 'POST', params, instanceParams, callBack, requestCallBack);
392
- }
393
-
394
- /**
395
- * This will make a GET request.
396
- *
397
- * @param {string} url
398
- * @param {(string|object)} params
399
- * @param {string} instanceParams
400
- * @param {function} callBack
401
- * @param {function} [requestCallBack]
402
- * @param {object}
403
- */
404
- _get(url, params, instanceParams, callBack, requestCallBack)
405
- {
406
- params = this.setupParams(params);
407
- params = this.addParams(params, instanceParams);
408
-
409
- url = url || '';
410
-
411
- if(params)
412
- {
413
- url += '?' + params;
414
- }
415
-
416
- return this.setupRequest(url, "GET", '', callBack, requestCallBack);
417
- }
418
-
419
- /**
420
- * This will make a POST request.
421
- *
422
- * @param {string} url
423
- * @param {(string|object)} params
424
- * @param {string} instanceParams
425
- * @param {function} callBack
426
- * @param {function} [requestCallBack]
427
- * @param {object}
428
- */
429
- _post(url, params, instanceParams, callBack, requestCallBack)
430
- {
431
- return this._request(url, 'POST', params, instanceParams, callBack, requestCallBack);
432
- }
433
-
434
- /**
435
- * This will make a PUT request.
436
- *
437
- * @param {string} url
438
- * @param {(string|object)} params
439
- * @param {string} instanceParams
440
- * @param {function} callBack
441
- * @param {function} [requestCallBack]
442
- * @param {object}
443
- */
444
- _put(url, params, instanceParams, callBack, requestCallBack)
445
- {
446
- return this._request(url, 'PUT', params, instanceParams, callBack, requestCallBack);
447
- }
448
-
449
- /**
450
- * This will make a PATCH request.
451
- *
452
- * @param {string} url
453
- * @param {(string|object)} params
454
- * @param {string} instanceParams
455
- * @param {function} callBack
456
- * @param {function} [requestCallBack]
457
- * @param {object}
458
- */
459
- _patch(url, params, instanceParams, callBack, requestCallBack)
460
- {
461
- return this._request(url, 'PATCH', params, instanceParams, callBack, requestCallBack);
462
- }
463
-
464
- /**
465
- * This will make a DELETE request.
466
- *
467
- * @param {string} url
468
- * @param {(string|object)} params
469
- * @param {string} instanceParams
470
- * @param {function} callBack
471
- * @param {function} [requestCallBack]
472
- * @param {object}
473
- */
474
- _delete(url, params, instanceParams, callBack, requestCallBack)
475
- {
476
- return this._request(url, 'DELETE', params, instanceParams, callBack, requestCallBack);
477
- }
478
-
479
- /**
480
- * This will make an ajax request.
481
- *
482
- * @param {string} url
483
- * @param {string} method
484
- * @param {(string|object)} params
485
- * @param {string} instanceParams
486
- * @param {function} callBack
487
- * @param {function} [requestCallBack]
488
- * @param {object}
489
- */
490
- _request(url, method, params, instanceParams, callBack, requestCallBack)
491
- {
492
- params = this.setupParams(params);
493
- params = this.addParams(params, instanceParams);
494
-
495
- return this.setupRequest(url, method, params, callBack, requestCallBack);
496
- }
497
-
498
- getResponse(response, callBack, xhr)
499
- {
500
- /* this will check to return the response
501
- to the callBack function */
502
- if(typeof callBack === 'function')
503
- {
504
- callBack(response, xhr);
505
- }
506
- }
507
-
508
- static extend(child)
509
- {
510
- if(!child)
511
- {
512
- return false;
513
- }
514
-
515
- var parent = this;
516
- class service extends parent
517
- {
518
- constructor(model)
519
- {
520
- super(model);
521
- }
522
- }
523
-
524
- Object.assign(service.prototype, child);
525
-
526
- return service;
527
- }
528
- }
@@ -1,133 +0,0 @@
1
- import {Data} from './deep-data.js';
2
- import {ModelService} from './model-service.js';
3
- import {setupAttrSettings} from './attrs.js';
4
-
5
- /**
6
- * This will get the defaults from the settings.
7
- *
8
- * @param {object} settings
9
- * @return {object}
10
- */
11
- const setupDefaultAttr = (settings) =>
12
- {
13
- let attributes = {};
14
- if(!settings || typeof settings !== 'object')
15
- {
16
- return attributes;
17
- }
18
-
19
- let defaults = settings.defaults;
20
- if(!defaults)
21
- {
22
- return attributes;
23
- }
24
-
25
- for(var prop in defaults)
26
- {
27
- if(defaults.hasOwnProperty(prop))
28
- {
29
- var attr = defaults[prop];
30
- if(typeof attr !== 'function')
31
- {
32
- attributes[prop] = attr;
33
- }
34
- }
35
- }
36
- delete settings.defaults;
37
- return attributes;
38
- };
39
-
40
- /**
41
- * This will get the xhr settings.
42
- *
43
- * @param {object} settings
44
- * @return {object}
45
- */
46
- const getXhr = (settings) =>
47
- {
48
- if(!settings || typeof settings.xhr !== 'object')
49
- {
50
- return {};
51
- }
52
-
53
- let settingsXhr = settings.xhr,
54
- xhr = Object.assign({}, settingsXhr);
55
- delete settings.xhr;
56
- return xhr;
57
- };
58
-
59
- /* this will track the number of model types */
60
- let modelTypeNumber = 0;
61
-
62
- /**
63
- * Model
64
- *
65
- * This will extend Data to add a model that can specify
66
- * a service that connects to a remote source.
67
- */
68
- export class Model extends Data
69
- {
70
- /**
71
- * @constructor
72
- * @param {object} [settings]
73
- */
74
- constructor(settings)
75
- {
76
- super(settings);
77
- this.initialize();
78
- }
79
-
80
- /**
81
- * This adds a method to call if you want the model
82
- * to do something when its initialized.
83
- */
84
- initialize()
85
- {
86
-
87
- }
88
-
89
- /**
90
- * This will extend the model to a child model.
91
- *
92
- * @param {object} [settings]
93
- * @return {class}
94
- */
95
- static extend(settings = {})
96
- {
97
- const parent = this,
98
- xhr = getXhr(settings),
99
- service = this.prototype.service.extend(xhr);
100
-
101
- /* this will setup the default attribute settings for
102
- the model */
103
- let defaultAttributes = setupDefaultAttr(settings);
104
- class model extends parent
105
- {
106
- constructor(instanceSettings)
107
- {
108
- /* this will get the instance attributes that
109
- the model will set as attribute data */
110
- let instanceAttr = setupAttrSettings(instanceSettings);
111
-
112
- /* we want to extend the default attr with the
113
- instance attr before we set the data and call
114
- the parent constructor */
115
- instanceAttr = Object.assign({}, defaultAttributes, instanceAttr);
116
- super(instanceAttr);
117
-
118
- /* this will setup the model service and
119
- pass the new model instance to the service */
120
- this.xhr = new service(this);
121
- }
122
-
123
- dataTypeId = 'bm' + (modelTypeNumber++);
124
- }
125
-
126
- Object.assign(model.prototype, settings);
127
- model.prototype.service = service;
128
-
129
- return model;
130
- }
131
- }
132
-
133
- Model.prototype.service = ModelService;
@@ -1,33 +0,0 @@
1
- import {BasicData} from './basic-data.js';
2
- import {dataBinder} from '../data-binder/data-binder.js';
3
-
4
- /**
5
- * SimpleData
6
- *
7
- * This will extend Data to add a simple data object
8
- * that doesn't allow deep nested data.
9
- * @class
10
- * @augments BasicData
11
- */
12
- export class SimpleData extends BasicData
13
- {
14
- /**
15
- * This will publish an update to the data binder.
16
- *
17
- * @override
18
- * @protected
19
- * @param {string} attr
20
- * @param {*} val
21
- * @param {*} committer
22
- * @param {*} prevValue
23
- */
24
- _publish(attr, val, committer, prevValue)
25
- {
26
- let message = attr + ':change';
27
- this.eventSub.publish(message, val, committer);
28
-
29
- committer = committer || this;
30
-
31
- dataBinder.publish(this._dataId + attr, val, committer);
32
- }
33
- }