Add the client code for the WinXP wizard.
[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         /*var target = xml.createNode(1, "target", "");
63         target.setAttribute("href", "https://pr0n-internal.sesse.net/webdav/upload/test/");
64         uploadTag.appendChild(target); */
65
66         xml.documentElement.appendChild(uploadTag);
67         window.external.FinalNext();
68 }
69
70 function OnCancel()
71 {
72         alert('OnCancel');
73 }
74
75 function somethingchanged()
76 {
77         var valid = true;
78         var form = document.getElementById('form1');
79         var disable_existingevent, disable_newevent;
80
81         if (form.existing.checked) {
82                 disable_existingevent = false;
83                 disable_newevent = true;
84
85                 if (form.existingevent.value == '') {
86                         valid = false;
87                 }
88         } else {
89                 disable_existingevent = true;
90                 disable_newevent = false;
91
92                 // this matches 1:1 the checks done on the server
93                 var id = form.neweventid.value;
94                 var date = form.neweventdate.value;
95                 var desc = form.neweventdesc.value;
96                 
97                 if (id.match(/^\s*$/) || !id.match(/^([a-zA-Z0-9-]+)$/)) {
98                         valid = false;
99                 }
100                 if (date.match(/^\s*$/) || date.match(/[<>&]/) || date.length > 100) {
101                         valid = false;
102                 }
103                 if (desc.match(/^\s*$/) || desc.match(/[<>&]/) || desc.length > 100) {
104                         valid = false;
105                 }
106         }
107
108         // enable/disable the "existing event" form
109         form.existingevent.disabled = disable_existingevent;
110         
111         var extexts = getElementsByClass(document, 'existingeventtext', '*');
112         for (i = 0; i < extexts.length; ++i) {
113                 extexts[i].style.color = disable_existingevent ? 'gray' : '';
114         }
115
116         // enable/disable the "new event" form
117         form.neweventid.disabled = disable_newevent;
118         form.neweventdate.disabled = disable_newevent;
119         form.neweventdesc.disabled = disable_newevent;
120
121         var netexts = getElementsByClass(document, 'neweventtext', '*');
122         for (i = 0; i < netexts.length; ++i) {
123                 netexts[i].style.color = disable_newevent ? 'gray' : '';
124         }
125
126         // and finally, the "who" form
127         var disable_who;
128         if (form.me.checked) {
129                 disable_who = true;
130         } else {
131                 disable_who = false;
132         
133                 var who = form.other.value;
134                 if (who.match(/^\s*$/) || who.match(/[<>&]/) || who.length > 100) {
135                         valid = false;
136                 }
137         }
138
139         form.other.disabled = disable_who;
140
141         var whotexts = getElementsByClass(document, 'whotext', '*');
142         for (i = 0; i < whotexts.length; ++i) {
143                 whotexts[i].style.color = disable_who ? 'gray' : '';
144         }
145
146
147         window.external.SetWizardButtons(true, valid, false);
148 }
149
150 function getElementsByClass(node,searchClass,tag) {
151         var classElements = new Array();
152         var els = node.getElementsByTagName(tag);
153         var elsLen = els.length;
154         for (i = 0, j = 0; i < elsLen; i++) {
155                 if (els[i].className == searchClass) {
156                         classElements[j] = els[i];
157                         j++;
158                 }
159         }
160         return classElements;
161 }
162
163 somethingchanged();