# HG changeset patch # User luisf # Date 1368121499 -3600 # Node ID 5ea1a213c7a56e5affe9484ad03191dfe639cc21 # Parent 052ea7c838f62415e8cc71287edb3689bcc5e269 Removed Ajax calls taht are no longer working in Rails 3 and started migrating them; added a new javascript file - bibliography.js - to hold the new jquery js code; added the new show_bibtex_fields.js.erb file to replace the RJS code that was in the controller. diff -r 052ea7c838f6 -r 5ea1a213c7a5 plugins/redmine_bibliography/app/controllers/publications_controller.rb --- a/plugins/redmine_bibliography/app/controllers/publications_controller.rb Thu May 09 11:49:03 2013 +0100 +++ b/plugins/redmine_bibliography/app/controllers/publications_controller.rb Thu May 09 18:44:59 2013 +0100 @@ -5,7 +5,8 @@ unloadable model_object Publication - before_filter :find_model_object, :except => [:new, :create, :index, :get_bibtex_required_fields, :autocomplete_for_project, :add_author, :sort_author_order, :autocomplete_for_author, :get_user_info ] + # before_filter :find_model_object, :except => [:new, :create, :index, :show_bibtex_fields, :autocomplete_for_project, :add_author, :sort_author_order, :autocomplete_for_author, :get_user_info ] + before_filter :find_project_by_project_id, :authorize, :only => [ :edit, :new, :update, :create ] def new @@ -60,23 +61,17 @@ end end - def get_bibtex_required_fields + def show_bibtex_fields + @fields = [] unless params[:value].empty? - fields = BibtexEntryType.fields(params[:value]) + @fields = BibtexEntryType.fields(params[:value]) end respond_to do |format| format.js { - render(:update) {|page| - if params[:value].empty? - page << "hideOnLoad();" - else - page << "show_required_bibtex_fields(#{fields.to_json()});" - end - } + render :show_bibtex_fields } - end end diff -r 052ea7c838f6 -r 5ea1a213c7a5 plugins/redmine_bibliography/app/views/publications/_authorship_fields.html.erb --- a/plugins/redmine_bibliography/app/views/publications/_authorship_fields.html.erb Thu May 09 11:49:03 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/publications/_authorship_fields.html.erb Thu May 09 18:44:59 2013 +0100 @@ -7,26 +7,20 @@
>

<%= f.text_field :search_name, :size => 25 %> - <%= observe_field( form_tag_id(f.object_name, :search_name), :frequency => 0.5, :update => form_tag_id( f.object_name, :search_results), :url => { :controller => 'publications', :action => 'autocomplete_for_author', :object_name => form_object_id(f.object_name) }, :with => 'q' ) %> -

- <%# link_to_function l(:label_author_is_me), "update_author_info(this," + User.current.get_author_info.to_json + ")", :id => "add_me_as_author" %> - -

- <%= f.select :search_results, options_for_select(@author_options), {}, {:size => 5, - :onChange => remote_function( :url => { :controller => :publications, :action => :get_user_info, :object_id => form_object_id(f.object_name) }, :with => "'value=' + - value" )} %> -

+

+ <%= f.select :search_results, options_for_select(@author_options) %> +


- +
- +

-
- + +

<%= f.text_field :name_on_paper, {:class => ("readonly" unless params[:action] == "new") } %>

@@ -37,10 +31,10 @@

><%= h l("text_author_email") %>

- +

diff -r 052ea7c838f6 -r 5ea1a213c7a5 plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb --- a/plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb Thu May 09 11:49:03 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb Thu May 09 18:44:59 2013 +0100 @@ -1,80 +1,78 @@

- <%= f.collection_select :entry_type, - BibtexEntryType.find(:all).reject { |x| x.redundant? }, - :id, - :label, - { :selected => @selected_bibtex_entry_type_id, :prompt => true }, - :onChange => remote_function( :url => { :controller => :publications, :action => :get_bibtex_required_fields}, :with => "'value=' + value" ) - %> + <%= f.collection_select :entry_type, + BibtexEntryType.find(:all).reject { |x| x.redundant? }, + :id, + :label, + { :selected => @selected_bibtex_entry_type_id, :prompt => true } %>

-

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

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

-

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

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

-

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

-

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

-

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

-

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

-

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

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

-

+

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

+

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

+

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

+

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

+

<%= f.text_field :address %>

-

+

<%= f.text_field :annote %>

-

+

<%= f.text_field :crossref %>

-

+

<%= f.text_field :edition %>

-

+

<%= f.text_field :eprint %>

-

+

<%= f.text_field :howpublished %>

-

+

<%= f.text_field :journal %>

-

+

<%= f.text_field :key %>

-

+

<%= f.text_field :note %>

-

+

<%= f.text_field :number %>

-

