Revision 445:77f88379115a vendor/plugins/redmine_bibliography

View differences:

vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb
6 6

  
7 7
  def new
8 8
    @publication = Publication.new      
9

  
9
    
10
    # we'll always want a new publication to have its bibtex entry
11
    @publication.build_bibtex_entry
12
    
10 13
    # the step we're at in the form
11 14
    @publication.current_step = session[:publication_step]
12 15

  
......
16 19

  
17 20
  def create
18 21
    @publication = Publication.new(params[:publication])
22

  
23
    if @publication.save
24
      flash[:notice] = "Successfully created publication."
25
      redirect_to @publication
26
    else
27
      render :action => 'new'
28
    end
29
  end
30

  
31
  def index
32
    @publications = Publication.find(:all)
33
  end
34

  
35
  def new_from_bibfile
19 36
    @publication.current_step = session[:publication_step]
20 37
    
21 38
    # contents of the paste text area
......
36 53
    end
37 54

  
38 55
    session[:publication_step] = @publication.current_step
39

  
40
    if @publication.new_record?
41
      render "new"
42
    else
43
      session[:publication_step] = session[:publication_params] = nil
44
      flash[:notice] = "New publication saved!"
45
      redirect_to @publication
46
    end
47
  end
48

  
49
  def index
50
    @publications = Publication.find(:all)
51
  end
52

  
53
  def edit
54
    
55
    @publication = Publication.find(params[:id])
56 56
    
57 57
  end
58 58

  
59
  def update
59

  
60
  def edit    
60 61
    @publication = Publication.find(params[:id])
62
  end
63

  
64
  def update    
65
    @publication = Publication.find(params[:id])
66
        
61 67
    if @publication.update_attributes(params[:publication])
62 68
      flash[:notice] = "Successfully updated Publication."
63
      redirect_to @publication
64 69
    else
65
      render :action => 'edit'
70
      flash[:notice] = "Could not Update Publication."
66 71
    end
72
    
67 73
  end
68 74

  
69 75
  def show
76
    logger.error "-------> No Show"
77
    
70 78
    @publication = Publication.find(params[:id])
71 79

  
72 80
    if @publication.nil?
vendor/plugins/redmine_bibliography/app/models/author.rb
2 2
  has_many :authorships
3 3
  has_many :publications, :through => :authorships
4 4

  
5
  belongs_to :user
5
  # belongs_to :user
6 6
  
7 7
end
vendor/plugins/redmine_bibliography/app/models/publication.rb
2 2

  
3 3
class Publication < ActiveRecord::Base
4 4
  unloadable
5

  
6

  
5
  
7 6
  has_many :authorships
8 7
  has_many :authors, :through => :authorships
9
  has_one :bibtex_entry
8
  has_one :bibtex_entry, :dependent => :destroy
10 9

  
11 10
  validates_presence_of :title
11

  
12
  accepts_nested_attributes_for :authorships
13
  accepts_nested_attributes_for :authors, :reject_if => lambda { |a| a[:name].blank? }, :allow_destroy => true
14
#  accepts_nested_attributes_for :bibtex_entry, :reject_if => lambda { |a| a[:name].blank? }, :allow_destroy => true 
12 15
  
13
  accepts_nested_attributes_for :authors, :bibtex_entry
16
  
14 17
  
15 18
  attr_writer :current_step
16 19

  
vendor/plugins/redmine_bibliography/app/views/publications/_edit.html.erb
1
<% form_for @publication do |f| -%>
2
  <%= f.error_messages %>
3
  <p>
4
    <%= f.label :title, l(:title) %>  <%= f.text_field :title %>  
5
  </p>
6
  
7
  <h3><%= l(:authors) %></h3>
8
  
9
  <%- f.fields_for :authors do |author| -%>
10
    <p>
11
      <%= author.label :name, l("name") %> <%= author.text_field :name %>            
12
    </p>
13
  <%- end -%>
14
  
15
  <% f.fields_for :bibtex_entry do |bib| -%>
16
    <p> 
17
      <%= bib.label :year, l(:year) %>  <%= bib.text_field :year %>  
18
    </p>
19
    <p> 
20
      <%= bib.label :chapter, l(:chapter) %>  <%= bib.text_field :chapter %>  
21
    </p>
22
    <p>  
23
      <%= bib.label :editor, l(:editor) %>  <%= bib.text_field :editor %>  
24
    </p>
25
    <p> 
26
      <%= bib.label :booktitle, l(:booktitle) %>  <%= bib.text_field :booktitle %>  
27
    </p>
28
    <p> 
29
      <%= bib.label :publisher, l(:publisher) %>  <%= bib.text_field :publisher %>  
30
    </p>
31
    <p> 
32
      <%= bib.label :pages, l(:pages) %>  <%= bib.text_field :pages %>  
33
    </p>
34
  <% end -%>
35

  
36
  <%= f.submit %>
37

  
38
<% end -%>
vendor/plugins/redmine_bibliography/app/views/publications/edit.html.erb
2 2

  
3 3
<%= render :partial => 'edit' %>
4 4

  
5

  
6 5
<p>
7 6
  <%= link_to :show %></p>
8 7

  
vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb
1 1
<h1>New Publication</h1>
2 2

  
3 3
<%= render :partial => 'edit' %>
4

  
vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb
1 1
<h2>Publication Details</h2>
2 2
<h4>Title</h4>
3
<%= @publication.title %>
3
<%= h @publication.title %>
4 4

  
5 5
<h4>Authors</h4>
6 6
<% @publication.authors.each do |author| %>
7
<%= author.name  %> <br />
7
<%= h author.name  %> <br />
8 8
<% end %>
9 9
<br />
10 10

  
11
<%- if @publication.bibtex_entry != nil -%>
11 12
<% @publication.bibtex_entry.attributes.each do |field| %>
12 13
  <% if field[1] != nil %>
13 14
    <h4><%= field[0] %></h4>
14 15
    <%= @publication.bibtex_entry.attributes[field[0]] unless field[1] == nil %>
15 16
    <br />
16
  <% end %>
17
<% end %>
17
  <%- end -%>
18
<%- end -%>
19
<%- end -%>
18 20

  
19 21

  
20

  

Also available in: Unified diff