annotate genajax.js @ 1069:5f92fa5e683a

Refactor how the "AJAX" stuff works.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 24 Jan 2017 17:25:48 +0200
parents ajax.js@82ecea33c477
children 7da8bde9b7be
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
755
c7b4139eb217 Add copyright header.
Matti Hamalainen <ccr@tnsp.org>
parents: 730
diff changeset
1 //
c7b4139eb217 Add copyright header.
Matti Hamalainen <ccr@tnsp.org>
parents: 730
diff changeset
2 // FAPWeb - Simple Web-based Demoparty Management System
c7b4139eb217 Add copyright header.
Matti Hamalainen <ccr@tnsp.org>
parents: 730
diff changeset
3 // Common JavaScript / AJAX code
1001
ffacd904fd1f Update copyrights.
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
4 // (C) Copyright 2012-2015 Tecnic Software productions (TNSP)
755
c7b4139eb217 Add copyright header.
Matti Hamalainen <ccr@tnsp.org>
parents: 730
diff changeset
5 //
876
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
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
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
8
858
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 function jsHandleMessageBoxKeys(ev)
fa12a996e86b ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
11 {
fa12a996e86b ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
12 ev = ev || window.event;
fa12a996e86b ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
13 var key = ev.keyCode ? ev.keyCode : ev.which;
fa12a996e86b ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
14 if (key == 27)
fa12a996e86b ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
15 {
876
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
16 jsCloseMessageBox(jsMessageBoxCBCancel, jsMessageBoxCBData);
858
fa12a996e86b ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
17 return false;
fa12a996e86b ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
18 }
fa12a996e86b ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
19 else
fa12a996e86b ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
20 return true;
fa12a996e86b ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
21 }
755
c7b4139eb217 Add copyright header.
Matti Hamalainen <ccr@tnsp.org>
parents: 730
diff changeset
22
c7b4139eb217 Add copyright header.
Matti Hamalainen <ccr@tnsp.org>
parents: 730
diff changeset
23
876
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
24 function jsSetMessageBoxCBs(cb_ok, cb_cancel, cb_data)
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
25 {
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
26 jsMessageBoxCBOK = cb_ok;
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
27 jsMessageBoxCBCancel = cb_cancel;
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
28 jsMessageBoxCBData = cb_data;
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
29 }
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
30
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
31
728
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 function jsCloseMessageBox(callback, cb_data)
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 {
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 var nitem = document.getElementById("messageBox");
858
fa12a996e86b ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
35 if (nitem)
728
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 {
858
fa12a996e86b ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
37 document.onkeydown = null;
876
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
38 jsSetMessageBoxCBs(null, null, null);
858
fa12a996e86b ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
39
fa12a996e86b ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
40 if (nitem.style.display != "none")
fa12a996e86b ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
41 {
fa12a996e86b ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
42 nitem.style.display = "none";
fa12a996e86b ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
43
fa12a996e86b ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
44 if (callback && typeof(callback) === "function")
fa12a996e86b ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
45 callback(cb_data);
fa12a996e86b ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
46 }
728
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
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 function jsMessageBox(msg)
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 {
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 var nitem = document.getElementById("messageBox");
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 if (nitem)
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 {
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 nitem.innerHTML = "<div class='messageBoxInner'>"+ msg +
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 "<div class='messageBoxControls'>"+
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 "<input id='msgBoxConfirmClose' type='button' value=' OK '>"+
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 "</div></div>";
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60
858
fa12a996e86b ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
61 document.onkeydown = jsHandleMessageBoxKeys;
876
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
62 jsSetMessageBoxCBs(null, null, null);
858
fa12a996e86b ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
63
728
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 var elem = document.getElementById("msgBoxConfirmClose");
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 elem.onclick = function () { jsCloseMessageBox(0, 0); }
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 nitem.style.display = "block";
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
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71
857
70a8d52a8d00 Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 851
diff changeset
72 function jsErrorMessageBox(msg)
70a8d52a8d00 Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 851
diff changeset
73 {
859
16cbfb3e7cd4 Change error message box title.
Matti Hamalainen <ccr@tnsp.org>
parents: 858
diff changeset
74 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
75 }
70a8d52a8d00 Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 851
diff changeset
76
70a8d52a8d00 Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 851
diff changeset
77
865
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
78 function jsTitleMessageBox(title, msg)
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
79 {
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
80 jsMessageBox("<h1>"+title+"</h1><div>"+msg+"</div>");
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
81 }
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
82
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
83
728
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 function jsConfirmBox(msg, cb_ok, cb_cancel, cb_data)
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 var nitem = document.getElementById("messageBox");
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 if (nitem)
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 {
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 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
90 "<div class='messageBoxControls'>"+
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 "<input id='msgBoxConfirmCancel' type='button' value=' Cancel '>"+
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 "<input id='msgBoxConfirmOK' type='button' value=' OK '>"+
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 "</div></div>";
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94
858
fa12a996e86b ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
95 document.onkeydown = jsHandleMessageBoxKeys;
876
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
96 jsSetMessageBoxCBs(cb_ok, cb_cancel, cb_data);
858
fa12a996e86b ESC handling for message boxes.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
97
728
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 var elem = document.getElementById("msgBoxConfirmCancel");
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 elem.onclick = function () { jsCloseMessageBox(cb_cancel, cb_data); }
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 elem = document.getElementById("msgBoxConfirmOK");
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 elem.onclick = function () { jsCloseMessageBox(cb_ok, cb_data); }
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 nitem.style.display = "block";
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
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108
826
8bee2554d95e Rename one javascript function.
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
109 function jsStatusMsg(msg)
728
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 {
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 var nitem = document.getElementById("nstatus");
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 if (nitem) nstatus.innerHTML = msg;
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
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 function strtrim(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 if (!str || str == null)
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 return "";
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 return str.replace(/^\s+|\s+$/g,'')
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
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 function strencode(str)
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 {
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 return encodeURIComponent(str);
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 jsCreateXMLRequest()
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 var req;
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 if (window.XMLHttpRequest)
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 // Modern browsers
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 req = new XMLHttpRequest();
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 else
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 // Old IE versions
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 req = new ActiveXObject("Microsoft.XMLHTTP");
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 return req;
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 //
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 // Function for creating AJAX POST request arguments list based
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 // 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
150 // 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
151 //
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 var lastPostArgs = Object();
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 function jsMakePostArgs(fields, fprefix, fsuffix, nofail)
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 {
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 var res = [];
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 lastPostArgs = Object();
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 for (var id in fields)
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 var elname = fprefix + id + fsuffix;
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 switch (fields[id])
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 {
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 case 4:
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 elname += "Sel";
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 break;
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
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 var elem = document.getElementById(elname);
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 if (!elem && !nofail)
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 {
857
70a8d52a8d00 Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 851
diff changeset
171 jsErrorMessageBox("No such DOM element '"+ elname +"'.");
728
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 return "";
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
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 if (elem)
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 switch (fields[id])
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 {
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 case 1:
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 var vstr = strtrim(elem.value);
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 res.push(id+"="+strencode(vstr));
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 lastPostArgs[id] = vstr;
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 break;
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 case 2:
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 var vint = parseInt(strtrim(elem.value));
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 res.push(id+"="+vint);
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 lastPostArgs[id] = vint;
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 break;
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 case 3:
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 res.push(id+"="+(elem.checked ? "1" : "0"));
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 lastPostArgs[id] = elem.checked;
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 break;
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 case 4:
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 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
198 res.push(id+"="+vval);
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 lastPostArgs[id] = vval;
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 break;
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 default:
857
70a8d52a8d00 Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 851
diff changeset
203 jsErrorMessageBox("Unsupported field type in "+ elname);
728
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 return "";
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 }
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 return res.join("&");
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
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 function jsGetValue(elname, eltype)
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 {
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 var elem = document.getElementById(elname);
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 if (!elem)
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 {
857
70a8d52a8d00 Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 851
diff changeset
217 jsErrorMessageBox("No such DOM element '"+ 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 switch (eltype)
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 {
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 case 1:
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 var vstr = strtrim(elem.value);
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 return strencode(vstr);
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 case 2:
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 var vint = parseInt(strtrim(elem.value));
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 return vint;
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 case 3:
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 return elem.checked ? "1" : "0";
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 case 4:
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235 if (elem.selectedIndex != -1)
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 return elem.options[elem.selectedIndex].value;
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 else
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 return null;
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 default:
857
70a8d52a8d00 Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 851
diff changeset
241 jsErrorMessageBox("Unsupported field type in "+ elname);
728
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 return "";
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 }
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245
730
c71948773f03 Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents: 728
diff changeset
246
c71948773f03 Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents: 728
diff changeset
247 function jsShowPreviewImage(file)
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 var nitem = document.getElementById("messageBox");
c71948773f03 Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents: 728
diff changeset
250 if (nitem)
c71948773f03 Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents: 728
diff changeset
251 {
785
7735f97b2bbf Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents: 755
diff changeset
252 nitem.innerHTML = "<div class='imageBoxInner'>"+
7735f97b2bbf Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents: 755
diff changeset
253 "<img src='"+file+"' alt='"+file+"' />"+
730
c71948773f03 Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents: 728
diff changeset
254 "</div>";
c71948773f03 Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents: 728
diff changeset
255
785
7735f97b2bbf Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents: 755
diff changeset
256 var elem = document.getElementById("messageBox");
730
c71948773f03 Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents: 728
diff changeset
257 elem.onclick = function () { jsCloseMessageBox(0, 0); }
c71948773f03 Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents: 728
diff changeset
258
c71948773f03 Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents: 728
diff changeset
259 nitem.style.display = "block";
785
7735f97b2bbf Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents: 755
diff changeset
260
7735f97b2bbf Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents: 755
diff changeset
261 return false;
730
c71948773f03 Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents: 728
diff changeset
262 }
785
7735f97b2bbf Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents: 755
diff changeset
263
7735f97b2bbf Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents: 755
diff changeset
264 return true;
730
c71948773f03 Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents: 728
diff changeset
265 }
842
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
8ec53995e64d Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
268 function jsFormatSize(bytes)
8ec53995e64d Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
269 {
8ec53995e64d Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
270 var suffixes = ["Bytes", "KiB", "MiB"];
8ec53995e64d Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
271 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
272 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
273 }
8ec53995e64d Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
274
8ec53995e64d Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
275
851
a385ac651d22 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 842
diff changeset
276 function jsStartFileUpload(formID, formTarget, fileSelID, fileMaxSize, fileCallback)
842
8ec53995e64d Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
277 {
857
70a8d52a8d00 Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 851
diff changeset
278 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
279 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
280 {
893
43fa1c4c783f Clarify error message.
Matti Hamalainen <ccr@tnsp.org>
parents: 876
diff changeset
281 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
282 return;
70a8d52a8d00 Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 851
diff changeset
283 }
842
8ec53995e64d Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
284
851
a385ac651d22 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 842
diff changeset
285 if (formFile.size > fileMaxSize)
a385ac651d22 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 842
diff changeset
286 {
916
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
287 jsErrorMessageBox("File size exceeds "+ jsFormatSize(fileMaxSize) +".");
851
a385ac651d22 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 842
diff changeset
288 return;
a385ac651d22 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 842
diff changeset
289 }
842
8ec53995e64d Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
290
916
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
291 var filename = formFile.name;
851
a385ac651d22 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 842
diff changeset
292 var formElem = document.getElementById(formID);
a385ac651d22 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 842
diff changeset
293 if (!formElem)
a385ac651d22 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 842
diff changeset
294 {
857
70a8d52a8d00 Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 851
diff changeset
295 jsErrorMessageBox("File upload form '"+ formID +"' element not found!");
851
a385ac651d22 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 842
diff changeset
296 return;
a385ac651d22 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 842
diff changeset
297 }
842
8ec53995e64d Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
298
851
a385ac651d22 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 842
diff changeset
299 var formData = new FormData(formElem);
842
8ec53995e64d Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
300 var req = jsCreateXMLRequest();
916
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
301 req.upload.addEventListener("progress", function(e)
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
302 {
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
303 if (e.lengthComputable)
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
304 {
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
305 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
306 if (complete < 100)
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
307 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
308 else
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
309 jsStatusMsg("Upload ["+filename+"] finished ...");
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
310 }
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
311 }, false);
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
312 req.addEventListener("error", function(e)
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
313 {
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
314 jsErrorMessageBox("Error occured while uploading "+filename);
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
315 }, false);
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
316 req.addEventListener("abort", function(e)
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
317 {
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
318 jsStatusMsg("Upload of '"+filename+"' aborted.");
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
319 }, false);
865
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
320
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
321 req.onreadystatechange = function()
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
322 {
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
323 if (req.readyState == 4)
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
324 {
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
325 switch (req.status)
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
326 {
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
327 case 902:
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
328 jsStatusMsg(req.statusText);
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
329 jsMessageBox(req.responseText);
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
330 break;
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
331
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
332 case 903:
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
333 {
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
334 var nitem = document.getElementById("messageBox");
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
335 if (nitem)
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
336 {
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
337 nitem.innerHTML = "<div class='messageBoxInner'>"+ req.responseText +
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
338 "<div class='messageBoxControls'>"+
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
339 "</div></div>";
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
340 nitem.style.display = "block";
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
341 }
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
342 }
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
343 break;
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
344
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
345 case 200:
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
346 if (fileCallback)
916
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
347 {
1067
82ecea33c477 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1001
diff changeset
348 var tid = setTimeout(function(qtid)
916
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
349 {
1067
82ecea33c477 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1001
diff changeset
350 jsRemoveUploadCB(qtid);
916
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
351 setTimeout(fileCallback, 10);
955
f931fd35136c Megapatch.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
352 //jsTitleMessageBox("File upload", req.responseText);
1067
82ecea33c477 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1001
diff changeset
353 }, 10, qtid);
916
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
354 jsUploadCBS.push(tid);
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
355 }
865
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
356 break;
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
357
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
358 default:
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
359 jsStatusMsg("["+req.status+" - "+req.statusText+"] "+ req.responseText);
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
360 break;
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
361 }
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
362 }
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
363 }
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
364
863
1a2ec2f85a97 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 862
diff changeset
365 req.open("POST", formTarget);
851
a385ac651d22 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 842
diff changeset
366 req.send(formData);
842
8ec53995e64d Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
367 }
8ec53995e64d Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
368
8ec53995e64d Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
369
916
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
370 function jsCancelUploadCBS()
842
8ec53995e64d Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
371 {
916
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
372 if (jsUploadCBS.length > 0)
842
8ec53995e64d Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
373 {
916
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
374 for (var tid in jsUploadCBS)
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
375 clearTimeout(tid);
842
8ec53995e64d Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
376 }
8ec53995e64d Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
377 }
8ec53995e64d Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
378
8ec53995e64d Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
379
916
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
380 function jsRemoveUploadCB(tid)
842
8ec53995e64d Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
381 {
916
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
382 var index = jsUploadCBS.indexOf(tid);
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
383 if (index >= 0)
42c3fbca0d86 Possibly address concurrency / switching tabs while uploading.
Matti Hamalainen <ccr@tnsp.org>
parents: 893
diff changeset
384 jsUploadCBS.splice(index, 1);
842
8ec53995e64d Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
385 }