]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
(Un)Subscribe form using ajaxForm()
authorcsarven <csarven@controlyourself.ca>
Thu, 20 Nov 2008 23:26:55 +0000 (18:26 -0500)
committercsarven <csarven@controlyourself.ca>
Thu, 20 Nov 2008 23:26:55 +0000 (18:26 -0500)
darcs-hash:20081120232655-eefa4-cf6a71e246828793d3bfa413db724ab33bc58bcf.gz

actions/showstream.php
actions/subscribe.php
actions/unsubscribe.php
js/util.js
lib/util.php
theme/default/display.css
theme/identica/display.css

index 3eae5eb0ffb3d9e0a6da940be990c2135b1769fa..419c4421ad1d1419a855d19b9a5cd5038b0b1fed 100644 (file)
@@ -174,9 +174,9 @@ class ShowstreamAction extends StreamAction {
                if ($cur) {
                        if ($cur->id != $profile->id) {
                                if ($cur->isSubscribed($profile)) {
-                                       $this->show_unsubscribe_form($profile);
+                                       common_unsubscribe_form($profile);
                                } else {
-                                       $this->show_subscribe_form($profile);
+                                       common_subscribe_form($profile);
                                }
                        }
                } else {
@@ -185,19 +185,9 @@ class ShowstreamAction extends StreamAction {
         common_element_end('li');
                
                $user = User::staticGet('id', $profile->id);
-               
-               if ($cur && $cur->id != $user->id && $cur->mutuallySubscribed($user)) {
-            common_element_start('li', array('id' => 'profile_send_a_new_message'));
-                       common_element('a', array('href' => common_local_url('newmessage', array('to' => $user->id))),
-                                                  _('Send a message'));
-            common_element_end('li');
-            if ($user->email && $user->emailnotifynudge) {
-                common_element_start('li', array('id' => 'profile_nudge'));
-                common_nudge_form($user);
-                common_element_end('li');
-            }
-               }
-        common_element_end('ul');
+               common_profile_new_message_nudge($cur, $user, $profile);
+        
+               common_element_end('ul');
                
                common_element_end('div');
 
@@ -229,20 +219,6 @@ class ShowstreamAction extends StreamAction {
                common_element_end('div');
        }
 
-       function show_subscribe_form($profile) {
-               common_element_start('form', array('id' => 'subscribe', 'method' => 'post',
-                                                                                  'action' => common_local_url('subscribe')));
-               common_hidden('token', common_session_token());
-               common_element('input', array('id' => 'subscribeto',
-                                                                         'name' => 'subscribeto',
-                                                                         'type' => 'hidden',
-                                                                         'value' => $profile->nickname));
-               common_element('input', array('type' => 'submit',
-                                                                         'class' => 'submit',
-                                                                         'value' => _('Subscribe')));
-               common_element_end('form');
-       }
-
        function show_remote_subscribe_link($profile) {
                $url = common_local_url('remotesubscribe',
                                        array('nickname' => $profile->nickname));
index 10951dc3b4bfb7b0cbeaeb00442a0d379a0fc0f4..856586f87a79bc5532ddd550f0811d1d8b649b89 100644 (file)
@@ -54,13 +54,16 @@ class SubscribeAction extends Action {
                        return;
                }
 
+               $cur = common_current_user();
+               $profile = Profile::staticGet('nickname', $other_nickname);
                if ($this->boolean('ajax')) {
                        common_start_html('text/xml');
                        common_element_start('head');
                        common_element('title', null, _('Subscribed'));
                        common_element_end('head');
                        common_element_start('body');
-                       common_subscribe_response();
+                       common_unsubscribe_form($profile);
+                       common_profile_new_message_nudge($cur, $profile);
                        common_element_end('body');
                        common_element_end('html');
                } else {
index 562dd00fc489c2d40bd3668f39726bbcc91afbd7..ad4f04a020589d2de923e0e3cee5c395761fd9ef 100644 (file)
@@ -49,13 +49,15 @@ class UnsubscribeAction extends Action {
                        return;
                }
 
+               $profile = Profile::staticGet('nickname', $other_nickname);
+               
                if ($this->boolean('ajax')) {
                        common_start_html('text/xml');
                        common_element_start('head');
                        common_element('title', null, _('Unsubscribed'));
                        common_element_end('head');
                        common_element_start('body');
-                       common_unsubscribe_response();
+                       common_subscribe_form($profile);
                        common_element_end('body');
                        common_element_end('html');
                } else {
index 53fc58011ef36a11e0bc495488af4285ba022e3c..b3165647f78ff61516d6eea127e32577d36d82e8 100644 (file)
@@ -90,7 +90,35 @@ $(document).ready(function(){
                                                        success: function(xml) { $("#nudge").replaceWith(document._importNode($("#nudge_response", xml).get(0),true)); }
                                                 });
        $("#nudge").each(addAjaxHidden);
-       $("#nudge .submit").bind('click', function(e) { $(this).addClass("processing"); }); 
+       $("#nudge .submit").bind('click', function(e) { $(this).addClass("processing"); });
+
+
+       var Subscribe = { dataType: 'xml',
+                                         success: function(xml) { var form_unsubscribe = document._importNode($('form', xml).get(0), true);
+                                                                                          var form_unsubscribe_id = form_unsubscribe.id;
+                                                                                          var form_subscribe_id = form_unsubscribe_id.replace('unsubscribe', 'subscribe');
+                                                                                          $("form#"+form_subscribe_id).replaceWith(form_unsubscribe);
+                                                                                          $("form#"+form_unsubscribe_id).ajaxForm(UnSubscribe).each(addAjaxHidden);
+                                                                                          $("#profile_actions").append(document._importNode($('#profile_send_a_new_message', xml).get(0), true));
+                                                                                          $("#profile_actions").append(document._importNode($('#profile_nudge', xml).get(0), true));
+                                                                                    }
+                                       };
+
+       var UnSubscribe = { dataType: 'xml',
+                                           success: function(xml) { var form_subscribe = document._importNode($('form', xml).get(0), true);
+                                                                                                var form_subscribe_id = form_subscribe.id;
+                                                                                                var form_unsubscribe_id = form_subscribe_id.replace('subscribe', 'unsubscribe');
+                                                                                                $("form#"+form_unsubscribe_id).replaceWith(form_subscribe);
+                                                                                                $("form#"+form_subscribe_id).ajaxForm(Subscribe).each(addAjaxHidden);
+                                                                                                $("#profile_send_a_new_message").remove();
+                                                                                                $("#profile_nudge").remove();
+                                                                                          }
+                                         };
+
+       $("form.subscribe").ajaxForm(Subscribe);
+       $("form.unsubscribe").ajaxForm(UnSubscribe);
+       $("form.subscribe").each(addAjaxHidden);
+       $("form.unsubscribe").each(addAjaxHidden);
 });
 
 function doreply(nick,id) {
index 2f64ea599109a75753074ed7092a72e37db5bce9..1365380ab9669270668a89dd8f01f5c71152d877 100644 (file)
@@ -1903,6 +1903,9 @@ function common_nudge_form($profile) {
                                                                  'value' => _('Send a nudge')));
        common_element_end('form');
 }
+function common_nudge_response() {
+       common_element('p', array('id' => 'nudge_response'), _('Nudge sent!'));
+}
 
 function common_subscribe_form($profile) {
        common_element_start('form', array('id' => 'subscribe-' . $profile->nickname,
@@ -1936,8 +1939,22 @@ function common_unsubscribe_form($profile) {
        common_element_end('form');
 }
 
-function common_nudge_response() {
-       common_element('p', array('id' => 'nudge_response'), _('Nudge sent!'));
+// XXX: Refactor this code
+function common_profile_new_message_nudge ($cur, $profile) {
+       $user = User::staticGet('id', $profile->id);
+
+       if ($cur && $cur->id != $user->id && $cur->mutuallySubscribed($user)) {
+        common_element_start('li', array('id' => 'profile_send_a_new_message'));
+               common_element('a', array('href' => common_local_url('newmessage', array('to' => $user->id))),
+                                          _('Send a message'));
+        common_element_end('li');
+     
+           if ($user->email && $user->emailnotifynudge) {
+            common_element_start('li', array('id' => 'profile_nudge'));
+            common_nudge_form($user);
+            common_element_end('li');
+        }
+       }
 }
 
 function common_cache_key($extra) {
index 6c230ea0a5059320a88fe944d37aae30bc84f08e..eb2c26235586bee094385ed5b7c346924fab39d8 100644 (file)
@@ -672,7 +672,7 @@ textarea {
        text-align: right;
 }
 /* ----- Subscribe Form ----- */
-#subscribe .submit, #unsubscribe .submit, #remotesubscribe .button, #remotesubscribe {
+#content .subscribe .submit, #content .unsubscribe .submit, #remotesubscribe .button, #remotesubscribe {
        clear: left;
        margin: 0;
        width: 96px;
@@ -691,7 +691,7 @@ textarea {
        padding: 5px 0 0 0;
        text-align: center;
        }
-#subscribe .button:hover, #unsubscribe .button:hover {
+#content .subscribe .button:hover, #content .unsubscribe .button:hover {
        background-color: #904632;
        cursor: pointer;
        }
index a3ef07f90b74cf4b637a1e368637decde356f315..52a63a5ae6a79647b8cde7e16a90d968db0bc97d 100644 (file)
@@ -158,7 +158,7 @@ textarea:focus, input:focus {
     background-color: #904632;
     }
 
-#subscribe .submit, #unsubscribe .submit, #remotesubscribe .button, #remotesubscribe {
+#content .subscribe .submit, #content .unsubscribe .submit, #remotesubscribe .button, #remotesubscribe {
     background-color: #c15d42;
     color: #fcfff5;
     }