changeset 1403:35732ac4324a biblio_alt_search_auth

hiding some fields; deleted unused code; fixed bug in ajax autocomplete function.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Mon, 30 Sep 2013 17:31:32 +0100
parents 5cb7eeccede1
children e2c17a09ce86
files plugins/redmine_bibliography/app/models/authorship.rb plugins/redmine_bibliography/app/views/publications/_authorship_fields.html.erb plugins/redmine_bibliography/assets/javascripts/authors.js plugins/redmine_bibliography/assets/stylesheets/bibliography.css
diffstat 4 files changed, 39 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/redmine_bibliography/app/models/authorship.rb	Mon Sep 30 13:53:20 2013 +0100
+++ b/plugins/redmine_bibliography/app/models/authorship.rb	Mon Sep 30 17:31:32 2013 +0100
@@ -52,10 +52,6 @@
     @search_author_class || aclass
   end
 
-  # def search_author_class=(search_author_class)
-  #  @search_author_class = search_author_class
-  # end
-
   def search_author_id
     if self.author.nil?
       authid = ""
@@ -99,44 +95,42 @@
   private
 
   def set_author
-    # if an author, simply associates with it
-    # if an user, checks if it has already an author associated with it
-    # if so, assicoates with that author
-    # otherwise, creates a new author
+    # do we want to associate the authorship
+    #  with an existing author/user?
+    if @search_author_tie
+      # if an author, simply associates with it
+      # if an user, checks if it has already an author associated with it
+      #   if so, associates with that author
+      #   otherwise, creates a new author
 
-    logger.error { "%%%%%%%%%%%%%%% Associate Author User %%%%%%%%%%%%%%" }
+      case @search_author_class
+      when ""
+        author = Author.new
+        author.save
 
-    logger.error { "Me #{self.to_yaml}" }
-    logger.error { "Class: #{@search_author_class}" }
-    logger.error { "ID #{@search_author_id}" }
+      when "User"
+        user = User.find(@search_author_id)
 
-    case @search_author_class
-    when ""
-      logger.debug { "Adding new author to the database." }
+        if user.author.nil?
+          # User w/o author:
+          # create new author and update user
+          author = Author.new
+          author.save
+          user.author = author
+          user.save
+        else
+          author = user.author
+        end
+
+      when "Author"
+        author = Author.find(@search_author_id)
+      end
+
+    # if we don't want to associate with an existing author/user
+    else
+      # todo: should we delete any previously existing relationship?
       author = Author.new
       author.save
-
-    when "User"
-      # get user id
-      user = User.find(@search_author_id)
-      logger.error { "Found user with this ID: #{user.id}" }
-
-      if user.author.nil?
-        logger.error { "The user has no author... creating one!" }
-
-        # User w/o author:
-        # create new author and update user
-        author = Author.new
-        author.save
-        user.author = author
-        user.save
-      else
-        logger.error { "found an author!" }
-        author = user.author
-      end
-
-    when "Author"
-      author = Author.find(@search_author_id)
     end
 
     self.author = author
--- a/plugins/redmine_bibliography/app/views/publications/_authorship_fields.html.erb	Mon Sep 30 13:53:20 2013 +0100
+++ b/plugins/redmine_bibliography/app/views/publications/_authorship_fields.html.erb	Mon Sep 30 17:31:32 2013 +0100
@@ -5,13 +5,13 @@
     <p><%= f.text_field :institution -%></p>
     <p><%= f.text_field :email -%></p>
 
-    <p class="author_associated">
-      <%= f.check_box :search_author_tie, :style => "float:left;" -%>
+    <p class="author_associated search_author_tie">
+      <%= f.check_box :search_author_tie -%>
       <span class="author_associated_name"></span>
     </p>
 
-    <%= f.text_field :search_author_class -%>
-    <%= f.text_field :search_author_id -%>
+    <%= f.hidden_field :search_author_class -%>
+    <%= f.hidden_field :search_author_id -%>
   </div>
 
   <div>
--- a/plugins/redmine_bibliography/assets/javascripts/authors.js	Mon Sep 30 13:53:20 2013 +0100
+++ b/plugins/redmine_bibliography/assets/javascripts/authors.js	Mon Sep 30 17:31:32 2013 +0100
@@ -28,8 +28,6 @@
             $this.closest('div').find("input[id$='search_author_id']").val(ui.item.search_author_id);
             $this.closest('div').find("input[id$='search_author_tie']").attr('checked', 'checked');
 
-
-
             // triggers the save button
             $this.closest('div').next('div').find('.author_save_btn').click();
         }
@@ -37,7 +35,7 @@
         .data( "autocomplete" )._renderItem = function( ul, item ) {
             return $( "<li>" )
                 .data("item.autocomplete", item )
-                .append( "<a>" + item.label + "<br><em>" + item.email + "</em><br>" + item.intitution + "</a>" )
+                .append( "<a>" + item.label + "<br><em>" + item.email + "</em><br>" + item.institution + "</a>" )
                 .appendTo(ul);
             };
         });
--- a/plugins/redmine_bibliography/assets/stylesheets/bibliography.css	Mon Sep 30 13:53:20 2013 +0100
+++ b/plugins/redmine_bibliography/assets/stylesheets/bibliography.css	Mon Sep 30 17:31:32 2013 +0100
@@ -66,6 +66,7 @@
   background-image: url(../../../images/loading.gif);
 }
 
-.author_edit_btn {
-  display:none;
+.authorship_tie {
+  display: none;
+  float: left;
 }