+

<%= f.text_field :organization %>

-

+

<%= f.text_field :school %>

-

+

<%= f.text_field :series %>

-

+

<%= f.text_field :type %>

-

+

<%= f.text_field :url %>

-

+

<%= f.text_field :volume %>

\ No newline at end of file diff -r 052ea7c838f6 -r 5ea1a213c7a5 plugins/redmine_bibliography/app/views/publications/_form.html.erb --- a/plugins/redmine_bibliography/app/views/publications/_form.html.erb Thu May 09 11:49:03 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/publications/_form.html.erb Thu May 09 18:44:59 2013 +0100 @@ -5,7 +5,7 @@

<%= l(:label_publication_other_details) %>

- <% f.fields_for :bibtex_entry do |builder| -%> + <%= f.fields_for :bibtex_entry do |builder| -%> <%= render :partial => 'bibtex_fields', :locals => { :f => builder} %> <%- end -%> @@ -26,7 +26,7 @@

<%= l(:authors) %>

- <% f.fields_for :authorships do |builder| -%> + <%= f.fields_for :authorships do |builder| -%> <%= render "authorship_fields", :f => builder %> <%- end -%> <%= link_to_add_author_fields l(:label_add_an_author), f, :authorships, params[:action] %> diff -r 052ea7c838f6 -r 5ea1a213c7a5 plugins/redmine_bibliography/app/views/publications/new.html.erb --- a/plugins/redmine_bibliography/app/views/publications/new.html.erb Thu May 09 11:49:03 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/publications/new.html.erb Thu May 09 18:44:59 2013 +0100 @@ -1,12 +1,13 @@ <% content_for :header_tags do %> <%= javascript_include_tag 'authors', :plugin => 'redmine_bibliography' %> + <%= javascript_include_tag 'bibliography', :plugin => 'redmine_bibliography' %> <%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %> <% end %>

<%=l(:label_publication_new)%>

-<% labelled_form_for @publication, :url => { :project_id => @project, :action => :create } do |f| -%> - <%= render :partial => 'form', :locals => { :f => f } %> -
- <%= f.submit %> +<%= labelled_form_for @publication, :url => { :project_id => @project, :action => :create } do |f| -%> + <%= render :partial => 'form', :locals => { :f => f } %> +
+ <%= f.submit %> <% end %> diff -r 052ea7c838f6 -r 5ea1a213c7a5 plugins/redmine_bibliography/app/views/publications/show_bibtex_fields.js.erb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/redmine_bibliography/app/views/publications/show_bibtex_fields.js.erb Thu May 09 18:44:59 2013 +0100 @@ -0,0 +1,12 @@ +fields = <%= @fields.to_json.html_safe -%>; + +$.each($(".bibtex"), function( key, value ) { + $this = $(this); + + input_id = $this.children('input').attr('id'); + name = input_id.split('_')[4]; + + if ($.inArray(name, fields)){ + $this.show(); + } +}); \ No newline at end of file diff -r 052ea7c838f6 -r 5ea1a213c7a5 plugins/redmine_bibliography/assets/javascripts/bibliography.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/redmine_bibliography/assets/javascripts/bibliography.js Thu May 09 18:44:59 2013 +0100 @@ -0,0 +1,13 @@ +$("#publication_bibtex_entry_attributes_entry_type").live("change", function() { + console.log("AJAX RULEZ"); + + $.ajax({ + type: "POST", + url: "/publications/show_bibtex_fields", + data: "value=" + $("#publication_bibtex_entry_attributes_entry_type").val(), + dataType: "script" + }); + + return false; +}); + diff -r 052ea7c838f6 -r 5ea1a213c7a5 plugins/redmine_bibliography/assets/javascripts/bibtex.js --- a/plugins/redmine_bibliography/assets/javascripts/bibtex.js Thu May 09 11:49:03 2013 +0100 +++ b/plugins/redmine_bibliography/assets/javascripts/bibtex.js Thu May 09 18:44:59 2013 +0100 @@ -1,5 +1,5 @@ function toggleBibtex(el) { - var dd = Element.up(el).next('dd') + var dd = Element.up(el).next('dd'); dd.toggleClassName('collapsed'); Effect.toggle(dd, 'slide', {duration:0.2}); diff -r 052ea7c838f6 -r 5ea1a213c7a5 plugins/redmine_bibliography/config/routes.rb --- a/plugins/redmine_bibliography/config/routes.rb Thu May 09 11:49:03 2013 +0100 +++ b/plugins/redmine_bibliography/config/routes.rb Thu May 09 18:44:59 2013 +0100 @@ -1,3 +1,7 @@ RedmineApp::Application.routes.draw do resources :publications + + match "publications/show_bibtex_fields", :to => 'publications#show_bibtex_fields' + + end \ No newline at end of file