Commit cdd82a9c7cf8388c4b45608d0a22760de10fe0bf

Authored by Victor Costa
2 parents 4a50f9f4 50033fd3

Merge branch 'task_responsible' into production

Conflicts:
	app/controllers/my_profile/tasks_controller.rb
	app/views/tasks/_task.html.erb
	public/javascripts/tasks.js
app/controllers/my_profile/tasks_controller.rb
... ... @@ -31,7 +31,7 @@ class TasksController < MyProfileController
31 31 responsible = profile.members.find(params[:responsible_id]) if params[:responsible_id].present?
32 32 task.responsible = responsible
33 33 task.save!
34   - render :json => {:notice => _('Task responsible successfully updated!'), :success => true}
  34 + render :json => {:notice => _('Task responsible successfully updated!'), :success => true, :new_responsible => {:id => responsible.present? ? responsible.id : nil}}
35 35 end
36 36  
37 37 VALID_DECISIONS = [ 'finish', 'cancel', 'skip' ]
... ...
app/views/tasks/_task.html.erb
... ... @@ -7,7 +7,7 @@
7 7 <span class="label"><%= _('Responsible:') %></span>
8 8 <span>
9 9 <% change_responsible_url = url_for :action => :change_responsible, :controller => :tasks %>
10   - <%= select_tag "tasks[#{task.id}][responsible]", options_from_collection_for_select(@responsible_candidates, :id, :name, task.responsible.present? ? task.responsible.id : nil), :include_blank => true, :onchange => "change_task_responsible('#{change_responsible_url}', #{task.id}, #{task.responsible.present? ? task.responsible.id : 'null'}, this);" %>
  10 + <%= select_tag "tasks[#{task.id}][responsible]", options_from_collection_for_select(@responsible_candidates, :id, :name, task.responsible.present? ? task.responsible.id : nil), :include_blank => true, :onchange => "change_task_responsible(this);", 'data-old-responsible' => task.responsible.present? ? task.responsible.id : nil, 'data-task' => task.id, 'data-url' => change_responsible_url %>
11 11 </span>
12 12 </div>
13 13 <% end %>
... ...
public/javascripts/tasks.js
... ... @@ -63,12 +63,13 @@
63 63  
64 64 })(jQuery)
65 65  
66   -function change_task_responsible(url, task_id, old_responsible_id, el) {
67   - jQuery.post(url, {task_id: task_id,
  66 +function change_task_responsible(el) {
  67 + jQuery.post($(el).data('url'), {task_id: $(el).data('task'),
68 68 responsible_id: $(el).val(),
69   - old_responsible_id: old_responsible_id}, function(data) {
  69 + old_responsible_id: $(el).data('old-responsible')}, function(data) {
70 70 if (data.success) {
71 71 $(el).effect("highlight");
  72 + $(el).data('old-responsible', data.new_responsible.id);
72 73 } else {
73 74 $(el).effect("highlight", {color: 'red'});
74 75 }
... ...