Revision 1383:f019ad7fcf1b plugins/redmine_bibliography/app

View differences:

plugins/redmine_bibliography/app/controllers/authorships_controller.rb
1 1
class AuthorshipsController < ApplicationController
2
  
3
  def index
4
    
5
  end
6
  
7 2

  
8
  def update
9
  end
3
    def sort
4
        @authorships = Authorship.find(params['authorship'])
5

  
6
        @authorships.each do |authorship|
7

  
8
            # note: auth_order is usually called position (default column name in the acts_as_list plugin )
9
            authorship.auth_order = params['authorship'].index(authorship.id.to_s) + 1
10
            authorship.save
11
        end
12

  
13
        render :nothing => true, :status => 200
14
    end
10 15
end
plugins/redmine_bibliography/app/models/authorship.rb
10 10
  validates_presence_of :name_on_paper
11 11

  
12 12
  attr_accessor :search_author_class, :search_author_id, :search_name, :search_results, :identify_author
13
  before_save :associate_author_user
14 13

  
15
  acts_as_list
14
  before_create :associate_author_user
15
  before_update :delete_publication_cache
16

  
17
  # tod: review scope of ordering
18
  acts_as_list :column => 'auth_order'
16 19

  
17 20
  # todo: review usage of scope --lf.20130108
18 21
  scope :like_unique, lambda {|q|
......
44 47
  end
45 48

  
46 49
  protected
50

  
51
  def delete_publication_cache
52
    publication = Publication.find(self.publication_id)
53
    Rails.cache.delete "publication-#{publication.id}-ieee"
54
    Rails.cache.delete "publication-#{publication.id}-bibtex"
55
  end
56

  
47 57
  def associate_author_user
48 58
    case self.search_author_class
49
      when "User"
50
        author = Author.new
51
        author.save
52
        self.author_id = author.id
59
    when ""
60
      logger.debug { "Unknown Author to be added..." }
61
    when "User"
62
      author = Author.new
63
      author.save
64
      self.author_id = author.id
65

  
66
    when "Author"
67
      selected = self.search_results
68
      selected_classname = Kernel.const_get(self.search_author_class)
69
      selected_id = self.search_author_id
70
      object = selected_classname.find(selected_id)
71

  
72
      if object.respond_to? :name_on_paper
73
        # Authorship
74
        self.author_id = object.author.id
53 75
      else
54
        selected = self.search_results
55
        selected_classname = Kernel.const_get(self.search_author_class)
56
        selected_id = self.search_author_id
57
        object = selected_classname.find(selected_id)
58

  
59
        if object.respond_to? :name_on_paper
60
          # Authorship
76
        # User
77
        unless object.author.nil?
61 78
          self.author_id = object.author.id
62 79
        else
63
          # User
64
          unless object.author.nil?
65
            self.author_id = object.author.id
66
          else
67
            author = Author.new
68
            object.author = author
69
            object.save
70
            self.author_id = object.author.id
71
          end
80
          author = Author.new
81
          object.author = author
82
          object.save
83
          self.author_id = object.author.id
72 84
        end
85
      end
73 86
    end
74 87
  end
75 88
end
plugins/redmine_bibliography/app/views/publications/_authorship_fields.html.erb
1
<% content_for :header_tags do %>
2
  <%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %>
3
<% end %>
1
<%- content_for :header_tags do -%>
2
  <%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' -%>
3
  <%= javascript_include_tag 'bibliography', :plugin => 'redmine_bibliography' -%>
4
  <%= javascript_tag "$('.author_save_btn').live('click', disable_fields);" -%>
5
  <%= javascript_tag "$('.author_edit_btn').live('click', enable_fields);" -%>
6
<%- end -%>
4 7

  
5 8
<div id="authors" class="fields">
6 9
  <div id="<%= form_tag_id( f.object_name, :search_author ) %>" style=<%= "display:none;" unless params[:action] == "new" %> >
......
15 18

  
16 19
    <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 />
17 20

  
18
        <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 />
19
      </p>
21
    <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 />
22
    </p>
20 23
    </div>
21 24

  
22 25
  <div class='author_edit' id="<%= form_tag_id( f.object_name, :edit_author_info ) %>">
23
    <p>
24
      <%= f.text_field :name_on_paper, {:class => ("readonly" unless params[:action] == "new") } %></p>
25
      <p class='description' style=<%= "display:none;" unless params[:action] == "new" %>><%= h l("text_author_name_on_paper") %></p>
26
      <p><%= f.text_field :institution, {:class => ("readonly" unless params[:action] == "new") }  %></p>
27
      <p class='description' style=<%= "display:none;" unless params[:action] == "new" %>><%= h l("text_author_institution") %></p>
28
      <p><%= f.text_field :email, {:class => ("readonly" unless params[:action] == "new") }  %></p>
29
      <p class='description' style=<%= "display:none;" unless params[:action] == "new" %>><%= h l("text_author_email") %></p>
30
    </p>
31
        <%= 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 )) -%>
