-
Notifications
You must be signed in to change notification settings - Fork 0
/
Result.js
78 lines (67 loc) · 2.15 KB
/
Result.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
define([
'mystique/messages!'
],
function(messages){
// module:
// mystique/Result
var Result = function(options){
for (var i in options){
this[i] = options[i]
}
},
props = {
//value: boolean,
//messages: array,
set: function(property, value){
if (this[property + 'Setter']){
this[property + 'Setter'](value);
}
this[property] = value;
},
get: function(property){
if (this[property + 'Getter']){
return this[property + 'Getter']();
}
return this[property];
},
messagesGetter: function(){
if (!this.messages){
return [];
}
var translated = [],
template,
i,
j;
for (i in this.messages){
if (typeof this.messages[i] == 'string'){
if (messages[this.messages[i]]){
translated[i] = messages[this.messages[i]];
} else {
translated[i] = this.messages[i];
}
} else {
template = this.messages[i];
if (messages[template[0]]){
template[0] = messages[template[0]];
}
for (j = 1; j < template.length; j++){
template[0] = template[0].replace('${' + j + '}', template[j]);
}
translated[i] = template[0];
}
}
return translated;
},
addMessage: function(message){
if (!this.messages){
this.messages = [];
}
this.messages.push(message);
}
},
i;
for (i in props){
Result.prototype[i] = props[i];
}
return Result;
});