Skip to content
Extraits de code Groupes Projets
aspect-edit.js 3,04 ko
Newer Older
  • Learn to ignore specific revisions
  • Raphael's avatar
    Raphael a validé
    /*   Copyright (c) 2010, Disapora Inc.  This file is
    *   licensed under the Affero General Public License version 3.  See
    *   the COPYRIGHT file.
    */
    
    Daniel Vincent Grippi's avatar
    Daniel Vincent Grippi a validé
    $('#move_friends_link').live( 'click', function(){
    
    Raphael's avatar
    Raphael a validé
      $.post('/aspects/move_friends',
        { 'moves' : $('#aspect_list').data() },
        function(){ $('#aspect_title').html("Groups edited successfully!");});
    
      $(".person").css('background-color','none');
    
    Raphael's avatar
    Raphael a validé
      $('#aspect_list').removeData();
      $(".person").attr('from_aspect_id', function(){return $(this).parent().attr('id')})
    
    maxwell's avatar
    maxwell a validé
    
    
    Daniel Vincent Grippi's avatar
    Daniel Vincent Grippi a validé
    });
    
    function decrementRequestsCounter(){
      var old_request_count = $(".new_requests").html().match(/\d+/);
    
      if( old_request_count == 1 ) {
        $(".new_requests").html(
          $(".new_requests").html().replace(/ \(\d+\)/,''));
    
      } else {
        $(".new_requests").html(
          $(".new_requests").html().replace(/\d+/,old_request_count-1));
      }
    
    }
    
    
    Daniel Vincent Grippi's avatar
    Daniel Vincent Grippi a validé
    $(function() {
    
      $("ul .person").draggable({
    
    Daniel Vincent Grippi's avatar
    Daniel Vincent Grippi a validé
        revert: true
      });
    
      $("ul .requested_person").draggable({
    
    ilya's avatar
    ilya a validé
      
    
    Raphael's avatar
    Raphael a validé
      $(".aspect ul").droppable({
    
    Daniel Vincent Grippi's avatar
    Daniel Vincent Grippi a validé
        drop: function(event, ui) {
    
          if ($(ui.draggable[0]).hasClass('requested_person')){
            $.ajax({
              type: "DELETE",
              url: "/requests/" + ui.draggable[0].getAttribute('request_id') ,
    
    Daniel Vincent Grippi's avatar
    Daniel Vincent Grippi a validé
              data: {"accept" : true  , "aspect_id" : $(this)[0].id },
              success: function(data){
    
                decrementRequestsCounter();
    
    Daniel Vincent Grippi's avatar
    Daniel Vincent Grippi a validé
              }
    
          }else {
            var move = {};
            move[ 'friend_id' ] = ui.draggable[0].id
            move[ 'to' ] = $(this)[0].id;
    
    Raphael's avatar
    Raphael a validé
            move[ 'from' ] = ui.draggable[0].getAttribute('from_aspect_id');
    
            if (move['to'] == move['from']){
    
    Raphael's avatar
    Raphael a validé
              $('#aspect_list').data( ui.draggable[0].id, []);
    
              ui.draggable.css('background-color','#eee');
    
    Raphael's avatar
    Raphael a validé
              $('#aspect_list').data( ui.draggable[0].id, move);
    
              ui.draggable.css('background-color','orange');
            }
          }
    
          $(this).closest("ul").append(ui.draggable);
    
    Daniel Vincent Grippi's avatar
    Daniel Vincent Grippi a validé
        }
      });
    
    
      $(".remove ul").droppable({
        drop: function(event, ui) {
    
    
          if ($(ui.draggable[0]).hasClass('requested_person')){
            $.ajax({
              type: "DELETE",
              url: "/requests/" + ui.draggable[0].getAttribute('request_id')
            });
    
            decrementRequestsCounter();
    
            $(ui.draggable[0]).fadeOut('slow')
          }else{
            $.ajax({
              type: "DELETE",
    
    ilya's avatar
    ilya a validé
              url: "/people/" + ui.draggable[0].id
    
            });
            alert("Removed Friend, proably want an undo countdown.")
            $(ui.draggable[0]).fadeOut('slow')
    
    
    $(".aspect h1").live( 'click', function() {
    
    Daniel Vincent Grippi's avatar
    Daniel Vincent Grippi a validé
      var $this = $(this);
      var id    = $this.closest("li").children("ul").attr("id");
    
    Raphael's avatar
    Raphael a validé
      var link  = "/aspects/"+ id;
    
    Daniel Vincent Grippi's avatar
    Daniel Vincent Grippi a validé
      $this.keypress(function(e) {
        if (e.which == 13) {
          e.preventDefault();
          $this.blur();
    
          //save changes
          $.ajax({
            type: "PUT",
            url: link,
    
    Raphael's avatar
    Raphael a validé
            data: {"aspect" : {"name" : $this.text() }}
    
    Daniel Vincent Grippi's avatar
    Daniel Vincent Grippi a validé
          });
        }
    
    Raphael's avatar
    Raphael a validé
        //update all other aspect links
    
    Daniel Vincent Grippi's avatar
    Daniel Vincent Grippi a validé
        $this.keyup(function(e) {
    
          $("#aspect_nav a[href='"+link+"']").text($this.text());
    
    Daniel Vincent Grippi's avatar
    Daniel Vincent Grippi a validé
        });
      });
    });