-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvent.js
More file actions
224 lines (172 loc) · 6.25 KB
/
Copy pathEvent.js
File metadata and controls
224 lines (172 loc) · 6.25 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
if(!javaxt) var javaxt={};
if(!javaxt.dhtml) javaxt.dhtml={};
if(!javaxt.dhtml.calendar) javaxt.dhtml.calendar={};
//******************************************************************************
//** Event Class
//*****************************************************************************/
/**
* Used to represent a calendar event.
*
******************************************************************************/
javaxt.dhtml.calendar.Event = function(config) {
var me = this;
var id;
var subject;
var startDate, endDate;
var editable;
var attr;
//**************************************************************************
//** Constructor
//**************************************************************************
/** Creates a new instance of an event. */
var init = function(){
id = config.id;
subject = config.subject;
startDate = new Date(config.startDate);
endDate = new Date(config.endDate);
editable = config.editable;
if (editable==true) editable = true;
else editable = false;
attr = {};
for (var key in config) {
if (config.hasOwnProperty(key)) {
switch(key) {
case 'subject', 'startDate', 'endDate', 'editable':
break;
default:
attr[key] = config[key];
}
}
}
};
this.getID = function(){
return id;
};
this.getSubject = function(){
return subject;
};
this.getStartDate = function(){
return new Date(startDate);
};
this.setStartDate = function(date){
startDate = new Date(date);
};
this.getEndDate = function(){
return new Date(endDate);
};
this.setEndDate = function(date){
endDate = new Date(date);
};
this.numDays = function(){
return Math.floor(javaxt.dhtml.calendar.Utils.getDaysBetween(startDate, endDate));
};
this.isEditable = function(){
return editable;
};
this.setEditable = function(b){
editable = b;
};
this.get = function(key){
switch(key) {
case 'subject':
return getSubject();
break;
case 'startDate':
return getStartDate();
break;
case 'endDate':
return getEndDate();
break;
case 'editable':
return isEditable();
break;
default:
return attr[key];
}
};
this.toJson = function(){
var json = {};
//Add all the original attributes
for (var key in attr) {
if (attr.hasOwnProperty(key)) {
json[key] = attr[key];
}
}
//Update JSON with values retrieved from public "get" and "is" methods
for (var key in me) {
if (me.hasOwnProperty(key)) {
if (key.indexOf("get")==0 && key!="get"){
//Get function
var fn = me[key];
//Update key
key = key.substring(3,4).toLowerCase() + key.substring(4);
if (key=="iD") key = "id";
//Get value
var val = fn.apply(me, []);
if (val instanceof Date) {
val = getISOString(val);
}
//Update JSON
json[key] = val;
}
else if (key.indexOf("is")==0){
var fn = me[key];
key = key.substring(2,3).toLowerCase() + key.substring(3);
json[key] = fn.apply(me, []);
}
}
}
return json;
};
this.equals = function(event){
var a = me.toJson();
var b = event.toJson();
for (var key in a) {
if (a.hasOwnProperty(key)) {
var x = a[key];
var y = b[key];
if (x==null && y!=null) return false;
if (x!=null && y==null) return false;
if (x!=null){
if (x instanceof Date){
if (!(y instanceof Date)) return false;
else{
x = x.getTime();
y = y.getTime();
}
}
//console.log(" -- " + x + " vs " + y + " (" + (x==y) + ")");
if (x!=y) return false;
}
}
}
return true;
};
this.createDiv = function(continueLeft, continueRight){
var outerDiv = document.createElement('div');
outerDiv.className = "javaxt-cal-event" +
(continueLeft==true? " javaxt-cal-event-continue-left" : "") +
(continueRight==true? " javaxt-cal-event-continue-right" : "");
outerDiv.style.height = "100%";
outerDiv.style.position = "relative";
outerDiv.style.overflow = "hidden";
var innerDiv = document.createElement('div');
innerDiv.style.width = "100%";
innerDiv.style.height = "100%";
innerDiv.style.position = "absolute";
innerDiv.style.overflow = "hidden";
innerDiv.innerHTML = me.getSubject();
outerDiv.appendChild(innerDiv);
return outerDiv;
};
var getISOString = function(date) {
function pad(n) {return n < 10 ? '0' + n : n;}
return date.getUTCFullYear() + '-'
+ pad(date.getUTCMonth() + 1) + '-'
+ pad(date.getUTCDate()) + 'T'
+ pad(date.getUTCHours()) + ':'
+ pad(date.getUTCMinutes()) + ':'
+ pad(date.getUTCSeconds()) + 'Z';
};
init();
};