# HG changeset patch # User Chris Cannam # Date 1379407894 -3600 # Node ID f019ad7fcf1be80ed4dc55a9238edd01770ae429 # Parent 7c0909052511a3d3f1932f4c85ffd109f190ed24# Parent ac411172d897beffb10e14d38475f82e03531976 Merge from live branch diff -r 7c0909052511 -r f019ad7fcf1b plugins/redmine_bibliography/app/controllers/authorships_controller.rb --- a/plugins/redmine_bibliography/app/controllers/authorships_controller.rb Thu Jul 18 12:21:57 2013 +0100 +++ b/plugins/redmine_bibliography/app/controllers/authorships_controller.rb Tue Sep 17 09:51:34 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 7c0909052511 -r f019ad7fcf1b plugins/redmine_bibliography/app/models/authorship.rb --- a/plugins/redmine_bibliography/app/models/authorship.rb Thu Jul 18 12:21:57 2013 +0100 +++ b/plugins/redmine_bibliography/app/models/authorship.rb Tue Sep 17 09:51:34 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 7c0909052511 -r f019ad7fcf1b 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:57 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/publications/_authorship_fields.html.erb Tue Sep 17 09:51:34 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_save_author), {}, :id => form_tag_id( f.object_name, :edit_save_button ) %> - - <%= link_to_remove_fields l("remove_author"), f %> -

-
-
diff -r 7c0909052511 -r f019ad7fcf1b plugins/redmine_bibliography/app/views/publications/_form.html.erb --- a/plugins/redmine_bibliography/app/views/publications/_form.html.erb Thu Jul 18 12:21:57 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/publications/_form.html.erb Tue Sep 17 09:51:34 2013 +0100 @@ -1,4 +1,18 @@ <%= error_messages_for 'publication' %> + <%= javascript_tag " + $('#publication_bibtex_entry_attributes_entry_type').live('change', function() { + $this = $(this); + $.ajax({ + type: 'get', + url: '#{url_for(:controller => :publications, :action => :show_bibtex_fields)}', + data: { + value: $this.val() + }, + dataType: 'script' + }); + return false; + });" + -%>

<%= f.text_field :title, :required => true, :size => 70 %>

diff -r 7c0909052511 -r f019ad7fcf1b plugins/redmine_bibliography/app/views/publications/edit.html.erb --- a/plugins/redmine_bibliography/app/views/publications/edit.html.erb Thu Jul 18 12:21:57 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/publications/edit.html.erb Tue Sep 17 09:51:34 2013 +0100 @@ -1,7 +1,7 @@ <% content_for :header_tags do %> <%= javascript_include_tag 'authors', :plugin => 'redmine_bibliography' %> - <%= javascript_include_tag 'bibliography', :plugin => 'redmine_bibliography' %> <%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %> + <%= javascript_tag "$(document).ready(function() { $('#publication_bibtex_entry_attributes_entry_type').trigger('change'); });" %> <% end %>

<%=l(:label_publication_show)%>

@@ -16,3 +16,4 @@ <%= link_to l(:label_publication_show), { :controller => "publications", :action => "show", :id => @publication, :project_id => @project_id } %> | <%= link_to l(:label_publication_index), { :controller => "publications", :action => "index", :project_id => @project } %>

+ diff -r 7c0909052511 -r f019ad7fcf1b plugins/redmine_bibliography/app/views/publications/new.html.erb --- a/plugins/redmine_bibliography/app/views/publications/new.html.erb Thu Jul 18 12:21:57 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/publications/new.html.erb Tue Sep 17 09:51:34 2013 +0100 @@ -1,6 +1,5 @@ <% content_for :header_tags do %> <%= javascript_include_tag 'authors', :plugin => 'redmine_bibliography' %> - <%= javascript_include_tag 'bibliography', :plugin => 'redmine_bibliography' %> <%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %> <% end %> diff -r 7c0909052511 -r f019ad7fcf1b plugins/redmine_bibliography/app/views/publications/show.html.erb --- a/plugins/redmine_bibliography/app/views/publications/show.html.erb Thu Jul 18 12:21:57 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/publications/show.html.erb Tue Sep 17 09:51:34 2013 +0100 @@ -1,3 +1,27 @@ +<%= javascript_tag "$(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: '#{url_for(:controller => :authorships, :action => :sort)}'}); + } + }); + }); +" -%> +

<%=l(:label_publication_show)%>

diff -r 7c0909052511 -r f019ad7fcf1b plugins/redmine_bibliography/assets/javascripts/bibliography.js --- a/plugins/redmine_bibliography/assets/javascripts/bibliography.js Thu Jul 18 12:21:57 2013 +0100 +++ b/plugins/redmine_bibliography/assets/javascripts/bibliography.js Tue Sep 17 09:51:34 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 7c0909052511 -r f019ad7fcf1b plugins/redmine_bibliography/assets/stylesheets/bibliography.css --- a/plugins/redmine_bibliography/assets/stylesheets/bibliography.css Thu Jul 18 12:21:57 2013 +0100 +++ b/plugins/redmine_bibliography/assets/stylesheets/bibliography.css Tue Sep 17 09:51:34 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 7c0909052511 -r f019ad7fcf1b plugins/redmine_bibliography/config/routes.rb --- a/plugins/redmine_bibliography/config/routes.rb Thu Jul 18 12:21:57 2013 +0100 +++ b/plugins/redmine_bibliography/config/routes.rb Tue Sep 17 09:51:34 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