-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathns_com.js
137 lines (97 loc) · 3.58 KB
/
ns_com.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
(function (root, factory) {
// Set up Backbone appropriately for the environment. Start with AMD.
if (typeof define === 'function' && define.amd) {
console.log('amd');
define([
'jquery',
'underscore',
'backbone'
], function ($, _, Backbone, exports) {
// Export global even in AMD case in case this script is loaded with
// others that may still expect a global Backbone.
var Retour = factory(root, exports, $, _, Backbone);
console.log(Retour);
return Retour;
});
// Next for Node.js or CommonJS. jQuery may not be needed as a module.
} else if (typeof exports !== 'undefined') {
var $ = require('jquery');
var _ = require('underscore');
var Backbone = require('backbone');
module.exports = factory(root, exports, $, _, Backbone);
//return Retour ;
// Finally, as a browser global.
} else {
//TODO
//root.Backbone = factory(root, {}, root._, (root.jQuery || root.Zepto || root.ender || root.$));
}
}(this, function (root, NsCom, $, _, Backbone) {
/*
define([
'jquery',
'underscore',
'backbone'
], function($, _, Backbone ) {*/
'use strict';
// I am the internal, static counter for the number of Coms
// that have been created in the system. This is used to
// power the unique identifier of each instance.
var instanceCount = 0;
// I get the next instance ID.
var getNewInstanceID = function () {
// Precrement the instance count in order to generate the
// next value instance ID.
return (++instanceCount);
};
// -------------------------------------------------- //
// -------------------------------------------------- //
// I return an initialized object.
function Com() {
// Store the private instance id.
this._instanceID = getNewInstanceID();
this.components = [];
this.motherColl = new Backbone.Collection();
// Return this object reference.
return (this);
}
// I return the current instance count. I am a static method
// on the Com class.
Com.getInstanceCount = function () {
return (instanceCount);
};
// Define the class methods.
Com.prototype = {
// I return the instance ID for this instance.
getInstanceID: function () {
return (this._instanceID);
},
setMotherColl: function (coll) {
this.motherColl = coll;
},
getMotherColl: function () {
return this.motherColl;
},
updateMotherColl: function (ids) {
for (var i = ids.length - 1; i >= 0; i--) {
this.motherColl.where({ id: ids[i] }, function (m) {
m.attributes.import = true;
});
};
},
addModule: function (m) {
this.components.push(m);
},
action: function (action, ids) {
if (action === 'selection' || action === 'selection') {
this.updateMotherColl(ids);
}
for (var i = 0; i < this.components.length; i++) {
this.components[i].action(action, ids);
};
},
};
// -------------------------------------------------- //
// -------------------------------------------------- //
// TODO Destroy components
return (Com);
}));