Mercurial > hg > soundsoftware-site
changeset 1382:ac411172d897 live
Merge from branch cannam
author | Chris Cannam |
---|---|
date | Tue, 17 Sep 2013 09:51:20 +0100 |
parents | 45dbcd39b9e9 (current diff) 5b8bd53fd65c (diff) |
children | f019ad7fcf1b 04cc33a44d4c |
files | |
diffstat | 10 files changed, 145 insertions(+), 70 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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
--- 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 -%> <div id="authors" class="fields"> <div id="<%= form_tag_id( f.object_name, :search_author ) %>" style=<%= "display:none;" unless params[:action] == "new" %> > @@ -15,34 +18,32 @@ <label class='inline'><%= radio_button_tag(:identify_author, "correct", false, :name => form_tag_name(f.object_name,:identify_author ), :id => form_tag_id( f.object_name, :identify_author_corrections )) %> <%= l(:identify_author_correct) %> </label><br /> - <label class='inline'><%= radio_button_tag(:identify_author, "no", true, :name => form_tag_name(f.object_name,:identify_author ), :id => form_tag_id( f.object_name, :identify_author_no )) %> <%= l(:identify_author_no) %> </label><br /> - </p> + <label class='inline'><%= radio_button_tag(:identify_author, "no", true, :name => form_tag_name(f.object_name,:identify_author ), :id => form_tag_id( f.object_name, :identify_author_no )) %> <%= l(:identify_author_no) %> </label><br /> + </p> </div> <div class='author_edit' id="<%= form_tag_id( f.object_name, :edit_author_info ) %>"> - <p> - <%= f.text_field :name_on_paper, {:class => ("readonly" unless params[:action] == "new") } %></p> - <p class='description' style=<%= "display:none;" unless params[:action] == "new" %>><%= h l("text_author_name_on_paper") %></p> - <p><%= f.text_field :institution, {:class => ("readonly" unless params[:action] == "new") } %></p> - <p class='description' style=<%= "display:none;" unless params[:action] == "new" %>><%= h l("text_author_institution") %></p> - <p><%= f.text_field :email, {:class => ("readonly" unless params[:action] == "new") } %></p> - <p class='description' style=<%= "display:none;" unless params[:action] == "new" %>><%= h l("text_author_email") %></p> - </p> - <%= 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 )) -%> + <p><%= f.text_field :name_on_paper, {:class => ("readonly" unless params[:action] == "new") } %></p> + <p class='description' style=<%= "display:none;" unless params[:action] == "new" %>><%= h l("text_author_name_on_paper") %></p> - <%= 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 )) -%> + <p><%= f.text_field :institution, {:class => ("readonly" unless params[:action] == "new") } %></p> + <p class='description' style=<%= "display:none;" unless params[:action] == "new" %>><%= h l("text_author_institution") %></p> + <p><%= f.text_field :email, {:class => ("readonly" unless params[:action] == "new") } %></p> + <p class='description' style=<%= "display:none;" unless params[:action] == "new" %>><%= h l("text_author_email") %></p> + + <%= 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 )) -%> </div> + <div> + <p> + <%= button_to_function l(:label_save_author), '', :id => form_tag_id(f.object_name, :edit_save_button), :class => 'author_save_btn' -%> - <div class="box" id="<%= form_tag_id( f.object_name, :show_author_info ) %>" style="display: none"> + <%= 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 %> + </p> </div> +</div> - <p> - - <%= 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 %> - </p> -</div> -<br/>
--- a/plugins/redmine_bibliography/app/views/publications/_form.html.erb Thu Jul 18 12:21:45 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/publications/_form.html.erb Tue Sep 17 09:51:20 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; + });" + -%> <h3><%= f.text_field :title, :required => true, :size => 70 %></h3>
--- a/plugins/redmine_bibliography/app/views/publications/edit.html.erb Thu Jul 18 12:21:45 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/publications/edit.html.erb Tue Sep 17 09:51:20 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 %> <h2><%=l(:label_publication_show)%></h2> @@ -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 } %> </p> +
--- a/plugins/redmine_bibliography/app/views/publications/new.html.erb Thu Jul 18 12:21:45 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/publications/new.html.erb Tue Sep 17 09:51:20 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 %>
--- a/plugins/redmine_bibliography/app/views/publications/show.html.erb Thu Jul 18 12:21:45 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/publications/show.html.erb Tue Sep 17 09:51:20 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)}'}); + } + }); + }); +" -%> + <h2><%=l(:label_publication_show)%></h2> <div class="box">
--- 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; +}
--- 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; +} +
--- 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