Skip to content
Extraits de code Groupes Projets
aspect-edit.js 3,28 ko
Newer Older
  • Learn to ignore specific revisions
  • /*   Copyright 2010 Diaspora Inc.
     *
     *   This file is part of Diaspora.
     *
     *   Diaspora is free software: you can redistribute it and/or modify
     *   it under the terms of the GNU Affero General Public License as published by
     *   the Free Software Foundation, either version 3 of the License, or
     *   (at your option) any later version.
     *
     *   Diaspora is distributed in the hope that it will be useful,
     *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *   GNU Affero General Public License for more details.
     *
     *   You should have received a copy of the GNU Affero General Public License
     *   along with Diaspora.  If not, see <http://www.gnu.org/licenses/>.
     */
    
    
    
    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!");});
    
    Daniel Vincent Grippi's avatar
    Daniel Vincent Grippi a validé
      $(".person").css('background-color','white');
    
    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é
    });
    
    Daniel Vincent Grippi's avatar
    Daniel Vincent Grippi a validé
    $(function() {
      $("li .person").draggable({
        revert: true
      });
    
      $("li .requested_person").draggable({
        revert: true
      });
    
    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') ,
    
    Raphael's avatar
    Raphael a validé
              data: {"accept" : true  , "aspect_id" : $(this)[0].id }
    
            });
            alert("Sent the ajax, check it out!")
          }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','white');
            } else {
    
    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')
            });
            alert("Removed Request, proably want an undo countdown.")
            $(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')
    
    
    Raphael's avatar
    Raphael a validé
    $(".aspect h3").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) {
          $("a[href='"+link+"']").text($this.text());
        });
      });
    });