Add post functionality
[blerg.git] / www / js / blerg.js
1 /* Blerg is (C) 2011 The Dominion of Awesome, and is distributed under a
2  * BSD-style license.  Please see the COPYING file for details.
3  */
4
5 LoginStatus.prototype.post = function(msg) {
6     if (!this.loggedIn) {
7         alert("You are not logged in!");
8         return;
9     }
10
11     new Ajax.Request(baseURL + '/put', {
12         parameters: {
13             username: this.username,
14             data: msg
15         },
16         onSuccess: function(r) {
17             var j = r.responseText.evalJSON();
18             if (j && j.status == 'success') {
19                 $('post.content').value = '';
20                 if (location.hash != '#' + this.username) {
21                     qlink(this.username);
22                 } else {
23                     currentPager.itemCount++;
24                     currentPager.reload();
25                 }
26             } else {
27                 alert('Post failed!');
28             }
29         }.bind(this),
30         onFailure: function(r) {
31             alert('Post failed!');
32         }
33     });
34 }
35
36 function passwd() {
37     var old_password = $('passwd.old_password').value;
38     var new_password = $('passwd.new_password').value;
39
40     new Ajax.Request(baseURL + '/passwd', {
41         parameters: {
42             username: loginStatus.username,
43             password: old_password,
44             new_password: new_password
45         },
46         onSuccess: function(r) {
47             if (r.responseJSON.status == 'success') {
48                 alert('Password changed');
49                 passwd_cancel();
50             } else {
51                 alert('Password change failed.  Your password has NOT been changed.');
52             }
53         },
54         onFailure: function(r) {
55             alert('Password change error');
56         }
57     });
58 }
59
60 function passwd_cancel() {
61     $('passwd').hide();
62     $('navigation').show();
63     urlSwitch();
64 }