annotate ajax.js @ 755:c7b4139eb217

Add copyright header.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 20 Nov 2014 08:58:10 +0200
parents c71948773f03
children 7735f97b2bbf
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 //
c7b4139eb217 Add copyright header.
Matti Hamalainen <ccr@tnsp.org>
parents: 730
diff changeset
6
c7b4139eb217 Add copyright header.
Matti Hamalainen <ccr@tnsp.org>
parents: 730
diff changeset
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
8b1abca34033 Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 function statusMsg(msg)
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 {
c71948773f03 Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents: 728
diff changeset
204 nitem.innerHTML = "<img src='"+file+"' alt='"+file+"' /><br />"+
c71948773f03 Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents: 728
diff changeset
205 "<div class='messageBoxControls'>"+
c71948773f03 Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents: 728
diff changeset
206 "<input id='messageBoxClose' type='button' value=' Close '>"+
c71948773f03 Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents: 728
diff changeset
207 "</div>";
c71948773f03 Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents: 728
diff changeset
208
c71948773f03 Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents: 728
diff changeset
209 var elem = document.getElementById("messageBoxClose");
c71948773f03 Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents: 728
diff changeset
210 elem.onclick = function () { jsCloseMessageBox(0, 0); }
c71948773f03 Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents: 728
diff changeset
211
c71948773f03 Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents: 728
diff changeset
212 nitem.style.display = "block";
c71948773f03 Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents: 728
diff changeset
213 }
c71948773f03 Add preliminary preview zoom function.
Matti Hamalainen <ccr@tnsp.org>
parents: 728
diff changeset
214 }