Revision 1051:ef882e222003

View differences:

app/models/attachment.rb
69 69
      end
70 70
    end
71 71
  end
72
	
72

  
73 73
  def file
74 74
    nil
75 75
  end
......
168 168
  end
169 169

  
170 170
  def self.latest_attach(attachments, filename)
171
    attachments.sort_by(&:created_on).reverse.detect { 
171
    attachments.sort_by(&:created_on).reverse.detect {
172 172
      |att| att.filename.downcase == filename.downcase
173 173
     }
174 174
  end
vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb
7 7
  unloadable
8 8

  
9 9
  model_object Publication
10
  before_filter :find_model_object, :except => [:parse_bibtex, :new, :create, :index, :get_bibtex_required_fields, :autocomplete_for_project, :add_author, :sort_author_order, :autocomplete_for_author, :get_user_info ]  
10
  before_filter :find_model_object, :except => [:parse_bibtex, :new, :create, :index, :get_bibtex_required_fields, :autocomplete_for_project, :add_author, :sort_author_order, :autocomplete_for_author, :get_user_info ]
11 11
  before_filter :find_project_by_project_id, :authorize, :only => [ :edit, :new, :update, :create ]
12 12

  
13 13
  def new
......
18 18
    @publication.build_bibtex_entry
19 19

  
20 20
    # and at least one author
21
    # @publication.authorships.build.build_author        
21
    # @publication.authorships.build.build_author
22 22
    @author_options = [["#{User.current.name} (@#{User.current.mail.partition('@')[2]})", "#{User.current.class.to_s}_#{User.current.id.to_s}"]]
23 23
  end
24 24

  
25

  
26 25
  def parse_bibtex
27 26
    find_project_by_project_id
28 27

  
29
    @bibtex_paste = params[:bibtex_paste]
28
    bibtex_paste = params[:bibtex_paste]
29
    bib = BibTeX.parse(bibtex_paste)
30 30

  
31
    begin
32
      bib = BibTeX.parse(@bibtex_paste)
31
    respond_to do |format|
32
      if bib.errors.present? or bib[0].class == NilClass
33 33

  
34
      if bib.errors.present? or bib[0].class == NilClass
35
        raise BibtexParsingError, "Bibtex Parsing Error"
34
        # todo: response for HTML
35
        format.html{}
36

  
37
        # todo: better error handling
38
        biberror = bib.errors[0].trace[4]
39
        logger.error { "BibTex Parsing Error: #{biberror}" }
40
        flash[:error] = "BibTex Parsing Error: #{biberror}"
41
        #raise BibtexParsingError, "Bibtex Parsing Error: biberror}"
42
        format.js
43
      else
44
        @ieee_prev = CiteProc.process bib.to_citeproc, :style => :ieee, :format => :html
45
        flash['notice'] = "OK!"
46
        format.js
36 47
      end
48
    end
49
  end
37 50

  
38
      respond_to do |format| 
39
        format.js {
40
          render(:update) {|page|
41
            flash[:notice] = "Correctly parsed BibTeX entry"
42 51

  
43
            bibtex_entry_no = BibtexEntryType.find_by_name(bib[0].type.to_s).id
44
            page["publication_title"].value = bib[0][:title]
45
            page["publication_bibtex_entry_attributes_entry_type"].value = bibtex_entry_no
46
            
47
            BibtexEntryType.fields(bibtex_entry_no).each do |field|
48
              page["publication_bibtex_entry_attributes_#{field}"].value = bib[0][field]
49
            end
52
#      respond_to do |format|
53
#        format.js {
54
#          render(:update) {|page|
55
#            flash.now[:notice] = "Correctly parsed BibTeX entry"
56
#
57
#            bibtex_entry_no = BibtexEntryType.find_by_name(bib[0].type.to_s).id
58
#            page["publication_title"].value = bib[0][:title]
59
#            page["publication_bibtex_entry_attributes_entry_type"].value = #bibtex_entry_no
60
#
61
#            BibtexEntryType.fields(bibtex_entry_no).each do |field|
62
#              page["publication_bibtex_entry_attributes_#{field}"].value = bib[0][field#]
63
#            end
64
#
65
#            # for each author simulates a click and fills the author info
66
##            bib[0].authors.each do |author|
67
##              page["add_another_author"].click
68
##              page.alert(bib[0].authors.length)
69
##              page.alert(page["authors"].first.id)
70
##            end
71
#
72
#
73
#
74
#          }
75
#        }
76
#      end
50 77

  
51
            # for each author simulates a click and fills the author info                        
52
            bib[0].authors.each do |author|            
53
              page["add_another_author"].click
54
#              page.alert(bib[0].authors.length)
55
#              page.alert(page["authors"].first.id)
56
            
57
            end
58
            
59

  
60

  
61
          }
62
        }
63
      end
64

  
65
    rescue BibtexParsingError => e
66
      logger.error { "Bibtex Parsing Error #{bib.errors}" }
78
#    rescue BibtexParsingError => e
79
#      logger.error { "Bibtex Parsing Error #{bib.errors}" }
67 80

  
68 81
      # todo: not showing... should be inside render?
69
      flash[:error] = e.message
70
      
71
      respond_to do |format|
72
       format.js{ 
73
         render(:update) {|page|
74
         }
75
       }
76
      end
82
#      flash[:error] = e.message
77 83

  
78
    end
84
#      respond_to do |format|
85
#       format.js{
86
#         render(:update) {|page|
87
#         }
88
#       }
89
#      end
79 90

  
80
  end
91
#    end
81 92

  
82 93

  
83
  def create            
94

  
95
  def create
84 96
    @project = Project.find(params[:project_id])
85 97

  
86 98
    @author_options = []
......
88 100
    @publication = Publication.new(params[:publication])
89 101
    @publication.projects << @project unless @project.nil?
90 102

  
91
    if @publication.save 
103
    if @publication.save
92 104
      @publication.notify_authors_publication_added(@project)
93 105

  
94 106
      flash[:notice] = "Successfully created publication."
......
116 128

  
117 129
    # method for creating "pasted" bibtex entries
118 130
    if bibtex_entry
119
      parse_bibtex_list bibtex_entry    
131
      parse_bibtex_list bibtex_entry
120 132
    end
121 133
  end
122 134

  
123 135
  def get_bibtex_required_fields
124 136

  
125
    fields = BibtexEntryType.fields(params[:q]) 
137
    fields = BibtexEntryType.fields(params[:q])
126 138

  
127 139
    respond_to do |format|
128 140
      format.js {
129
        render(:update) {|page|       
141
        render(:update) {|page|
130 142
          if params[:q].empty?
131 143
            page << "hideOnLoad();"
132 144
          else
......
148 160
    end
149 161
  end
150 162

  
151
  def edit   
163
  def edit
152 164
    find_project_by_project_id unless params[:project_id].nil?
153 165

  
154 166
    @edit_view = true;
155 167
    @publication = Publication.find(params[:id])
156 168
    @selected_bibtex_entry_type_id = @publication.bibtex_entry.entry_type
157 169

  
158
    @author_options = []  
170
    @author_options = []
159 171

  
160
    @bibtype_fields = BibtexEntryType.fields(@selected_bibtex_entry_type_id)    
172
    @bibtype_fields = BibtexEntryType.fields(@selected_bibtex_entry_type_id)
161 173
  end
162 174

  
163
  def update    
164
    @publication = Publication.find(params[:id])        
175
  def update
176
    @publication = Publication.find(params[:id])
165 177

  
166 178
    @author_options = []
167 179

  
......
175 187
      end
176 188
    else
177 189
      render :action => 'edit'
178
    end   
190
    end
179 191
  end
180 192

  
181 193

  
......
197 209
    return authors_entry.split(" and ")
198 210
  end
199 211

  
200
  # parses a list of bibtex 
212
  # parses a list of bibtex
201 213
  def parse_bibtex_list(bibtex_list)
202 214
    bibliography = BibTeX.parse bibtex_list
203 215

  
......
210 222
        create_bibtex_entry d
211 223
      end
212 224
    end
213
  end 
225
  end
214 226

  
215
  def create_bibtex_entry(d)        
227
  def create_bibtex_entry(d)
216 228
    @publication = Publication.new
217
    @bentry = BibtexEntry.new        
229
    @bentry = BibtexEntry.new
218 230
    authors = []
219 231
    institution = ""
220 232
    email = ""
......
232 244
      else
233 245
        @bentry[field] = d[field]
234 246
      end
235
    end 
247
    end
236 248

  
237 249
    @publication.bibtex_entry = @bentry
238 250
    @publication.save
239 251

  
240
    # what is this for??? 
252
    # what is this for???
241 253
    # @created_publications << @publication.id
242 254

  
243 255
    # need to save all authors
244
    #   and establish the author-publication association 
245
    #   via the authorships table 
256
    #   and establish the author-publication association
257
    #   via the authorships table
246 258
    authors.each_with_index.map do |authorname, idx|
247 259
      author = Author.new(:name => authorname)
248 260
      if author.save!
......
274 286
  def autocomplete_for_project
275 287
    @publication = Publication.find(params[:id])
276 288

  
277
    @projects = Project.active.like(params[:q]).find(:all, :limit => 100) - @publication.projects            
289
    @projects = Project.active.like(params[:q]).find(:all, :limit => 100) - @publication.projects
278 290
    logger.debug "Query for \"#{params[:q]}\" returned \"#{@projects.size}\" results"
279 291
    render :layout => false
280 292
  end
281
  
282 293

  
283
  def autocomplete_for_author    
294

  
295
  def autocomplete_for_author
284 296
    @results = []
285 297

  
286 298
    object_id = params[:object_id]
......
294 306

  
295 307
    @results = users_list
296 308

  
297
    # TODO: can be optimized…    
298
    authorships_list.each do |authorship|      
309
    # TODO: can be optimized…
310
    authorships_list.each do |authorship|
299 311
      flag = true
300 312

  
301 313
      users_list.each do |user|
......
309 321
      @results << authorship if flag
310 322
    end
311 323

  
312
    render :layout => false    
324
    render :layout => false
313 325
  end
314 326

  
315 327
  def get_user_info
......
327 339

  
328 340
    respond_to do |format|
329 341
      format.js {
330
        render(:update) {|page| 
342
        render(:update) {|page|
331 343
          page[name_field].value = item.name
332 344
          page[email_field].value = item.mail
333 345
          page[institution_field].value = item.institution
......
349 361
  end
350 362

  
351 363
  def add_project
352
    @projects = Project.find(params[:publication][:project_ids])    
364
    @projects = Project.find(params[:publication][:project_ids])
353 365
    @publication.projects << @projects
354
    @project = Project.find(params[:project_id])    
366
    @project = Project.find(params[:project_id])
355 367

  
356
    # TODO luisf should also respond to HTML??? 
368
    # TODO luisf should also respond to HTML???
357 369
    respond_to do |format|
358 370
      format.html { redirect_to :back }
359
      format.js { 
360
        render(:update) {|page| 
361
          page[:add_project_form].reset          
371
      format.js {
372
        render(:update) {|page|
373
          page[:add_project_form].reset
362 374
          page.replace_html :list_projects, :partial => 'list_projects'
363 375
        }
364 376
      }
......
375 387
        @publication.projects.delete proj if request.post?
376 388
      end
377 389
    else
378
      logger.error { "Cannot remove project from publication list" }      
390
      logger.error { "Cannot remove project from publication list" }
379 391
    end
380 392

  
381 393
    logger.error { "CURRENT project name#{proj.name} and wanna delete #{@project.name}" }
382 394

  
383
    render(:update) {|page| 
395
    render(:update) {|page|
384 396
      page.replace_html "list_projects", :partial => 'list_projects', :id  => @publication
385
    }    
397
    }
386 398
  end
387 399

  
388 400
  def destroy
vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb
5 5
  include AuthorshipsHelper
6 6

  
7 7
  def create_publication_tabs
8
    tabs = [{:name => 'default', :partial => 'publications/new/default', :label => :label_default},
9
            {:name => 'bibtex', :partial => 'publications/new/bibtex', :label => :label_bibtex},
10
          ]
8
    tabs = [
9
      {:name => 'bibtex', :partial => 'publications/new/bibtex', :label => :label_bibtex},
10
      {:name => 'default', :partial => 'publications/new/default', :label => :label_default}
11
    ]
11 12
  end
12 13

  
13 14
  def link_to_publication(publication, options={}, html_options = nil)
vendor/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
    <%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %>  
3
    <%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %>
4 4
    <%= javascript_tag 'Event.observe(window, "load", function(e){show_required_bibtex_fields(' + @bibtype_fields.to_json + ')});' %>
5 5
<% end %>
6 6

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

  
6
<%= error_messages_for 'publication' %>
7

  
6 8
<h2><%=l(:label_publication_new)%></h2>
7 9

  
10
<div class="splitcontentleft">
8 11
  <p>To create a publication you can either parse a BibTeX entry or enter the publication details manually.<p>
9 12

  
10
  <%= render_tabs create_publication_tabs %>
13
    <%= render :partial => 'publications/new/bibtex' %>
11 14

  
15
 <!-- <%= render_tabs create_publication_tabs %> -->
16
</div>
17

  
18
<div class="splitcontentright">
19

  
20
    <%= render :partial => 'publications/new/default' %>
21

  
22

  
23
</div>
vendor/plugins/redmine_bibliography/app/views/publications/new/_bibtex.html.erb
1
<%- remote_form_for @publication, :url =>  { :project_id  => @project, :action => :parse_bibtex }, :class => "tabular" do |f| -%>
2
  <div class="box tabular settings">
3
    <%= text_area_tag :bibtex_paste, "Please paste your bibtex entry here" , :class => "wiki", :style => 'width:90%' -%>
4
    <div style="clear:both"></div>
5
    <%= f.submit "Parse BibTex" %>
6
  </div>
7
<%- end -%>
1

  
2

  
3
<div class="box">
4
  <%= text_area_tag :bibtex_paste, "Please paste your bibtex entry here" , :class => "wiki", :style => 'width:90%' -%>
5

  
6
  <br />
7

  
8
  <%= link_to_remote "Parse BiBTeX", :url =>  { :project_id  => @project, :action => :parse_bibtex}, :with => "'bibtex_paste=' + $('bibtex_paste').value" -%>
9
</div>
10

  
11
<div class="box" id="ieee_prev"></div>
12

  
vendor/plugins/redmine_bibliography/app/views/publications/new/_default.html.erb
1
<% form_for @publication, :url => { :project_id  => @project, :action => :create }, :class => "tabular" do |f| -%>
1
<% form_for @publication, :url => { :project_id  => @project, :action => :create }, :builder => TabularFormBuilder do |f| -%>
2 2
  <div class="box tabular settings">
3
    <%= render :partial => 'form', :locals => { :f => f }  %>
4
    <div style="clear:both"></div>
5
    <%= f.submit %>
3
    <fieldset>
4
      <%= render :partial => 'form', :locals => { :f => f }  %>
5

  
6
      <div style="clear:both"></div>
7
      <%= f.submit %>
8
    </fieldset>
6 9
  </div>
7 10
<%- end -%>
vendor/plugins/redmine_bibliography/app/views/publications/parse_bibtex.rjs
1
page.replace_html :ieee_prev, @ieee_prev
2

  
3
page.replace_html :error, flash[:error]
4
flash.discard

Also available in: Unified diff