Revision 1403:35732ac4324a
| plugins/redmine_bibliography/app/models/authorship.rb | ||
|---|---|---|
| 52 | 52 |
@search_author_class || aclass |
| 53 | 53 |
end |
| 54 | 54 |
|
| 55 |
# def search_author_class=(search_author_class) |
|
| 56 |
# @search_author_class = search_author_class |
|
| 57 |
# end |
|
| 58 |
|
|
| 59 | 55 |
def search_author_id |
| 60 | 56 |
if self.author.nil? |
| 61 | 57 |
authid = "" |
| ... | ... | |
| 99 | 95 |
private |
| 100 | 96 |
|
| 101 | 97 |
def set_author |
| 102 |
# if an author, simply associates with it |
|
| 103 |
# if an user, checks if it has already an author associated with it |
|
| 104 |
# if so, assicoates with that author |
|
| 105 |
# otherwise, creates a new author |
|
| 98 |
# do we want to associate the authorship |
|
| 99 |
# with an existing author/user? |
|
| 100 |
if @search_author_tie |
|
| 101 |
# if an author, simply associates with it |
|
| 102 |
# if an user, checks if it has already an author associated with it |
|
| 103 |
# if so, associates with that author |
|
| 104 |
# otherwise, creates a new author |
|
| 106 | 105 |
|
| 107 |
logger.error { "%%%%%%%%%%%%%%% Associate Author User %%%%%%%%%%%%%%" }
|
|
| 106 |
case @search_author_class |
|
| 107 |
when "" |
|
| 108 |
author = Author.new |
|
| 109 |
author.save |
|
| 108 | 110 |
|
| 109 |
logger.error { "Me #{self.to_yaml}" }
|
|
| 110 |
logger.error { "Class: #{@search_author_class}" }
|
|
| 111 |
logger.error { "ID #{@search_author_id}" }
|
|
| 111 |
when "User" |
|
| 112 |
user = User.find(@search_author_id) |
|
| 112 | 113 |
|
| 113 |
case @search_author_class |
|
| 114 |
when "" |
|
| 115 |
logger.debug { "Adding new author to the database." }
|
|
| 114 |
if user.author.nil? |
|
| 115 |
# User w/o author: |
|
| 116 |
# create new author and update user |
|
| 117 |
author = Author.new |
|
| 118 |
author.save |
|
| 119 |
user.author = author |
|
| 120 |
user.save |
|
| 121 |
else |
|
| 122 |
author = user.author |
|
| 123 |
end |
|
| 124 |
|
|
| 125 |
when "Author" |
|
| 126 |
author = Author.find(@search_author_id) |
|
| 127 |
end |
|
| 128 |
|
|
| 129 |
# if we don't want to associate with an existing author/user |
|
| 130 |
else |
|
| 131 |
# todo: should we delete any previously existing relationship? |
|
| 116 | 132 |
author = Author.new |
| 117 | 133 |
author.save |
| 118 |
|
|
| 119 |
when "User" |
|
| 120 |
# get user id |
|
| 121 |
user = User.find(@search_author_id) |
|
| 122 |
logger.error { "Found user with this ID: #{user.id}" }
|
|
| 123 |
|
|
| 124 |
if user.author.nil? |
|
| 125 |
logger.error { "The user has no author... creating one!" }
|
|
| 126 |
|
|
| 127 |
# User w/o author: |
|
| 128 |
# create new author and update user |
|
| 129 |
author = Author.new |
|
| 130 |
author.save |
|
| 131 |
user.author = author |
|
| 132 |
user.save |
|
| 133 |
else |
|
| 134 |
logger.error { "found an author!" }
|
|
| 135 |
author = user.author |
|
| 136 |
end |
|
| 137 |
|
|
| 138 |
when "Author" |
|
| 139 |
author = Author.find(@search_author_id) |
|
| 140 | 134 |
end |
| 141 | 135 |
|
| 142 | 136 |
self.author = author |
| plugins/redmine_bibliography/app/views/publications/_authorship_fields.html.erb | ||
|---|---|---|
| 5 | 5 |
<p><%= f.text_field :institution -%></p> |
| 6 | 6 |
<p><%= f.text_field :email -%></p> |
| 7 | 7 |
|
| 8 |
<p class="author_associated"> |
|
| 9 |
<%= f.check_box :search_author_tie, :style => "float:left;" -%>
|
|
| 8 |
<p class="author_associated search_author_tie">
|
|
| 9 |
<%= f.check_box :search_author_tie -%> |
|
| 10 | 10 |
<span class="author_associated_name"></span> |
| 11 | 11 |
</p> |
| 12 | 12 |
|
| 13 |
<%= f.text_field :search_author_class -%>
|
|
| 14 |
<%= f.text_field :search_author_id -%>
|
|
| 13 |
<%= f.hidden_field :search_author_class -%>
|
|
| 14 |
<%= f.hidden_field :search_author_id -%>
|
|
| 15 | 15 |
</div> |
| 16 | 16 |
|
| 17 | 17 |
<div> |
| plugins/redmine_bibliography/assets/javascripts/authors.js | ||
|---|---|---|
| 28 | 28 |
$this.closest('div').find("input[id$='search_author_id']").val(ui.item.search_author_id);
|
| 29 | 29 |
$this.closest('div').find("input[id$='search_author_tie']").attr('checked', 'checked');
|
| 30 | 30 |
|
| 31 |
|
|
| 32 |
|
|
| 33 | 31 |
// triggers the save button |
| 34 | 32 |
$this.closest('div').next('div').find('.author_save_btn').click();
|
| 35 | 33 |
} |
| ... | ... | |
| 37 | 35 |
.data( "autocomplete" )._renderItem = function( ul, item ) {
|
| 38 | 36 |
return $( "<li>" ) |
| 39 | 37 |
.data("item.autocomplete", item )
|
| 40 |
.append( "<a>" + item.label + "<br><em>" + item.email + "</em><br>" + item.intitution + "</a>" ) |
|
| 38 |
.append( "<a>" + item.label + "<br><em>" + item.email + "</em><br>" + item.institution + "</a>" )
|
|
| 41 | 39 |
.appendTo(ul); |
| 42 | 40 |
}; |
| 43 | 41 |
}); |
| plugins/redmine_bibliography/assets/stylesheets/bibliography.css | ||
|---|---|---|
| 66 | 66 |
background-image: url(../../../images/loading.gif); |
| 67 | 67 |
} |
| 68 | 68 |
|
| 69 |
.author_edit_btn {
|
|
| 70 |
display:none; |
|
| 69 |
.authorship_tie {
|
|
| 70 |
display: none; |
|
| 71 |
float: left; |
|
| 71 | 72 |
} |
Also available in: Unified diff