]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
if favor/disfavor submitted through ajax, return micro-html of form
authorEvan Prodromou <evan@controlyourself.ca>
Thu, 18 Sep 2008 13:56:08 +0000 (09:56 -0400)
committerEvan Prodromou <evan@controlyourself.ca>
Thu, 18 Sep 2008 13:56:08 +0000 (09:56 -0400)
darcs-hash:20080918135608-5ed1f-d753cb01f96e04871eb4f503ccd258674a03623a.gz

actions/disfavor.php
actions/favor.php
js/util.js
lib/util.php

index 6f4a078862076c4f3b3c16a9293f1cb757c4479c..ef01e891f83bcd10c89c9959e1f63f09a5b3635e 100644 (file)
@@ -64,9 +64,18 @@ class DisfavorAction extends Action {
                        return;
                }
 
-               # XXX: ajax response
-
-               common_redirect(common_local_url('showfavorites',
-                                                                                array('nickname' => $user->nickname)));
+               if ($this->boolean('ajax')) {
+                       common_start_html('text/xml');
+                       common_element_start('head');
+                       common_element('title', _('Favor'));
+                       common_element_end('head');
+                       common_element_start('body');
+                       common_favor_form($notice);
+                       common_element_end('body');
+                       common_element_end('html');
+               } else {
+                       common_redirect(common_local_url('showfavorites',
+                                                                                        array('nickname' => $user->nickname)));
+               }
        }
 }
\ No newline at end of file
index 10ad6b809df929707f65b47f9858cd22ac7f9eaa..142d83ae1f0a180f9735d2221098ac4113ade78b 100644 (file)
@@ -63,8 +63,19 @@ class FavorAction extends Action {
 
                $this->notify($fave, $notice, $user);
 
-               common_redirect(common_local_url('showfavorites',
-                                                                                array('nickname' => $user->nickname)));
+               if ($this->boolean('ajax')) {
+                       common_start_html('text/xml');
+                       common_element_start('head');
+                       common_element('title', _('Disfavor'));
+                       common_element_end('head');
+                       common_element_start('body');
+                       common_disfavor_form($notice);
+                       common_element_end('body');
+                       common_element_end('html');
+               } else {
+                       common_redirect(common_local_url('showfavorites',
+                                                                                        array('nickname' => $user->nickname)));
+               }
        }
 
        function notify($fave, $notice, $user) {
index d5e1c872001052424f97481853d3243a07f2d092..9f66e393ca55d88f46401d30ea2648827638e56a 100644 (file)
@@ -68,9 +68,20 @@ $(document).ready(function(){
                     var id = new_form.id.replace('favor', 'disfavor');
                     $('form#'+id).replace(new_form);
                }};
-          
+
+     function addAjaxHidden(form) {
+          ajax = document.newElement('input');
+          ajax.addAttribute('type', 'hidden');
+          ajax.addAttribute('name', 'ajax');
+          ajax.addAttribute('value', 1);
+          form.appendChild(ajax);
+     }
+     
      $("form.favor").ajaxForm(favoptions);
-     $("form.disfavor").ajaxForm(disoptions);          
+     $("form.disfavor").ajaxForm(disoptions);
+     
+     $("form.favor").each(addAjaxHidden);
+     $("form.disfavor").each(addAjaxHidden);          
 });
 
 function doreply(nick) {
index 69fe2a89841a77eca610d33646f5358b85adaa83..48dd1a1b4a075fd106746545d33174854c3eb6d2 100644 (file)
@@ -151,34 +151,11 @@ function common_init_language() {
 define('PAGE_TYPE_PREFS', 'text/html,application/xhtml+xml,application/xml;q=0.3,text/xml;q=0.2');
 
 function common_show_header($pagetitle, $callable=NULL, $data=NULL, $headercall=NULL) {
+       
        global $config, $xw;
 
-       $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : NULL;
-
-       # XXX: allow content negotiation for RDF, RSS, or XRDS
-
-       $type = common_negotiate_type(common_accept_to_prefs($httpaccept),
-                                                                 common_accept_to_prefs(PAGE_TYPE_PREFS));
-
-       if (!$type) {
-               common_user_error(_('This page is not available in a media type you accept'), 406);
-               exit(0);
-       }
-
-       header('Content-Type: '.$type);
-
-       common_start_xml('html',
-                                        '-//W3C//DTD XHTML 1.0 Strict//EN',
-                                        'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd');
-
-       # FIXME: correct language for interface
-
-       $language = common_language();
-
-       common_element_start('html', array('xmlns' => 'http://www.w3.org/1999/xhtml',
-                                                                          'xml:lang' => $language,
-                                                                          'lang' => $language));
-
+       common_start_html();
+       
        common_element_start('head');
        common_element('title', NULL,
                                   $pagetitle . " - " . $config['site']['name']);
@@ -252,6 +229,37 @@ function common_show_header($pagetitle, $callable=NULL, $data=NULL, $headercall=
        common_element_start('div', array('id' => 'content'));
 }
 
+function common_start_html($type=NULL) {
+       
+       if (!$type) {
+               $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : NULL;
+               
+               # XXX: allow content negotiation for RDF, RSS, or XRDS
+               
+               $type = common_negotiate_type(common_accept_to_prefs($httpaccept),
+                                                                         common_accept_to_prefs(PAGE_TYPE_PREFS));
+               
+               if (!$type) {
+                       common_user_error(_('This page is not available in a media type you accept'), 406);
+                       exit(0);
+               }
+       }
+       
+       header('Content-Type: '.$type);
+
+       common_start_xml('html',
+                                        '-//W3C//DTD XHTML 1.0 Strict//EN',
+                                        'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd');
+
+       # FIXME: correct language for interface
+
+       $language = common_language();
+
+       common_element_start('html', array('xmlns' => 'http://www.w3.org/1999/xhtml',
+                                                                          'xml:lang' => $language,
+                                                                          'lang' => $language));
+}
+
 function common_show_footer() {
        global $xw, $config;
        common_element_end('div'); # content div