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