From cbb990a2c2ad12b57724607d43dc46d6fb564b86 Mon Sep 17 00:00:00 2001 From: Per Cederqvist <ceder@lysator.liu.se> Date: Fri, 7 Jul 2006 20:53:48 +0000 Subject: [PATCH] Added ability to give recordings to users. --- app/controllers/recordings_controller.rb | 16 ++++++++++++++ app/views/recordings/_list.rhtml | 27 +++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/app/controllers/recordings_controller.rb b/app/controllers/recordings_controller.rb index 3fb912f..5c5a561 100644 --- a/app/controllers/recordings_controller.rb +++ b/app/controllers/recordings_controller.rb @@ -150,6 +150,22 @@ class RecordingsController < ApplicationController :page => cookies[:recording_page] end + def give + recording = Recording.find(params[:id]) + user = User.find(params[:user_id]) + if user.nil? + logger.add(Logger::DEBUG, "User to give to not found") + return + end + + recording.user_id = user.id + recording.save! + rec_id = recording["when"].strftime("%Y-%m-%d %H:%M:%S") + flash[:notice] = 'Recording ' + rec_id + ' given to ' + user.username + '.' + redirect_to :action => cookies[:recording_goal], + :page => cookies[:recording_page] + end + def archive recording = Recording.find(params[:id]) user_id = cookies[:user_id] diff --git a/app/views/recordings/_list.rhtml b/app/views/recordings/_list.rhtml index 9c37cbe..9ae6209 100644 --- a/app/views/recordings/_list.rhtml +++ b/app/views/recordings/_list.rhtml @@ -9,7 +9,8 @@ <table border="1"> <tr> - <th colspan="3"> </th> + <th colspan="3">Action</th> + <th>Give to</th> <% for column_name in sorted_columns %> <th><%= Recording.columns_hash[column_name].human_name %></th> <%end%> @@ -41,6 +42,24 @@ </form> <% end %> </td> + <td> + <% give_printed = false %> + <% for user in User.find(:all) %> + <% if user.id != @owner.id && user.id != recording.user_id %> + <form class="actionform" method="post" + action="<%= url_for :controller=>"recordings", + :action=>"give" %>" > + <input type="hidden" name="id" value="<%= recording.id %>" /> + <input type="hidden" name="user_id" value="<%= user.id %>" /> + <input type="submit" value="<%=h user.username %>" /> + </form> + <% give_printed = true %> + <% end %> + <% end %> + <% if !give_printed %> + + <% end %> + </td> <% for column_name in sorted_columns %> <td> @@ -49,6 +68,12 @@ <%= recording["when"].strftime("%Y-%m-%d %H:%M:%S") %> <% when "length": %> <%= (10*recording["length"].to_f).round / 10.0 %> + <% when "user_id": %> + <% if recording.user.nil? %> + + <% else %> + <%=h recording.user.username %> + <% end %> <% else %> <% if recording[column_name].to_s != "" %> <%=h recording.send(column_name) %> -- GitLab