Mercurial > hg > fapweb
annotate genajax.js @ 1103:1fe7df7c77fb
Remove useless meta-equiv charset.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 14 May 2019 14:12:42 +0300 |
parents | 5f48cb05bfff |
children |
rev | line source |
---|---|
755 | 1 // |
2 // FAPWeb - Simple Web-based Demoparty Management System | |
3 // Common JavaScript / AJAX code | |
1072 | 4 // (C) Copyright 2012-2017 Tecnic Software productions (TNSP) |
755 | 5 // |
876 | 6 var jsMessageBoxCBCancel = null, jsMessageBoxCBData = null, jsMessageBoxCBOK = null; |
916
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
7 var jsUploadCBS = []; |
876 | 8 |
858
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
9 |
1078 | 10 function jsAddEventListener(velem, vev, vfunc) |
11 { | |
12 if (velem) | |
13 { | |
14 if (velem.attachEvent) | |
15 return velem.attachEvent('on'+ vev, vfunc); | |
16 else | |
17 return velem.addEventListener(vev, vfunc, false); | |
18 } | |
19 } | |
20 | |
21 | |
22 function jsAddEventListenerById(velem, vev, vfunc) | |
23 { | |
24 jsAddEventListener(document.getElementById(velem), vev, vfunc); | |
25 } | |
26 | |
27 | |
858
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
28 function jsHandleMessageBoxKeys(ev) |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
29 { |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
30 ev = ev || window.event; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
31 var key = ev.keyCode ? ev.keyCode : ev.which; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
32 if (key == 27) |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
33 { |
876 | 34 jsCloseMessageBox(jsMessageBoxCBCancel, jsMessageBoxCBData); |
858
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
35 return false; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
36 } |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
37 else |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
38 return true; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
39 } |
755 | 40 |
41 | |
876 | 42 function jsSetMessageBoxCBs(cb_ok, cb_cancel, cb_data) |
43 { | |
44 jsMessageBoxCBOK = cb_ok; | |
45 jsMessageBoxCBCancel = cb_cancel; | |
46 jsMessageBoxCBData = cb_data; | |
47 } | |
48 | |
49 | |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 function jsCloseMessageBox(callback, cb_data) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 var nitem = document.getElementById("messageBox"); |
858
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
53 if (nitem) |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
54 { |
858
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
55 document.onkeydown = null; |
876 | 56 jsSetMessageBoxCBs(null, null, null); |
858
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
57 |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
58 if (nitem.style.display != "none") |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
59 { |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
60 nitem.style.display = "none"; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
61 |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
62 if (callback && typeof(callback) === "function") |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
63 callback(cb_data); |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
64 } |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
66 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
67 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
68 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
69 function jsMessageBox(msg) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
70 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
71 var nitem = document.getElementById("messageBox"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
72 if (nitem) |
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 nitem.innerHTML = "<div class='messageBoxInner'>"+ msg + |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
75 "<div class='messageBoxControls'>"+ |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
76 "<input id='msgBoxConfirmClose' type='button' value=' OK '>"+ |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
77 "</div></div>"; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
78 |
858
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
79 document.onkeydown = jsHandleMessageBoxKeys; |
876 | 80 jsSetMessageBoxCBs(null, null, null); |
858
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
81 |
1078 | 82 jsAddEventListenerById("msgBoxConfirmClose", "click", function () { jsCloseMessageBox(0, 0); }); |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
84 nitem.style.display = "block"; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
85 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
86 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
87 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
88 |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
89 function jsErrorMessageBox(msg) |
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
90 { |
859
16cbfb3e7cd4
Change error message box title.
Matti Hamalainen <ccr@tnsp.org>
parents:
858
diff
changeset
|
91 jsMessageBox("<h1>Error!</h1><div>"+msg+"</div>"); |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
92 } |
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
93 |
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
94 |
865 | 95 function jsTitleMessageBox(title, msg) |
96 { | |
97 jsMessageBox("<h1>"+title+"</h1><div>"+msg+"</div>"); | |
98 } | |
99 | |
100 | |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
101 function jsConfirmBox(msg, cb_ok, cb_cancel, cb_data) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
102 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
103 var nitem = document.getElementById("messageBox"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
104 if (nitem) |
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 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
|
107 "<div class='messageBoxControls'>"+ |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
108 "<input id='msgBoxConfirmCancel' type='button' value=' Cancel '>"+ |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
109 "<input id='msgBoxConfirmOK' type='button' value=' OK '>"+ |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
110 "</div></div>"; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
111 |
858
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
112 document.onkeydown = jsHandleMessageBoxKeys; |
876 | 113 jsSetMessageBoxCBs(cb_ok, cb_cancel, cb_data); |
858
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
114 |
1078 | 115 jsAddEventListenerById("msgBoxConfirmCancel", "click", function () { jsCloseMessageBox(cb_cancel, cb_data); }); |
116 jsAddEventListenerById("msgBoxConfirmOK", "click", function () { jsCloseMessageBox(cb_ok, cb_data); }); | |
728
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 nitem.style.display = "block"; |
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 } |
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 |
826
8bee2554d95e
Rename one javascript function.
Matti Hamalainen <ccr@tnsp.org>
parents:
785
diff
changeset
|
123 function jsStatusMsg(msg) |
728
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 var nitem = document.getElementById("nstatus"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
126 if (nitem) nstatus.innerHTML = msg; |
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 |
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 function strtrim(str) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
131 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 if (!str || str == null) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
133 return ""; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
134 return str.replace(/^\s+|\s+$/g,'') |
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 strencode(str) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
139 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 return encodeURIComponent(str); |
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 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
143 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 function jsCreateXMLRequest() |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
146 var req; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 if (window.XMLHttpRequest) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
148 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
149 // Modern browsers |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 req = new XMLHttpRequest(); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
151 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
152 else |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
153 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
154 // Old IE versions |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
155 req = new ActiveXObject("Microsoft.XMLHTTP"); |
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 return req; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
158 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
159 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
160 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
161 // |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
162 // Function for creating AJAX POST request arguments list based |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
163 // 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
|
164 // 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
|
165 // |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
166 var lastPostArgs = Object(); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
167 function jsMakePostArgs(fields, fprefix, fsuffix, nofail) |
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 var res = []; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
170 lastPostArgs = Object(); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
171 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
172 for (var id in fields) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
173 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
174 var elname = fprefix + id + fsuffix; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
175 switch (fields[id]) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
176 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
177 case 4: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
178 elname += "Sel"; |
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 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 var elem = document.getElementById(elname); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 if (!elem && !nofail) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
184 { |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
185 jsErrorMessageBox("No such DOM element '"+ elname +"'."); |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
186 return ""; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
188 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
189 if (elem) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
190 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
191 switch (fields[id]) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
192 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
193 case 1: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
194 var vstr = strtrim(elem.value); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
195 res.push(id+"="+strencode(vstr)); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 lastPostArgs[id] = vstr; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
197 break; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
198 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
199 case 2: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
200 var vint = parseInt(strtrim(elem.value)); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
201 res.push(id+"="+vint); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
202 lastPostArgs[id] = vint; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
203 break; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
204 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
205 case 3: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
206 res.push(id+"="+(elem.checked ? "1" : "0")); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
207 lastPostArgs[id] = elem.checked; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
208 break; |
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 case 4: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
211 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
|
212 res.push(id+"="+vval); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
213 lastPostArgs[id] = vval; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
214 break; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
215 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
216 default: |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
217 jsErrorMessageBox("Unsupported field type in "+ elname); |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
218 return ""; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
219 } |
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 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
222 return res.join("&"); |
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 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
225 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
226 function jsGetValue(elname, eltype) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
227 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
228 var elem = document.getElementById(elname); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
229 if (!elem) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
230 { |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
231 jsErrorMessageBox("No such DOM element '"+ 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 switch (eltype) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
236 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
237 case 1: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
238 var vstr = strtrim(elem.value); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
239 return strencode(vstr); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
240 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
241 case 2: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
242 var vint = parseInt(strtrim(elem.value)); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
243 return vint; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
244 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
245 case 3: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
246 return elem.checked ? "1" : "0"; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
247 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
248 case 4: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
249 if (elem.selectedIndex != -1) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
250 return elem.options[elem.selectedIndex].value; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
251 else |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
252 return null; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
253 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
254 default: |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
255 jsErrorMessageBox("Unsupported field type in "+ elname); |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
256 return ""; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
257 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
258 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
259 |
730
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
260 |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
261 function jsShowPreviewImage(file) |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
262 { |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
263 var nitem = document.getElementById("messageBox"); |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
264 if (nitem) |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
265 { |
785
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
266 nitem.innerHTML = "<div class='imageBoxInner'>"+ |
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
267 "<img src='"+file+"' alt='"+file+"' />"+ |
730
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
268 "</div>"; |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
269 |
1078 | 270 jsAddEventListenerById("messageBox", "click", function () { jsCloseMessageBox(0, 0); }); |
730
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
271 |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
272 nitem.style.display = "block"; |
785
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
273 return false; |
730
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
274 } |
785
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
275 |
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
276 return true; |
730
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
277 } |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
278 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
279 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
280 function jsFormatSize(bytes) |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
281 { |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
282 var suffixes = ["Bytes", "KiB", "MiB"]; |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
283 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
|
284 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
|
285 } |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
286 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
287 |
851 | 288 function jsStartFileUpload(formID, formTarget, fileSelID, fileMaxSize, fileCallback) |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
289 { |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
290 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
|
291 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
|
292 { |
893 | 293 jsErrorMessageBox("No file selected to be uploaded."); |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
294 return; |
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
295 } |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
296 |
851 | 297 if (formFile.size > fileMaxSize) |
298 { | |
916
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
299 jsErrorMessageBox("File size exceeds "+ jsFormatSize(fileMaxSize) +"."); |
851 | 300 return; |
301 } | |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
302 |
916
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
303 var filename = formFile.name; |
851 | 304 var formElem = document.getElementById(formID); |
305 if (!formElem) | |
306 { | |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
307 jsErrorMessageBox("File upload form '"+ formID +"' element not found!"); |
851 | 308 return; |
309 } | |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
310 |
851 | 311 var formData = new FormData(formElem); |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
312 var req = jsCreateXMLRequest(); |
916
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
313 req.upload.addEventListener("progress", function(e) |
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
314 { |
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
315 if (e.lengthComputable) |
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
316 { |
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
317 var complete = Math.round(e.loaded * 100 / e.total); |
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
318 if (complete < 100) |
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
319 jsStatusMsg("Uploaded ["+filename+"] "+ complete.toString() +'%, '+ jsFormatSize(e.loaded)); |
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
320 else |
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
321 jsStatusMsg("Upload ["+filename+"] finished ..."); |
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
322 } |
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
323 }, false); |
1078 | 324 |
916
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
325 req.addEventListener("error", function(e) |
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
326 { |
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
327 jsErrorMessageBox("Error occured while uploading "+filename); |
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
328 }, false); |
1078 | 329 |
916
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
330 req.addEventListener("abort", function(e) |
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
331 { |
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
332 jsStatusMsg("Upload of '"+filename+"' aborted."); |
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
333 }, false); |
865 | 334 |
335 req.onreadystatechange = function() | |
336 { | |
337 if (req.readyState == 4) | |
338 { | |
339 switch (req.status) | |
340 { | |
341 case 902: | |
342 jsStatusMsg(req.statusText); | |
343 jsMessageBox(req.responseText); | |
344 break; | |
345 | |
346 case 903: | |
347 { | |
348 var nitem = document.getElementById("messageBox"); | |
349 if (nitem) | |
350 { | |
351 nitem.innerHTML = "<div class='messageBoxInner'>"+ req.responseText + | |
352 "<div class='messageBoxControls'>"+ | |
353 "</div></div>"; | |
354 nitem.style.display = "block"; | |
355 } | |
356 } | |
357 break; | |
358 | |
359 case 200: | |
360 if (fileCallback) | |
916
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
361 { |
1081 | 362 var tid = setTimeout(function() |
916
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
363 { |
1081 | 364 jsRemoveUploadCB(tid); |
916
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
365 setTimeout(fileCallback, 10); |
955 | 366 //jsTitleMessageBox("File upload", req.responseText); |
1081 | 367 }, 10); |
916
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
368 jsUploadCBS.push(tid); |
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
369 } |
865 | 370 break; |
371 | |
372 default: | |
373 jsStatusMsg("["+req.status+" - "+req.statusText+"] "+ req.responseText); | |
374 break; | |
375 } | |
376 } | |
377 } | |
378 | |
863 | 379 req.open("POST", formTarget); |
851 | 380 req.send(formData); |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
381 } |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
382 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
383 |
916
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
384 function jsCancelUploadCBS() |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
385 { |
916
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
386 if (jsUploadCBS.length > 0) |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
387 { |
916
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
388 for (var tid in jsUploadCBS) |
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
389 clearTimeout(tid); |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
390 } |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
391 } |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
392 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
393 |
916
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
394 function jsRemoveUploadCB(tid) |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
395 { |
916
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
396 var index = jsUploadCBS.indexOf(tid); |
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
397 if (index >= 0) |
42c3fbca0d86
Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
398 jsUploadCBS.splice(index, 1); |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
399 } |