@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,777 +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.dirty = false;
20
-
21
- /* this will setup the attributes object and the
22
- attribute stage object */
23
- this.attributes = {};
24
- this.stage = {};
25
-
26
- /* this will setup the event sub for
27
- one way binding */
28
- this.eventSub = new base.DataPubSub();
29
-
30
- /* this will set the construct attributes */
31
- var attributes = setupAttrSettings(settings);
32
- this.set(attributes);
33
-
34
- /* this will setup the data binding for two
35
- way binding */
36
- this.bind = true;
37
-
38
- this.initialize();
39
-
40
- this.xhr = null;
41
- };
42
-
43
- Model.prototype =
44
- {
45
- constructor: Model,
46
-
47
- /* this will setup the model number and unique
48
- instance id */
49
- _init: function()
50
- {
51
- var constructor = this.constructor;
52
- this._modelNumber = (typeof constructor._modelNumber === 'undefined')? constructor._modelNumber = 0 : (++constructor._modelNumber);
53
-
54
- var modelId = this.modelTypeId + '-';
55
- this._id = modelId + this._modelNumber;
56
- },
57
-
58
- /* this will get the unique model id
59
- @return (string) the id */
60
- getModelId: function()
61
- {
62
- return this._id;
63
- },
64
-
65
- remove: function()
66
- {
67
-
68
- },
69
-
70
- initialize: function()
71
- {
72
-
73
- },
74
-
75
- on: function(attrName, callBack)
76
- {
77
- var message = attrName + ':change';
78
- this.eventSub.on(message, callBack);
79
- },
80
-
81
- off: function(attrName, callBack)
82
- {
83
- var message = attrName + ':change';
84
- this.eventSub.off(message, callBack);
85
- },
86
-
87
- set: function()
88
- {
89
- var self = this;
90
- var set = function(attr, val, committer, stopMerge)
91
- {
92
- var setValue = function(obj, attr, val)
93
- {
94
- var test = /(\.|\[)/;
95
- if(test.test(attr))
96
- {
97
- var pattern = /(\w+)|(?:\[(\d)\))/g;
98
- var props = attr.match(pattern);
99
- for (var i = 0, length = props.length - 1; i < length; i++)
100
- {
101
- var prop = props[i];
102
- var propValue = obj[prop];
103
- if (propValue === undefined)
104
- {
105
- /* this will check to setup a new object
106
- or an array if the prop is a number */
107
- obj[prop] = !isNaN(prop)? {} : [];
108
- }
109
-
110
- obj = propValue;
111
- }
112
-
113
- obj[props[i]] = val;
114
- }
115
- else
116
- {
117
- obj[attr] = val;
118
- }
119
- };
120
-
121
- if(self.bind === true)
122
- {
123
- var binder = base.DataBinder,
124
- msg = self._id + ':change';
125
-
126
- /* this will recursivley update the data binder to
127
- publish updates on values. this will convert the value
128
- to a string path to where the object is stored to allow
129
- deep nested data to update on the bound elements.
130
- @param (mixed) obj
131
- @param (string) pathString */
132
- var publish = function(obj, pathString)
133
- {
134
- pathString = pathString || "";
135
- if(obj && typeof obj === 'object')
136
- {
137
- var subPath, value;
138
- if(Array.isArray(obj))
139
- {
140
- var length = obj.length;
141
- for(var i = 0; i < length; i++)
142
- {
143
- value = obj[i];
144
- subPath = pathString + '[' + i + ']';
145
- if(value && typeof value === 'object')
146
- {
147
- publish(value, subPath);
148
- }
149
- else
150
- {
151
- /* save path and value */
152
- binder.publish(msg, subPath, value, self);
153
- }
154
- }
155
- }
156
- else
157
- {
158
- for(var prop in obj)
159
- {
160
- if(obj.hasOwnProperty(prop))
161
- {
162
- value = obj[prop];
163
- subPath = pathString + '.' + prop;
164
- if(value && typeof value === 'object')
165
- {
166
- publish(value, subPath);
167
- }
168
- else
169
- {
170
- /* save path and value */
171
- binder.publish(msg, subPath, value, self);
172
- }
173
- }
174
- }
175
- }
176
- }
177
- else
178
- {
179
- /* save path and value */
180
- binder.publish(msg, pathString, obj, self);
181
- }
182
- return pathString;
183
- };
184
-
185
- /* this will check to update the model based on who
186
- updated it. if the data binder updated the data only
187
- the stage data is updated */
188
- if(!committer)
189
- {
190
- /* this will publish the data to the data binder
191
- to update any ui elements that are subscribed */
192
- publish(val, attr);
193
-
194
- /* this will update both stage and attribute
195
- data because it wasupdated outside the data
196
- binder */
197
- if(stopMerge !== true)
198
- {
199
- setValue(self.attributes, attr, val);
200
- }
201
- setValue(self.stage, attr, val);
202
- }
203
- else
204
- {
205
- setValue(self.stage, attr, val);
206
-
207
- if(self.dirty === false)
208
- {
209
- self.dirty = true;
210
- }
211
- }
212
- }
213
- else
214
- {
215
- if(stopMerge !== true)
216
- {
217
- setValue(self.attributes, attr, val);
218
- }
219
- setValue(self.stage, attr, val);
220
- }
221
-
222
- /* this will check to update any local events
223
- on the model */
224
- var message = attr + ':change';
225
- self.eventSub.publish(message, attr, val);
226
- };
227
-
228
- var setupObject = function(object, committer, stopMerge)
229
- {
230
- var items = object;
231
- for(var attr in items)
232
- {
233
- if(items.hasOwnProperty(attr))
234
- {
235
- var item = items[attr];
236
- if(typeof item === 'function')
237
- {
238
- continue;
239
- }
240
- set(attr, item, committer, stopMerge);
241
- }
242
- }
243
- };
244
-
245
- var args = arguments;
246
- if(typeof args[0] === 'object')
247
- {
248
- setupObject(args[0], args[1], args[2]);
249
- }
250
- else
251
- {
252
- set(args[0], args[1], args[2], args[3]);
253
- }
254
- },
255
-
256
- mergeStage: function()
257
- {
258
- /* this will clone the stage object to the
259
- attribute object */
260
- this.attributes = JSON.parse(JSON.stringify(this.stage));
261
- this.dirty = false;
262
- },
263
-
264
- getModelData: function()
265
- {
266
- this.mergeStage();
267
- return this.attributes;
268
- },
269
-
270
- revert: function()
271
- {
272
- /* this will reset the stage to the previous
273
- attributes */
274
- this.set(this.attributes);
275
- this.dirty = false;
276
- },
277
-
278
- get: function( attrName )
279
- {
280
- if(typeof attrName !== 'undefined')
281
- {
282
- var get = function(obj, attr)
283
- {
284
- var test = /(\.|\[)/;
285
- if(test.test(attr))
286
- {
287
- var pattern = /(\w+)|(?:\[(\d)\))/g;
288
- var props = attr.match(pattern);
289
- for (var i = 0, length = props.length - 1; i < length; i++)
290
- {
291
- var prop = props[i];
292
- var propValue = obj[prop];
293
- if (propValue !== undefined)
294
- {
295
- obj = propValue;
296
- }
297
- else
298
- {
299
- break;
300
- }
301
- }
302
-
303
- return obj[props[i]];
304
- }
305
- else
306
- {
307
- return obj[attr];
308
- }
309
- };
310
- return get(this.stage, attrName);
311
- }
312
- else
313
- {
314
- return this.getModelData();
315
- }
316
- }
317
- };
318
-
319
- /* this will get the model attributes.
320
- @param (object) settings = the model settings
321
- @return (object) the attributes */
322
- var setupAttrSettings = function(settings)
323
- {
324
- var attributes = {};
325
- if(settings && typeof settings === 'object')
326
- {
327
- for(var prop in settings)
328
- {
329
- if(settings.hasOwnProperty(prop))
330
- {
331
- var setting = settings[prop];
332
- if(typeof setting !== 'function')
333
- {
334
- attributes[prop] = setting;
335
- delete settings[prop];
336
- }
337
- }
338
- }
339
- }
340
- return attributes;
341
- };
342
-
343
- /* this will get the model attributes.
344
- @param (object) settings = the model settings
345
- @return (object) the attributes */
346
- var setupDefaultAttr = function(settings)
347
- {
348
- var attributes = {};
349
- if(settings && typeof settings === 'object')
350
- {
351
- var defaults = settings.defaults;
352
- if(defaults)
353
- {
354
- for(var prop in defaults)
355
- {
356
- if(defaults.hasOwnProperty(prop))
357
- {
358
- var attr = defaults[prop];
359
- if(typeof attr !== 'function')
360
- {
361
- attributes[prop] = attr;
362
- }
363
- }
364
- }
365
- delete settings.defaults;
366
- }
367
- }
368
- return attributes;
369
- };
370
-
371
- /* this will get the model attributes.
372
- @param (object) settings = the model settings
373
- @return (object) the attributes */
374
- var getXhr = function(settings)
375
- {
376
- if(settings && typeof settings === 'object')
377
- {
378
- var settingsXhr = settings.xhr;
379
- if(settingsXhr && typeof settingsXhr === 'object')
380
- {
381
- var xhr = base.createObject(settingsXhr);
382
- delete settings.xhr;
383
- return xhr;
384
- }
385
- }
386
- return {};
387
- };
388
-
389
- /* this will track the number of model types */
390
- var modelTypeNumber = 0;
391
-
392
- /* this will extend the model.
393
- @param (object) settings = the new model properties
394
- and methods
395
- @param (object) the new model */
396
- Model.extend = function(settings)
397
- {
398
- var parent = this;
399
-
400
- var xhr = getXhr(settings);
401
- var modelService = this.prototype.xhr.extend(xhr);
402
-
403
- settings = settings || {};
404
-
405
- /* this will setup the default attribute settings for
406
- the model */
407
- var defaultAttributes = setupDefaultAttr(settings);
408
- var model = function(instanceSettings)
409
- {
410
- /* this will clone the original
411
- instance settings object */
412
- if(instanceSettings && typeof instanceSettings === 'object')
413
- {
414
- instanceSettings = JSON.parse(JSON.stringify(instanceSettings));
415
- }
416
-
417
- /* this will get the instance attributes that
418
- the model will set as attribute data */
419
- var instanceAttr = setupAttrSettings(instanceSettings);
420
-
421
- /* we want to extend the default attr with the
422
- instance attr before we set the data and call
423
- the parent constructor */
424
- instanceAttr = base.extendObject(defaultAttributes, instanceAttr);
425
- parent.call(this, instanceAttr);
426
-
427
- /* this will setup the model service and
428
- pass the new model instance to the service */
429
- this.xhr = new modelService(this);
430
- };
431
-
432
- /* this will extend the model and add the static
433
- methods to the new object */
434
- model.prototype = base.extendClass(this.prototype, settings);
435
- model.prototype.constructor = model;
436
- model.prototype.xhr = modelService;
437
-
438
- /* this will assign a unique id to the model type */
439
- model.prototype.modelTypeId = 'bm' + (modelTypeNumber++);
440
-
441
- /* this will extend the static methods */
442
- base.extendObject(parent, model);
443
- return model;
444
- };
445
-
446
- base.extend.Model = Model;
447
-
448
- /*
449
- ModelService
450
-
451
- this is a service that can connect a model to
452
- a web service api.
453
-
454
- @param (object) model
455
- */
456
- var ModelService = function(model)
457
- {
458
- this.model = model;
459
- this.url = '';
460
-
461
- this.init();
462
- };
463
-
464
- ModelService.prototype =
465
- {
466
- constrcutor: ModelService,
467
-
468
- init: function()
469
- {
470
- var model = this.model;
471
- if(model && model.url)
472
- {
473
- this.url = model.url;
474
- }
475
- },
476
-
477
- validateCallBack: null,
478
-
479
- isValid: function()
480
- {
481
- var result = this.validate();
482
- if(result === false)
483
- {
484
- var callBack = this.validateCallBack;
485
- if(typeof callBack === 'function')
486
- {
487
- callBack(result);
488
- }
489
- }
490
- return result;
491
- },
492
-
493
- /* this is a method to use to override to set
494
- a default validate methode to check the model
495
- before sending data.
496
- @return (bool) true or false to submit */
497
- validate: function()
498
- {
499
- return true;
500
- },
501
-
502
- /* this is a method to use to override to set
503
- a default param string to be appended to each
504
- xhr request
505
- @return (string) params */
506
- getDefaultParams: function()
507
- {
508
- return '';
509
- },
510
-
511
- /* this will add the individual params with the default
512
- params.
513
- @param (string) params
514
- @return (string) the appended params */
515
- setupParams: function(params)
516
- {
517
- var defaults = this.getDefaultParams();
518
- params = this.addParams(params, defaults);
519
- return params;
520
- },
521
-
522
- parseQueryString: function(str)
523
- {
524
- str = str || '';
525
- var objURL = {},
526
- regExp = /([^?=&]+)(=([^&]*))?/g;
527
-
528
- str.replace(regExp, function(a, b, c, d)
529
- {
530
- /* we want to save the key and the
531
- value to the objURL */
532
- objURL[b] = d;
533
- });
534
-
535
- /* we want to check if the url has any params */
536
- return objURL;
537
- },
538
-
539
- /* this will add params strings.
540
- @param (string) params
541
- @param (string) addingParams
542
- @return (string) the params combined */
543
- addParams: function(params, addingParams)
544
- {
545
- params = params || {};
546
- if(typeof params !== 'object')
547
- {
548
- params = this.parseQueryString(params);
549
- }
550
-
551
- addingParams = addingParams || {};
552
- if(typeof addingParams === 'string')
553
- {
554
- addingParams = this.parseQueryString(addingParams);
555
- }
556
-
557
- return base.extendObject(params, addingParams);
558
- },
559
-
560
- /* this is a property to override the return type
561
- used in the the request and response xhr calls. this
562
- will define what the web service defines as the object type. */
563
- objectType: 'item',
564
-
565
- /* this will get a model object from the service.
566
- @param [(string)] instanceParams = the params to add
567
- to the service instance
568
- @param [(function)] callBack = the callBack to handle
569
- the service xhr response
570
- @return (object) xhr object */
571
- get: function(instanceParams, callBack)
572
- {
573
- var id = this.model.get('id');
574
- var params = 'op=get' +
575
- '&id=' + id;
576
-
577
- var model = this.model,
578
- self = this;
579
- return this.request(params, instanceParams, callBack, function(response)
580
- {
581
- if(response)
582
- {
583
- /* this will update the model with the get request
584
- response */
585
- var object = self.getObject(response);
586
- if(object)
587
- {
588
- model.set(object);
589
- }
590
- }
591
- });
592
- },
593
-
594
- getObject: function(response)
595
- {
596
- /* this will update the model with the get request
597
- response */
598
- var object = response[this.objectType] || response;
599
- return (object)? object : false;
600
- },
601
-
602
- /* this will add or update a model object to the service.
603
- @param [(string)] instanceParams = the params to add
604
- to the service instance
605
- @param [(function)] callBack = the callBack to handle
606
- the service xhr response
607
- @return (object) xhr object or false on error */
608
- setup: function(instanceParams, callBack)
609
- {
610
- if(this.isValid())
611
- {
612
- var item = this.model.get();
613
- var params = 'op=setup' +
614
- '&' + this.objectType + '=' + base.prepareJsonUrl(item);
615
-
616
- /* this will add the instance params with the
617
- method params */
618
- params = this.addParams(params, instanceParams, instanceParams);
619
-
620
- return this.request(params, callBack);
621
- }
622
- return false;
623
- },
624
-
625
- /* this will add a model object from the service.
626
- @param [(string)] instanceParams = the params to add
627
- to the service instance
628
- @param [(function)] callBack = the callBack to handle
629
- the service xhr response
630
- @return (object) xhr object or false on error*/
631
- add: function(instanceParams, callBack)
632
- {
633
- if(this.isValid())
634
- {
635
- var item = this.model.get();
636
- var params = 'op=add' +
637
- '&' + this.objectType + '=' + base.prepareJsonUrl(item);
638
-
639
- return this.request(params, instanceParams, callBack);
640
- }
641
- return false;
642
- },
643
-
644
- /* this will update a model object from the service.
645
- @param [(string)] instanceParams = the params to add
646
- to the service instance
647
- @param [(function)] callBack = the callBack to handle
648
- the service xhr response
649
- @return (object) xhr object or false on error*/
650
- update: function(instanceParams, callBack)
651
- {
652
- if(this.isValid())
653
- {
654
- var item = this.model.get();
655
- var params = 'op=update' +
656
- '&' + this.objectType + '=' + base.prepareJsonUrl(item);
657
-
658
- return this.request(params, instanceParams, callBack);
659
- }
660
- return false;
661
- },
662
-
663
- /* this will delete a model object from the service.
664
- @param [(string)] instanceParams = the params to add
665
- to the service instance
666
- @param [(function)] callBack = the callBack to handle
667
- the service xhr response
668
- @return (object) xhr object */
669
- delete: function(instanceParams, callBack)
670
- {
671
- var id = this.model.get('id');
672
- var params = 'op=delete' +
673
- '&id=' + id;
674
-
675
- return this.request(params, instanceParams, callBack);
676
- },
677
-
678
- /* this will get a list of model object from the service.
679
- @param [(string)] instanceParams = the params to add
680
- to the service instance
681
- @param [(function)] callBack = the callBack to handle
682
- the service xhr response
683
- @param [(int)] start = the row start count
684
- @param [(int)] count = the row numbers to get
685
- @param [(string)] filter = the filter
686
- @return (object) xhr object */
687
- all: function(instanceParams, callBack, start, count, filter)
688
- {
689
- filter = filter || '';
690
- start = !isNaN(start)? start : 0;
691
- count = !isNaN(count)? count : 50;
692
-
693
- var params = 'op=all' +
694
- '&option=' + filter +
695
- '&start=' + start +
696
- '&stop=' + count;
697
-
698
- return this.request(params, instanceParams, callBack);
699
- },
700
-
701
- /* this will make the xhr request to the
702
- service.
703
- @param (string) params
704
- @param (string) instanceParams = the params to add
705
- to the service instance
706
- @param (function) callBack
707
- @param [(function)] requestCallBack = the call back for the
708
- service method
709
- @return (object) xhr object */
710
- request: function(params, instanceParams, callBack, requestCallBack)
711
- {
712
- params = this.setupParams(params);
713
-
714
- /* this will add the instance params with the
715
- method params */
716
- params = this.addParams(params, instanceParams);
717
-
718
- var self = this;
719
- return base.ajax({
720
- url: this.url,
721
- params: params,
722
- completed: function(response, xhr)
723
- {
724
- if(typeof requestCallBack === 'function')
725
- {
726
- requestCallBack(response);
727
- }
728
-
729
- self.getResponse(response, callBack, xhr);
730
- }
731
- });
732
- },
733
-
734
- /* this will handle the xhr response.
735
- @param (mixed) response = the xhr response
736
- @param (function) callBack
737
- @param (object) the xhr object */
738
- getResponse: function(response, callBack, xhr)
739
- {
740
- /* this will check to return the response
741
- to the callBack function */
742
- if(typeof callBack === 'function')
743
- {
744
- callBack(response, xhr);
745
- }
746
- }
747
- };
748
-
749
- /* this will setup the service object to extend itself.
750
- @param (object) settings = the new service settings to
751
- extend
752
- @return (object) the new model service */
753
- ModelService.extend = function(settings)
754
- {
755
- var parent = this;
756
-
757
- /* this will setup a new model service constructor */
758
- var modelService = function(model)
759
- {
760
- /* this will call the parent contructor */
761
- parent.call(this, model);
762
- };
763
-
764
- /* this will extend the model and add the static
765
- methods to the new object */
766
- modelService.prototype = base.extendClass(this.prototype, settings);
767
- modelService.prototype.constructor = modelService;
768
-
769
- base.extendObject(parent, modelService);
770
-
771
- return modelService;
772
- };
773
-
774
- /* we need to add the service object to the
775
- model prototype as the xhr service */
776
- Model.prototype.xhr = ModelService;
777
- })();