annotate ajax.js @ 865:80f6f31d3711

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