@base-framework/base 2.6.1 → 2.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/base.js +1 -0
- package/package.json +30 -26
- 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,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
|
-
})();
|