From 8ff0977e538685f89e590eb754a8c718ef40d3da Mon Sep 17 00:00:00 2001 From: Matt Moriarity Date: Sat, 28 Jul 2007 15:32:20 -0400 Subject: [PATCH] Sortables are no longer in the view Left to remove: * Delete links. Should be easy to make a behavior. * In-place-editors --- app/views/shows/edit.haml | 4 +--- public/javascripts/application.js | 35 +++++++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/app/views/shows/edit.haml b/app/views/shows/edit.haml index 2aef03e..f26164d 100644 --- a/app/views/shows/edit.haml +++ b/app/views/shows/edit.haml @@ -8,6 +8,4 @@ %h3 Songs in this show %ol#songs_list - = render :partial => @show.usages.reject {|u| u.song.nil?} - -= sortable_element 'songs_list', :url => reorder_show_path(@show), :handle => 'drag_me', :method => :put, :constraint => false \ No newline at end of file + = render :partial => @show.usages.reject {|u| u.song.nil?} \ No newline at end of file diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 31362c9..43ba0f8 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -26,16 +26,35 @@ Lyrix.Droppable = Behavior.create({ } }); +Lyrix.Sortable = Behavior.create({ + initialize: function(options) { + this.options = (options || {}); + Sortable.create(this.element, this.options); + } +}); + Event.addBehavior({ '.song, .usage': Lyrix.Draggable({handle: 'drag_me'}), - '#songs_list': Lyrix.Droppable({ - accept: 'song', - onDrop: function(element) { - new Ajax.Request('/usages?show_id=' + $P('show_id'), { - parameters: 'id=' + encodeURIComponent(element.id.gsub('song_', '')) - }); - } - }), + '#songs_list': function() { + Lyrix.Droppable.attach(this, { + accept: 'song', + onDrop: function(element) { + new Ajax.Request('/usages?show_id=' + $P('show_id'), { + parameters: 'id=' + encodeURIComponent(element.id.gsub('song_', '')) + }); + } + }); + Lyrix.Sortable.attach(this, { + constraint: false, + handle: 'drag_me', + onUpdate: function(element) { + new Ajax.Request('/shows/' + $P('show_id') + ';reorder', { + method: 'put', + parameters: Sortable.serialize(element) + }) + } + }); + }, '#side_songs_list': Lyrix.Droppable({ accept: 'usage', onDrop: function(element) { -- 2.11.4.GIT