Mercurial > hg > fapweb
annotate ajax.js @ 893:43fa1c4c783f
Clarify error message.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 26 Nov 2014 20:11:32 +0200 |
parents | a397d2be6d53 |
children | 42c3fbca0d86 |
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 // | |
876 | 6 var jsMessageBoxCBCancel = null, jsMessageBoxCBData = null, jsMessageBoxCBOK = null; |
7 | |
858
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
8 |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
9 function jsHandleMessageBoxKeys(ev) |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
10 { |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
11 ev = ev || window.event; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
12 var key = ev.keyCode ? ev.keyCode : ev.which; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
13 if (key == 27) |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
14 { |
876 | 15 jsCloseMessageBox(jsMessageBoxCBCancel, jsMessageBoxCBData); |
858
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
16 return false; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
17 } |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
18 else |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
19 return true; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
20 } |
755 | 21 |
22 | |
876 | 23 function jsSetMessageBoxCBs(cb_ok, cb_cancel, cb_data) |
24 { | |
25 jsMessageBoxCBOK = cb_ok; | |
26 jsMessageBoxCBCancel = cb_cancel; | |
27 jsMessageBoxCBData = cb_data; | |
28 } | |
29 | |
30 | |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 function jsCloseMessageBox(callback, cb_data) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 var nitem = document.getElementById("messageBox"); |
858
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
34 if (nitem) |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 { |
858
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
36 document.onkeydown = null; |
876 | 37 jsSetMessageBoxCBs(null, null, null); |
858
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
38 |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
39 if (nitem.style.display != "none") |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
40 { |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
41 nitem.style.display = "none"; |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
42 |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
43 if (callback && typeof(callback) === "function") |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
44 callback(cb_data); |
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
45 } |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 } |
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 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 function jsMessageBox(msg) |
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"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 if (nitem) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
54 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 nitem.innerHTML = "<div class='messageBoxInner'>"+ msg + |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
56 "<div class='messageBoxControls'>"+ |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 "<input id='msgBoxConfirmClose' type='button' value=' OK '>"+ |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 "</div></div>"; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 |
858
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
60 document.onkeydown = jsHandleMessageBoxKeys; |
876 | 61 jsSetMessageBoxCBs(null, null, null); |
858
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
62 |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
63 var elem = document.getElementById("msgBoxConfirmClose"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 elem.onclick = function () { jsCloseMessageBox(0, 0); } |
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 nitem.style.display = "block"; |
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 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
70 |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
71 function jsErrorMessageBox(msg) |
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
72 { |
859
16cbfb3e7cd4
Change error message box title.
Matti Hamalainen <ccr@tnsp.org>
parents:
858
diff
changeset
|
73 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
|
74 } |
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
75 |
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
76 |
865 | 77 function jsTitleMessageBox(title, msg) |
78 { | |
79 jsMessageBox("<h1>"+title+"</h1><div>"+msg+"</div>"); | |
80 } | |
81 | |
82 | |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 function jsConfirmBox(msg, cb_ok, cb_cancel, cb_data) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
84 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
85 var nitem = document.getElementById("messageBox"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
86 if (nitem) |
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 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
|
89 "<div class='messageBoxControls'>"+ |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
90 "<input id='msgBoxConfirmCancel' type='button' value=' Cancel '>"+ |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
91 "<input id='msgBoxConfirmOK' type='button' value=' OK '>"+ |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
92 "</div></div>"; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
93 |
858
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
94 document.onkeydown = jsHandleMessageBoxKeys; |
876 | 95 jsSetMessageBoxCBs(cb_ok, cb_cancel, cb_data); |
858
fa12a996e86b
ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents:
857
diff
changeset
|
96 |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
97 var elem = document.getElementById("msgBoxConfirmCancel"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 elem.onclick = function () { jsCloseMessageBox(cb_cancel, cb_data); } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
99 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
100 elem = document.getElementById("msgBoxConfirmOK"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
101 elem.onclick = function () { jsCloseMessageBox(cb_ok, 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 nitem.style.display = "block"; |
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 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
107 |
826
8bee2554d95e
Rename one javascript function.
Matti Hamalainen <ccr@tnsp.org>
parents:
785
diff
changeset
|
108 function jsStatusMsg(msg) |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
109 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
110 var nitem = document.getElementById("nstatus"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
111 if (nitem) nstatus.innerHTML = msg; |
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 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
115 function strtrim(str) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
116 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
117 if (!str || str == null) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
118 return ""; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 return str.replace(/^\s+|\s+$/g,'') |
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 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
123 function strencode(str) |
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 return encodeURIComponent(str); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
126 } |
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 function jsCreateXMLRequest() |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
131 var req; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 if (window.XMLHttpRequest) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
133 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
134 // Modern browsers |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
135 req = new XMLHttpRequest(); |
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 else |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
138 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
139 // Old IE versions |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 req = new ActiveXObject("Microsoft.XMLHTTP"); |
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 return req; |
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 |
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 // |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 // Function for creating AJAX POST request arguments list based |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
148 // 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
|
149 // 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
|
150 // |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
151 var lastPostArgs = Object(); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
152 function jsMakePostArgs(fields, fprefix, fsuffix, nofail) |
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 var res = []; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
155 lastPostArgs = Object(); |
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 for (var id in fields) |
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 var elname = fprefix + id + fsuffix; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
160 switch (fields[id]) |
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 case 4: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
163 elname += "Sel"; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
164 break; |
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 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
167 var elem = document.getElementById(elname); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
168 if (!elem && !nofail) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
169 { |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
170 jsErrorMessageBox("No such DOM element '"+ elname +"'."); |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
171 return ""; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
172 } |
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 if (elem) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
175 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
176 switch (fields[id]) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
177 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
178 case 1: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
179 var vstr = strtrim(elem.value); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
180 res.push(id+"="+strencode(vstr)); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
181 lastPostArgs[id] = vstr; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 break; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
184 case 2: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
185 var vint = parseInt(strtrim(elem.value)); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
186 res.push(id+"="+vint); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 lastPostArgs[id] = vint; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
188 break; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
189 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
190 case 3: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
191 res.push(id+"="+(elem.checked ? "1" : "0")); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
192 lastPostArgs[id] = elem.checked; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
193 break; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
194 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
195 case 4: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 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
|
197 res.push(id+"="+vval); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
198 lastPostArgs[id] = vval; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
199 break; |
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 default: |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
202 jsErrorMessageBox("Unsupported field type in "+ elname); |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
203 return ""; |
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 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
206 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
207 return res.join("&"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
208 } |
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 function jsGetValue(elname, 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 var elem = document.getElementById(elname); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
214 if (!elem) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
215 { |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
216 jsErrorMessageBox("No such DOM element '"+ elname +"'."); |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
217 return ""; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
218 } |
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 switch (eltype) |
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 case 1: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
223 var vstr = strtrim(elem.value); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
224 return strencode(vstr); |
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 case 2: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
227 var vint = parseInt(strtrim(elem.value)); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
228 return vint; |
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 case 3: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
231 return elem.checked ? "1" : "0"; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
232 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
233 case 4: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
234 if (elem.selectedIndex != -1) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
235 return elem.options[elem.selectedIndex].value; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
236 else |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
237 return null; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
238 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
239 default: |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
240 jsErrorMessageBox("Unsupported field type in "+ elname); |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
241 return ""; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
242 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
243 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
244 |
730
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
245 |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
246 function jsShowPreviewImage(file) |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
247 { |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
248 var nitem = document.getElementById("messageBox"); |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
249 if (nitem) |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
250 { |
785
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
251 nitem.innerHTML = "<div class='imageBoxInner'>"+ |
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
252 "<img src='"+file+"' alt='"+file+"' />"+ |
730
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
253 "</div>"; |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
254 |
785
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
255 var elem = document.getElementById("messageBox"); |
730
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
256 elem.onclick = function () { jsCloseMessageBox(0, 0); } |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
257 |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
258 nitem.style.display = "block"; |
785
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
259 |
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
260 return false; |
730
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
261 } |
785
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
262 |
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
263 return true; |
730
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
264 } |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
265 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
266 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
267 function jsFormatSize(bytes) |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
268 { |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
269 var suffixes = ["Bytes", "KiB", "MiB"]; |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
270 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
|
271 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
|
272 } |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
273 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
274 |
851 | 275 function jsStartFileUpload(formID, formTarget, fileSelID, fileMaxSize, fileCallback) |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
276 { |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
277 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
|
278 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
|
279 { |
893 | 280 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
|
281 return; |
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
282 } |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
283 |
851 | 284 if (formFile.size > fileMaxSize) |
285 { | |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
286 jsErrorMessageBox("File size exceeds "+ jsFormatSize(maxSize) +"."); |
851 | 287 return; |
288 } | |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
289 |
851 | 290 var formElem = document.getElementById(formID); |
291 if (!formElem) | |
292 { | |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
293 jsErrorMessageBox("File upload form '"+ formID +"' element not found!"); |
851 | 294 return; |
295 } | |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
296 |
851 | 297 var formData = new FormData(formElem); |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
298 var req = jsCreateXMLRequest(); |
863 | 299 req.upload.addEventListener("progress", jsUploadProgress, false); |
300 req.addEventListener("error", jsUploadError, false); | |
301 req.addEventListener("abort", jsUploadAbort, false); | |
865 | 302 |
303 req.onreadystatechange = function() | |
304 { | |
305 if (req.readyState == 4) | |
306 { | |
307 switch (req.status) | |
308 { | |
309 case 902: | |
310 jsStatusMsg(req.statusText); | |
311 jsMessageBox(req.responseText); | |
312 break; | |
313 | |
314 case 903: | |
315 { | |
316 var nitem = document.getElementById("messageBox"); | |
317 if (nitem) | |
318 { | |
319 nitem.innerHTML = "<div class='messageBoxInner'>"+ req.responseText + | |
320 "<div class='messageBoxControls'>"+ | |
321 "</div></div>"; | |
322 nitem.style.display = "block"; | |
323 } | |
324 } | |
325 break; | |
326 | |
327 case 200: | |
328 if (fileCallback) | |
329 setTimeout(fileCallback, 1); | |
330 | |
331 jsTitleMessageBox("File upload", req.responseText); | |
332 break; | |
333 | |
334 default: | |
335 jsStatusMsg("["+req.status+" - "+req.statusText+"] "+ req.responseText); | |
336 break; | |
337 } | |
338 } | |
339 } | |
340 | |
863 | 341 req.open("POST", formTarget); |
851 | 342 req.send(formData); |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
343 } |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
344 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
345 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
346 function jsUploadProgress(e) |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
347 { |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
348 if (e.lengthComputable) |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
349 { |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
350 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
|
351 if (complete < 100) |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
352 jsStatusMsg("Uploaded "+ complete.toString() +'%, '+ jsFormatSize(e.loaded)); |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
353 else |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
354 jsStatusMsg("Upload finished ..."); |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
355 } |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
356 } |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
357 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
358 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
359 function jsUploadError(e) |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
360 { |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
361 jsErrorMessageBox("Error occured while uploading: "); |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
362 } |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
363 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
364 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
365 function jsUploadAbort(e) |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
366 { |
851 | 367 jsStatusMsg("File upload aborted."); |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
368 } |