aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author藍挺瑋 <lantw44@gmail.com>2012-12-19 23:49:48 +0800
committerLAN-TW <lantw44@gmail.com>2012-12-19 23:49:48 +0800
commit225738e772499537de12d8dc356ff98e9f8b9efa (patch)
treeae35ead48f94abff76bfbb7c324381a2ff64ea30
parentc0cce9dbfce8ebc228ec787c7cd4fcadd622f9e9 (diff)
downloadinccalendar-225738e772499537de12d8dc356ff98e9f8b9efa.tar.gz
inccalendar-225738e772499537de12d8dc356ff98e9f8b9efa.tar.zst
inccalendar-225738e772499537de12d8dc356ff98e9f8b9efa.zip
月曆版加入移除功能,以及修正許多 bug
-rw-r--r--access/fetch.py2
-rw-r--r--access/insert.py3
-rw-r--r--jinhtml/month.html2
-rw-r--r--js/caledit.js44
-rw-r--r--js/data.js24
-rw-r--r--js/month.js1
6 files changed, 66 insertions, 10 deletions
diff --git a/access/fetch.py b/access/fetch.py
index 6de6fd8..3202abe 100644
--- a/access/fetch.py
+++ b/access/fetch.py
@@ -75,7 +75,7 @@ class FetchEvent(webapp2.RequestHandler):
data.with_cursor(withcursor)
eventroot = etree.Element('inccalender')
- for entry in data.run(limit=10):
+ for entry in data.run(limit=50):
calevent = etree.SubElement(eventroot, 'calevent')
XMLBuildCalEvent(calevent, entry)
diff --git a/access/insert.py b/access/insert.py
index 2f4184a..61236a7 100644
--- a/access/insert.py
+++ b/access/insert.py
@@ -48,5 +48,8 @@ class InsertEvent(webapp2.RequestHandler):
newcalevent.put()
+ self.response.headers['Content-Type'] = 'text/plain'
+ self.response.out.write(str(newcalevent.key()))
+
app = webapp2.WSGIApplication([('/access/insert', InsertEvent)])
diff --git a/jinhtml/month.html b/jinhtml/month.html
index 430d562..1e1e36f 100644
--- a/jinhtml/month.html
+++ b/jinhtml/month.html
@@ -107,7 +107,7 @@
<span id="caledit_datafrom"></span>
</fieldset>
<input id="caledit_save" type="submit" value="儲存">
- <input id="caledit_discard" type="button" value="捨棄" onclick="caledit_discard_func()">
+ <input id="caledit_discard" type="button" value="重設" onclick="caledit_discard_func()">
</form>
</div>
</div>
diff --git a/js/caledit.js b/js/caledit.js
index ffa816a..e32affb 100644
--- a/js/caledit.js
+++ b/js/caledit.js
@@ -4,7 +4,7 @@ var caledit_ismodified;
var caledit_loaded;
var current_form;
var saved_form;
-var caledit_defmsg = "(Esc)返回 (Ctrl-M)切換編輯 (Ctrl-左)左側 (Ctrl-右)右側 (Alt-U)儲存 (Alt-R)捨棄";
+var caledit_defmsg = "(Esc)返回 (Ctrl-M)切換編輯 (Ctrl-左)左側 (Ctrl-右)右側 (Alt-U)新增或儲存 (Alt-K)刪除 (Alt-R)復原";
function caledit(year, month, date){
var allbrowseobj = document.getElementsByName("calbrowse");
@@ -17,6 +17,7 @@ function caledit(year, month, date){
$(document).bind("keydown.caledit", "esc", caledit_quit);
$(document).bind("keydown.caledit", "alt+u", caledit_save_func);
$(document).bind("keydown.caledit", "alt+r", caledit_discard_func);
+ $(document).bind("keydown.caledit", "alt+k", caledit_delete_func);
status_bar_save();
status_bar_set(caledit_defmsg);
caledit_switchedit_disable();
@@ -76,6 +77,7 @@ function caledit_quit(){
caledit_clean();
if(caledit_ismodified){
setmonthcal();
+ setfocusblock(value_date);
}
}
@@ -318,7 +320,6 @@ function caledit_validate(){
return false;
}
- status_bar_set(caledit_defmsg);
return true;
}
@@ -388,7 +389,11 @@ function caledit_loader(myself){
dataindex++;
status_bar_set(dataindex.toString() + " " + caledit_defmsg);
caledit_switchedit_disable();
- document.getElementById("caledit_save").value = "儲存";
+ if(current_form.deleted){
+ document.getElementById("caledit_save").value = "重新插入";
+ }else{
+ document.getElementById("caledit_save").value = "儲存";
+ }
document.getElementById("caledit_delete").style.display = "inline";
}
caledit_select_oldval = myself.value;
@@ -404,6 +409,30 @@ function caledit_discard_func(){
caledit_fill(saved_form);
}
+function caledit_delete_func(){
+ caledit_write_current();
+ if(current_form.key == null){
+ return;
+ }else{
+ inccal_remove(current_form, function(){
+ var selobj = document.getElementById("caledit_select");
+ var oldval = parseInt(caledit_select_oldval);
+ current_form.key = null;
+ current_form.deleted = true;
+ saved_form = current_form.clone();
+ activecalevt[oldval] = current_form.clone();
+ document.getElementById("calselopt" +
+ caledit_select_oldval.toString()).innerHTML =
+ '<刪>';
+ caledit_ismodified = true;
+ if(oldval < activecalevt.length - 1){
+ selobj.value = (oldval + 1).toString();
+ caledit_loader(selobj);
+ }
+ });
+ }
+}
+
function caledit_save_func(){
var oldtree;
var newnode;
@@ -413,10 +442,11 @@ function caledit_save_func(){
}else{
return false;
}
- inccal_send(current_form, function(){
+ inccal_send(current_form, function(resp){
if(current_form.key == null){
- newcount = activecalevt.length + 1;
- activecalevt[newcount - 1] = current_form.clone();
+ current_form.key = resp;
+ newcount = activecalevt.length;
+ activecalevt[newcount] = current_form.clone();
oldtree = document.getElementById("caledit_select");
newnode = document.createElement("option");
newnode.setAttribute("id", "calselopt" + newcount.toString());
@@ -438,7 +468,7 @@ function caledit_save_func(){
'<改> 其他日期';
}
}
- saved_form = current_form;
+ saved_form = current_form.clone();
caledit_ismodified = true;
});
return false; /* 這樣才不會真的 submit */
diff --git a/js/data.js b/js/data.js
index b88c890..20a81a5 100644
--- a/js/data.js
+++ b/js/data.js
@@ -9,6 +9,7 @@ function CalEvent(){
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);
@@ -29,6 +30,7 @@ function CalEvent(){
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(),
@@ -133,6 +135,27 @@ function inccal_send(calevt, do_func){
if(rq.status == 200){
status_bar_set("資料已儲存");
if(do_func != null){
+ do_func(rq.responseText);
+ }
+ }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{
@@ -140,4 +163,5 @@ function inccal_send(calevt, do_func){
}
}
}
+
}
diff --git a/js/month.js b/js/month.js
index 9c699c4..0f03390 100644
--- a/js/month.js
+++ b/js/month.js
@@ -356,7 +356,6 @@ function setmonthcal(){
i++;
}
}
- inccal_fetch(value_year, value_month);
calload();
}