# HG changeset patch
# User Chris Cannam
# Date 1379407880 -3600
# Node ID ac411172d897beffb10e14d38475f82e03531976
# Parent 45dbcd39b9e9f1b6520b970db4eb0e37e188a15d# Parent 5b8bd53fd65c66368ce427f3af77e463ccb7e7ef
Merge from branch cannam
diff -r 45dbcd39b9e9 -r ac411172d897 plugins/redmine_bibliography/app/controllers/authorships_controller.rb
--- a/plugins/redmine_bibliography/app/controllers/authorships_controller.rb Thu Jul 18 12:21:45 2013 +0100
+++ b/plugins/redmine_bibliography/app/controllers/authorships_controller.rb Tue Sep 17 09:51:20 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 45dbcd39b9e9 -r ac411172d897 plugins/redmine_bibliography/app/models/authorship.rb
--- a/plugins/redmine_bibliography/app/models/authorship.rb Thu Jul 18 12:21:45 2013 +0100
+++ b/plugins/redmine_bibliography/app/models/authorship.rb Tue Sep 17 09:51:20 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
diff -r 45dbcd39b9e9 -r ac411172d897 plugins/redmine_bibliography/app/views/publications/_authorship_fields.html.erb
--- a/plugins/redmine_bibliography/app/views/publications/_authorship_fields.html.erb Thu Jul 18 12:21:45 2013 +0100
+++ b/plugins/redmine_bibliography/app/views/publications/_authorship_fields.html.erb Tue Sep 17 09:51:20 2013 +0100
@@ -1,6 +1,9 @@
-<% content_for :header_tags do %>
- <%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %>
-<% end %>
+<%- content_for :header_tags do -%>
+ <%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' -%>
+ <%= javascript_include_tag 'bibliography', :plugin => 'redmine_bibliography' -%>
+ <%= javascript_tag "$('.author_save_btn').live('click', disable_fields);" -%>
+ <%= javascript_tag "$('.author_edit_btn').live('click', enable_fields);" -%>
+<%- end -%>
>
@@ -15,34 +18,32 @@
-
-
+
+
-
- <%= f.text_field :name_on_paper, {:class => ("readonly" unless params[:action] == "new") } %>
-
><%= h l("text_author_name_on_paper") %>
-
<%= f.text_field :institution, {:class => ("readonly" unless params[:action] == "new") } %>
-
><%= h l("text_author_institution") %>
-
<%= f.text_field :email, {:class => ("readonly" unless params[:action] == "new") } %>
-
><%= h l("text_author_email") %>
-
- <%= hidden_field_tag(:search_author_class, '', :name => form_tag_name(f.object_name,:search_author_class ), :id => form_tag_id( f.object_name, :search_author_class )) -%>
+
<%= f.text_field :name_on_paper, {:class => ("readonly" unless params[:action] == "new") } %>
+
><%= h l("text_author_name_on_paper") %>
- <%= hidden_field_tag(:search_author_id, '', :name => form_tag_name(f.object_name,:search_author_id ), :id => form_tag_id( f.object_name, :search_author_id )) -%>
+
<%= f.text_field :institution, {:class => ("readonly" unless params[:action] == "new") } %>
+
><%= h l("text_author_institution") %>
+
<%= f.text_field :email, {:class => ("readonly" unless params[:action] == "new") } %>
+
><%= h l("text_author_email") %>
+
+ <%= hidden_field_tag(:search_author_class, '', :name => form_tag_name(f.object_name,:search_author_class ), :id => form_tag_id( f.object_name, :search_author_class )) -%>
+
+ <%= hidden_field_tag(:search_author_id, '', :name => form_tag_name(f.object_name,:search_author_id ), :id => form_tag_id( f.object_name, :search_author_id )) -%>
+
+
+ <%= button_to_function l(:label_save_author), '', :id => form_tag_id(f.object_name, :edit_save_button), :class => 'author_save_btn' -%>
-
+ <%= button_to_function l(:label_edit_author), '', :id => form_tag_id(f.object_name, :edit_button), :class => 'author_edit_btn' -%>
+ <%= link_to_remove_fields l("remove_author"), f %>
+
+
-
-
- <%= button_to_function l(:label_save_author), {}, :id => form_tag_id( f.object_name, :edit_save_button ) %>
-
- <%= link_to_remove_fields l("remove_author"), f %>
-
-
-
diff -r 45dbcd39b9e9 -r ac411172d897 plugins/redmine_bibliography/assets/javascripts/bibliography.js
--- a/plugins/redmine_bibliography/assets/javascripts/bibliography.js Thu Jul 18 12:21:45 2013 +0100
+++ b/plugins/redmine_bibliography/assets/javascripts/bibliography.js Tue Sep 17 09:51:20 2013 +0100
@@ -1,18 +1,27 @@
+// bibliography.js
-$("#publication_bibtex_entry_attributes_entry_type").live("change", function() {
- $this = $(this);
+function disable_fields(){
+ $this = $(this);
+ $author_info = $this.closest('div').prev();
+ $author_info.children('.description').toggle();
+ $author_info.find('p :input').attr("readonly", true);
+ $author_info.find('p :input').addClass('readonly');
- $.ajax({
- type: "get",
- url: "/publications/show_bibtex_fields",
- data: {
- value: $this.val()
- },
- dataType: "script"
- });
+ $this.siblings('.author_edit_btn').show();
+ $this.hide();
return false;
-});
-$(document).ready(function() {
- $("#publication_bibtex_entry_attributes_entry_type").trigger('change');
-});
\ No newline at end of file
+}
+
+function enable_fields(){
+ $this = $(this);
+ $author_info = $this.closest('div').prev();
+ $author_info.children('.description').toggle();
+ $author_info.find('p :input').attr("readonly", false);
+ $author_info.find('p :input').removeClass('readonly');
+
+ $this.siblings('.author_save_btn').show();
+ $this.hide();
+
+ return false;
+}
diff -r 45dbcd39b9e9 -r ac411172d897 plugins/redmine_bibliography/assets/stylesheets/bibliography.css
--- a/plugins/redmine_bibliography/assets/stylesheets/bibliography.css Thu Jul 18 12:21:45 2013 +0100
+++ b/plugins/redmine_bibliography/assets/stylesheets/bibliography.css Tue Sep 17 09:51:20 2013 +0100
@@ -4,7 +4,7 @@
color: #777;
}
-input.readonly {
+.readonly {
border: none;
padding: 0;
margin: 0;
@@ -71,3 +71,7 @@
background-image: url(../../../images/loading.gif);
}
+.author_edit_btn {
+ display:none;
+}
+
diff -r 45dbcd39b9e9 -r ac411172d897 plugins/redmine_bibliography/config/routes.rb
--- a/plugins/redmine_bibliography/config/routes.rb Thu Jul 18 12:21:45 2013 +0100
+++ b/plugins/redmine_bibliography/config/routes.rb Tue Sep 17 09:51:20 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