Revision 1394:0f918e37e1d6 plugins

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 %>
plugins/redmine_bibliography/assets/javascripts/authors.js
10 10
  $(link).closest(".fields").hide();
11 11
}
12 12

  
13
$(".author_search").live('keyup.autocomplete', function(){
13
$(".author_name_on_paper").live('keyup.autocomplete', function(){
14 14
     $this = $(this);
15 15

  
16 16
     $this.autocomplete({
......
21 21
            return false;
22 22
        },
23 23
        select: function(event, ui){
24
            $this.closest('div').next().find("input[id$='name_on_paper']").val(ui.item.name);
25
            $this.closest('div').next().find("input[id$='institution']").val(ui.item.institution);
26
            $this.closest('div').next().find("input[id$='email']").val(ui.item.email);
27
            $this.closest('div').next().find("input[id$='search_author_class']").val(ui.item.search_author_class);
28
            $this.closest('div').next().find("input[id$='search_author_id']").val(ui.item.search_author_id);
24
            $this.closest('div').find("input[id$='institution']").val(ui.item.institution);
25
            $this.closest('div').find("input[id$='email']").val(ui.item.email);
26

  
27
            $this.closest('div').find("input[id$='search_author_class']").val(ui.item.search_author_class);
28
            $this.closest('div').find("input[id$='search_author_id']").val(ui.item.search_author_id);
29
            $this.closest('div').find("input[id$='search_author_tie']").attr('checked', 'checked');
30

  
31

  
32

  
33
            // triggers the save button
34
            $this.closest('div').next('div').find('.author_save_btn').click();
29 35
        }
30 36
        })
31 37
        .data( "autocomplete" )._renderItem = function( ul, item ) {
......
36 42
            };
37 43
        });
38 44

  
39

  
40
$("input[id$='identify_author_yes']").live("click", function() {
41
    console.log("aaaa");
42
});
43

  
44
$("input[id$='identify_author_no']").live("click", function() {
45
    $this.closest('div').next().find("input[id$='name_on_paper']").val('');
46
    $this.closest('div').next().find("input[id$='institution']").val('');
47
    $this.closest('div').next().find("input[id$='email']").val('');
48
    $this.closest('div').next().find("input[id$='search_author_class']").val('');
49
});
50

  
plugins/redmine_bibliography/assets/javascripts/bibliography.js
2 2

  
3 3
function disable_fields(){
4 4
	$this = $(this);
5

  
5 6
	$author_info = $this.closest('div').prev();
6
	$author_info.children('.description').toggle();
7
//    $author_info.children('.description').toggle();
7 8
	$author_info.find('p :input').attr("readonly", true);
8 9
    $author_info.find('p :input').addClass('readonly');
9 10

  
......
15 16

  
16 17
function enable_fields(){
17 18
    $this = $(this);
19

  
18 20
    $author_info = $this.closest('div').prev();
19
    $author_info.children('.description').toggle();
21
//    $author_info.children('.description').toggle();
20 22
    $author_info.find('p :input').attr("readonly", false);
21 23
    $author_info.find('p :input').removeClass('readonly');
22 24

  
......
25 27

  
26 28
    return false;
27 29
}
30

  
plugins/redmine_bibliography/assets/stylesheets/bibliography.css
20 20
}
21 21

  
22 22
.tabular .author_edit .description {
23
    padding-top: 0;
24 23
    font-style: italic;
24
    font-size: small;
25 25
}
26 26

  
27 27
.publication_project {
28 28
    margin-right: 18px;
29 29
}
30 30

  
31
#authors select {
32
    min-width: 150px;
33
}
34

  
35

  
36 31
div#bibliography dd { margin-bottom: 1em; font-size: 0.9em; }
37 32

  
38 33
div#bibliography dd .authors { font-style: italic; }
......
74 69
.author_edit_btn {
75 70
  display:none;
76 71
}
77

  

Also available in: Unified diff