Mercurial > hg > soundsoftware-site
changeset 1274:5ea1a213c7a5 redmine-2.2-integration
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.
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Thu, 09 May 2013 18:44:59 +0100 |
parents | 052ea7c838f6 |
children | 1194982f28ba |
files | plugins/redmine_bibliography/app/controllers/publications_controller.rb plugins/redmine_bibliography/app/views/publications/_authorship_fields.html.erb plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb plugins/redmine_bibliography/app/views/publications/_form.html.erb plugins/redmine_bibliography/app/views/publications/new.html.erb plugins/redmine_bibliography/app/views/publications/show_bibtex_fields.js.erb plugins/redmine_bibliography/assets/javascripts/bibliography.js plugins/redmine_bibliography/assets/javascripts/bibtex.js plugins/redmine_bibliography/config/routes.rb |
diffstat | 9 files changed, 91 insertions(+), 74 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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 @@ <div id="<%= form_tag_id( f.object_name, :search_author ) %>" style=<%= "display:none;" unless params[:action] == "new" %> > <p> <%= 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' ) %> - </p> - <%# link_to_function l(:label_author_is_me), "update_author_info(this," + User.current.get_author_info.to_json + ")", :id => "add_me_as_author" %> - - <p> - <%= 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" )} %> - </p> + <p> + <%= f.select :search_results, options_for_select(@author_options) %> + </p> <p style="margin-bottom: -2.5em; padding-bottom; 0"><label><%= l(:identify_author_question) %></label></p> <p class="author_identify"> <label class='inline'><%= radio_button_tag(:identify_author, "yes", false, :name => form_tag_name(f.object_name,:identify_author ), :id => form_tag_id( f.object_name, :identify_author_yes ), :onchange => "identify_author_status($(this).value, #{form_object_id(f.object_name) });") %> <%= l(:identify_author_yes) %> </label><br /> - + <label class='inline'><%= radio_button_tag(:identify_author, "correct", false, :name => form_tag_name(f.object_name,:identify_author ), :id => form_tag_id( f.object_name, :identify_author_corrections ), :onchange => "identify_author_status($(this).value, #{form_object_id(f.object_name) });") %> <%= l(:identify_author_correct) %> </label><br /> - + <label class='inline'><%= radio_button_tag(:identify_author, "no", true, :name => form_tag_name(f.object_name,:identify_author ), :id => form_tag_id( f.object_name, :identify_author_no ), :onchange => "identify_author_status($(this).value, #{form_object_id(f.object_name) });") %> <%= l(:identify_author_no) %> </label><br /> </p> - </div> - + </div> + <div class='author_edit' id="<%= form_tag_id( f.object_name, :edit_author_info ) %>"> <p> <%= f.text_field :name_on_paper, {:class => ("readonly" unless params[:action] == "new") } %></p> @@ -37,10 +31,10 @@ <p class='description' style=<%= "display:none;" unless params[:action] == "new" %>><%= h l("text_author_email") %></p> </p> </div> - + <div class="box" id="<%= form_tag_id( f.object_name, :show_author_info ) %>" style="display: none"> - + </div> <p>
--- 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 @@ <p> <label for="bibtex_entry_type"><%=l("field_entry_type")%> <span class="required">*</span></label> - <%= 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 } %> </p> -<p class="bibtex hol"> - <%= f.text_field :year, :size => 4 %> +<p class="bibtex hol"> + <%= f.text_field :year, :size => 4 %> </p> -<p class="bibtex hol"> - <%= f.text_field :month, :size => 4%> +<p class="bibtex hol"> + <%= f.text_field :month, :size => 4%> </p> -<p class="bibtex hol"> - <%= f.text_field :chapter, :size => 15%> -</p> -<p class="bibtex hol"> - <%= f.text_field :editor, :size => 33 %> -</p> -<p class="bibtex hol"> - <%= f.text_field :booktitle, :size => 33 %> -</p> -<p class="bibtex hol"> - <%= f.text_field :publisher,:size => 33 %> -</p> -<p class="bibtex hol"> - <%= f.text_field :pages, :size => 12 %> +<p class="bibtex hol"> + <%= f.text_field :chapter, :size => 15%> </p> -<p class="bibtex hol"> +<p class="bibtex hol"> + <%= f.text_field :editor, :size => 33 %> +</p> +<p class="bibtex hol"> + <%= f.text_field :booktitle, :size => 33 %> +</p> +<p class="bibtex hol"> + <%= f.text_field :publisher,:size => 33 %> +</p> +<p class="bibtex hol"> + <%= f.text_field :pages, :size => 12 %> +</p> +<p class="bibtex hol"> <%= f.text_field :address %> </p> -<p class="bibtex hol"> +<p class="bibtex hol"> <%= f.text_field :annote %> </p> -<p class="bibtex hol"> +<p class="bibtex hol"> <%= f.text_field :crossref %> </p> -<p class="bibtex hol"> +<p class="bibtex hol"> <%= f.text_field :edition %> </p> -<p class="bibtex hol"> +<p class="bibtex hol"> <%= f.text_field :eprint %> </p> -<p class="bibtex hol"> +<p class="bibtex hol"> <%= f.text_field :howpublished %> </p> -<p class="bibtex hol"> +<p class="bibtex hol"> <%= f.text_field :journal %> </p> -<p class="bibtex hol"> +<p class="bibtex hol"> <%= f.text_field :key %> </p> -<p class="bibtex hol"> +<p class="bibtex hol"> <%= f.text_field :note %> </p> -<p class="bibtex hol"> +<p class="bibtex hol"> <%= f.text_field :number %> </p> -<p class="bibtex hol"> +<p class="bibtex hol"> <%= f.text_field :organization %> </p> -<p class="bibtex hol"> +<p class="bibtex hol"> <%= f.text_field :school %> </p> -<p class="bibtex hol"> +<p class="bibtex hol"> <%= f.text_field :series %> </p> -<p class="bibtex hol"> +<p class="bibtex hol"> <%= f.text_field :type %> </p> -<p class="bibtex hol"> +<p class="bibtex hol"> <%= f.text_field :url %> </p> -<p class="bibtex hol"> +<p class="bibtex hol"> <%= f.text_field :volume %> </p> \ No newline at end of file
--- 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 @@ <div class="splitcontentleft"> <h3><%= l(:label_publication_other_details) %></h3> <div class="box tabular"> - <% 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 @@ <div class="splitcontentright"> <h3><%= l(:authors) %></h3> <div class="box tabular"> - <% 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] %>
--- 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 %> <h2><%=l(:label_publication_new)%></h2> -<% labelled_form_for @publication, :url => { :project_id => @project, :action => :create } do |f| -%> - <%= render :partial => 'form', :locals => { :f => f } %> - <div style="clear:both"></div> - <%= f.submit %> +<%= labelled_form_for @publication, :url => { :project_id => @project, :action => :create } do |f| -%> + <%= render :partial => 'form', :locals => { :f => f } %> + <div style="clear:both"></div> + <%= f.submit %> <% end %>
--- /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
--- /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; +}); +
--- 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});
--- 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