]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Added ajax responses
authorZach Copley <zach@controlyourself.ca>
Thu, 23 Apr 2009 02:17:58 +0000 (02:17 +0000)
committerZach Copley <zach@controlyourself.ca>
Thu, 23 Apr 2009 02:17:59 +0000 (02:17 +0000)
actions/newmessage.php

index 82276ff341c6e6d8ea54d033fe2588aba48e21c3..52d4899ba2d453d8012465eaa60def69458df4a2 100644 (file)
@@ -172,15 +172,54 @@ class NewmessageAction extends Action
 
         $this->notify($user, $this->other, $message);
 
-        $url = common_local_url('outbox', array('nickname' => $user->nickname));
+        if ($this->boolean('ajax')) {
+            $this->startHTML('text/xml;charset=utf-8');
+            $this->elementStart('head');
+            $this->element('title', null, _('Message sent'));
+            $this->elementEnd('head');
+            $this->elementStart('body');
+            $this->element('p', array('id' => 'command_result'),
+                sprintf(_('Direct message to %s sent'),
+                    $this->other->nickname));
+            $this->elementEnd('body');
+            $this->elementEnd('html');
+        } else {
+            $url = common_local_url('outbox',
+                array('nickname' => $user->nickname));
+            common_redirect($url, 303);
+        }
+    }
 
-        common_redirect($url, 303);
+    /**
+     * Show an Ajax-y error message
+     *
+     * Goes back to the browser, where it's shown in a popup.
+     *
+     * @param string $msg Message to show
+     *
+     * @return void
+     */
+
+    function ajaxErrorMsg($msg)
+    {
+        $this->startHTML('text/xml;charset=utf-8', true);
+        $this->elementStart('head');
+        $this->element('title', null, _('Ajax Error'));
+        $this->elementEnd('head');
+        $this->elementStart('body');
+        $this->element('p', array('id' => 'error'), $msg);
+        $this->elementEnd('body');
+        $this->elementEnd('html');
     }
 
     function showForm($msg = null)
     {
-        $this->msg = $msg;
+        if ($msg && $this->boolean('ajax')) {
+            $this->ajaxErrorMsg($msg);
+            return;
+        }
 
+        $this->msg = $msg;
         $this->showPage();
     }