26
    <p><%= f.text_field :name_on_paper, {:class => ("readonly" unless params[:action] == "new") } %></p>
27
    <p class='description' style=<%= "display:none;" unless params[:action] == "new" %>><%= h l("text_author_name_on_paper") %></p>
32 28

  
33
        <%= 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 )) -%>
29
    <p><%= f.text_field :institution, {:class => ("readonly" unless params[:action] == "new") }  %></p>
30
    <p class='description' style=<%= "display:none;" unless params[:action] == "new" %>><%= h l("text_author_institution") %></p>
31
    <p><%= f.text_field :email, {:class => ("readonly" unless params[:action] == "new") }  %></p>
32
    <p class='description' style=<%= "display:none;" unless params[:action] == "new" %>><%= h l("text_author_email") %></p>
33

  
34
    <%= 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 )) -%>
35

  
36
    <%= 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 )) -%>
34 37
  </div>
35 38

  
39
  <div>
40
    <p>
41
      <%= button_to_function l(:label_save_author), '', :id => form_tag_id(f.object_name, :edit_save_button), :class => 'author_save_btn' -%>
36 42

  
37
  <div class="box" id="<%= form_tag_id( f.object_name, :show_author_info ) %>" style="display: none">
43
      <%= button_to_function l(:label_edit_author), '', :id => form_tag_id(f.object_name, :edit_button), :class => 'author_edit_btn' -%>
38 44

  
45
      <%= link_to_remove_fields l("remove_author"), f %>
46
    </p>
39 47
  </div>
48
</div>
40 49

  
41
  <p>
42

  
43
  <%= button_to_function l(:label_save_author), {}, :id => form_tag_id( f.object_name, :edit_save_button ) %>
44

  
45
  <%= link_to_remove_fields l("remove_author"), f %>
46
  </p>
47
</div>
48
<br/>
plugins/redmine_bibliography/app/views/publications/_form.html.erb
1 1
<%= error_messages_for 'publication' %>
2
    <%= javascript_tag "
3
        $('#publication_bibtex_entry_attributes_entry_type').live('change', function() {
4
            $this = $(this);
5
            $.ajax({
6
                type: 'get',
7
                url: '#{url_for(:controller => :publications, :action => :show_bibtex_fields)}',
8
                data: {
9
                    value: $this.val()
10
                },
11
                dataType: 'script'
12
            });
13
            return false;
14
        });"
15
    -%>
2 16

  
3 17
<h3><%= f.text_field :title, :required => true, :size => 70 %></h3>
4 18

  
plugins/redmine_bibliography/app/views/publications/edit.html.erb
1 1
<% content_for :header_tags do %>
2 2
    <%= javascript_include_tag 'authors', :plugin => 'redmine_bibliography' %>
3
    <%= javascript_include_tag 'bibliography', :plugin => 'redmine_bibliography' %>
4 3
    <%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %>
4
    <%= javascript_tag "$(document).ready(function() { $('#publication_bibtex_entry_attributes_entry_type').trigger('change'); });" %>
5 5
<% end %>
6 6

  
7 7
<h2><%=l(:label_publication_show)%></h2>
......
16 16
  <%= link_to l(:label_publication_show), { :controller => "publications", :action => "show", :id => @publication, :project_id => @project_id } %> |
17 17
  <%= link_to l(:label_publication_index), { :controller => "publications", :action => "index", :project_id => @project } %>
18 18
</p>
19

  
plugins/redmine_bibliography/app/views/publications/new.html.erb
1 1
<% content_for :header_tags do %>
2 2
    <%= javascript_include_tag 'authors', :plugin => 'redmine_bibliography' %>
3
    <%= javascript_include_tag 'bibliography', :plugin => 'redmine_bibliography' %>
4 3
    <%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %>
5 4
<% end %>
6 5

  
plugins/redmine_bibliography/app/views/publications/show.html.erb
1
<%= javascript_tag "$(document).ready(function(){
2

  
3
   $('#authorships').sortable({
4
       axis: 'y',
5
       dropOnEmpty: false,
6
       handle: '.handle',
7
       cursor: 'crosshair',
8
       items: 'li',
9
       opacity: 0.4,
10
       scroll: true,
11
       update: function(){
12
          $.ajax({
13
              type: 'post',
14
              data: $('#authorships').sortable('serialize'),
15
              dataType: 'script',
16
              complete: function(request){
17
                 $('#authorship').effect('highlight');
18
              },
19
                 url: '#{url_for(:controller => :authorships, :action => :sort)}'});
20
              }
21
          });
22
     });
23
" -%>
24

  
1 25
<h2><%=l(:label_publication_show)%></h2>
2 26

  
3 27
<div class="box">

Also available in: Unified diff