-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathGroup.js
More file actions
165 lines (135 loc) · 3.88 KB
/
Group.js
File metadata and controls
165 lines (135 loc) · 3.88 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
Copyright 2012 Rustici Software
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
TinCan client library
@module TinCan
@submodule TinCan.Group
**/
(function () {
"use strict";
/**
@class TinCan.Group
@constructor
*/
var Group = TinCan.Group = function (cfg) {
this.log("constructor");
/**
@property name
@type String
*/
this.name = null;
/**
@property mbox
@type String
*/
this.mbox = null;
/**
@property mbox_sha1sum
@type String
*/
this.mbox_sha1sum = null;
/**
@property openid
@type String
*/
this.openid = null;
/**
@property account
@type TinCan.AgentAccount
*/
this.account = null;
/**
@property member
@type Array
*/
this.member = [];
this.init(cfg);
};
Group.prototype = {
/**
@property objectType
@type String
@default "Group"
@static
*/
objectType: "Group",
/**
@property LOG_SRC
*/
LOG_SRC: "Group",
/**
@method log
*/
log: TinCan.prototype.log,
/**
@method init
@param {Object} [options] Configuration used to initialize
*/
init: function (cfg) {
this.log("init");
var i;
cfg = cfg || {};
TinCan.Agent.prototype.init.call(this, cfg);
if (typeof cfg.member !== "undefined") {
for (i = 0; i < cfg.member.length; i += 1) {
if (cfg.member[i] instanceof TinCan.Agent) {
this.member.push(cfg.member[i]);
}
else {
this.member.push(new TinCan.Agent (cfg.member[i]));
}
}
}
},
toString: function (lang) {
this.log("toString");
var result = TinCan.Agent.prototype.toString.call(this, lang);
if (result !== this.objectType + ": unidentified") {
result = this.objectType + ": " + result;
}
return result;
},
/**
@method asVersion
@param {String} [version] Version to return (defaults to newest supported)
*/
asVersion: function (version) {
this.log("asVersion: " + version);
var result,
i
;
version = version || TinCan.versions()[0];
result = TinCan.Agent.prototype.asVersion.call(this, version);
if (this.member.length > 0) {
result.member = [];
for (i = 0; i < this.member.length; i += 1) {
result.member.push(this.member[i].asVersion(version));
}
}
return result;
}
};
/**
@method fromJSON
@return {Object} Group
@static
*/
Group.fromJSON = function (groupJSON) {
Group.prototype.log("fromJSON");
var _group = JSON.parse(groupJSON);
if (_group.hasOwnProperty("objectType") && _group.objectType !== Group.prototype.objectType) {
throw "Unexpected object type for group: " + _group.objectType;
}
return new Group(_group);
};
}());