# HG changeset patch # User luisf # Date 1316447052 -3600 # Node ID 2b665b7e67f4eac89ce46cbfe1317bff408da931 # Parent 614b2d1580d0504d3cd9d10e00320a8381436d1a Bug #297 - Simplified JS; no more need to have BibtexEntryType.all_fields; solves the "Please Select" bug in New Publication view. diff -r 614b2d1580d0 -r 2b665b7e67f4 vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb --- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Mon Sep 19 12:49:31 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Mon Sep 19 16:44:12 2011 +0100 @@ -64,21 +64,21 @@ def get_bibtex_required_fields - fields = BibtexEntryType.fields(params[:value]) - all_fields = BibtexEntryType.all_fields + unless params[:value].empty? + fields = BibtexEntryType.fields(params[:value]) + end respond_to do |format| format.js { - render(:update) {|page| - all_fields.each_with_index do |field, idx| - unless fields.include? field - page["publication_bibtex_entry_attributes_#{field}"].up('p').hide() - else - page["publication_bibtex_entry_attributes_#{field}"].up('p').show() - end + render(:update) {|page| + if params[:value].empty? + page << "hideOnLoad();" + else + page << "show_required_bibtex_fields(#{fields.to_json()});" end } } + end end diff -r 614b2d1580d0 -r 2b665b7e67f4 vendor/plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb --- a/vendor/plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb Mon Sep 19 12:49:31 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb Mon Sep 19 16:44:12 2011 +0100 @@ -8,73 +8,73 @@ :onChange => remote_function( :url => { :controller => :publications, :action => :get_bibtex_required_fields}, :with => "'value=' + value" ) %>

-

- <%= f.text_field :year, :size => 4, :class => 'bibtex' %> + +

+ <%= f.text_field :year, :size => 4 %>

-

- <%= f.text_field :month, :size => 4, :class => 'bibtex' %> +

+ <%= f.text_field :month, :size => 4%>

-

- <%= f.text_field :chapter, :size => 15, :class => 'bibtex' %> +

+ <%= f.text_field :chapter, :size => 15%>

-

- <%= f.text_field :editor, :size => 33, :class => 'bibtex' %> +

+ <%= f.text_field :editor, :size => 33 %>

-

- <%= f.text_field :booktitle, :size => 33, :class => 'bibtex' %> +

+ <%= f.text_field :booktitle, :size => 33 %>

-

- <%= f.text_field :publisher,:size => 33, :class => 'bibtex' %> +

+ <%= f.text_field :publisher,:size => 33 %>

-

- <%= f.text_field :pages, :size => 12, :class => 'bibtex' %> +

+ <%= f.text_field :pages, :size => 12 %>

-

- <%= f.text_field :address, :class => 'bibtex' %> +

+ <%= f.text_field :address %>

-

- <%= f.text_field :annote, :class => 'bibtex' %> +

+ <%= f.text_field :annote %>

-

- <%= f.text_field :crossref, :class => 'bibtex' %> +

+ <%= f.text_field :crossref %>

-

- <%= f.text_field :edition, :class => 'bibtex' %> +

+ <%= f.text_field :edition %>

-

- <%= f.text_field :eprint, :class => 'bibtex' %> +

+ <%= f.text_field :eprint %>

-

- <%= f.text_field :howpublished, :class => 'bibtex' %> +

+ <%= f.text_field :howpublished %>

-

- <%= f.text_field :journal, :class => 'bibtex' %> +

+ <%= f.text_field :journal %>

-

- <%= f.text_field :key, :class => 'bibtex' %> +

+ <%= f.text_field :key %>

-

- <%= f.text_field :note, :class => 'bibtex' %> +

+ <%= f.text_field :note %>

-

- <%= f.text_field :number, :class => 'bibtex' %> +

+ <%= f.text_field :number %>

-

- <%= f.text_field :organization, :class => 'bibtex' %> +

+ <%= f.text_field :organization %>

-

- <%= f.text_field :school, :class => 'bibtex' %> +

+ <%= f.text_field :school %>

-

- <%= f.text_field :series, :class => 'bibtex' %> +

+ <%= f.text_field :series %>

-

- <%= f.text_field :type, :class => 'bibtex' %> +

+ <%= f.text_field :type %>

-

- <%= f.text_field :url, :class => 'bibtex' %> +

+ <%= f.text_field :url %>

-

- <%= f.text_field :volume, :class => 'bibtex' %> -

- +

+ <%= f.text_field :volume %> +

\ No newline at end of file diff -r 614b2d1580d0 -r 2b665b7e67f4 vendor/plugins/redmine_bibliography/app/views/publications/edit.html.erb --- a/vendor/plugins/redmine_bibliography/app/views/publications/edit.html.erb Mon Sep 19 12:49:31 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/edit.html.erb Mon Sep 19 16:44:12 2011 +0100 @@ -1,7 +1,7 @@ <% content_for :header_tags do %> <%= javascript_include_tag 'authors', :plugin => 'redmine_bibliography' %> <%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %> - <%= javascript_tag 'Event.observe(window, "load", function(e){show_all_required_bibtex_fields(' + @bibtype_fields.to_json + ')});' %> + <%= javascript_tag 'Event.observe(window, "load", function(e){show_required_bibtex_fields(' + @bibtype_fields.to_json + ')});' %> <% end %>

<%=l(:label_publication_show)%>

diff -r 614b2d1580d0 -r 2b665b7e67f4 vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb --- a/vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb Mon Sep 19 12:49:31 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb Mon Sep 19 16:44:12 2011 +0100 @@ -1,7 +1,6 @@ <% content_for :header_tags do %> <%= javascript_include_tag 'authors', :plugin => 'redmine_bibliography' %> <%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %> - <%= javascript_tag 'Event.observe(window, "load", hide_all_bibtex_required_fields);' %> <% end %>

<%=l(:label_publication_new)%>

diff -r 614b2d1580d0 -r 2b665b7e67f4 vendor/plugins/redmine_bibliography/assets/javascripts/authors.js --- a/vendor/plugins/redmine_bibliography/assets/javascripts/authors.js Mon Sep 19 12:49:31 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/assets/javascripts/authors.js Mon Sep 19 16:44:12 2011 +0100 @@ -57,16 +57,17 @@ toggle_div("publication_authorships_attributes_" + form_object_id +"_search_author"); } -function edit_author(form_object_id){} +function hide_all_bibtex_required_fields(){$$('p.bibtex').each(function(s){s.hide()})} -function hide_all_bibtex_required_fields() { - $$('input.bibtex').each(function(s){ - s.up('p').hide(); - })} - -function show_all_required_bibtex_fields(entrytype_fields) { - $$('input.bibtex').each(function(s){ - if(entrytype_fields.indexOf(s.id.split('_').last()) == -1){s.up('p').hide()}; +// entrytype_fields is a jsno array with the fields requires by the selected bibtex entry +function show_required_bibtex_fields(entrytype_fields) { + $$('p.bibtex').each(function(s){ + if(entrytype_fields.indexOf(s.down('input').id.split('_').last()) != -1){ + s.show(); + } + else { + s.hide(); + } }) } \ No newline at end of file