]>
Commit | Line | Data |
---|---|---|
391f51ff CP |
1 | qwebirc.ui.FeedbackPane = new Class({ |
2 | Implements: [Events], | |
3 | initialize: function(parent) { | |
17f40fd9 | 4 | this.textboxVisible = false; |
0239618f CP |
5 | var delayfn = function() { parent.set("html", "<div class=\"loading\">Loading. . .</div>"); }; |
6 | var cb = delayfn.delay(500); | |
17f40fd9 CP |
7 | |
8 | this.addEvent("select", this.onSelect); | |
9 | ||
66bf0806 | 10 | var r = new Request.HTML({url: "panes/feedback.html", update: parent, onSuccess: function() { |
0239618f | 11 | $clear(cb); |
391f51ff CP |
12 | parent.getElement("input[class=close]").addEvent("click", function() { |
13 | this.fireEvent("close"); | |
14 | }.bind(this)); | |
15 | parent.getElement("input[class=close2]").addEvent("click", function() { | |
16 | this.fireEvent("close"); | |
17 | }.bind(this)); | |
18 | ||
19 | var textbox = parent.getElement("textarea"); | |
17f40fd9 | 20 | this.textbox = textbox; |
391f51ff CP |
21 | parent.getElement("input[class=submitfeedback]").addEvent("click", function() { |
22 | this.sendFeedback(parent, textbox, textbox.value); | |
23 | }.bind(this)); | |
24 | ||
17f40fd9 CP |
25 | this.textboxVisible = true; |
26 | this.onSelect(); | |
391f51ff CP |
27 | }.bind(this)}); |
28 | r.get(); | |
29 | }, | |
17f40fd9 CP |
30 | onSelect: function() { |
31 | if(this.textboxVisible) | |
32 | this.textbox.focus(); | |
33 | }, | |
391f51ff CP |
34 | sendFeedback: function(parent, textbox, text) { |
35 | text = text.replace(/^\s*/, "").replace(/\s*$/, ""); | |
36 | var mainText = parent.getElement("p[class=maintext]"); | |
37 | ||
38 | if(text.length < 25) { | |
39 | mainText.set("text", "I don't suppose you could enter a little bit more? Thanks!"); | |
40 | textbox.focus(); | |
41 | return; | |
42 | } | |
43 | ||
17f40fd9 | 44 | this.textboxVisible = false; |
391f51ff CP |
45 | var mainBody = parent.getElement("div[class=enterarea]"); |
46 | mainBody.setStyle("display", "none"); | |
47 | ||
48 | var messageBody = parent.getElement("div[class=messagearea]"); | |
49 | var messageText = parent.getElement("p[class=messagetext]"); | |
50 | var messageClose = parent.getElement("input[class=close2]"); | |
51 | ||
52 | messageText.set("text", "Submitting. . ."); | |
53 | messageBody.setStyle("display", ""); | |
54 | ||
55 | /* basic checksum to stop really lame kiddies spamming */ | |
56 | var checksum = 0; | |
6d66b5de | 57 | var esctext = encodeURIComponent(text); |
391f51ff | 58 | for(var i=0;i<text.length;i++) |
6d66b5de | 59 | checksum = ((checksum + 1) % 256) ^ (text.charCodeAt(i) % 256); |
391f51ff CP |
60 | |
61 | var r = new Request({url: "/feedback", onSuccess: function() { | |
62 | messageText.set("text", "Submitted successfully, thanks for the feedback!"); | |
63 | messageClose.setStyle("display", ""); | |
64 | }, onFailure: function() { | |
17f40fd9 | 65 | this.textboxVisible = true; |
391f51ff CP |
66 | messageBody.setStyle("display", "none"); |
67 | mainBody.setStyle("display", ""); | |
68 | mainText.set("text", "Looks like something went wrong submitting :("); | |
17f40fd9 | 69 | }.bind(this)}).send("feedback=" + text + "&c=" + checksum); |
391f51ff CP |
70 | } |
71 | }); |