@base-framework/base 2.6.0 → 2.6.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.
Files changed (190) hide show
  1. package/base.min.js +1 -0
  2. package/es5/base.js +2968 -0
  3. package/es5/modules/ajax.js +663 -0
  4. package/es5/modules/animation.js +188 -0
  5. package/es5/modules/animations.js +1080 -0
  6. package/es5/modules/atom.js +65 -0
  7. package/es5/modules/component.js +1310 -0
  8. package/es5/modules/data-binder.js +1131 -0
  9. package/es5/modules/data.js +1808 -0
  10. package/es5/modules/date.js +525 -0
  11. package/es5/modules/form-validator.js +324 -0
  12. package/es5/modules/history.js +126 -0
  13. package/es5/modules/html-builder.js +461 -0
  14. package/es5/modules/layout.js +1679 -0
  15. package/es5/modules/mouse.js +124 -0
  16. package/es5/modules/nav-link.js +123 -0
  17. package/es5/modules/olderversions/animations-ease.js +1095 -0
  18. package/es5/modules/olderversions/animations-update.js +1048 -0
  19. package/es5/modules/olderversions/base-animations.js +636 -0
  20. package/es5/modules/olderversions/base-component-class.js +100 -0
  21. package/es5/modules/olderversions/base-data-binder-1.js +407 -0
  22. package/es5/modules/olderversions/base-data-binder-class.js +358 -0
  23. package/es5/modules/olderversions/base-layout-parser-class.js +172 -0
  24. package/es5/modules/olderversions/base-mode-1.js +777 -0
  25. package/es5/modules/olderversions/base-model-class.js +585 -0
  26. package/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
  27. package/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
  28. package/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
  29. package/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
  30. package/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
  31. package/es5/modules/olderversions/data-tracker.js +187 -0
  32. package/es5/modules/olderversions/event-update.js +666 -0
  33. package/es5/modules/olderversions/nav-link.js +119 -0
  34. package/es5/modules/olderversions/router-with-templates-1.js +785 -0
  35. package/es5/modules/olderversions/router-with-templates.js +701 -0
  36. package/es5/modules/prototypes/ajax.js +657 -0
  37. package/es5/modules/prototypes/atom.js +65 -0
  38. package/es5/modules/prototypes/component.js +972 -0
  39. package/es5/modules/prototypes/data-binder.js +1089 -0
  40. package/es5/modules/prototypes/data.js +1290 -0
  41. package/es5/modules/prototypes/html-builder.js +414 -0
  42. package/es5/modules/prototypes/layout.js +879 -0
  43. package/es5/modules/router.js +1680 -0
  44. package/es5/modules/state.js +274 -0
  45. package/es6/.jshintrc +3 -0
  46. package/es6/base.js +41 -0
  47. package/es6/core.js +1 -0
  48. package/es6/data-tracker.js +351 -0
  49. package/es6/events.js +602 -0
  50. package/es6/legacy/es5/base.js +2968 -0
  51. package/es6/legacy/es5/modules/ajax.js +663 -0
  52. package/es6/legacy/es5/modules/animation.js +188 -0
  53. package/es6/legacy/es5/modules/animations.js +1080 -0
  54. package/es6/legacy/es5/modules/atom.js +65 -0
  55. package/es6/legacy/es5/modules/component.js +1310 -0
  56. package/es6/legacy/es5/modules/data-binder.js +1131 -0
  57. package/es6/legacy/es5/modules/data.js +1808 -0
  58. package/es6/legacy/es5/modules/date.js +525 -0
  59. package/es6/legacy/es5/modules/form-validator.js +324 -0
  60. package/es6/legacy/es5/modules/history.js +126 -0
  61. package/es6/legacy/es5/modules/html-builder.js +461 -0
  62. package/es6/legacy/es5/modules/layout.js +1679 -0
  63. package/es6/legacy/es5/modules/mouse.js +124 -0
  64. package/es6/legacy/es5/modules/nav-link.js +123 -0
  65. package/es6/legacy/es5/modules/olderversions/animations-ease.js +1095 -0
  66. package/es6/legacy/es5/modules/olderversions/animations-update.js +1048 -0
  67. package/es6/legacy/es5/modules/olderversions/base-animations.js +636 -0
  68. package/es6/legacy/es5/modules/olderversions/base-component-class.js +100 -0
  69. package/es6/legacy/es5/modules/olderversions/base-data-binder-1.js +407 -0
  70. package/es6/legacy/es5/modules/olderversions/base-data-binder-class.js +358 -0
  71. package/es6/legacy/es5/modules/olderversions/base-layout-parser-class.js +172 -0
  72. package/es6/legacy/es5/modules/olderversions/base-mode-1.js +777 -0
  73. package/es6/legacy/es5/modules/olderversions/base-model-class.js +585 -0
  74. package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
  75. package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
  76. package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
  77. package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
  78. package/es6/legacy/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
  79. package/es6/legacy/es5/modules/olderversions/data-tracker.js +187 -0
  80. package/es6/legacy/es5/modules/olderversions/event-update.js +666 -0
  81. package/es6/legacy/es5/modules/olderversions/nav-link.js +119 -0
  82. package/es6/legacy/es5/modules/olderversions/router-with-templates-1.js +785 -0
  83. package/es6/legacy/es5/modules/olderversions/router-with-templates.js +701 -0
  84. package/es6/legacy/es5/modules/prototypes/ajax.js +657 -0
  85. package/es6/legacy/es5/modules/prototypes/atom.js +65 -0
  86. package/es6/legacy/es5/modules/prototypes/component.js +972 -0
  87. package/es6/legacy/es5/modules/prototypes/data-binder.js +1089 -0
  88. package/es6/legacy/es5/modules/prototypes/data.js +1290 -0
  89. package/es6/legacy/es5/modules/prototypes/html-builder.js +414 -0
  90. package/es6/legacy/es5/modules/prototypes/layout.js +879 -0
  91. package/es6/legacy/es5/modules/router.js +1680 -0
  92. package/es6/legacy/es5/modules/state.js +274 -0
  93. package/es6/main.js +1331 -0
  94. package/es6/modules/ajax/ajax.js +514 -0
  95. package/es6/modules/animation/animation.js +236 -0
  96. package/es6/modules/animations/animation-controller.js +231 -0
  97. package/es6/modules/animations/animation.js +64 -0
  98. package/es6/modules/animations/attr-movement.js +66 -0
  99. package/es6/modules/animations/css-movement.js +170 -0
  100. package/es6/modules/animations/movement.js +131 -0
  101. package/es6/modules/animations/value.js +187 -0
  102. package/es6/modules/atom/atom.js +54 -0
  103. package/es6/modules/component/component.js +230 -0
  104. package/es6/modules/component/event-helper.js +119 -0
  105. package/es6/modules/component/jot.js +144 -0
  106. package/es6/modules/component/state-helper.js +262 -0
  107. package/es6/modules/component/unit.js +551 -0
  108. package/es6/modules/data/attrs.js +40 -0
  109. package/es6/modules/data/basic-data.js +500 -0
  110. package/es6/modules/data/data-utils.js +29 -0
  111. package/es6/modules/data/data.js +3 -0
  112. package/es6/modules/data/deep-data.js +541 -0
  113. package/es6/modules/data/model-service.js +528 -0
  114. package/es6/modules/data/model.js +133 -0
  115. package/es6/modules/data/simple-data.js +33 -0
  116. package/es6/modules/data-binder/connection-tracker.js +113 -0
  117. package/es6/modules/data-binder/connection.js +16 -0
  118. package/es6/modules/data-binder/data-binder.js +352 -0
  119. package/es6/modules/data-binder/data-pub-sub.js +141 -0
  120. package/es6/modules/data-binder/data-source.js +56 -0
  121. package/es6/modules/data-binder/element-source.js +219 -0
  122. package/es6/modules/data-binder/one-way-connection.js +46 -0
  123. package/es6/modules/data-binder/one-way-source.js +43 -0
  124. package/es6/modules/data-binder/source.js +36 -0
  125. package/es6/modules/data-binder/two-way-connection.js +75 -0
  126. package/es6/modules/data-binder/two-way-source.js +41 -0
  127. package/es6/modules/date/date.js +544 -0
  128. package/es6/modules/history/history.js +89 -0
  129. package/es6/modules/html-builder/html-builder.js +434 -0
  130. package/es6/modules/import/import.js +390 -0
  131. package/es6/modules/layout/layout-builder.js +1269 -0
  132. package/es6/modules/layout/layout-parser.js +134 -0
  133. package/es6/modules/layout/watcher-helper.js +282 -0
  134. package/es6/modules/mouse/mouse.js +114 -0
  135. package/es6/modules/router/component-helper.js +163 -0
  136. package/es6/modules/router/history-controller.js +216 -0
  137. package/es6/modules/router/nav-link.js +124 -0
  138. package/es6/modules/router/route.js +401 -0
  139. package/es6/modules/router/router.js +789 -0
  140. package/es6/modules/router/utils.js +31 -0
  141. package/es6/modules/state/state-target.js +91 -0
  142. package/es6/modules/state/state.js +171 -0
  143. package/es6/package-lock.json +13 -0
  144. package/es6/package.json +28 -0
  145. package/es6/shared/objects.js +99 -0
  146. package/legacy/es5/base.js +2968 -0
  147. package/legacy/es5/modules/ajax.js +663 -0
  148. package/legacy/es5/modules/animation.js +188 -0
  149. package/legacy/es5/modules/animations.js +1080 -0
  150. package/legacy/es5/modules/atom.js +65 -0
  151. package/legacy/es5/modules/component.js +1310 -0
  152. package/legacy/es5/modules/data-binder.js +1131 -0
  153. package/legacy/es5/modules/data.js +1808 -0
  154. package/legacy/es5/modules/date.js +525 -0
  155. package/legacy/es5/modules/form-validator.js +324 -0
  156. package/legacy/es5/modules/history.js +126 -0
  157. package/legacy/es5/modules/html-builder.js +461 -0
  158. package/legacy/es5/modules/layout.js +1679 -0
  159. package/legacy/es5/modules/mouse.js +124 -0
  160. package/legacy/es5/modules/nav-link.js +123 -0
  161. package/legacy/es5/modules/olderversions/animations-ease.js +1095 -0
  162. package/legacy/es5/modules/olderversions/animations-update.js +1048 -0
  163. package/legacy/es5/modules/olderversions/base-animations.js +636 -0
  164. package/legacy/es5/modules/olderversions/base-component-class.js +100 -0
  165. package/legacy/es5/modules/olderversions/base-data-binder-1.js +407 -0
  166. package/legacy/es5/modules/olderversions/base-data-binder-class.js +358 -0
  167. package/legacy/es5/modules/olderversions/base-layout-parser-class.js +172 -0
  168. package/legacy/es5/modules/olderversions/base-mode-1.js +777 -0
  169. package/legacy/es5/modules/olderversions/base-model-class.js +585 -0
  170. package/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
  171. package/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
  172. package/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
  173. package/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
  174. package/legacy/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
  175. package/legacy/es5/modules/olderversions/data-tracker.js +187 -0
  176. package/legacy/es5/modules/olderversions/event-update.js +666 -0
  177. package/legacy/es5/modules/olderversions/nav-link.js +119 -0
  178. package/legacy/es5/modules/olderversions/router-with-templates-1.js +785 -0
  179. package/legacy/es5/modules/olderversions/router-with-templates.js +701 -0
  180. package/legacy/es5/modules/prototypes/ajax.js +657 -0
  181. package/legacy/es5/modules/prototypes/atom.js +65 -0
  182. package/legacy/es5/modules/prototypes/component.js +972 -0
  183. package/legacy/es5/modules/prototypes/data-binder.js +1089 -0
  184. package/legacy/es5/modules/prototypes/data.js +1290 -0
  185. package/legacy/es5/modules/prototypes/html-builder.js +414 -0
  186. package/legacy/es5/modules/prototypes/layout.js +879 -0
  187. package/legacy/es5/modules/router.js +1680 -0
  188. package/legacy/es5/modules/state.js +274 -0
  189. package/package.json +8 -3
  190. package/update +16 -0
