commit:fc5b9f1f68322c876b331c049749f113eb0271f7
author:Chip Black
committer:Chip Black
date:Fri May 25 13:41:37 2012 -0700
parents:4720a1f90f7d42f3611f064cc5ba3d768a92b5c6
Add post functionality
diff --git a/www/jssrc/blerg/API.js b/www/jssrc/blerg/API.js
line changes: +23/-0
index a5aa965..30dc7b5
--- a/www/jssrc/blerg/API.js
+++ b/www/jssrc/blerg/API.js
@@ -222,4 +222,27 @@ enyo.kind({
             username: blerg.API.username
         });
     },
+    post: function(data) {
+        var req = new enyo.Ajax({
+            url: baseURL + '/put',
+            method: 'POST'
+        });
+        req.response(function(inSender, inResponse) {
+            if (inResponse && inResponse.status == 'success') {
+                this.bubble('onPostSuccessful', {
+                    username: blerg.API.username,
+                    data: data
+                });
+            } else {
+                this.bubble('onPostFailed', {
+                    username: blerg.API.username,
+                    data: data
+                });
+            }
+        }.bind(this));
+        req.go({
+            username: blerg.API.username,
+            data: data
+        });
+    }
 });

diff --git a/www/jssrc/blerg/Post.js b/www/jssrc/blerg/Post.js
line changes: +13/-2
index 112a497..ee537f2
--- a/www/jssrc/blerg/Post.js
+++ b/www/jssrc/blerg/Post.js
@@ -17,7 +17,10 @@ enyo.kind({
             {name: "loginReminder", tag: "span", classes: "blerg-error", style: "margin-right: 8px; vertical-align: 60%", content: "You must log in before posting."},
             {kind: "onyx.Button", content: "Close", onclick: "closePost", classes: "onyx-negative", attributes: {tabindex: 6}},
             {name: "postButton", kind: "onyx.Button", content: "Post", onclick: "doPost", classes: "onyx-affirmative", disabled: true, attributes: {tabindex: 5}}
-        ]}
+        ]},
+        {name: "api", kind: "blerg.API",
+         onPostSuccessful: "postSuccessful",
+         onPostFailed: "postFailed"}
     ],
     create: function() {
         this.inherited(arguments);
@@ -32,7 +35,15 @@ enyo.kind({
         this.bubble('onPostVisibility', {showing: false});
     },
     doPost: function() {
-        this.bubble('onPost', {data: this.getData()});
+        this.$.api.post(this.getData());
+    },
+    postSuccessful: function() {
+        this.setData('');
+        this.closePost();
+        this.href = '#' + blerg.API.username;
+    },
+    postFailed: function() {
+        alert('Could not post!');
     },
     postVisibilityUpdate: function(inSender, inEvent) {
         if (inEvent.showing) {