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
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
c7b4139eb217 Add copyright header.
Matti Hamalainen <ccr@tnsp.org>
parents: 730
diff changeset
4 // (C) Copyright 2012-2014 Tecnic Software productions (TNSP)
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;
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
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
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
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
c7b4139eb217 Add copyright header.
Matti Hamalainen <ccr@tnsp.org>
parents: 730
diff changeset
21
c7b4139eb217 Add copyright header.
Matti Hamalainen <ccr@tnsp.org>
parents: 730
diff changeset
22
876
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
23 function jsSetMessageBoxCBs(cb_ok, cb_cancel, cb_data)
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
24 {
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
25 jsMessageBoxCBOK = cb_ok;
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
26 jsMessageBoxCBCancel = cb_cancel;
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
27 jsMessageBoxCBData = cb_data;
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
28 }
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
29
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
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
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
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
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
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
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
77 function jsTitleMessageBox(title, msg)
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
78 {
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
79 jsMessageBox("<h1>"+title+"</h1><div>"+msg+"</div>");
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
80 }
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
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
a397d2be6d53 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 865
diff changeset
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
a385ac651d22 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 842
diff changeset
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
43fa1c4c783f Clarify error message.
Matti Hamalainen <ccr@tnsp.org>
parents: 876
diff changeset
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
a385ac651d22 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 842
diff changeset
284 if (formFile.size > fileMaxSize)
a385ac651d22 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 842
diff changeset
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
a385ac651d22 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 842
diff changeset
287 return;
a385ac651d22 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 842
diff changeset
288 }
842
8ec53995e64d Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
289
851
a385ac651d22 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 842
diff changeset
290 var formElem = document.getElementById(formID);
a385ac651d22 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 842
diff changeset
291 if (!formElem)
a385ac651d22 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 842
diff changeset
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
a385ac651d22 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 842
diff changeset
294 return;
a385ac651d22 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 842
diff changeset
295 }
842
8ec53995e64d Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
296
851
a385ac651d22 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 842
diff changeset
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
1a2ec2f85a97 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 862
diff changeset
299 req.upload.addEventListener("progress", jsUploadProgress, false);
1a2ec2f85a97 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 862
diff changeset
300 req.addEventListener("error", jsUploadError, false);
1a2ec2f85a97 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 862
diff changeset
301 req.addEventListener("abort", jsUploadAbort, false);
865
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
302
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
303 req.onreadystatechange = function()
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
304 {
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
305 if (req.readyState == 4)
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
306 {
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
307 switch (req.status)
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
308 {
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
309 case 902:
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
310 jsStatusMsg(req.statusText);
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
311 jsMessageBox(req.responseText);
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
312 break;
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
313
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
314 case 903:
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
315 {
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
316 var nitem = document.getElementById("messageBox");
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
317 if (nitem)
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
318 {
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
319 nitem.innerHTML = "<div class='messageBoxInner'>"+ req.responseText +
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
320 "<div class='messageBoxControls'>"+
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
321 "</div></div>";
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
322 nitem.style.display = "block";
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
323 }
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 break;
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 200:
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
328 if (fileCallback)
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
329 setTimeout(fileCallback, 1);
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
330
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
331 jsTitleMessageBox("File upload", req.responseText);
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
332 break;
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 default:
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
335 jsStatusMsg("["+req.status+" - "+req.statusText+"] "+ req.responseText);
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
336 break;
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
337 }
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
338 }
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
339 }
80f6f31d3711 File upload fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
340
863
1a2ec2f85a97 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 862
diff changeset
341 req.open("POST", formTarget);
851
a385ac651d22 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 842
diff changeset
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
a385ac651d22 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 842
diff changeset
367 jsStatusMsg("File upload aborted.");
842
8ec53995e64d Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
368 }