VRFS-1890 : Mechanism to move track up/down, hook up in admin UI.
This commit is contained in:
parent
bac1f69c88
commit
207b7b9e20
|
|
@ -11,6 +11,18 @@ ActiveAdmin.register JamRuby::JamTrack, :as => 'JamTracks' do
|
||||||
form :partial => 'form'
|
form :partial => 'form'
|
||||||
|
|
||||||
index do
|
index do
|
||||||
|
|
||||||
|
# default_actions # use this for all view/edit/delete links
|
||||||
|
column "Actions" do |jam_track|
|
||||||
|
links = ''.html_safe
|
||||||
|
clz = "member_link view_link show_tracks"
|
||||||
|
clz += ' expand' if params[:focus_track]==jam_track.id
|
||||||
|
links << link_to("Show Tracks", '#', :class => clz)
|
||||||
|
links << link_to("Update", edit_resource_path(jam_track), :class => "member_link edit_link")
|
||||||
|
links
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
column :id
|
column :id
|
||||||
column :name
|
column :name
|
||||||
column :description
|
column :description
|
||||||
|
|
@ -40,18 +52,35 @@ ActiveAdmin.register JamRuby::JamTrack, :as => 'JamTracks' do
|
||||||
column :track_type
|
column :track_type
|
||||||
column :instrument
|
column :instrument
|
||||||
column :part
|
column :part
|
||||||
column :track do |track|
|
|
||||||
|
column "" do |track|
|
||||||
|
if track.position > 1
|
||||||
|
link_to 'Move Up', "jam_tracks/#{track.id}/move_up"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
column "" do |track|
|
||||||
|
if track.position < jam_track.jam_track_tracks.count
|
||||||
|
link_to 'Move Down', "jam_tracks/#{track.id}/move_down"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
column "" do |track|
|
||||||
link_to 'Play', '#'
|
link_to 'Play', '#'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# default_actions # use this for all view/edit/delete links
|
|
||||||
column "Actions" do |jam_track|
|
end
|
||||||
links = ''.html_safe
|
|
||||||
links << link_to("Show Tracks", '#', :class => "member_link view_link show_tracks")
|
member_action :move_up, :method => :get do
|
||||||
links << link_to("Update", edit_resource_path(jam_track), :class => "member_link edit_link")
|
track = JamTrackTrack.where("id=?",params[:id]).first
|
||||||
links
|
track.move_up
|
||||||
end
|
redirect_to("/admin/jam_tracks?focus_track=#{track.jam_track_id}", {:notice => "Moved Up."})
|
||||||
|
end
|
||||||
|
|
||||||
|
member_action :move_down, :method => :get do
|
||||||
|
track = JamTrackTrack.where("id=?",params[:id]).first
|
||||||
|
track.move_down
|
||||||
|
redirect_to("/admin/jam_tracks?focus_track=#{track.jam_track_id}", {:notice => "Moved Down."})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -1,43 +1,48 @@
|
||||||
|
function showTracks(rowJamTrack) {
|
||||||
|
var $jamTrackTracks = rowJamTrack.find("td.jam_track_tracks");
|
||||||
|
|
||||||
|
var name=rowJamTrack.find("td.name").text()
|
||||||
|
var count = $jamTrackTracks.find("table tbody tr").length;
|
||||||
|
|
||||||
|
if (rowJamTrack.next().attr('id') == "jam_track_tracks_detail") {
|
||||||
|
$(this).html("Show Tracks");
|
||||||
|
rowJamTrack.next().remove();
|
||||||
|
} else {
|
||||||
|
$(this).html('Hide Tracks');
|
||||||
|
if (count == 0) {
|
||||||
|
rowJamTrack.after(
|
||||||
|
$("<tr id=\"jam_track_tracks_detail\"></tr>").html(
|
||||||
|
$("<td colspan=\"1\"></td>")
|
||||||
|
).append(
|
||||||
|
$("<td colspan=\"4\"></td>").html(
|
||||||
|
"No Tracks"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rowJamTrack.after(
|
||||||
|
$("<tr id=\"jam_track_tracks_detail\"></tr>").html(
|
||||||
|
$("<td/><td colspan=\"1\"><em><strong>Tracks in '" + name + "':</strong></em></td>")
|
||||||
|
).append(
|
||||||
|
$("<td colspan=\"4\"></td>").html(
|
||||||
|
$jamTrackTracks.html()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$("th.jam_track_tracks").css('display', 'none');
|
$("th.jam_track_tracks").css('display', 'none');
|
||||||
$("td.jam_track_tracks").css('display', 'none');
|
$("td.jam_track_tracks").css('display', 'none');
|
||||||
|
showTracks($("a.expand").parents("tr"))
|
||||||
|
|
||||||
$(".show_tracks").click(function(e) {
|
$(".show_tracks").click(function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
var $rowJamTrack = $(this).parents('tr');
|
var $rowJamTrack = $(this).parents('tr');
|
||||||
var $jamTrackTracks = $($rowJamTrack).find("td.jam_track_tracks");
|
showTracks($rowJamTrack)
|
||||||
|
|
||||||
var count = $jamTrackTracks.find("table tbody tr").length;
|
|
||||||
|
|
||||||
if ($rowJamTrack.next().attr('id') == "jam_track_tracks_detail") {
|
|
||||||
$(this).html("Show Tracks");
|
|
||||||
$rowJamTrack.next().remove();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$(this).html('Hide Tracks');
|
|
||||||
if (count == 0) {
|
|
||||||
$rowJamTrack.after(
|
|
||||||
$("<tr id=\"jam_track_tracks_detail\"></tr>").html(
|
|
||||||
$("<td colspan=\"18\"></td>")
|
|
||||||
).append(
|
|
||||||
$("<td colspan=\"4\"></td>").html(
|
|
||||||
"No Tracks"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$rowJamTrack.after(
|
|
||||||
$("<tr id=\"jam_track_tracks_detail\"></tr>").html(
|
|
||||||
$("<td colspan=\"18\"></td>")
|
|
||||||
).append(
|
|
||||||
$("<td colspan=\"4\"></td>").html(
|
|
||||||
$jamTrackTracks.html()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
@ -43,5 +43,52 @@ module JamRuby
|
||||||
# I think we have to make a special case for 'previews', but maybe that's just up to the controller to not check can_download?
|
# I think we have to make a special case for 'previews', but maybe that's just up to the controller to not check can_download?
|
||||||
jam_track.owners.include?(user)
|
jam_track.owners.include?(user)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
def move_up
|
||||||
|
#normalize_position
|
||||||
|
if self.position > 1
|
||||||
|
# Switch with previous
|
||||||
|
previous_track = self.jam_track.jam_track_tracks.where("position=?", self.position-1).first
|
||||||
|
if previous_track
|
||||||
|
JamTrack.transaction do
|
||||||
|
previous_track.position,self.position = self.position,previous_track.position
|
||||||
|
previous_track.save(validate:false)
|
||||||
|
self.save(validate:false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def move_down
|
||||||
|
count=normalize_position
|
||||||
|
if self.position < count
|
||||||
|
# Switch with next:
|
||||||
|
next_track = self.jam_track.jam_track_tracks.where("position=?", self.position+1).first
|
||||||
|
if next_track
|
||||||
|
next_track.position,self.position = self.position,next_track.position
|
||||||
|
next_track.save(validate:false)
|
||||||
|
self.save(validate:false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def normalize_position
|
||||||
|
parent = self.jam_track
|
||||||
|
position = 0
|
||||||
|
if parent
|
||||||
|
JamTrack.transaction do
|
||||||
|
parent.jam_track_tracks.each do |jtt|
|
||||||
|
position += 1
|
||||||
|
if jtt.position != position
|
||||||
|
jtt.position = position
|
||||||
|
jtt.save(validate:false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
position
|
||||||
|
end # normalize_position
|
||||||
|
|
||||||
|
end # class
|
||||||
|
end # module
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue