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