Merge branch 'BenjaminHae-sortable'
authorAndrew Karpow <andy@ndyk.de>
Mon, 22 Jan 2018 03:40:52 +0000 (04:40 +0100)
committerAndrew Karpow <andy@ndyk.de>
Mon, 22 Jan 2018 03:40:52 +0000 (04:40 +0100)
1  2 
htdocs/index.html
htdocs/js/mpd.js
src/mpd_client.c
src/mpd_client.h

Simple merge
@@@ -272,7 -242,26 +272,23 @@@ function webSocketConnect() 
                              socket.send('MPD_API_PLAY_TRACK,'+$(this).attr('trackid'));
                              $(this).addClass('active');
                          },
 -                        mouseleave: function(){
 -                            $(this).children().last().find("a").stop().remove();
 -                        }
                      });
+                     //Helper function to keep table row from collapsing when being sorted
+                     var fixHelperModified = function(e, tr) {
+                       var $originals = tr.children();
+                       var $helper = tr.clone();
+                       $helper.children().each(function(index)
+                       {
+                         $(this).width($originals.eq(index).width())
+                       });
+                       return $helper;
+                     };
+                     
+                     //Make queue table sortable
+                     $("#salamisandwich > tbody").sortable({
+                       helper: fixHelperModified,
+                       stop: function(event,ui) {renumber_table('#salamisandwich',ui.item)}
+                     }).disableSelection();
                      break;
                  case "search":
                      $('#wait').modal('hide');
@@@ -633,19 -593,16 +652,29 @@@ function clickPlay() 
          socket.send('MPD_API_SET_PAUSE');
  }
  
 +function trash(tr) {
 +    if ( $('#btntrashmodeup').hasClass('active') ) {
 +        socket.send('MPD_API_RM_RANGE,0,' + (tr.index() + 1));
 +        tr.remove();
 +    } else if ( $('#btntrashmodesingle').hasClass('active') ) {
 +        socket.send('MPD_API_RM_TRACK,' + tr.attr('trackid'));
 +        tr.remove();
 +    } else if ( $('#btntrashmodedown').hasClass('active') ) {
 +        socket.send('MPD_API_RM_RANGE,' + tr.index() + ',-1');
 +        tr.remove();
 +    };
 +}
 +
+ function renumber_table(tableID,item) {
+     was = item.children("td").first().text();//Check if first item exists!
+     is = item.index() + 1;//maybe add pagination
+     if (was != is) {
+         socket.send("MPD_API_MOVE_TRACK," + was + "," + is);
+         socket.send('MPD_API_GET_QUEUE,'+pagination);
+     }
+ }
  function basename(path) {
      return path.split('/').reverse()[0];
  }
@@@ -93,10 -85,14 +93,18 @@@ int callback_mpd(struct mg_connection *
              if(sscanf(c->content, "MPD_API_RM_TRACK,%u", &uint_buf))
                  mpd_run_delete_id(mpd.conn, uint_buf);
              break;
 +        case MPD_API_RM_RANGE:
 +            if(sscanf(c->content, "MPD_API_RM_RANGE,%u,%u", &uint_buf, &uint_buf_2))
 +                mpd_run_delete_range(mpd.conn, uint_buf, uint_buf_2);
 +            break;
+         case MPD_API_MOVE_TRACK:
+             if (sscanf(c->content, "MPD_API_MOVE_TRACK,%u,%u", &uint_buf, &uint_buf_2) == 2)
+             {
+                 uint_buf -= 1;
+                 uint_buf_2 -= 1;
+                 mpd_run_move(mpd.conn, uint_buf, uint_buf_2);
+             }
+             break;
          case MPD_API_PLAY_TRACK:
              if(sscanf(c->content, "MPD_API_PLAY_TRACK,%u", &uint_buf))
                  mpd_run_play_id(mpd.conn, uint_buf);
@@@ -46,8 -46,8 +46,9 @@@
      X(MPD_API_PLAY_TRACK) \
      X(MPD_API_SAVE_QUEUE) \
      X(MPD_API_RM_TRACK) \
 +    X(MPD_API_RM_RANGE) \
      X(MPD_API_RM_ALL) \
+     X(MPD_API_MOVE_TRACK) \
      X(MPD_API_SEARCH) \
      X(MPD_API_SET_VOLUME) \
      X(MPD_API_SET_PAUSE) \