Mercurial > hg > fapweb
annotate ajax.js @ 851:a385ac651d22
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 26 Nov 2014 00:49:23 +0200 |
parents | 8ec53995e64d |
children | 70a8d52a8d00 |
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 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 function jsConfirmBox(msg, cb_ok, cb_cancel, cb_data) |
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 var nitem = document.getElementById("messageBox"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 if (nitem) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 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
|
45 "<div class='messageBoxControls'>"+ |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 "<input id='msgBoxConfirmCancel' type='button' value=' Cancel '>"+ |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 "<input id='msgBoxConfirmOK' type='button' value=' OK '>"+ |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 "</div></div>"; |
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 var elem = document.getElementById("msgBoxConfirmCancel"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 elem.onclick = function () { jsCloseMessageBox(cb_cancel, cb_data); } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 elem = document.getElementById("msgBoxConfirmOK"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
54 elem.onclick = function () { jsCloseMessageBox(cb_ok, cb_data); } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
56 nitem.style.display = "block"; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 } |
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 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 |
826
8bee2554d95e
Rename one javascript function.
Matti Hamalainen <ccr@tnsp.org>
parents:
785
diff
changeset
|
61 function jsStatusMsg(msg) |
728
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 var nitem = document.getElementById("nstatus"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 if (nitem) nstatus.innerHTML = msg; |
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 |
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 function strtrim(str) |
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 if (!str || str == null) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
71 return ""; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
72 return str.replace(/^\s+|\s+$/g,'') |
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 |
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 function strencode(str) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
77 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
78 return encodeURIComponent(str); |
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 jsCreateXMLRequest() |
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 var req; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
85 if (window.XMLHttpRequest) |
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 // Modern browsers |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
88 req = new XMLHttpRequest(); |
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 else |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
91 { |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
92 // Old IE versions |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
93 req = new ActiveXObject("Microsoft.XMLHTTP"); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
94 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
95 return req; |
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 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 |
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 // Function for creating AJAX POST request arguments list based |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
101 // 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
|
102 // 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
|
103 // |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
104 var lastPostArgs = Object(); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
105 function jsMakePostArgs(fields, fprefix, fsuffix, nofail) |
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 res = []; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
108 lastPostArgs = Object(); |
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 for (var id in fields) |
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 var elname = fprefix + id + fsuffix; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
113 switch (fields[id]) |
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 case 4: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
116 elname += "Sel"; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
117 break; |
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 var elem = document.getElementById(elname); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
121 if (!elem && !nofail) |
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 jsMessageBox("No such DOM element '"+ elname +"'."); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
124 return ""; |
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 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
127 if (elem) |
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 switch (fields[id]) |
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 case 1: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 var vstr = strtrim(elem.value); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
133 res.push(id+"="+strencode(vstr)); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
134 lastPostArgs[id] = vstr; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
135 break; |
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 2: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
138 var vint = parseInt(strtrim(elem.value)); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
139 res.push(id+"="+vint); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 lastPostArgs[id] = vint; |
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 3: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 res.push(id+"="+(elem.checked ? "1" : "0")); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 lastPostArgs[id] = elem.checked; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
146 break; |
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 case 4: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
149 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
|
150 res.push(id+"="+vval); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
151 lastPostArgs[id] = vval; |
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 default: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
155 jsMessageBox("Unsupported field type in "+ elname); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
156 return ""; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
157 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
158 } |
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 return res.join("&"); |
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 |
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 function jsGetValue(elname, eltype) |
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 var elem = document.getElementById(elname); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
167 if (!elem) |
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 jsMessageBox("No such DOM element '"+ elname +"'."); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
170 return ""; |
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 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
173 switch (eltype) |
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 return strencode(vstr); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
178 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
179 case 2: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
180 var vint = parseInt(strtrim(elem.value)); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
181 return vint; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 case 3: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
184 return elem.checked ? "1" : "0"; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
185 |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
186 case 4: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 if (elem.selectedIndex != -1) |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
188 return elem.options[elem.selectedIndex].value; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
189 else |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
190 return null; |
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 default: |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
193 jsMessageBox("Unsupported field type in "+ elname); |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
194 return ""; |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
195 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 } |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
197 |
730
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
198 |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
199 function jsShowPreviewImage(file) |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
200 { |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
201 var nitem = document.getElementById("messageBox"); |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
202 if (nitem) |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
203 { |
785
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
204 nitem.innerHTML = "<div class='imageBoxInner'>"+ |
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
205 "<img src='"+file+"' alt='"+file+"' />"+ |
730
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
206 "</div>"; |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
207 |
785
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
208 var elem = document.getElementById("messageBox"); |
730
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
209 elem.onclick = function () { jsCloseMessageBox(0, 0); } |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
210 |
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
211 nitem.style.display = "block"; |
785
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
212 |
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
213 return false; |
730
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
214 } |
785
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
215 |
7735f97b2bbf
Preliminal implementation of the preview image zoom box.
Matti Hamalainen <ccr@tnsp.org>
parents:
755
diff
changeset
|
216 return true; |
730
c71948773f03
Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
217 } |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
218 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
219 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
220 function jsFormatSize(bytes) |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
221 { |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
222 var suffixes = ["Bytes", "KiB", "MiB"]; |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
223 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
|
224 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
|
225 } |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
226 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
227 |
851 | 228 function jsStartFileUpload(formID, formTarget, fileSelID, fileMaxSize, fileCallback) |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
229 { |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
230 |
851 | 231 if (formFile.size > fileMaxSize) |
232 { | |
233 jsMessageBox("File size exceeds "+ jsFormatSize(maxSize) +"."); | |
234 return; | |
235 } | |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
236 |
851 | 237 var formElem = document.getElementById(formID); |
238 if (!formElem) | |
239 { | |
240 jsMessageBox("File upload form '"+ formID +"' element not found!"); | |
241 return; | |
242 } | |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
243 |
851 | 244 var formData = new FormData(formElem); |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
245 var req = jsCreateXMLRequest(); |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
246 req.upload.addEventListener('progress', jsUploadProgress, false); |
851 | 247 req.addEventListener('load', function(e) |
248 { | |
249 }, false); | |
250 | |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
251 req.addEventListener('error', jsUploadError, false); |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
252 req.addEventListener('abort', jsUploadAbort, false); |
851 | 253 req.open('POST', formTarget); |
254 req.send(formData); | |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
255 } |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
256 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
257 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
258 function jsUploadProgress(e) |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
259 { |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
260 if (e.lengthComputable) |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
261 { |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
262 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
|
263 if (complete < 100) |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
264 jsStatusMsg("Uploaded "+ complete.toString() +'%, '+ jsFormatSize(e.loaded)); |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
265 else |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
266 jsStatusMsg("Upload finished ..."); |
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 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
271 function jsUploadError(e) |
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 jsMessageBox("Error occured while uploading."); |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
274 } |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
275 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
276 |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
277 function jsUploadAbort(e) |
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
278 { |
851 | 279 jsStatusMsg("File upload aborted."); |
842
8ec53995e64d
Preliminary javascript code for file uploads.
Matti Hamalainen <ccr@tnsp.org>
parents:
826
diff
changeset
|
280 } |