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