Mercurial > hg > soundsoftware-site
changeset 1375:c28ce1a71a22 cannam
Merge from branch "luisf"
author | Chris Cannam |
---|---|
date | Thu, 29 Aug 2013 12:13:16 +0100 |
parents | 2f4c076ed281 (current diff) a2e51c0a7860 (diff) |
children | 5b8bd53fd65c |
files | |
diffstat | 5 files changed, 82 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/redmine_bibliography/app/controllers/authorships_controller.rb Thu Aug 29 12:13:01 2013 +0100 +++ b/plugins/redmine_bibliography/app/controllers/authorships_controller.rb Thu Aug 29 12:13:16 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
--- a/plugins/redmine_bibliography/app/models/authorship.rb Thu Aug 29 12:13:01 2013 +0100 +++ b/plugins/redmine_bibliography/app/models/authorship.rb Thu Aug 29 12:13:16 2013 +0100 @@ -10,9 +10,12 @@ 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 - acts_as_list + before_create :associate_author_user + before_update :delete_publication_cache + + # tod: review scope of ordering + acts_as_list :column => 'auth_order' # todo: review usage of scope --lf.20130108 scope :like_unique, lambda {|q| @@ -44,32 +47,42 @@ end protected + + def delete_publication_cache + publication = Publication.find(self.publication_id) + Rails.cache.delete "publication-#{publication.id}-ieee" + Rails.cache.delete "publication-#{publication.id}-bibtex" + end + def associate_author_user case self.search_author_class - when "User" - author = Author.new - author.save - self.author_id = author.id + when "" + logger.debug { "Unknown Author to be added..." } + when "User" + author = Author.new + author.save + self.author_id = author.id + + when "Author" + selected = self.search_results + selected_classname = Kernel.const_get(self.search_author_class) + selected_id = self.search_author_id + object = selected_classname.find(selected_id) + + if object.respond_to? :name_on_paper + # Authorship + self.author_id = object.author.id else - selected = self.search_results - selected_classname = Kernel.const_get(self.search_author_class) - selected_id = self.search_author_id - object = selected_classname.find(selected_id) - - if object.respond_to? :name_on_paper - # Authorship + # User + unless object.author.nil? self.author_id = object.author.id else - # User - unless object.author.nil? - self.author_id = object.author.id - else - author = Author.new - object.author = author - object.save - self.author_id = object.author.id - end + author = Author.new + object.author = author + object.save + self.author_id = object.author.id end + end end end end
--- a/plugins/redmine_bibliography/app/views/publications/show.html.erb Thu Aug 29 12:13:01 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/publications/show.html.erb Thu Aug 29 12:13:16 2013 +0100 @@ -1,3 +1,5 @@ +<%= javascript_include_tag 'order_authorships', :plugin => 'redmine_bibliography' %> + <h2><%=l(:label_publication_show)%></h2> <div class="box">
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/redmine_bibliography/assets/javascripts/order_authorships.js Thu Aug 29 12:13:16 2013 +0100 @@ -0,0 +1,28 @@ +$(document).ready(function(){ + + $('#authorships').sortable({ + axis: 'y', + dropOnEmpty: false, + handle: '.handle', + cursor: 'crosshair', + items: 'li', + opacity: 0.4, + scroll: true, + update: function(){ + $.ajax({ + type: 'post', + data: $('#authorships').sortable('serialize'), + dataType: 'script', + complete: function(request){ + $('#authorship').effect('highlight'); + }, + url: '/authorships/sort'}); + } + }); + }); + + + + + +
--- a/plugins/redmine_bibliography/config/routes.rb Thu Aug 29 12:13:01 2013 +0100 +++ b/plugins/redmine_bibliography/config/routes.rb Thu Aug 29 12:13:16 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