Mercurial > hg > fapweb
annotate ajax.js @ 857:70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 26 Nov 2014 10:02:41 +0200 |
parents | a385ac651d22 |
children | fa12a996e86b |
rev | line source |
---|---|
755 | 1 // |
2 // FAPWeb - Simple Web-based Demoparty Management System | |
3 // Common JavaScript / AJAX code | |
4 // (C) Copyright 2012-2014 Tecnic Software productions (TNSP) | |
5 // | |
6 | |
7 | |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 function jsCloseMessageBox(callback, cb_data) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 var nitem = document.getElementById("messageBox"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 if (nitem && nitem.style.display != "none") |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 nitem.style.display = "none"; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 if (callback && typeof(callback) === "function") |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 callback(cb_data); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
21 function jsMessageBox(msg) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 var nitem = document.getElementById("messageBox"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 if (nitem) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 nitem.innerHTML = "<div class='messageBoxInner'>"+ msg + |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 "<div class='messageBoxControls'>"+ |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 "<input id='msgBoxConfirmClose' type='button' value=' OK '>"+ |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 "</div></div>"; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
30 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 var elem = document.getElementById("msgBoxConfirmClose"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 elem.onclick = function () { jsCloseMessageBox(0, 0); } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
34 nitem.style.display = "block"; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
39 function jsErrorMessageBox(msg) |
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
40 { |
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
41 jsMessageBox("<h1>An error occured</h1><div>"+msg+"</div>"); |
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
42 } |
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
43 |
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
44 |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 function jsConfirmBox(msg, cb_ok, cb_cancel, cb_data) |
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 var nitem = document.getElementById("messageBox"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 if (nitem) |
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 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
|
51 "<div class='messageBoxControls'>"+ |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 "<input id='msgBoxConfirmCancel' type='button' value=' Cancel '>"+ |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 "<input id='msgBoxConfirmOK' type='button' value=' OK '>"+ |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
54 "</div></div>"; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
56 var elem = document.getElementById("msgBoxConfirmCancel"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 elem.onclick = function () { jsCloseMessageBox(cb_cancel, cb_data); } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 elem = document.getElementById("msgBoxConfirmOK"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 elem.onclick = function () { jsCloseMessageBox(cb_ok, cb_data); } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
61 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
62 nitem.style.display = "block"; |
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 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
66 |
826
8bee2554d95e
Rename one javascript function.
Matti Hamalainen <ccr@tnsp.org>
parents:
785
diff
changeset
|
67 function jsStatusMsg(msg) |
728
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 var nitem = document.getElementById("nstatus"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
70 if (nitem) nstatus.innerHTML = msg; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
71 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
72 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
73 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
74 function strtrim(str) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
75 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
76 if (!str || str == null) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
77 return ""; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
78 return str.replace(/^\s+|\s+$/g,'') |
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 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
81 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
82 function strencode(str) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
84 return encodeURIComponent(str); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
85 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
86 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
87 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
88 function jsCreateXMLRequest() |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
89 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
90 var req; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
91 if (window.XMLHttpRequest) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
92 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
93 // Modern browsers |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
94 req = new XMLHttpRequest(); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
95 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
96 else |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
97 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 // Old IE versions |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
99 req = new ActiveXObject("Microsoft.XMLHTTP"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
100 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
101 return req; |
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 |
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 // Function for creating AJAX POST request arguments list based |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
107 // 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
|
108 // 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
|
109 // |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
110 var lastPostArgs = Object(); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
111 function jsMakePostArgs(fields, fprefix, fsuffix, nofail) |
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 var res = []; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
114 lastPostArgs = Object(); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
115 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
116 for (var id in fields) |
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 var elname = fprefix + id + fsuffix; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 switch (fields[id]) |
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 case 4: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
122 elname += "Sel"; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
123 break; |
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 var elem = document.getElementById(elname); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
127 if (!elem && !nofail) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
128 { |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
129 jsErrorMessageBox("No such DOM element '"+ elname +"'."); |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 return ""; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
131 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
133 if (elem) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
134 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
135 switch (fields[id]) |
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 case 1: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
138 var vstr = strtrim(elem.value); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
139 res.push(id+"="+strencode(vstr)); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 lastPostArgs[id] = vstr; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
141 break; |
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 case 2: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 var vint = parseInt(strtrim(elem.value)); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 res.push(id+"="+vint); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
146 lastPostArgs[id] = vint; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 break; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
148 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
149 case 3: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 res.push(id+"="+(elem.checked ? "1" : "0")); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
151 lastPostArgs[id] = elem.checked; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
152 break; |
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 case 4: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
155 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
|
156 res.push(id+"="+vval); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
157 lastPostArgs[id] = vval; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
158 break; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
159 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
160 default: |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
161 jsErrorMessageBox("Unsupported field type in "+ elname); |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
162 return ""; |
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 } |
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 return res.join("&"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
167 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
168 |
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 function jsGetValue(elname, eltype) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
171 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
172 var elem = document.getElementById(elname); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
173 if (!elem) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
174 { |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
175 jsErrorMessageBox("No such DOM element '"+ elname +"'."); |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
176 return ""; |
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 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
179 switch (eltype) |
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 1: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 var vstr = strtrim(elem.value); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 return strencode(vstr); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
184 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
185 case 2: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
186 var vint = parseInt(strtrim(elem.value)); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 return vint; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
188 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
189 case 3: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
190 return elem.checked ? "1" : "0"; |
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 if (elem.selectedIndex != -1) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
194 return elem.options[elem.selectedIndex].value; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
195 else |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 return null; |
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 |
730
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
204 |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
205 function jsShowPreviewImage(file) |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
206 { |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
207 var nitem = document.getElementById("messageBox"); |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
208 if (nitem) |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
209 { |
785
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
210 nitem.innerHTML = "<div class='imageBoxInner'>"+ |
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
211 "<img src='"+file+"' alt='"+file+"' />"+ |
730
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
212 "</div>"; |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
213 |
785
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
214 var elem = document.getElementById("messageBox"); |
730
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
215 elem.onclick = function () { jsCloseMessageBox(0, 0); } |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
216 |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
217 nitem.style.display = "block"; |
785
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
218 |
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
219 return false; |
730
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
220 } |
785
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
221 |
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
222 return true; |
730
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
223 } |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
224 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
225 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
226 function jsFormatSize(bytes) |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
227 { |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
228 var suffixes = ["Bytes", "KiB", "MiB"]; |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
229 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
|
230 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
|
231 } |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
232 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
233 |
851 | 234 function jsStartFileUpload(formID, formTarget, fileSelID, fileMaxSize, fileCallback) |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
235 { |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
236 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
|
237 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
|
238 { |
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
239 jsErrorMessageBox("No file selected."); |
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
240 return; |
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
241 } |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
242 |
851 | 243 if (formFile.size > fileMaxSize) |
244 { | |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
245 jsErrorMessageBox("File size exceeds "+ jsFormatSize(maxSize) +"."); |
851 | 246 return; |
247 } | |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
248 |
851 | 249 var formElem = document.getElementById(formID); |
250 if (!formElem) | |
251 { | |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
252 jsErrorMessageBox("File upload form '"+ formID +"' element not found!"); |
851 | 253 return; |
254 } | |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
255 |
851 | 256 var formData = new FormData(formElem); |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
257 var req = jsCreateXMLRequest(); |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
258 req.upload.addEventListener('progress', jsUploadProgress, false); |
851 | 259 req.addEventListener('load', function(e) |
260 { | |
261 }, false); | |
262 | |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
263 req.addEventListener('error', jsUploadError, false); |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
264 req.addEventListener('abort', jsUploadAbort, false); |
851 | 265 req.open('POST', formTarget); |
266 req.send(formData); | |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
267 } |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
268 |
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 function jsUploadProgress(e) |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
271 { |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
272 if (e.lengthComputable) |
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 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
|
275 if (complete < 100) |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
276 jsStatusMsg("Uploaded "+ complete.toString() +'%, '+ jsFormatSize(e.loaded)); |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
277 else |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
278 jsStatusMsg("Upload finished ..."); |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
279 } |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
280 } |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
281 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
282 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
283 function jsUploadError(e) |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
284 { |
857
70a8d52a8d00
Add new helper function jsErrorMessageBox() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
851
diff
changeset
|
285 jsErrorMessageBox("Error occured while uploading: "); |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
286 } |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
287 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
288 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
289 function jsUploadAbort(e) |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
290 { |
851 | 291 jsStatusMsg("File upload aborted."); |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
292 } |