Commit 56b6ebc30a37579ea09dd6103eb0c243d7c51633

Authored by Fabio Teixeira
1 parent 90eb5f31

find_offerer: Add tokenized to find new offerers for software

Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com>
Signed-off-by: Parley Martins <parley@outlook.com>
controllers/mpog_software_plugin_myprofile_controller.rb
... ... @@ -59,6 +59,16 @@ class MpogSoftwarePluginMyprofileController &lt; MyProfileController
59 59  
60 60 if valid_software_info && valid_community && valid_libraries && valid_license && valid_language && valid_database && valid_operating_system
61 61 @community = Community.create_after_moderation(user, {:environment => environment}.merge(params[:community]), @software_info, @license_info, @controlled_vocabulary)
  62 +
  63 + unless params[:q].nil?
  64 + admins = params[:q].split(/,/).map{|n| environment.people.find n.to_i}
  65 +
  66 + admins.each do |admin|
  67 + @community.add_member(admin)
  68 + @community.add_admin(admin)
  69 + end
  70 + end
  71 +
62 72 redirect_to :controller => 'memberships', :action => 'index'
63 73 else
64 74 @list_libraries.each do |lib|
... ... @@ -82,4 +92,9 @@ class MpogSoftwarePluginMyprofileController &lt; MyProfileController
82 92 end
83 93 end
84 94  
  95 + def search_offerers
  96 + arg = params[:q].downcase
  97 + result = environment.people.find(:all, :conditions => ['LOWER(name) LIKE ?', "%#{arg}%"])
  98 + render :text => prepare_to_token_input(result).to_json
  99 + end
85 100 end
... ...
test/functional/mpog_software_plugin_myprofile_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,30 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) +
  3 +'/../../controllers/mark_comment_as_read_plugin_profile_controller'
  4 +
  5 +class MpogSoftwarePluginMyprofileController; def rescue_action(e) raise e end;
  6 +end
  7 +
  8 +class MpogSoftwarePluginMyprofileControllerTest < ActionController::TestCase
  9 + def setup
  10 + @controller = MpogSoftwarePluginMyprofileController.new
  11 + @request = ActionController::TestRequest.new
  12 + @response = ActionController::TestResponse.new
  13 + # @organization = Community.create!(:name => 'My Software', :identifier =>
  14 + # 'my-software')
  15 + @person = create_user('person').person
  16 + #@organization.add_admin(@person)
  17 + login_as(@person.user.login)
  18 + e = Environment.default
  19 + e.enable_plugin('MpogSoftwarePlugin')
  20 + e.save!
  21 + end
  22 +
  23 + attr_accessor :person
  24 +
  25 + should 'search new offerers while creating a new software' do
  26 + end
  27 +
  28 + should 'search new offerers while edting a new software' do
  29 + end
  30 +end
... ...
views/mpog_software_plugin_myprofile/new_software.html.erb
... ... @@ -97,7 +97,13 @@
97 97 <%= swf.text_field(:demonstration_url) %>
98 98 </div>
99 99 <% end %>
100   -
  100 +
  101 + <div class="formfieldline">
  102 + <%= content_tag('label', _('Fill in the search field to add offerers for this Software'), :id => "text-input-search-offerers") %>
  103 + <%= token_input_field_tag(:q, 'search-offerers', {:action => 'search_offerers'}, { :focus => true, :hint_text => _('Type in a search term for a person to be added as
  104 +offerers'), :pre_populate => @tokenized_children}) %>
  105 + </div>
  106 +
101 107 <div id='libraries_fields'>
102 108 <h4> <%= _("Libraries") %> </h4>
103 109 <%= render :partial => 'library_fields', :locals => { :f => f, :object_name => 'community', :profile => @community, :libraries => @list_libraries } %>
... ...