Mercurial > hg > soundsoftware-site
changeset 472:0ce4139187fa feature_36
Add Me as Author: started building the AJAX call to fill the form.
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Fri, 24 Jun 2011 17:13:29 +0100 |
parents | 49fb7a9ef79c |
children | ec7c78040115 aeedcec4df5f |
files | vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb vendor/plugins/redmine_bibliography/app/views/publications/_edit.html.erb vendor/plugins/redmine_bibliography/app/views/publications/add_me_as_author.rjs vendor/plugins/redmine_bibliography/config/locales/en.yml |
diffstat | 5 files changed, 31 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Fri Jun 24 15:11:30 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Fri Jun 24 17:13:29 2011 +0100 @@ -24,9 +24,6 @@ @publication = Publication.new(params[:publication]) @project = Project.find(params[:project_id]) - logger.error { "FIGUEIRA" } - Rails.logger.debug { @project } - @publication.projects << @project if @publication.save @@ -64,6 +61,23 @@ end end + def add_me_as_author + if (request.xhr?) + if User.current.author.nil? + logger.error { "current user has an author" } + @author = Author.new(:user_id => User.current) + else + logger.error { "current user does not have an author" } + @author = User.current.author + end + @authorship = Authorship.create(:author => @author, :publication => @publication) + else + # No? Then render an action. + #render :action => 'view_attribute', :attr => @name + logger.error { "ERROR ADD ME AS AUTHOR" } + end + end + def edit @publication = Publication.find(params[:id])
--- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Fri Jun 24 15:11:30 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Fri Jun 24 17:13:29 2011 +0100 @@ -18,6 +18,6 @@ fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder| render(association.to_s.singularize + "_fields", :f => builder) end - link_to_function(name, h("add_fields(this, '#{association}', '#{escape_javascript(fields)}')")) + link_to_function(name, h("add_fields(this, '#{association}', '#{escape_javascript(fields)}')"), { :class => 'icon icon-add', :id => "add_another_author" }) end end
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_edit.html.erb Fri Jun 24 15:11:30 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_edit.html.erb Fri Jun 24 17:13:29 2011 +0100 @@ -14,7 +14,16 @@ <% f.fields_for :authorships do |builder| %> <%= render "authorship_fields", :f => builder %> <% end %> - <p><%= link_to_add_fields l(:add_another_author), f, :authorships %></p> + <p><%= link_to_add_fields l(:label_add_another_author), f, :authorships %></p> + + <%= link_to_remote l(:label_add_me_as_author), + { :url => { :controller => 'publications', :action => 'add_me_as_author', :project_id => @project }, + :method => 'post', + :update => 'me', + :complete => "" + }, { :class => 'icon icon-add', :id => "add_me_as_author" } %> + + <div id="me"></div> <h3>Other Details</h3> <% f.fields_for :bibtex_entry do |builder| -%>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/add_me_as_author.rjs Fri Jun 24 17:13:29 2011 +0100 @@ -0,0 +1,1 @@ +page.insert_html :bottom, :authors, :partial => 'authorships_fields', :locals => { :authorships => @authorship } \ No newline at end of file
--- a/vendor/plugins/redmine_bibliography/config/locales/en.yml Fri Jun 24 15:11:30 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/config/locales/en.yml Fri Jun 24 17:13:29 2011 +0100 @@ -5,8 +5,8 @@ author: "Author" name: "Name" - add_me_as_author: "Add me as an author" - add_another_author: "Add another author" + label_add_me_as_author: "Add me as an author" + label_add_another_author: "Add another author" remove_author: "Remove this author"