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
|
var caleventlist;
var caleventok;
function CalEvent(){
this.key = null;
this.title = "新活動";
this.content = "關於此活動的描述";
this.icon = 0;
this.remind = 30;
this.datafrom = "native";
this.datetime = new Date();
this.deleted = false;
this.equal = function(another){
return this.key == another.key &&
this.equalIgnoreKey(another);
}
this.equalIgnoreKey = function(another){
return this.title == another.title &&
this.content == another.content &&
this.icon == another.icon &&
(this.remind == another.remind ||
((isNaN(this.remind) || this.remind == null) &&
(isNaN(another.remind) || another.remind == null))) &&
this.datafrom == another.datafrom &&
this.datetime.toString() == another.datetime.toString();
}
this.clone = function(){
var newobj = new CalEvent();
newobj.key = this.key;
newobj.title = this.title;
newobj.content = this.content;
newobj.icon = this.icon;
newobj.remind = this.remind;
newobj.datafrom = this.datafrom;
newobj.deleted = this.deleted;
newobj.datetime.setFullYear(
this.datetime.getFullYear(),
this.datetime.getMonth(),
this.datetime.getDate());
newobj.datetime.setHours(
this.datetime.getHours(),
this.datetime.getMinutes(), 0, 0);
return newobj;
}
}
function create_xmlhttp_object(){
var rq;
try{
rq = new XMLHttpRequest();
}catch(err){
try{
rq = new ActiveXObject("Msxml2.XMLHTTP");
}catch(err){
try{
rq = new ActiveXObject("Microsoft.XMLHTTP");
}catch(err){
rq = null;
}
}
}
return rq;
}
function inccal_fetch(year, month){
status_bar_save();
caleventok = false;
caleventlist = new Array();
var should_continue = true;
var gqlcursor = null;
var postdata;
var retrdata;
var calevent;
var eventobj;
var progcounter = 0;
var timecounter = 0;
var loadingstr = '載入中......';
var rq;
var i;
while(should_continue){
status_bar_set(loadingstr + ' 已下載 ' + timecounter.toString() +
' 次,共取得 ' + progcounter.toString() + ' 項資料');
rq = create_xmlhttp_object();
rq.open('POST', '/access/fetch', false);
rq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
if(month == null){
postdata = 'year=' + year.toString();
}else{
postdata = 'year=' + year.toString() + '&month=' + month.toString();
}
if(gqlcursor != null){
postdata = postdata + '&gqlcursor=' + encodeURIComponent(gqlcursor);
}
rq.send(postdata);
retrdata = rq.responseXML.documentElement;
calevent = retrdata.getElementsByTagName("calevent");
if(calevent.length == 0){
should_continue = false;
}
for(i=0; i<calevent.length; i++){
eventobj = new CalEvent();
eventobj.key = XMLGetDataByTagName(calevent[i], "key");
eventobj.title = XMLGetDataByTagName(calevent[i], "title");
eventobj.content = XMLGetDataByTagName(calevent[i], "content");
eventobj.icon = parseInt(XMLGetDataByTagName(calevent[i], "icon"));
eventobj.remind = parseInt(XMLGetDataByTagName(calevent[i], "remind"));
if(!isFinite(eventobj.remind)){
eventobj.remind = null;
}
eventobj.datafrom = XMLGetDataByTagName(calevent[i], "datafrom");
eventobj.datetime = new Date();
eventobj.datetime.setFullYear(
parseInt(XMLGetDataByTagName(calevent[i], "year")),
parseInt(XMLGetDataByTagName(calevent[i], "month") - 1),
parseInt(XMLGetDataByTagName(calevent[i], "date"))
);
eventobj.datetime.setHours(
parseInt(XMLGetDataByTagName(calevent[i], "hour")),
parseInt(XMLGetDataByTagName(calevent[i], "minute")),
0, 0);
caleventlist.push(eventobj);
}
timecounter++;
progcounter += calevent.length;
try{
gqlcursor = XMLGetDataByTagName(retrdata, "gqlcursor");
}catch(err){
should_continue = false;
}
}
caleventok = true;
status_bar_restore();
}
function inccal_send(calevt, do_func, funcseconddata){
var rq = create_xmlhttp_object();
var str = "";
str = 'icon=' + encodeURIComponent(calevt.icon.toString()) + '&' +
'title=' + encodeURIComponent(calevt.title) + '&' +
'content=' + encodeURIComponent(calevt.content) + '&' +
'remind=' + encodeURIComponent(calevt.remind.toString()) + '&' +
'datafrom=' + encodeURIComponent(calevt.datafrom) + '&' +
'year=' + encodeURIComponent(calevt.datetime.getFullYear()) + '&' +
'month=' + encodeURIComponent(calevt.datetime.getMonth() + 1) + '&' +
'date=' + encodeURIComponent(calevt.datetime.getDate()) + '&' +
'hour=' + encodeURIComponent(calevt.datetime.getHours()) + '&' +
'minute=' + encodeURIComponent(calevt.datetime.getMinutes());
if(calevt.key == null){
rq.open('POST', '/access/insert');
rq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
rq.send(str);
}else{
rq.open('POST', '/access/update');
rq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
rq.send(str + '&key=' + encodeURIComponent(calevt.key));
}
rq.onreadystatechange = function(){
if(rq.readyState == 4){
if(rq.status == 200){
if(do_func != null){
do_func(rq.responseText, funcseconddata);
}
}else{
status_bar_warning("伺服器回傳 " + rq.status.toString() + " 錯誤");
}
}
}
}
function inccal_remove(calevt, do_func){
var rq = create_xmlhttp_object();
var str = "";
str = 'key=' + encodeURIComponent(calevt.key);
rq.open('POST', '/access/remove');
rq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
rq.send(str);
rq.onreadystatechange = function(){
if(rq.readyState == 4){
if(rq.status == 200){
status_bar_set("資料已刪除");
if(do_func != null){
do_func();
}
}else{
status_bar_warning("伺服器回傳 " + rq.status.toString() + " 錯誤");
}
}
}
}
|