diff --git a/controllers/software_communities_plugin_controller.rb b/controllers/software_communities_plugin_controller.rb index d3bb2c5..16ff893 100644 --- a/controllers/software_communities_plugin_controller.rb +++ b/controllers/software_communities_plugin_controller.rb @@ -5,11 +5,9 @@ class SoftwareCommunitiesPluginController < ApplicationController def get_license_data return render :json=>{} if !request.xhr? || params[:query].nil? - data = if params[:query].empty? - LicenseInfo.all - else - LicenseInfo.where("version ILIKE ?", "%#{params[:query]}%").select("id, version") - end + data = LicenseHelper.find_licenses(params[:query]) if params[:query] + data ||= LicenseInfo.all + render :json=> data.collect { |license| {:id=>license.id, :label=>license.version} } diff --git a/controllers/software_communities_plugin_myprofile_controller.rb b/controllers/software_communities_plugin_myprofile_controller.rb index ddb9680..eda06e2 100644 --- a/controllers/software_communities_plugin_myprofile_controller.rb +++ b/controllers/software_communities_plugin_myprofile_controller.rb @@ -5,9 +5,6 @@ class SoftwareCommunitiesPluginMyprofileController < MyProfileController end def new_software - @licenses = LicenseHelper.getListLicenses - @license_another = LicenseHelper.getAnotherLicense - set_software_as_template @community = Community.new(params[:community]) @@ -25,9 +22,6 @@ class SoftwareCommunitiesPluginMyprofileController < MyProfileController end def edit_software - @licenses = LicenseHelper.getListLicenses - @license_another = LicenseHelper.getAnotherLicense - update_software_atributes return unless request.post? diff --git a/lib/license_helper.rb b/lib/license_helper.rb index 58ee898..8a21a2b 100644 --- a/lib/license_helper.rb +++ b/lib/license_helper.rb @@ -1,11 +1,9 @@ module LicenseHelper - def self.getListLicenses - licenses = LicenseInfo.select{|license| license.version != "Another"} - licenses - end - - def self.getAnotherLicense + def self.find_licenses query + licenses = LicenseInfo.where("version ILIKE ?", "%#{query}%").select("id, version") + licenses.reject!{|license| license.version == "Another"} license_another = LicenseInfo.find_by_version("Another") - license_another + licenses << license_another if license_another + licenses end end diff --git a/views/software_communities_plugin_myprofile/_license_info_fields.html.erb b/views/software_communities_plugin_myprofile/_license_info_fields.html.erb index abcc0dd..d706b46 100644 --- a/views/software_communities_plugin_myprofile/_license_info_fields.html.erb +++ b/views/software_communities_plugin_myprofile/_license_info_fields.html.erb @@ -1,11 +1,3 @@ -<% @licenses.each do | license | %> - -<% end %> - -<% if @license_another %> - " value = "<%=@license_another.link%>"> -<% end %> - <%= text_field_tag "license_info[version]", license_version, :id=>"license_info_version", :class=>"license_info_version", :placeholder=>_('Autocomplete field, type some license') %> <%= hidden_field_tag "license[license_infos_id]", license_id, :id=>"license_info_id", :class=>"license_info_id", :data => {:label=>license_version} %> -- libgit2 0.21.2