@base-framework/base 2.6.1 → 2.6.3

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 +30 -26
  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,585 +0,0 @@
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
- })();