Skip to content
Extraits de code Groupes Projets
aspect-edit.js 3,85 ko
Newer Older
  • Learn to ignore specific revisions
  • Raphael's avatar
    Raphael a validé
    /*   Copyright (c) 2010, Diaspora Inc.  This file is
    
    Raphael's avatar
    Raphael a validé
    *   licensed under the Affero General Public License version 3 or later.  See
    
    Raphael's avatar
    Raphael a validé
    *   the COPYRIGHT file.
    */
    
    function decrementRequestsCounter() {
    
      var $new_requests     = $(".new_requests");
      var request_html      = $new_requests.html();
      var old_request_count = request_html.match(/\d+/);
    
    
      if( old_request_count == 1 ) {
    
          request_html.replace(/ \(\d+\)/,'')
    
          request_html.replace(/\d+/,old_request_count-1)
    
    // Dragging person between aspects
    
    Daniel Vincent Grippi's avatar
    Daniel Vincent Grippi a validé
    $(function() {
    
    danielvincent's avatar
    danielvincent a validé
      $("ul .person").draggable({
    
    danielvincent's avatar
    danielvincent a validé
        revert: true,
        start: function(event,ui){
          $(this).children("img").animate({'height':80, 'width':80, 'opacity':0.8},200);
    
    danielvincent's avatar
    danielvincent a validé
          $(".draggable_info").fadeIn(100);
    
    danielvincent's avatar
    danielvincent a validé
        },
        stop: function(event,ui){
          $(this).children("img").animate({'height':70, 'width':70, 'opacity':1},200);
    
    danielvincent's avatar
    danielvincent a validé
          $(".draggable_info").fadeOut(100);
    
    danielvincent's avatar
    danielvincent a validé
        }
      });
    
    danielvincent's avatar
    danielvincent a validé
      $(".aspect ul.dropzone").droppable({
    
    Daniel Vincent Grippi's avatar
    Daniel Vincent Grippi a validé
        drop: function(event, ui) {
    
          var dropzone = $(this);
          var person   = ui.draggable;
    
          if( person.hasClass('request') ){
    
              url: "/requests/" + person.attr('data-guid'),
    
    danielvincent's avatar
    danielvincent a validé
              data: {"accept" : true, "aspect_id" : dropzone.attr('data-aspect_id') },
    
    Daniel Vincent Grippi's avatar
    Daniel Vincent Grippi a validé
              success: function(data){
    
                decrementRequestsCounter();
    
    Daniel Vincent Grippi's avatar
    Daniel Vincent Grippi a validé
              }
    
    danielvincent's avatar
    danielvincent a validé
          if( dropzone.attr('data-aspect_id') != person.attr('data-aspect_id' )){
            $.ajax({
              url: "/aspects/move_friend/",
              data: {"friend_id" : person.attr('data-guid'),
                     "from"      : person.attr('data-aspect_id'),
                     "to"        : { "to" : dropzone.attr('data-aspect_id') }},
              success: function(data){
                person.attr('data-aspect_id', dropzone.attr('data-aspect_id'));
              }});
    
    danielvincent's avatar
    danielvincent a validé
    
          $(this).closest("ul").append(person);
    
    Daniel Vincent Grippi's avatar
    Daniel Vincent Grippi a validé
        }
      });
    
      $(".aspect_remove ul").droppable({
        hoverClass: 'active',
        drop: function(event, ui) {
    
    
          var person = ui.draggable;
    
          if ( person.attr('data-guid').length == 1 ) {
    
            alert("You can not remove the person from the last aspect");
    
            if( !person.hasClass('request') ){
    
    
              $.ajax({
                type: "POST",
                url: "/aspects/remove_from_aspect",
                data:{
    
                      'friend_id' : person.attr('data-guid'),
                      'aspect_id' : person.attr('data-aspect_id') }
    
    danielvincent's avatar
    danielvincent a validé
          person.fadeOut('slow', $(this).remove());
    
    // Person deletion
    
    $(".delete").live("click", function() {
    
      var person = $(this).closest("li.person");
    
    
      if (person.hasClass('request')){
    
        if( confirm("Ignore request?") ){
          var request_id = person.attr("data-guid");
    
    
          $.ajax({
            type: "DELETE",
            url: "/requests/" + request_id,
            success: function () {
              decrementRequestsCounter();
            }
          });
        }
    
      } else {
    
    
    danielvincent's avatar
    danielvincent a validé
        if( confirm("Remove this person from all aspects?") ){
          var person_id = $(this).closest("li.person").attr('data-guid');
    
    danielvincent's avatar
    danielvincent a validé
          $.ajax({
            type: "DELETE",
            url: "/people/" + person_id,
            success: function() {
              person.fadeOut(200);
            }
          });
        }
    
    Daniel Vincent Grippi's avatar
    Daniel Vincent Grippi a validé
    });
    
    
    // Editing aspect name
    $(".aspect h3").live('focus', function() {
    
      var $this = $(this);
      var id    = $this.closest("li.aspect").attr("data-guid");
      var link  = "/aspects/"+ id;
    
      $this.keypress(function(e) {
        if (e.which == 13) {
          e.preventDefault();
          $this.blur();
    
          //save changes
          $.ajax({
            type: "PUT",
            url: link,
            data: {"aspect" : {"name" : $this.text() }}
          });
        }
        //update all other aspect links
        $this.keyup(function(e) {
          $("#aspect_nav a[href='"+link+"']").text($this.text());
        });
      });
    });