@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,1290 +0,0 @@
1
- /* base framework module */
2
- (function()
3
- {
4
- "use strict";
5
-
6
- /**
7
- * This will get the data attribute settings.
8
- *
9
- * @param {object} settings
10
- * @return {object}
11
- */
12
- var setupAttrSettings = function(settings)
13
- {
14
- var attributes = {};
15
- if(!settings && typeof settings !== 'object')
16
- {
17
- return attributes;
18
- }
19
-
20
- settings = base.clone(settings);
21
-
22
- for(var prop in settings)
23
- {
24
- if(settings.hasOwnProperty(prop))
25
- {
26
- var setting = settings[prop];
27
- if(typeof setting !== 'function')
28
- {
29
- attributes[prop] = setting;
30
- delete settings[prop];
31
- }
32
- }
33
- }
34
- return attributes;
35
- };
36
-
37
- var DataUtils =
38
- {
39
- deepDataPattern: /(\w+)|(?:\[(\d)\))/g,
40
-
41
- /**
42
- * This will check if a string has deep data.
43
- *
44
- * @param {string} str
45
- * @return {bool}
46
- */
47
- hasDeepData: function(str)
48
- {
49
- return (str.indexOf('.') !== -1 || str.indexOf('[') !== -1);
50
- },
51
-
52
- /**
53
- * This will get the deep data segments
54
- * @param {string} str
55
- * @return {array}
56
- */
57
- getSegments: function(str)
58
- {
59
- var pattern = this.deepDataPattern;
60
- return str.match(pattern);
61
- }
62
- };
63
-
64
- var BasicData = base.Class.extend(
65
- {
66
- /**
67
- * @constructor
68
- * @param {object} [settings]
69
- */
70
- constructor: function(settings)
71
- {
72
- this.dirty = false;
73
-
74
- this._init();
75
- this.setup();
76
-
77
- /* this will setup the event sub for
78
- one way binding */
79
- this.eventSub = new base.DataPubSub();
80
-
81
- /* this will set the construct attributes */
82
- var attributes = setupAttrSettings(settings);
83
- this.set(attributes);
84
- },
85
-
86
- setup: function()
87
- {
88
- this.stage = {};
89
- },
90
-
91
- /**
92
- * @member {string} dataTypeId
93
- */
94
- dataTypeId: 'bd',
95
-
96
- /**
97
- * This will setup the number and unique id of the data object.
98
- * @protected
99
- */
100
- _init: function()
101
- {
102
- var constructor = this.constructor;
103
- this._dataNumber = (typeof constructor._dataNumber === 'undefined')? constructor._dataNumber = 0 : (++constructor._dataNumber);
104
-
105
- var dataId = this.dataTypeId + '-';
106
- this._id = dataId + this._dataNumber;
107
- this._dataId = this._id + ':';
108
- },
109
-
110
- /**
111
- * This will get the data id.
112
- * @return {string}
113
- */
114
- getDataId: function()
115
- {
116
- return this._id;
117
- },
118
-
119
- /**
120
- * This is a placeholder.
121
- */
122
- remove: function()
123
- {
124
-
125
- },
126
-
127
- /**
128
- * This will setup a one way bind.
129
- *
130
- * @param {string} attrName
131
- * @param {function} callBack
132
- * @return {string} The subscription token.
133
- */
134
- on: function(attrName, callBack)
135
- {
136
- var message = attrName + ':change';
137
- return this.eventSub.on(message, callBack);
138
- },
139
-
140
- /**
141
- * This will unbind from a one way bind.
142
- *
143
- * @param {string} attrName
144
- * @param {string} token
145
- */
146
- off: function(attrName, token)
147
- {
148
- var message = attrName + ':change';
149
- this.eventSub.off(message, token);
150
- },
151
-
152
- /**
153
- * This will set the attribute value.
154
- *
155
- * @protected
156
- * @param {string} attr
157
- * @param {*} val
158
- * @param {object} committer
159
- */
160
- _setAttr: function(attr, val, committer)
161
- {
162
- var prevValue = this.stage[attr];
163
- if(val === prevValue)
164
- {
165
- return false;
166
- }
167
-
168
- this.stage[attr] = val;
169
-
170
- committer = committer || this;
171
-
172
- /* this will publish the data to the data binder
173
- to update any ui elements that are subscribed */
174
- this._publish(attr, val, committer, prevValue);
175
- },
176
-
177
- /**
178
- * This will set the data value of an attribute or attributes.
179
- *
180
- * @param {string} key
181
- * @param {*} value
182
- *
183
- * or
184
- *
185
- * @param {object} data
186
- */
187
- set: function()
188
- {
189
- var args = arguments;
190
- if(typeof args[0] === 'object')
191
- {
192
- var items = args[0],
193
- committer = args[1],
194
- stopMerge = args[2];
195
-
196
- for(var attr in items)
197
- {
198
- if(items.hasOwnProperty(attr))
199
- {
200
- var item = items[attr];
201
- if(typeof item === 'function')
202
- {
203
- continue;
204
- }
205
- this._setAttr(attr, item, committer, stopMerge);
206
- }
207
- }
208
- }
209
- else
210
- {
211
- this._setAttr(args[0], args[1], args[2], args[3]);
212
- }
213
- },
214
-
215
- /**
216
- * This will get the model data.
217
- */
218
- getModelData: function()
219
- {
220
- return this.stage;
221
- },
222
-
223
- /**
224
- * This will delete an attribute.
225
- *
226
- * @param {object} obj
227
- * @param {string} attr
228
- * @return {*}
229
- */
230
- _deleteAttr: function(obj, attr)
231
- {
232
- delete obj[attr];
233
- },
234
-
235
- /**
236
- * This will delete a property value or the model data.
237
- *
238
- * @param {string} [attrName]
239
- * @return {*}
240
- */
241
- delete: function(attrName)
242
- {
243
- if(typeof attrName !== 'undefined')
244
- {
245
- this._deleteAttr(this.stage, attrName);
246
- return;
247
- }
248
-
249
- // this will clear the stage and attributes
250
- this.setup();
251
- },
252
-
253
- /**
254
- * This will get the value of an attribute.
255
- *
256
- * @param {object} obj
257
- * @param {string} attr
258
- * @return {*}
259
- */
260
- _getAttr: function(obj, attr)
261
- {
262
- return obj[attr];
263
- },
264
-
265
- /**
266
- * This will get a property value or the model data.
267
- *
268
- * @param {string} [attrName]
269
- * @return {*}
270
- */
271
- get: function(attrName)
272
- {
273
- if(typeof attrName !== 'undefined')
274
- {
275
- return this._getAttr(this.stage, attrName);
276
- }
277
- else
278
- {
279
- return this.getModelData();
280
- }
281
- }
282
- });
283
-
284
- var DataBinder = base.DataBinder;
285
-
286
-
287
- /**
288
- * Data
289
- *
290
- * This will create a new data object that can be used to
291
- * bind elements to values.
292
- * @class
293
- * @augments BasicData
294
- */
295
- var Data = BasicData.extend(
296
- {
297
- /**
298
- * This will setup the stage and attributes object.
299
- */
300
- setup: function()
301
- {
302
- this.attributes = {};
303
- this.stage = {};
304
- },
305
-
306
- /**
307
- * This will update an attribute value.
308
- *
309
- * @protected
310
- * @param {object} obj
311
- * @param {string} attr
312
- * @param {*} val
313
- */
314
- _updateAttr: function(obj, attr, val)
315
- {
316
- var utils = DataUtils;
317
- /* this will check if we need to update
318
- deep nested data */
319
- if(utils.hasDeepData(attr))
320
- {
321
- var prop,
322
- props = utils.getSegments(attr),
323
- length = props.length,
324
- end = length - 1;
325
-
326
- for (var i = 0; i < length; i++)
327
- {
328
- prop = props[i];
329
-
330
- /* this will add the value to the last prop */
331
- if(i === end)
332
- {
333
- obj[prop] = val;
334
- break;
335
- }
336
-
337
- if (obj[prop] === undefined)
338
- {
339
- /* this will check to setup a new object
340
- or an array if the prop is a number */
341
- obj[prop] = isNaN(prop)? {} : [];
342
- }
343
- obj = obj[prop];
344
- }
345
- }
346
- else
347
- {
348
- obj[attr] = val;
349
- }
350
- },
351
-
352
- /**
353
- * This will set the attribute value.
354
- *
355
- * @protected
356
- * @param {string} attr
357
- * @param {*} val
358
- * @param {object} committer
359
- * @param {boolean} stopMerge
360
- */
361
- _setAttr: function(attr, val, committer, stopMerge)
362
- {
363
- /* this will check to update the model based on who
364
- updated it. if the data binder updated the data only
365
- the stage data is updated */
366
- if(!committer && stopMerge !== true)
367
- {
368
- /* this will update the attribute data because
369
- it was updated outside the data binder */
370
- this._updateAttr(this.attributes, attr, val);
371
- }
372
- else
373
- {
374
- if(this.dirty === false)
375
- {
376
- this.dirty = true;
377
- }
378
- }
379
-
380
- this._updateAttr(this.stage, attr, val);
381
-
382
- /* this will publish the data to the data binder
383
- to update any ui elements that are subscribed */
384
- committer = committer || this;
385
- this._publish(attr, val, committer);
386
- },
387
-
388
- /**
389
- * This will publish an update to the data binder.
390
- *
391
- * @protected
392
- * @param {string} attr
393
- * @param {*} val
394
- * @param {*} committer
395
- */
396
- _publish: function(attr, val, committer)
397
- {
398
- this.publish(attr, val, committer);
399
- },
400
-
401
- /**
402
- * This will publish deep and simple data to the data binder.
403
- *
404
- * @protected
405
- * @param {string} attr
406
- * @param {*} val
407
- * @param {object} committer
408
- */
409
- publishDeep: function(attr, val, committer)
410
- {
411
- var utils = DataUtils;
412
- if(utils.hasDeepData(attr))
413
- {
414
- var prop,
415
- props = utils.getSegments(attr),
416
- length = props.length,
417
- end = length - 1;
418
-
419
- /* the path is a string equivalent of the javascript dot notation path
420
- of the object being published. */
421
- var path = '',
422
- obj = this.stage;
423
- for (var i = 0; i < length; i++)
424
- {
425
- var prop = props[i];
426
-
427
- /* we need to setup the object to go to the next level
428
- of the data object before calling the next property. */
429
- obj = obj[prop];
430
-
431
- if (i > 0)
432
- {
433
- /* this will add the property to the path based on if its an
434
- object property or an array. */
435
- if(isNaN(prop))
436
- {
437
- path += '.' + prop;
438
- }
439
- }
440
- else
441
- {
442
- path = prop;
443
- }
444
-
445
- var publish;
446
- if(i === end)
447
- {
448
- /* if the loop is on the last pass it only needs to publish
449
- the val. */
450
- publish = val;
451
- }
452
- else
453
- {
454
- /* we only want to publish the modified branches. we need to
455
- get the next property in the props array and create a publish
456
- object or array with the next property value. */
457
- var nextProp = props[i + 1];
458
- if(isNaN(nextProp) === false)
459
- {
460
- path += '[' + nextProp + ']';
461
- continue;
462
- }
463
-
464
- var nextAttr = {};
465
- nextAttr[nextProp] = obj[nextProp];
466
- publish = nextAttr;
467
- }
468
-
469
- this.publish(path, publish, committer);
470
- }
471
- }
472
- else
473
- {
474
- this.publish(attr, val, committer);
475
- }
476
- },
477
-
478
- /**
479
- * This will publish an update to the data binder.
480
- *
481
- * @protected
482
- * @param {string} pathString
483
- * @param {*} obj
484
- * @param {*} committer
485
- */
486
- publish: function(pathString, obj, committer)
487
- {
488
- pathString = pathString || "";
489
- this._publishAttr(pathString, obj, committer);
490
-
491
- if(obj && typeof obj === 'object')
492
- {
493
- var subPath, value;
494
- if(obj.constructor === Array)
495
- {
496
- var length = obj.length;
497
- for(var i = 0; i < length; i++)
498
- {
499
- value = obj[i];
500
- subPath = pathString + '[' + i + ']';
501
- this._checkPublish(subPath, value, committer);
502
- }
503
- }
504
- else
505
- {
506
- for(var prop in obj)
507
- {
508
- if(obj.hasOwnProperty(prop))
509
- {
510
- value = obj[prop];
511
- subPath = pathString + '.' + prop;
512
- this._checkPublish(subPath, value, committer);
513
- }
514
- }
515
- }
516
- }
517
- },
518
-
519
- _checkPublish: function(subPath, val, committer)
520
- {
521
- if(!val || typeof val !== 'object')
522
- {
523
- this._publishAttr(subPath, val, committer);
524
- }
525
- else
526
- {
527
- this.publish(subPath, val, committer);
528
- }
529
- },
530
-
531
- /**
532
- * This will publish an update on an attribute.
533
- *
534
- * @protected
535
- * @param {string} subPath
536
- * @param {*} val
537
- * @param {object} committer
538
- */
539
- _publishAttr: function(subPath, val, committer)
540
- {
541
- /* save path and value */
542
- DataBinder.publish(this._dataId + subPath, val, committer);
543
-
544
- var message = subPath + ':change';
545
- this.eventSub.publish(message, val, committer);
546
- },
547
-
548
- /**
549
- * This will merge the attribute with the stage.
550
- * @protected
551
- */
552
- mergeStage: function()
553
- {
554
- /* this will clone the stage object to the
555
- attribute object */
556
- this.attributes = base.clone(this.stage);
557
- this.dirty = false;
558
- },
559
-
560
- /**
561
- * This will get the model data.
562
- */
563
- getModelData: function()
564
- {
565
- this.mergeStage();
566
- return this.attributes;
567
- },
568
-
569
- /**
570
- * This will revert the stage back to the previous attributes.
571
- */
572
- revert: function()
573
- {
574
- /* this will reset the stage to the previous
575
- attributes */
576
- this.set(this.attributes);
577
- this.dirty = false;
578
- },
579
-
580
- /**
581
- * This will delete an attribute.
582
- *
583
- * @param {object} obj
584
- * @param {string} attr
585
- * @return {*}
586
- */
587
- _deleteAttr: function(obj, attr)
588
- {
589
- var utils = DataUtils;
590
- if(utils.hasDeepData(attr))
591
- {
592
- var props = utils.getSegments(attr),
593
- length = props.length,
594
- end = length - 1;
595
-
596
- for (var i = 0; i < length; i++)
597
- {
598
- var prop = props[i];
599
- var propValue = obj[prop];
600
- if (propValue !== undefined)
601
- {
602
- if(i === end)
603
- {
604
- if(obj.constructor === Array)
605
- {
606
- obj.splice(prop, 1);
607
- break;
608
- }
609
-
610
- delete obj[prop];
611
- break;
612
- }
613
- obj = propValue;
614
- }
615
- else
616
- {
617
- break;
618
- }
619
- }
620
- }
621
- else
622
- {
623
- delete obj[attr];
624
- }
625
- },
626
-
627
- /**
628
- * This will get the value of an attribute.
629
- *
630
- * @param {object} obj
631
- * @param {string} attr
632
- * @return {*}
633
- */
634
- _getAttr: function(obj, attr)
635
- {
636
- var utils = DataUtils;
637
- if(utils.hasDeepData(attr))
638
- {
639
- var props = utils.getSegments(attr),
640
- length = props.length,
641
- end = length - 1;
642
-
643
- for (var i = 0; i < length; i++)
644
- {
645
- var prop = props[i];
646
- var propValue = obj[prop];
647
- if (propValue !== undefined)
648
- {
649
- obj = propValue;
650
-
651
- if(i === end)
652
- {
653
- return obj;
654
- }
655
- }
656
- else
657
- {
658
- break;
659
- }
660
- }
661
-
662
- return undefined;
663
- }
664
- else
665
- {
666
- return obj[attr];
667
- }
668
- }
669
- });
670
-
671
- /**
672
- * SimpleData
673
- *
674
- * This will extend Data to add a simple data object
675
- * that doesn't allow deep nested data.
676
- * @class
677
- * @augments BasicData
678
- */
679
- var SimpleData = BasicData.extend(
680
- {
681
- /**
682
- * This will publish an update to the data binder.
683
- *
684
- * @override
685
- * @protected
686
- * @param {string} attr
687
- * @param {*} val
688
- * @param {*} committer
689
- * @param {*} prevValue
690
- */
691
- _publish: function(attr, val, committer, prevValue)
692
- {
693
- var message = attr + ':change';
694
- this.eventSub.publish(message, val, prevValue, committer);
695
-
696
- committer = committer || this;
697
-
698
- DataBinder.publish(this._dataId + attr, val, committer);
699
- }
700
- });
701
-
702
- base.extend.Data = Data;
703
- base.extend.SimpleData = SimpleData;
704
-
705
- /**
706
- * Model
707
- *
708
- * This will extend Data to add a model that can specify
709
- * a service that connects to a remote source.
710
- */
711
- var Model = Data.extend(
712
- {
713
- /**
714
- * @constructor
715
- * @param {object} [settings]
716
- */
717
- constructor: function(settings)
718
- {
719
- Data.call(this, settings);
720
-
721
- this.initialize();
722
-
723
- /**
724
- * @member {object} xhr The model service.
725
- */
726
- this.xhr = null;
727
- },
728
-
729
- /**
730
- * This adds a method to call if you want the model
731
- * to do something when its initialized.
732
- */
733
- initialize: function()
734
- {
735
-
736
- }
737
- });
738
-
739
- /**
740
- * This will get the defaults from the settings.
741
- *
742
- * @param {object} settings
743
- * @return {object}
744
- */
745
- var setupDefaultAttr = function(settings)
746
- {
747
- var attributes = {};
748
- if(!settings || typeof settings !== 'object')
749
- {
750
- return attributes;
751
- }
752
-
753
- var defaults = settings.defaults;
754
- if(!defaults)
755
- {
756
- return attributes;
757
- }
758
-
759
- for(var prop in defaults)
760
- {
761
- if(defaults.hasOwnProperty(prop))
762
- {
763
- var attr = defaults[prop];
764
- if(typeof attr !== 'function')
765
- {
766
- attributes[prop] = attr;
767
- }
768
- }
769
- }
770
- delete settings.defaults;
771
- return attributes;
772
- };
773
-
774
- /**
775
- * This will get the xhr settings.
776
- *
777
- * @param {object} settings
778
- * @return {object}
779
- */
780
- var getXhr = function(settings)
781
- {
782
- if(!settings || typeof settings.xhr !== 'object')
783
- {
784
- return {};
785
- }
786
-
787
- var settingsXhr = settings.xhr,
788
- xhr = base.createObject(settingsXhr);
789
- delete settings.xhr;
790
- return xhr;
791
- };
792
-
793
- /* this will track the number of model types */
794
- var modelTypeNumber = 0;
795
-
796
- /**
797
- * This will extend the model to a child model.
798
- *
799
- * @static
800
- * @param {object} settings
801
- * @return {object} The new model.
802
- */
803
- Model.extend = function(settings)
804
- {
805
- var parent = this,
806
- xhr = getXhr(settings),
807
- modelService = this.prototype.xhr.extend(xhr);
808
-
809
- settings = settings || {};
810
-
811
- /* this will setup the default attribute settings for
812
- the model */
813
- var defaultAttributes = setupDefaultAttr(settings),
814
- model = function(instanceSettings)
815
- {
816
- /* this will get the instance attributes that
817
- the model will set as attribute data */
818
- var instanceAttr = setupAttrSettings(instanceSettings);
819
-
820
- /* we want to extend the default attr with the
821
- instance attr before we set the data and call
822
- the parent constructor */
823
- instanceAttr = base.extendObject(defaultAttributes, instanceAttr);
824
- parent.call(this, instanceAttr);
825
-
826
- /* this will setup the model service and
827
- pass the new model instance to the service */
828
- this.xhr = new modelService(this);
829
- };
830
-
831
- /* this will extend the model and add the static
832
- methods to the new object */
833
- var extended = model.prototype = base.extendClass(this.prototype, settings);
834
- extended.constructor = model;
835
- extended.xhr = modelService;
836
-
837
- /* this will assign a unique id to the model type */
838
- extended.dataTypeId = 'bm' + (modelTypeNumber++);
839
-
840
- /* this will extend the static methods */
841
- base.extendObject(parent, model);
842
- return model;
843
- };
844
-
845
- base.extend.Model = Model;
846
-
847
- /**
848
- * ModelService
849
- *
850
- * This will create a new model service.
851
- * @class
852
- */
853
- var ModelService = base.Class.extend(
854
- {
855
- /**
856
- * @constructor
857
- * @param {object} model
858
- */
859
- constructor: function(model)
860
- {
861
- /**
862
- * @member {object} model
863
- */
864
- this.model = model;
865
-
866
- this.url = '';
867
- this.init();
868
- },
869
-
870
- init: function()
871
- {
872
- var model = this.model;
873
- if(model && model.url)
874
- {
875
- this.url = model.url;
876
- }
877
- },
878
-
879
- validateCallBack: null,
880
-
881
- /**
882
- * This will check if the model is valid.
883
- *
884
- * @return {boolean}
885
- */
886
- isValid: function()
887
- {
888
- var result = this.validate();
889
- if(result !== false)
890
- {
891
- var callBack = this.validateCallBack;
892
- if(typeof callBack === 'function')
893
- {
894
- callBack(result);
895
- }
896
- }
897
- return result;
898
- },
899
-
900
- /**
901
- * This should be overriden to validate the model
902
- * before submitting.
903
- *
904
- * @return {boolean}
905
- */
906
- validate: function()
907
- {
908
- return true;
909
- },
910
-
911
- /**
912
- * This can be overriden to add default params
913
- * with each request.
914
- *
915
- * @protected
916
- * @return {string}
917
- */
918
- getDefaultParams: function()
919
- {
920
- return '';
921
- },
922
-
923
- /**
924
- * This will setup the request params.
925
- *
926
- * @protected
927
- * @param {(string|object)} params
928
- * @return {(string|object)}
929
- */
930
- setupParams: function(params)
931
- {
932
- var defaults = this.getDefaultParams();
933
- params = this.addParams(params, defaults);
934
- return params;
935
- },
936
-
937
- /**
938
- * This will add the params.
939
- *
940
- * @protected
941
- * @param {*} params
942
- * @param {*} addingParams
943
- * @return {(string|object)}
944
- */
945
- addParams: function(params, addingParams)
946
- {
947
- params = params || {};
948
- if(typeof params === 'string')
949
- {
950
- params = base.parseQueryString(params);
951
- }
952
-
953
- if(!addingParams)
954
- {
955
- return (!this._isFormData(params))? this.objectToString(params) : params;
956
- }
957
-
958
- if(typeof addingParams === 'string')
959
- {
960
- addingParams = base.parseQueryString(addingParams);
961
- }
962
-
963
- if(this._isFormData(params))
964
- {
965
- for(var key in addingParams)
966
- {
967
- if(addingParams.hasOwnProperty(key))
968
- {
969
- params.append(key, addingParams[key]);
970
- }
971
- }
972
- }
973
- else
974
- {
975
- params = base.extendObject(params, addingParams);
976
- }
977
-
978
- return params;
979
- },
980
-
981
- /**
982
- * @member {string} objectType The return type.
983
- */
984
- objectType: 'item',
985
-
986
- /**
987
- * This will get the model by id.
988
- *
989
- * @param {string} [instanceParams]
990
- * @param {function} [callBack]
991
- * @return {object}
992
- */
993
- get: function(instanceParams, callBack)
994
- {
995
- var id = this.model.get('id'),
996
- params = 'op=get' +
997
- '&id=' + id;
998
-
999
- var model = this.model,
1000
- self = this;
1001
- return this.request(params, instanceParams, callBack, function(response)
1002
- {
1003
- if(response)
1004
- {
1005
- /* this will update the model with the get request
1006
- response */
1007
- var object = self.getObject(response);
1008
- if(object)
1009
- {
1010
- model.set(object);
1011
- }
1012
- }
1013
- });
1014
- },
1015
-
1016
- /**
1017
- * This will get the object from the response.
1018
- *
1019
- * @protected
1020
- * @param {object} response
1021
- * @return {object}
1022
- */
1023
- getObject: function(response)
1024
- {
1025
- /* this will update the model with the get request
1026
- response */
1027
- var object = response[this.objectType] || response;
1028
- return object || false;
1029
- },
1030
-
1031
- /**
1032
- * This will return a string with the model data json encoded.
1033
- *
1034
- * @protected
1035
- * @return {string}
1036
- */
1037
- setupObjectData: function()
1038
- {
1039
- var item = this.model.get();
1040
- return this.objectType + '=' + base.prepareJsonUrl(item);
1041
- },
1042
-
1043
- /**
1044
- * This will add or update the model.
1045
- *
1046
- * @param {string} [instanceParams]
1047
- * @param {function} [callBack]
1048
- * @return {object}
1049
- */
1050
- setup: function(instanceParams, callBack)
1051
- {
1052
- if(!this.isValid())
1053
- {
1054
- return false;
1055
- }
1056
-
1057
- var params = 'op=setup' +
1058
- '&' + this.setupObjectData();
1059
-
1060
- /* this will add the instance params with the
1061
- method params */
1062
- params = this.addParams(params, instanceParams, instanceParams);
1063
-
1064
- return this.request(params, callBack);
1065
- },
1066
-
1067
- /**
1068
- * This will add the model.
1069
- *
1070
- * @param {string} [instanceParams]
1071
- * @param {function} [callBack]
1072
- * @return {object}
1073
- */
1074
- add: function(instanceParams, callBack)
1075
- {
1076
- if(!this.isValid())
1077
- {
1078
- return false;
1079
- }
1080
-
1081
- var params = 'op=add' +
1082
- '&' + this.setupObjectData();
1083
-
1084
- return this.request(params, instanceParams, callBack);
1085
- },
1086
-
1087
- /**
1088
- * This will update the model.
1089
- *
1090
- * @param {string} [instanceParams]
1091
- * @param {function} [callBack]
1092
- * @return {object}
1093
- */
1094
- update: function(instanceParams, callBack)
1095
- {
1096
- if(!this.isValid())
1097
- {
1098
- return false;
1099
- }
1100
-
1101
- var params = 'op=update' +
1102
- '&' + this.setupObjectData();
1103
-
1104
- return this.request(params, instanceParams, callBack);
1105
- },
1106
-
1107
- /**
1108
- * This will delete the model.
1109
- *
1110
- * @param {string} [instanceParams]
1111
- * @param {function} [callBack]
1112
- * @return {object}
1113
- */
1114
- delete: function(instanceParams, callBack)
1115
- {
1116
- var id = this.model.get('id'),
1117
- params = 'op=delete' +
1118
- '&id=' + id;
1119
-
1120
- return this.request(params, instanceParams, callBack);
1121
- },
1122
-
1123
- /**
1124
- * This will list rows of the model.
1125
- *
1126
- * @param {string} [instanceParams]
1127
- * @param {function} [callBack]
1128
- * @param {int} start
1129
- * @param {int} count
1130
- * @param {string} filter
1131
- * @return {object}
1132
- */
1133
- all: function(instanceParams, callBack, start, count, filter)
1134
- {
1135
- filter = filter || '';
1136
- start = !isNaN(start)? start : 0;
1137
- count = !isNaN(count)? count : 50;
1138
-
1139
- var params = 'op=all' +
1140
- '&option=' + filter +
1141
- '&start=' + start +
1142
- '&stop=' + count;
1143
-
1144
- return this.request(params, instanceParams, callBack);
1145
- },
1146
-
1147
- /**
1148
- * This will make an ajax request.
1149
- *
1150
- * @param {string} method
1151
- * @param {(string|object)} params
1152
- * @param {function} callBack
1153
- * @param {function} [requestCallBack]
1154
- * @param {object}
1155
- */
1156
- setupRequest: function(method, params, callBack, requestCallBack)
1157
- {
1158
- var self = this,
1159
- settings = {
1160
- url: this.url,
1161
- type: method,
1162
- params: params,
1163
- completed: function(response, xhr)
1164
- {
1165
- if(typeof requestCallBack === 'function')
1166
- {
1167
- requestCallBack(response);
1168
- }
1169
-
1170
- self.getResponse(response, callBack, xhr);
1171
- }
1172
- };
1173
-
1174
- var overrideHeader = this._isFormData(params);
1175
- if(overrideHeader)
1176
- {
1177
- settings.headers = {};
1178
- }
1179
-
1180
- return base.ajax(settings);
1181
- },
1182
-
1183
- _isFormData: function(data)
1184
- {
1185
- return data instanceof FormData;
1186
- },
1187
-
1188
- /**
1189
- * This will make an ajax request.
1190
- *
1191
- * @param {(string|object)} params
1192
- * @param {string} instanceParams
1193
- * @param {function} callBack
1194
- * @param {function} [requestCallBack]
1195
- * @param {object}
1196
- */
1197
- request: function(params, instanceParams, callBack, requestCallBack)
1198
- {
1199
- return this._request('POST', params, instanceParams, callBack, requestCallBack);
1200
- },
1201
-
1202
- /**
1203
- * This will make a GET request.
1204
- *
1205
- * @param {(string|object)} params
1206
- * @param {string} instanceParams
1207
- * @param {function} callBack
1208
- * @param {function} [requestCallBack]
1209
- * @param {object}
1210
- */
1211
- _get: function(params, instanceParams, callBack, requestCallBack)
1212
- {
1213
- return this._request('GET', params, instanceParams, callBack, requestCallBack);
1214
- },
1215
-
1216
- /**
1217
- * This will make a POST request.
1218
- *
1219
- * @param {(string|object)} params
1220
- * @param {string} instanceParams
1221
- * @param {function} callBack
1222
- * @param {function} [requestCallBack]
1223
- * @param {object}
1224
- */
1225
- _post: function(params, instanceParams, callBack, requestCallBack)
1226
- {
1227
- return this._request('POST', params, instanceParams, callBack, requestCallBack);
1228
- },
1229
-
1230
- /**
1231
- * This will make a PUT request.
1232
- *
1233
- * @param {(string|object)} params
1234
- * @param {string} instanceParams
1235
- * @param {function} callBack
1236
- * @param {function} [requestCallBack]
1237
- * @param {object}
1238
- */
1239
- _put: function(params, instanceParams, callBack, requestCallBack)
1240
- {
1241
- return this._request('PUT', params, instanceParams, callBack, requestCallBack);
1242
- },
1243
-
1244
- /**
1245
- * This will make a DELETE request.
1246
- *
1247
- * @param {(string|object)} params
1248
- * @param {string} instanceParams
1249
- * @param {function} callBack
1250
- * @param {function} [requestCallBack]
1251
- * @param {object}
1252
- */
1253
- _delete: function(params, instanceParams, callBack, requestCallBack)
1254
- {
1255
- return this._request('DELETE', params, instanceParams, callBack, requestCallBack);
1256
- },
1257
-
1258
- /**
1259
- * This will make an ajax request.
1260
- *
1261
- * @param {string} method
1262
- * @param {(string|object)} params
1263
- * @param {string} instanceParams
1264
- * @param {function} callBack
1265
- * @param {function} [requestCallBack]
1266
- * @param {object}
1267
- */
1268
- _request: function(method, params, instanceParams, callBack, requestCallBack)
1269
- {
1270
- params = this.setupParams(params);
1271
- params = this.addParams(params, instanceParams);
1272
-
1273
- return this.setupRequest(method, params, callBack, requestCallBack);
1274
- },
1275
-
1276
- getResponse: function(response, callBack, xhr)
1277
- {
1278
- /* this will check to return the response
1279
- to the callBack function */
1280
- if(typeof callBack === 'function')
1281
- {
1282
- callBack(response, xhr);
1283
- }
1284
- }
1285
- });
1286
-
1287
- /* we need to add the service object to the
1288
- model prototype as the xhr service */
1289
- Model.prototype.xhr = ModelService;
1290
- })();