# HG changeset patch # User luisf # Date 1376923671 -3600 # Node ID 4d5d25039a5f1836c990c7627e1a9683f780d27c # Parent 855b4ae5ecddb62ebc847a1abebbc3e6bd74610d Fixes Bug #668 - reordering of authors in the publication's detail view is working again. diff -r 855b4ae5ecdd -r 4d5d25039a5f plugins/redmine_bibliography/app/controllers/authorships_controller.rb --- a/plugins/redmine_bibliography/app/controllers/authorships_controller.rb Mon Aug 19 13:40:58 2013 +0100 +++ b/plugins/redmine_bibliography/app/controllers/authorships_controller.rb Mon Aug 19 15:47:51 2013 +0100 @@ -1,10 +1,15 @@ class AuthorshipsController < ApplicationController - - def index - - end - - def update - end + def sort + @authorships = Authorship.find(params['authorship']) + + @authorships.each do |authorship| + + # note: auth_order is usually called position (default column name in the acts_as_list plugin ) + authorship.auth_order = params['authorship'].index(authorship.id.to_s) + 1 + authorship.save + end + + render :nothing => true, :status => 200 + end end diff -r 855b4ae5ecdd -r 4d5d25039a5f plugins/redmine_bibliography/app/models/authorship.rb --- a/plugins/redmine_bibliography/app/models/authorship.rb Mon Aug 19 13:40:58 2013 +0100 +++ b/plugins/redmine_bibliography/app/models/authorship.rb Mon Aug 19 15:47:51 2013 +0100 @@ -10,7 +10,8 @@ validates_presence_of :name_on_paper attr_accessor :search_author_class, :search_author_id, :search_name, :search_results, :identify_author - before_save :associate_author_user + + before_create :associate_author_user # tod: review scope of ordering acts_as_list :column => 'auth_order' diff -r 855b4ae5ecdd -r 4d5d25039a5f plugins/redmine_bibliography/app/views/publications/show.html.erb --- a/plugins/redmine_bibliography/app/views/publications/show.html.erb Mon Aug 19 13:40:58 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/publications/show.html.erb Mon Aug 19 15:47:51 2013 +0100 @@ -1,3 +1,5 @@ +<%= javascript_include_tag 'order_authorships', :plugin => 'redmine_bibliography' %> +

<%=l(:label_publication_show)%>

diff -r 855b4ae5ecdd -r 4d5d25039a5f plugins/redmine_bibliography/config/routes.rb --- a/plugins/redmine_bibliography/config/routes.rb Mon Aug 19 13:40:58 2013 +0100 +++ b/plugins/redmine_bibliography/config/routes.rb Mon Aug 19 15:47:51 2013 +0100 @@ -9,6 +9,11 @@ match "publications/autocomplete_for_project", :to => 'publications#autocomplete_for_project' + resources :authorships do + collection do + post 'sort', :action => 'sort' + end + end resources :publications end \ No newline at end of file