Show
Ignore:
Timestamp:
10/01/08 17:35:19 (3 months ago)
Author:
kenji
Message:

Refactoring Follow/Remove

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • events/phpframework/codeigniter/trunk/system/application/views/user/main.php

    r20311 r20373  
    33        $(function(){ 
    44                $('#follow_button').click(function(){ 
    5                         $.post('<?=site_url('friendships/create')?>', {id: $('#follow_id').val(), ticket: $('#ticket').val()}, followMsg, 'html'); 
     5                        $.post('<?=site_url('friendships/create')?>', {id: $('#follow_id').val(), ticket: $('#ticket').val()}, followMsg, 'json'); 
    66                        return false; 
    77                }); 
    88        }); 
    99    function followMsg(data){ 
    10                         $('div[class="main"]').prepend(data); 
     10                if (data.status == 'ok') { 
     11                        $('div[class="main"]').prepend(data.html); 
    1112                        $('#follow_button').hide(); 
    1213                        $('#remove_button').show(); 
    1314                        $('#msg').fadeOut(3000); 
     15                        count = parseInt($('#side_count_follow').text()) + 1; 
     16                        $('#side_count_follow').text(count); 
     17                } 
     18                else { 
     19                        alert(data.html); 
     20                } 
    1421    } 
    1522 
     
    1724        $(function(){ 
    1825                $('#remove_button').click(function(){ 
    19                         $.post('<?=site_url('friendships/destroy')?>', {id: $('#follow_id').val(), ticket: $('#ticket').val()}, removeMsg, 'html'); 
     26                        $.post('<?=site_url('friendships/destroy')?>', {id: $('#follow_id').val(), ticket: $('#ticket').val()}, removeMsg, 'json'); 
    2027                        return false; 
    2128                }); 
    2229        }); 
    2330    function removeMsg(data){ 
    24                         $('div[class="main"]').prepend(data); 
     31        if (data.status == 'ok') { 
     32                        $('div[class="main"]').prepend(data.html); 
    2533                        $('#follow_button').show(); 
    2634                        $('#remove_button').hide(); 
    2735                        $('#msg').fadeOut(3000); 
     36                        count = parseInt($('#side_count_follow').text()) - 1; 
     37                        $('#side_count_follow').text(count); 
     38                } 
     39                else { 
     40                        alert(data.html); 
     41                } 
    2842    } 
    2943</script>