cirandas.net

ref: master

public/javascripts/add-and-join.js


  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
noosfero.add_and_join = {
  locales: {
    leaveConfirmation: '',
  },
};

jQuery(function($) {

  $(".add-friend").live('click', function(){
    clicked = $(this);
    url = clicked.attr("href");
    loading_for_button(this);
    $.post(url, function(data){
      clicked.fadeOut();
      display_notice(data);
    });
    return false;
  })

  $(".join-community").live('click', function(){
    $('#cboxClose').remove();
    clicked = $(this);
    url = clicked.attr("href");
    if (!clicked.hasClass('modal-toggle'))
      loading_for_button(this);
    $.post(url, function(data){
      clicked.fadeOut(function(){
        clicked.css("display","none");
        clicked.parent().parent().find(".leave-community").fadeIn();
        clicked.parent().parent().find(".leave-community").css("display", "");
      });
      clicked.css("cursor","");
      $(".small-loading").remove();
      display_notice(data.message);
    }, "json");
    return false;
  })

  $(".leave-community").live('click', function(){
    if (!confirm(noosfero.add_and_join.locales.leaveConfirmation))
      return false;
    clicked = $(this);
    url = clicked.attr("href");
    loading_for_button(this);
    $.post(url, function(data){
      if(data.redirect_to){
        document.location.href = data.redirect_to;
      }
      else if(data.reload){
        document.location.reload(true);
      }
      else{
        clicked.fadeOut(function(){
          clicked.css("display","none");
          clicked.parent().parent().find(".join-community").fadeIn();
          clicked.parent().parent().find(".join-community").css("display", "");
        });
        clicked.css("cursor","");
        $(".small-loading").remove();

        display_notice(data.message);
      }
    }, "json");
    return false;
  })

  $('body').on('click', '.person-trigger', function(){
    clicked = $(this);
    url = clicked.attr("url");
    $.get(url, function(data){
      if(data == "true"){
        clicked.parent().find(".add-friend").fadeOut(function(){
          clicked.parent().find(".send-an-email").fadeIn();
        })
      }
      else if(data == "false"){
        clicked.parent().find(".send-an-email").fadeOut(function(){
          clicked.parent().find(".add-friend").fadeIn();
        });
      }
    })
  })

  $('body').on('click', '.community-trigger', function(){
    clicked = $(this);
    url = clicked.attr("url");
    $.get(url, function(data){
      if(data == "true"){
        clicked.parent().find(".join-community").fadeOut(function(){
          clicked.parent().find(".leave-community").fadeIn();
          clicked.parent().find(".send-an-email").fadeIn();
        });
      }
      else if(data == "false"){
        clicked.parent().find(".send-an-email").fadeOut();
        clicked.parent().find(".leave-community").fadeOut(function(){
          clicked.parent().find(".join-community").fadeIn();
        });
      }
    })
  })

  $('body').on('click', '.enterprise-trigger', function(){
    clicked = $(this);
    url = clicked.attr("url");
    $.get(url, function(data){
      if(data == "true")
        clicked.parent().find(".send-an-email").fadeIn();
      else if(data == "false")
        clicked.parent().find(".send-an-email").fadeOut();
    })
  })

  $(".comment-trigger").live('click', function(){
    clicked = $(this);
    url = clicked.attr("url");
    $.get(url, function(data){
      ids = [];
      if(data && data.ids) {
        for(var i=0; i<data.ids.length; i++) {
          clicked.parent().find(data.ids[i]).fadeIn();
          ids.push(data.ids[i]);
        }
      }
      clicked.parent().find('.comment-action-extra').each(function() {
        if($.inArray('#'+$(this).attr('id'), ids))
          $(this).fadeOut();
      });
    })
    return false;
  })

  $(".remove-suggestion").live('click', function(){
    clicked = $(this);
    removeSuggestionFromList(clicked);
  })

  $(".accept-suggestion").live('click', function(){
    clicked = $(this)
    loading_for_button(this);
    url = clicked.attr("href");
    removeSuggestionFromList(clicked.parents('li').find('.remove-suggestion'));
    $.post(url, function(add_data){
      clicked.parents('li').fadeOut();
    });
    return false;
  })

});

/* Used after clicking on remove and after adding a suggestion */
function removeSuggestionFromList( element ) {
  url = element.attr("href");
  loading_for_button(element);
  jQuery.post(url, function(data){
    element.fadeOut();
    element.parents('.profiles-suggestions').html(data);
  });
}