Revision 1394:0f918e37e1d6 plugins/redmine_bibliography/app

View differences:

plugins/redmine_bibliography/app/helpers/publications_helper.rb
106 106
    end
107 107
  end
108 108

  
109

  
110 109
  def show_bibtex_fields(bibtex_entry)
111 110
    s = ""
112 111
    bibtex_entry.attributes.keys.sort.each do |key|
......
124 123
    s
125 124
  end
126 125
end
127

  
plugins/redmine_bibliography/app/models/authorship.rb
9 9

  
10 10
  validates_presence_of :name_on_paper
11 11

  
12
  attr_accessor :search_author_class, :search_author_id, :search_name, :search_results, :identify_author
12
  attr_writer :search_author_id, :search_author_class
13
  attr_writer :search_author_tie
13 14

  
14
  before_create :associate_author_user
15
  ### attr_accessor :search_results, :identify_author
16
  ## attr_writer :search_author_class
17

  
18
  before_create :set_author
15 19
  before_update :delete_publication_cache
16 20

  
17 21
  # tod: review scope of ordering
......
34 38
    }
35 39
  }
36 40

  
41
  def search_author_class
42
    # Authorship must always have an Author
43
    # unless it hasn't been saved yet
44
    # using default setter (attr_writer)
45

  
46
    if self.author.nil?
47
      return ""
48
    else
49
      return "Author"
50
    end
51
  end
52

  
53
  def search_author_id
54
    if self.author.nil?
55
      return ""
56
    else
57
      return self.author_id
58
    end
59
  end
60

  
61
  def search_author_tie
62
    if self.author.nil?
63
      return false
64
    else
65
      return true
66
    end
67

  
68
  end
69

  
37 70
  def name
38 71
    return self.name_on_paper
39 72
  end
......
54 87
    Rails.cache.delete "publication-#{publication.id}-bibtex"
55 88
  end
56 89

  
57
  def associate_author_user
90
  def set_author
91
    # if an author, simply associates with it
92
    # if an user, checks if it has already an author associated with it
93
    # if so, assicoates with that author
94
    # otherwise, creates a new author
95

  
96
    logger.error { "%%%%%%%%%%%%%%% Associate Author User %%%%%%%%%%%%%%" }
97

  
98
    logger.error { "EU #{self.to_yaml}" }
99
    logger.error { "Class: #{search_author_class}" }
100
    logger.error { "ID #{search_author_id}" }
101

  
58 102
    case self.search_author_class
59 103
    when ""
60
      logger.debug { "Unknown Author to be added..." }
61
    when "User"
104
      logger.debug { "Adding new author to the database." }
62 105
      author = Author.new
63 106
      author.save
64
      self.author_id = author.id
107

  
108
    when "User"
109
      # get user id
110
      user = User.find(self.search_author_id)
111
      logger.error { "Found user with this ID: #{user.id}" }
112

  
113
      if user.author.nil?
114
        logger.error { "The user has no author... creating one!" }
115

  
116
        # User w/o author:
117
        # create new author and update user
118
        author = Author.new
119
        author.save
120
        user << author
121
      else
122
        logger.error { "found an author!" }
123
        author = user.author
124
      end
65 125

  
66 126
    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)
127
      author = Author.find(self.search_author_id)
128
    end
71 129

  
72
      if object.respond_to? :name_on_paper
73
        # Authorship
74
        self.author_id = object.author.id
75
      else
76
        # User
77
        unless object.author.nil?
78
          self.author_id = object.author.id
79
        else
80
          author = Author.new
81
          object.author = author
82
          object.save
83
          self.author_id = object.author.id
84
        end
85
      end
86
    end
130
    self.author = author
87 131
  end
88 132
end
plugins/redmine_bibliography/app/models/bibtex_entry_type.rb
1 1
class BibtexEntryType < ActiveRecord::Base
2 2
  unloadable
3 3

  
4
  @@fields = Hash['article', ['journal', 'year', 'volume', 'number', 'pages', 'month', 'note' ], 
4
  @@fields = Hash['article', ['journal', 'year', 'volume', 'number', 'pages', 'month', 'note' ],
5 5
                  'book' , [ 'editor', 'publisher', 'volume', 'series', 'address', 'edition', 'month', 'year', 'note' ],
6 6
                  'booklet' , [ 'howpublished', 'address', 'year', 'month', 'note', 'key' ],
7 7
                  'conference', [ 'booktitle', 'year', 'editor', 'pages', 'organization', 'publisher', 'address', 'month', 'note' ],
......
25 25
  end
26 26

  
27 27
  def self.fields (type)
28
    @@fields[ self.find(type).name ]    
28
    @@fields[ self.find(type).name ]
29 29
  end
30 30
end
plugins/redmine_bibliography/app/views/publications/_authorship_fields.html.erb
1 1
<div id="authors" class="fields">
2
  <div id="<%= form_tag_id( f.object_name, :search_author ) %>" >
3
    <p>
4
      <%= f.text_field :search_name, :size => 25, :class => "author_search" %>
2
  <div class="author_edit" id="<%= form_tag_id( f.object_name, :edit_author_info ) %>">
3

  
4
    <p><%= f.text_field :name_on_paper, :class => "author_name_on_paper" -%></p>
5
    <p><%= f.text_field :institution -%></p>
6
    <p><%= f.text_field :email -%></p>
7

  
8
    <p class="author_associated">
9
      <%= f.check_box :search_author_tie, :style => "float:left;" -%>
10
      <span class="author_associated_name"></span>
5 11
    </p>
6 12

  
7
    <p style="margin-bottom: -2.5em; padding-bottom; 0"><label><%= l(:identify_author_question) %></label></p>
8

  
9
    <p class="author_identify">
10
      <label class='inline'><%= radio_button_tag(:identify_author, "yes", false, :name => form_tag_name(f.object_name,:identify_author ), :id => form_tag_id( f.object_name, :identify_author_yes )) %> <%= l(:identify_author_yes) %> </label><br />
11

  
12
      <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 />
13

  
14
      <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 />
15
    </p>
16
  </div>
17

  
18
  <div class='author_edit' id="<%= form_tag_id( f.object_name, :edit_author_info ) %>">
19
    <p><%= f.text_field :name_on_paper -%></p>
20
    <p class="description"><%= h l("text_author_name_on_paper") -%></p>
21

  
22
    <p><%= f.text_field :institution -%></p>
23
    <p class="description"><%= h l("text_author_institution") %></p>
24

  
25
    <p><%= f.text_field :email -%></p>
26
    <p class="description"><%= h l("text_author_email") %></p>
27

  
28
    <%= 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 )) -%>
29
    <%= 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 )) -%>
13
    <%= f.text_field :search_author_class -%>
14
    <%= f.text_field :search_author_id -%>
30 15
  </div>
31 16

  
32 17
  <div>
......
38 23
      <%= link_to_remove_fields l("remove_author"), f %>
39 24
    </p>
40 25
  </div>
41
</div>
42

  
26
</div>
plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.html.erb
1
<%= raw @results.map {|result| {
1
<%= raw @results.map { |result|
2
    {
2 3
    'label' => result.name,
3 4
    'value' => result.name,
4 5
    'search_author_class' => result.class.name,
5 6
    'search_author_id' => result.id,
6 7
    'name' => result.name,
7 8
    'institution' => result.institution,
8
    'email' => result.mail,
9
    'email' => result.mail
9 10
    }
10 11
}.to_json %>

Also available in: Unified diff