Always show dates in GMT; it is the law.
[pr0n] / files / wizard.js
1 function OnBack()
2 {
3         window.external.FinalBack();
4 }
5
6 function OnNext()
7 {
8         var xml = window.external.Property("TransferManifest");
9         var files = xml.selectNodes("transfermanifest/filelist/file");
10         var form = document.getElementById('form1');
11         var vhost = ((window.location+"").split("/"))[2];
12         var evname;
13
14         for (i = 0; i < files.length; i++) {
15                 var postTag = xml.createNode(1, "post", "");
16                 postTag.setAttribute("href", "http://" + vhost + "/webdav/upload/");
17                 postTag.setAttribute("name", "image");
18
19                 // event
20                 if (form.existing.checked) {
21                         var dataTag = xml.createNode(1, "formdata", "");
22                         dataTag.setAttribute("name", "event");
23                         dataTag.text = form.existingevent.value;
24                         postTag.appendChild(dataTag);
25
26                         evname = form.existingevent.value;
27                 } else {
28                         var dataTag = xml.createNode(1, "formdata", "");
29                         dataTag.setAttribute("name", "neweventid");
30                         dataTag.text = form.neweventid.value;
31                         postTag.appendChild(dataTag);
32                         
33                         dataTag = xml.createNode(1, "formdata", "");
34                         dataTag.setAttribute("name", "neweventdate");
35                         dataTag.text = form.neweventdate.value;
36                         postTag.appendChild(dataTag);
37                         
38                         dataTag = xml.createNode(1, "formdata", "");
39                         dataTag.setAttribute("name", "neweventdesc");
40                         dataTag.text = form.neweventdesc.value;
41                         postTag.appendChild(dataTag);
42                         
43                         evname = form.neweventid.value;
44                 }
45
46                 // who took this
47                 if (form.others.checked) {
48                         var dataTag = xml.createNode(1, "formdata", "");
49                         dataTag.setAttribute("name", "takenby");
50                         dataTag.text = form.other.value;
51                         postTag.appendChild(dataTag);
52                 }
53                 
54                 // original file size (to avoid the evil resizing)
55                 dataTag = xml.createNode(1, "formdata", "");
56                 dataTag.setAttribute("name", "size");
57                 dataTag.text = files.item(i).getAttribute("size");
58                 postTag.appendChild(dataTag);
59         
60                 files.item(i).appendChild(postTag);
61         }
62
63         var uploadTag = xml.createNode(1, "uploadinfo", "");
64         var htmluiTag = xml.createNode(1, "htmlui", "");
65         htmluiTag.text = "http://" + vhost + "/" + evname + "/";
66         uploadTag.appendChild(htmluiTag);
67
68         xml.documentElement.appendChild(uploadTag);
69
70         window.external.FinalNext();
71 }
72
73 function OnCancel()
74 {
75         alert('OnCancel');
76 }
77
78 function somethingchanged()
79 {
80         var valid = true;
81         var form = document.getElementById('form1');
82         var disable_existingevent, disable_newevent;
83
84         if (form.existing.checked) {
85                 disable_existingevent = false;
86                 disable_newevent = true;
87
88                 if (form.existingevent.value == '') {
89                         valid = false;
90                 }
91         } else {
92                 disable_existingevent = true;
93                 disable_newevent = false;
94
95                 // this matches 1:1 the checks done on the server
96                 var id = form.neweventid.value;
97                 var date = form.neweventdate.value;
98                 var desc = form.neweventdesc.value;
99                 
100                 if (id.match(/^\s*$/) || !id.match(/^([a-zA-Z0-9-]+)$/)) {
101                         valid = false;
102                 }
103                 if (date.match(/^\s*$/) || date.match(/[<>&]/) || date.length > 100) {
104                         valid = false;
105                 }
106                 if (desc.match(/^\s*$/) || desc.match(/[<>&]/) || desc.length > 100) {
107                         valid = false;
108                 }
109         }
110
111         // enable/disable the "existing event" form
112         form.existingevent.disabled = disable_existingevent;
113         
114         var extexts = getElementsByClass(document, 'existingeventtext', '*');
115         for (i = 0; i < extexts.length; ++i) {
116                 extexts[i].style.color = disable_existingevent ? 'gray' : '';
117         }
118
119         // enable/disable the "new event" form
120         form.neweventid.disabled = disable_newevent;
121         form.neweventdate.disabled = disable_newevent;
122         form.neweventdesc.disabled = disable_newevent;
123
124         var netexts = getElementsByClass(document, 'neweventtext', '*');
125         for (i = 0; i < netexts.length; ++i) {
126                 netexts[i].style.color = disable_newevent ? 'gray' : '';
127         }
128
129         // and finally, the "who" form
130         var disable_who;
131         if (form.me.checked) {
132                 disable_who = true;
133         } else {
134                 disable_who = false;
135         
136                 var who = form.other.value;
137                 if (who.match(/^\s*$/) || who.match(/[<>&]/) || who.length > 100) {
138                         valid = false;
139                 }
140         }
141
142         form.other.disabled = disable_who;
143
144         var whotexts = getElementsByClass(document, 'whotext', '*');
145         for (i = 0; i < whotexts.length; ++i) {
146                 whotexts[i].style.color = disable_who ? 'gray' : '';
147         }
148
149
150         window.external.SetWizardButtons(true, valid, false);
151 }
152
153 function getElementsByClass(node,searchClass,tag) {
154         var classElements = new Array();
155         var els = node.getElementsByTagName(tag);
156         var elsLen = els.length;
157         for (i = 0, j = 0; i < elsLen; i++) {
158                 if (els[i].className == searchClass) {
159                         classElements[j] = els[i];
160                         j++;
161                 }
162         }
163         return classElements;
164 }
165
166 somethingchanged();