@@ -0,0 +1,604 @@
1
+ /* base framework module */
2
+ (function()
3
+ {
4
+ "use strict";
5
+
6
+ /*
7
+ Model
8
+
9
+ this create a model module that can bind
10
+ the data using the dase data binder.
11
+
12
+ @param (object) settings = the new model properties
13
+ and methods
14
+ */
15
+ var Model = function(settings)
16
+ {
17
+ this._init();
18
+
19
+ /* this will setup the attributes object and the
20
+ attribute stage object */
21
+ this.attributes = {};
22
+ this.stage = {};
23
+
24
+ /* this will setup the event sub for
25
+ one way binding */
26
+ this.eventSub = new base.DataPubSub();
27
+
28
+ /* this will set the construct attributes */
29
+ var attributes = setupAttrSettings(settings);
30
+ this.set(attributes);
31
+
32
+ /* this will setup the data binding for two
33
+ way binding */
34
+ this.bind = true;
35
+ this._setupDataBinder();
36
+
37
+ this.initialize();
38
+
39
+ this.xhr = null;
40
+ };
41
+
42
+ Model.prototype =
43
+ {
44
+ constructor: Model,
45
+
46
+ /* this will setup the model number and unique
47
+ instance id */
48
+ _init: function()
49
+ {
50
+ var constructor = this.constructor;
51
+ this._modelNumber = (typeof constructor._modelNumber === 'undefined')? constructor._modelNumber = 0 : (++constructor._modelNumber);
52
+
53
+ var modelId = this.modelTypeId + '-';
54
+ this._id = modelId + this._modelNumber;
55
+ },
56
+
57
+ /* this will get the unique model id
58
+ @return (string) the id */
59
+ getModelId: function()
60
+ {
61
+ return this._id;
62
+ },
63
+
64
+ /* this will setup the model to the databinder */
65
+ _setupDataBinder: function()
66
+ {
67
+ var self = this;
68
+ if(this.bind)
69
+ {
70
+ var dataBinder = base.DataBinder;
71
+ dataBinder.onChange(this._id, function(evt, attrName, val, committer)
72
+ {
73
+ if(committer !== self)
74
+ {
75
+ self.set(attrName, val, committer);
76
+ }
77
+ });
78
+ }
79
+ },
80
+
81
+ remove: function()
82
+ {
83
+ base.DataBinder.unbind(this);
84
+ },
85
+
86
+ initialize: function()
87
+ {
88
+
89
+ },
90
+
91
+ on: function(attrName, callBack)
92
+ {
93
+ var message = attrName + ':change';
94
+ this.eventSub.on(message, callBack);
95
+ },
96
+
97
+ off: function(attrName, callBack)
98
+ {
99
+ var message = attrName + ':change';
100
+ this.eventSub.off(message, callBack);
101
+ },
102
+
103
+ set: function()
104
+ {
105
+ var self = this;
106
+ var set = function(attr, val, committer)
107
+ {
108
+ if(self.bind === true)
109
+ {
110
+ /* this will block the data binder if we have
111
+ been updated from outside of the model and not
112
+ the model updated directly */
113
+ if(!committer)
114
+ {
115
+ /* this will publish to the data binder but tell it
116
+ to cancel calls from this commiter the set to stop
117
+ this settings twice */
118
+ base.DataBinder.publish(self._id, attr, val, self);
119
+ self.attributes[attr] = val;
120
+ self.stage[attr] = val;
121
+ }
122
+ else
123
+ {
124
+ self.stage[attr] = val;
125
+ }
126
+ }
127
+ else
128
+ {
129
+ self.attributes[attr] = val;
130
+ self.stage[attr] = val;
131
+ }
132
+
133
+ /* this will check to update any local events
134
+ on the model */
135
+ var message = attr + ':change';
136
+ self.eventSub.publish(message, attr, val);
137
+ };
138
+
139
+ var setupObject = function(object, committer)
140
+ {
141
+ var items = object;
142
+ for(var attr in items)
143
+ {
144
+ if(items.hasOwnProperty(attr))
145
+ {
146
+ var item = items[attr];
147
+ if(typeof item === 'function')
148
+ {
149
+ continue;
150
+ }
151
+ set(attr, item, committer);
152
+ }
153
+ }
154
+ };
155
+
156
+ var args = arguments;
157
+ if(typeof args[0] === 'object')
158
+ {
159
+ setupObject(args[0], args[1]);
160
+ }
161
+ else
162
+ {
163
+ set(args[0], args[1], args[2]);
164
+ }
165
+ },
166
+
167
+ mergeStage: function()
168
+ {
169
+ /* this will clone the stage object to the
170
+ attribute object */
171
+ this.attributes = JSON.parse(JSON.stringify(this.stage));
172
+ },
173
+
174
+ getModelData: function()
175
+ {
176
+ this.mergeStage();
177
+ return this.attributes;
178
+ },
179
+
180
+ revert: function()
181
+ {
182
+ /* this will reset the stage to the previous
183
+ attributes */
184
+ this.set(this.attributes);
185
+ },
186
+
187
+ get: function( attrName )
188
+ {
189
+ if(typeof attrName !== 'undefined')
190
+ {
191
+ return this.stage[attrName];
192
+ }
193
+ else
194
+ {
195
+ return this.getModelData();
196
+ }
197
+ }
198
+ };
199
+
200
+ /* this will get the model attributes.
201
+ @param (object) settings = the model settings
202
+ @return (object) the attributes */
203
+ var setupAttrSettings = function(settings)
204
+ {
205
+ var attributes = {};
206
+ if(settings && typeof settings === 'object')
207
+ {
208
+ for(var prop in settings)
209
+ {
210
+ if(settings.hasOwnProperty(prop))
211
+ {
212
+ var setting = settings[prop];
213
+ if(typeof setting !== 'function')
214
+ {
215
+ attributes[prop] = setting;
216
+ delete settings[prop];
217
+ }
218
+ }
219
+ }
220
+ }
221
+ return attributes;
222
+ };
223
+
224
+ /* this will get the model attributes.
225
+ @param (object) settings = the model settings
226
+ @return (object) the attributes */
227
+ var setupDefaultAttr = function(settings)
228
+ {
229
+ var attributes = {};
230
+ if(settings && typeof settings === 'object')
231
+ {
232
+ var defaults = settings.defaults;
233
+ if(defaults)
234
+ {
235
+ for(var prop in defaults)
236
+ {
237
+ if(defaults.hasOwnProperty(prop))
238
+ {
239
+ var attr = defaults[prop];
240
+ if(typeof attr !== 'function')
241
+ {
242
+ attributes[prop] = attr;
243
+ }
244
+ }
245
+ }
246
+ delete settings.defaults;
247
+ }
248
+ }
249
+ return attributes;
250
+ };
251
+
252
+ /* this will get the model attributes.
253
+ @param (object) settings = the model settings
254
+ @return (object) the attributes */
255
+ var getXhr = function(settings)
256
+ {
257
+ if(settings && typeof settings === 'object')
258
+ {
259
+ if(settings.xhr)
260
+ {
261
+ var xhr = base.createObject(settings.xhr);
262
+ delete settings.xhr;
263
+ return xhr;
264
+ }
265
+ }
266
+ return {};
267
+ };
268
+
269
+ /* this will track the number of model types */
270
+ var modelTypeNumber = 0;
271
+
272
+ /* this will extend the model.
273
+ @param (object) settings = the new model properties
274
+ and methods
275
+ @param (object) the new model */
276
+ Model.extend = function(settings)
277
+ {
278
+ var parent = this;
279
+
280
+ var xhr = getXhr(settings);
281
+ var modelService = this.prototype.xhr.extend(xhr);
282
+
283
+ /* this will setup the default attribute settings for
284
+ the model */
285
+ settings = settings || {};
286
+ var defaultAttributes = setupDefaultAttr(settings);
287
+ var model = function(instanceSettings)
288
+ {
289
+ /* this will get the instance attributes that
290
+ the model will set as attribute data */
291
+ var instanceAttr = setupAttrSettings(instanceSettings);
292
+
293
+ /* we want to extend the default attr with the
294
+ instance attr before we set the data and call
295
+ the parent constructor */
296
+ instanceAttr = base.extendObject(defaultAttributes, instanceAttr);
297
+ parent.call(this, instanceAttr);
298
+
299
+ this.xhr = new modelService(this);
300
+ };
301
+
302
+ /* this will extend the model and add the static
303
+ methods to the new object */
304
+ model.prototype = base.extendClass(this.prototype, settings);
305
+ model.prototype.constructor = model;
306
+ model.prototype.xhr = modelService;
307
+
308
+ /* this will assign a unique id to the model type */
309
+ model.prototype.modelTypeId = 'bm' + (modelTypeNumber++);
310
+
311
+ /* this will extend the static methods */
312
+ base.extendObject(parent, model);
313
+ return model;
314
+ };
315
+
316
+ base.extend.Model = Model;
317
+
318
+ /*
319
+ ModelService
320
+
321
+ this is a service that can connect a model to
322
+ a web service api.
323
+
324
+ @param (object) model
325
+ */
326
+ var ModelService = function(model)
327
+ {
328
+ this.model = model;
329
+ this.url = '';
330
+
331
+ this.init();
332
+ };
333
+
334
+ ModelService.prototype =
335
+ {
336
+ constrcutor: ModelService,
337
+
338
+ init: function()
339
+ {
340
+ var model = this.model;
341
+ if(model && model.url)
342
+ {
343
+ this.url = model.url;
344
+ }
345
+ },
346
+
347
+ validateCallBack: null,
348
+
349
+ isValid: function()
350
+ {
351
+ var result = this.validate();
352
+ if(result === false)
353
+ {
354
+ var callBack = this.validateCallBack;
355
+ if(typeof callBack === 'function')
356
+ {
357
+ callBack(result);
358
+ }
359
+ }
360
+ return result;
361
+ },
362
+
363
+ /* this is a method to use to override to set
364
+ a default validate methode to check the model
365
+ before sending data.
366
+ @return (bool) true or false to submit */
367
+ validate: function()
368
+ {
369
+ return true;
370
+ },
371
+
372
+ /* this is a method to use to override to set
373
+ a default param string to be appended to each
374
+ xhr request
375
+ @return (string) params */
376
+ getDefaultParams: function()
377
+ {
378
+ return '';
379
+ },
380
+
381
+ /* this will add the individual params with the default
382
+ params.
383
+ @param (string) params
384
+ @return (string) the appended params */
385
+ setupParams: function(params)
386
+ {
387
+ var defaults = this.getDefaultParams();
388
+ params += (defaults[0] !== '&')? '&' + defaults : defaults;
389
+ return params;
390
+ },
391
+
392
+ /* this is a property to override the return type
393
+ used in the the request and response xhr calls. this
394
+ will define what the web service defines as the object type. */
395
+ objectType: 'item',
396
+
397
+ xhr: null,
398
+
399
+ /* this will clear the previous xhr is still set. */
400
+ clearXhr: function()
401
+ {
402
+ var xhr = this.xhr;
403
+ if(this.xhr !== null)
404
+ {
405
+ this.xhr.abort();
406
+ this.xhr = null;
407
+ }
408
+ },
409
+
410
+ /* this will get a model object from the service.
411
+ @param (function) callBack = the callBack to handle
412
+ the service xhr response */
413
+ get: function(callBack)
414
+ {
415
+ this.clearXhr();
416
+
417
+ var id = this.model.get('id');
418
+ var params = 'op=get' +
419
+ '&id=' + id;
420
+
421
+ var model = this.model,
422
+ self = this;
423
+ this.request(params, callBack, function(response)
424
+ {
425
+ if(response)
426
+ {
427
+ /* this will update the model with the get request
428
+ response */
429
+ var object = self.getObject(response);
430
+ if(object)
431
+ {
432
+ model.set(object);
433
+ }
434
+ }
435
+ });
436
+ },
437
+
438
+ getObject: function(response)
439
+ {
440
+ /* this will update the model with the get request
441
+ response */
442
+ var object = response[this.objectType] || response;
443
+ return (object)? object : false;
444
+ },
445
+
446
+ /* this will add or update a model object to the service.
447
+ @param (function) callBack = the callBack to handle
448
+ the service xhr response */
449
+ setup: function(callBack)
450
+ {
451
+ this.clearXhr();
452
+
453
+ if(this.isValid())
454
+ {
455
+ var item = this.model.get();
456
+ var params = 'op=setup' +
457
+ '&' + this.objectType + '=' + base.prepareJsonUrl(item);
458
+
459
+ this.request(params, callBack);
460
+ }
461
+ },
462
+
463
+ /* this will add a model object from the service.
464
+ @param (function) callBack = the callBack to handle
465
+ the service xhr response */
466
+ add: function(callBack)
467
+ {
468
+ this.clearXhr();
469
+
470
+ if(this.isValid())
471
+ {
472
+ var item = this.model.get();
473
+ var params = 'op=add' +
474
+ '&' + this.objectType + '=' + base.prepareJsonUrl(item);
475
+
476
+ this.request(params, callBack);
477
+ }
478
+ },
479
+
480
+ /* this will update a model object from the service.
481
+ @param (function) callBack = the callBack to handle
482
+ the service xhr response */
483
+ update: function(callBack)
484
+ {
485
+ this.clearXhr();
486
+
487
+ if(this.isValid())
488
+ {
489
+ var item = this.model.get();
490
+ var params = 'op=update' +
491
+ '&' + this.objectType + '=' + base.prepareJsonUrl(item);
492
+
493
+ this.request(params, callBack);
494
+ }
495
+ },
496
+
497
+ /* this will delete a model object from the service.
498
+ @param (function) callBack = the callBack to handle
499
+ the service xhr response */
500
+ delete: function(callBack)
501
+ {
502
+ this.clearXhr();
503
+
504
+ var id = this.model.get('id');
505
+ var params = 'op=delete' +
506
+ '&id=' + id;
507
+
508
+ this.request(params, callBack);
509
+ },
510
+
511
+ /* this will get a list of model object from the service.
512
+ @param (function) callBack = the callBack to handle
513
+ the service xhr response
514
+ @param (int) start = the row start count
515
+ @param (int) count = the row numbers to get
516
+ @param [(string)] filter = the filter */
517
+ all: function(callBack, start, count, filter)
518
+ {
519
+ this.clearXhr();
520
+
521
+ var params = 'op=all' +
522
+ '&option=' + filter +
523
+ '&start=' + start +
524
+ '&stop=' + count;
525
+
526
+ this.request(params, callBack);
527
+ },
528
+
529
+ /* this will make the xhr request to the
530
+ service.
531
+ @param (string) params
532
+ @param (function) callBack
533
+ @param [(function)] requestCallBack = the call back for the
534
+ service method */
535
+ request: function(params, callBack, requestCallBack)
536
+ {
537
+ params = this.setupParams(params);
538
+
539
+ var self = this;
540
+ this.xhr = base.ajax({
541
+ url: this.url,
542
+ params: params,
543
+ completed: function(response, xhr)
544
+ {
545
+ if(typeof requestCallBack === 'function')
546
+ {
547
+ requestCallBack(response);
548
+ }
549
+
550
+ self.getResponse(response, callBack);
551
+ }
552
+ });
553
+ },
554
+
555
+ /* this will handle the xhr response.
556
+ @param (mixed) response = the xhr response
557
+ @param (function) callBack */
558
+ getResponse: function(response, callBack)
559
+ {
560
+ /* clear the xhr object */
561
+ var xhr = this.xhr;
562
+ if(xhr !== null)
563
+ {
564
+ xhr = null;
565
+ }
566
+
567
+ /* this will check to return the response
568
+ to the callBack function */
569
+ if(typeof callBack === 'function')
570
+ {
571
+ callBack(response);
572
+ }
573
+ }
574
+ };
575
+
576
+ /* this will setup the service object to extend itself.
577
+ @param (object) settings = the new service settings to
578
+ extend
579
+ @return (object) the new model service */
580
+ ModelService.extend = function(settings)
581
+ {
582
+ var parent = this;
583
+
584
+ /* this will setup a new model service constructor */
585
+ var modelService = function(model)
586
+ {
587
+ /* this will call the parent contructor */
588
+ parent.call(this, model);
589
+ };
590
+
591
+ /* this will extend the model and add the static
592
+ methods to the new object */
593
+ modelService.prototype = base.extendClass(this.prototype, settings);
594
+ modelService.prototype.constructor = modelService;
595
+
596
+ base.extendObject(parent, modelService);
597
+
598
+ return modelService;
599
+ };
600
+
601
+ /* we need to add the service object to the
602
+ model prototype as the xhr service */
603
+ Model.prototype.xhr = ModelService;
604
+ })();