Mercurial > hg > fapweb
annotate ajax.js @ 858:fa12a996e86b
ESC handling for message boxes.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 26 Nov 2014 10:29:40 +0200 |
parents | 70a8d52a8d00 |
children | 16cbfb3e7cd4 |
rev | line source |
---|---|
755 | 1 // |
2 // FAPWeb - Simple Web-based Demoparty Management System | |
3 // Common JavaScript / AJAX code | |
4 // (C) Copyright 2012-2014 Tecnic Software productions (TNSP) | |
5 // | |
858
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
6 var jsMessageBoxCancelCB = null, jsMessageBoxCBData = null, jsMessageBoxOKCB = null; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
7 |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
8 function jsHandleMessageBoxKeys(ev) |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
9 { |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
10 ev = ev || window.event; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
11 var key = ev.keyCode ? ev.keyCode : ev.which; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
12 if (key == 27) |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
13 { |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
14 jsCloseMessageBox(jsMessageBoxCancelCB, jsMessageBoxCBData); |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
15 return false; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
16 } |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
17 else |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
18 return true; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
19 } |
755 | 20 |
21 | |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 function jsCloseMessageBox(callback, cb_data) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 var nitem = document.getElementById("messageBox"); |
858
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
25 if (nitem) |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 { |
858
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
27 document.onkeydown = null; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
28 jsMessageBoxCancelCB = null; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
29 jsMessageBoxCBData = null; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
30 jsMessageBoxOKCB = null; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
31 |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
32 if (nitem.style.display != "none") |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
33 { |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
34 nitem.style.display = "none"; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
35 |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
36 if (callback && typeof(callback) === "function") |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
37 callback(cb_data); |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
38 } |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 function jsMessageBox(msg) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 var nitem = document.getElementById("messageBox"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 if (nitem) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 nitem.innerHTML = "<div class='messageBoxInner'>"+ msg + |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 "<div class='messageBoxControls'>"+ |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 "<input id='msgBoxConfirmClose' type='button' value=' OK '>"+ |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 "</div></div>"; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 |
858
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
53 document.onkeydown = jsHandleMessageBoxKeys; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
54 jsMessageBoxCancelCB = null; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
55 jsMessageBoxCBData = null; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
56 jsMessageBoxOKCB = null; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
57 |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 var elem = document.getElementById("msgBoxConfirmClose"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 elem.onclick = function () { jsCloseMessageBox(0, 0); } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
61 nitem.style.display = "block"; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
62 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
63 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
66 function jsErrorMessageBox(msg) |
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
67 { |
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
68 jsMessageBox("<h1>An error occured</h1><div>"+msg+"</div>"); |
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
69 } |
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
70 |
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
71 |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
72 function jsConfirmBox(msg, cb_ok, cb_cancel, cb_data) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
73 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
74 var nitem = document.getElementById("messageBox"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
75 if (nitem) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
76 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
77 nitem.innerHTML = "<div class='messageBoxInner'><h1>Confirmation</h1><p>"+ msg +"</p>"+ |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
78 "<div class='messageBoxControls'>"+ |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
79 "<input id='msgBoxConfirmCancel' type='button' value=' Cancel '>"+ |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
80 "<input id='msgBoxConfirmOK' type='button' value=' OK '>"+ |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
81 "</div></div>"; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
82 |
858
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
83 document.onkeydown = jsHandleMessageBoxKeys; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
84 jsMessageBoxOKCB = cb_ok; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
85 jsMessageBoxCancelCB = cb_cancel; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
86 jsMessageBoxCBData = cb_data; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
87 |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
88 var elem = document.getElementById("msgBoxConfirmCancel"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
89 elem.onclick = function () { jsCloseMessageBox(cb_cancel, cb_data); } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
90 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
91 elem = document.getElementById("msgBoxConfirmOK"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
92 elem.onclick = function () { jsCloseMessageBox(cb_ok, cb_data); } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
93 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
94 nitem.style.display = "block"; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
95 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
96 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
97 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 |
826
8bee2554d95e
Rename one javascript function.
Matti Hamalainen <ccr@tnsp.org>
parents:
785
diff
changeset
|
99 function jsStatusMsg(msg) |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
100 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
101 var nitem = document.getElementById("nstatus"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
102 if (nitem) nstatus.innerHTML = msg; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
103 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
104 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
105 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
106 function strtrim(str) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
107 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
108 if (!str || str == null) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
109 return ""; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
110 return str.replace(/^\s+|\s+$/g,'') |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
111 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
112 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
113 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
114 function strencode(str) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
115 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
116 return encodeURIComponent(str); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
117 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
118 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
120 function jsCreateXMLRequest() |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
121 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
122 var req; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
123 if (window.XMLHttpRequest) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
124 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
125 // Modern browsers |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
126 req = new XMLHttpRequest(); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
127 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
128 else |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
129 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 // Old IE versions |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
131 req = new ActiveXObject("Microsoft.XMLHTTP"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
133 return req; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
134 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
135 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
136 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
137 // |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
138 // Function for creating AJAX POST request arguments list based |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
139 // on fields and giving them specified types. Also basic check |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 // for validity can be performed (e.g. field empty or not) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
141 // |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
142 var lastPostArgs = Object(); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
143 function jsMakePostArgs(fields, fprefix, fsuffix, nofail) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 var res = []; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
146 lastPostArgs = Object(); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
148 for (var id in fields) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
149 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 var elname = fprefix + id + fsuffix; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
151 switch (fields[id]) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
152 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
153 case 4: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
154 elname += "Sel"; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
155 break; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
156 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
157 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
158 var elem = document.getElementById(elname); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
159 if (!elem && !nofail) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
160 { |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
161 jsErrorMessageBox("No such DOM element '"+ elname +"'."); |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
162 return ""; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
163 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
164 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
165 if (elem) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
166 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
167 switch (fields[id]) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
168 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
169 case 1: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
170 var vstr = strtrim(elem.value); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
171 res.push(id+"="+strencode(vstr)); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
172 lastPostArgs[id] = vstr; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
173 break; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
174 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
175 case 2: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
176 var vint = parseInt(strtrim(elem.value)); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
177 res.push(id+"="+vint); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
178 lastPostArgs[id] = vint; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
179 break; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
180 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
181 case 3: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 res.push(id+"="+(elem.checked ? "1" : "0")); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 lastPostArgs[id] = elem.checked; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
184 break; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
185 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
186 case 4: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 var vval = (elem.selectedIndex != -1) ? elem.options[elem.selectedIndex].value : -1; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
188 res.push(id+"="+vval); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
189 lastPostArgs[id] = vval; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
190 break; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
191 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
192 default: |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
193 jsErrorMessageBox("Unsupported field type in "+ elname); |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
194 return ""; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
195 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
197 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
198 return res.join("&"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
199 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
200 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
201 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
202 function jsGetValue(elname, eltype) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
203 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
204 var elem = document.getElementById(elname); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
205 if (!elem) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
206 { |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
207 jsErrorMessageBox("No such DOM element '"+ elname +"'."); |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
208 return ""; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
209 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
210 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
211 switch (eltype) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
212 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
213 case 1: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
214 var vstr = strtrim(elem.value); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
215 return strencode(vstr); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
216 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
217 case 2: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
218 var vint = parseInt(strtrim(elem.value)); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
219 return vint; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
220 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
221 case 3: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
222 return elem.checked ? "1" : "0"; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
223 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
224 case 4: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
225 if (elem.selectedIndex != -1) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
226 return elem.options[elem.selectedIndex].value; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
227 else |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
228 return null; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
229 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
230 default: |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
231 jsErrorMessageBox("Unsupported field type in "+ elname); |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
232 return ""; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
233 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
234 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
235 |
730
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
236 |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
237 function jsShowPreviewImage(file) |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
238 { |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
239 var nitem = document.getElementById("messageBox"); |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
240 if (nitem) |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
241 { |
785
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
242 nitem.innerHTML = "<div class='imageBoxInner'>"+ |
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
243 "<img src='"+file+"' alt='"+file+"' />"+ |
730
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
244 "</div>"; |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
245 |
785
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
246 var elem = document.getElementById("messageBox"); |
730
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
247 elem.onclick = function () { jsCloseMessageBox(0, 0); } |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
248 |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
249 nitem.style.display = "block"; |
785
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
250 |
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
251 return false; |
730
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
252 } |
785
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
253 |
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
254 return true; |
730
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
255 } |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
256 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
257 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
258 function jsFormatSize(bytes) |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
259 { |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
260 var suffixes = ["Bytes", "KiB", "MiB"]; |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
261 var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
262 return (bytes / Math.pow(1024, i)).toFixed(1) +' '+ suffixes[i]; |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
263 } |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
264 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
265 |
851 | 266 function jsStartFileUpload(formID, formTarget, fileSelID, fileMaxSize, fileCallback) |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
267 { |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
268 var formFile = document.getElementById(fileSelID).files[0]; |
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
269 if (!formFile || typeof(formFile) !== "object") |
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
270 { |
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
271 jsErrorMessageBox("No file selected."); |
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
272 return; |
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
273 } |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
274 |
851 | 275 if (formFile.size > fileMaxSize) |
276 { | |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
277 jsErrorMessageBox("File size exceeds "+ jsFormatSize(maxSize) +"."); |
851 | 278 return; |
279 } | |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
280 |
851 | 281 var formElem = document.getElementById(formID); |
282 if (!formElem) | |
283 { | |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
284 jsErrorMessageBox("File upload form '"+ formID +"' element not found!"); |
851 | 285 return; |
286 } | |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
287 |
851 | 288 var formData = new FormData(formElem); |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
289 var req = jsCreateXMLRequest(); |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
290 req.upload.addEventListener('progress', jsUploadProgress, false); |
851 | 291 req.addEventListener('load', function(e) |
292 { | |
293 }, false); | |
294 | |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
295 req.addEventListener('error', jsUploadError, false); |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
296 req.addEventListener('abort', jsUploadAbort, false); |
851 | 297 req.open('POST', formTarget); |
298 req.send(formData); | |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
299 } |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
300 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
301 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
302 function jsUploadProgress(e) |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
303 { |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
304 if (e.lengthComputable) |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
305 { |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
306 var complete = Math.round(e.loaded * 100 / e.total); |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
307 if (complete < 100) |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
308 jsStatusMsg("Uploaded "+ complete.toString() +'%, '+ jsFormatSize(e.loaded)); |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
309 else |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
310 jsStatusMsg("Upload finished ..."); |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
311 } |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
312 } |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
313 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
314 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
315 function jsUploadError(e) |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
316 { |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
317 jsErrorMessageBox("Error occured while uploading: "); |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
318 } |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
319 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
320 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
321 function jsUploadAbort(e) |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
322 { |
851 | 323 jsStatusMsg("File upload aborted."); |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
324 } |