Commit 202f02130410c86a251e6ddab7a1788b4dd89f7d
Committed by
Thiago Ribeiro
1 parent
4a7ff579
Exists in
refactor_software_info_365
Always show Another license option
Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com> Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com>
Showing
4 changed files
with
8 additions
and
26 deletions
Show diff stats
controllers/software_communities_plugin_controller.rb
| ... | ... | @@ -5,11 +5,9 @@ class SoftwareCommunitiesPluginController < ApplicationController |
| 5 | 5 | def get_license_data |
| 6 | 6 | return render :json=>{} if !request.xhr? || params[:query].nil? |
| 7 | 7 | |
| 8 | - data = if params[:query].empty? | |
| 9 | - LicenseInfo.all | |
| 10 | - else | |
| 11 | - LicenseInfo.where("version ILIKE ?", "%#{params[:query]}%").select("id, version") | |
| 12 | - end | |
| 8 | + data = LicenseHelper.find_licenses(params[:query]) if params[:query] | |
| 9 | + data ||= LicenseInfo.all | |
| 10 | + | |
| 13 | 11 | render :json=> data.collect { |license| |
| 14 | 12 | {:id=>license.id, :label=>license.version} |
| 15 | 13 | } | ... | ... |
controllers/software_communities_plugin_myprofile_controller.rb
| ... | ... | @@ -5,9 +5,6 @@ class SoftwareCommunitiesPluginMyprofileController < MyProfileController |
| 5 | 5 | end |
| 6 | 6 | |
| 7 | 7 | def new_software |
| 8 | - @licenses = LicenseHelper.getListLicenses | |
| 9 | - @license_another = LicenseHelper.getAnotherLicense | |
| 10 | - | |
| 11 | 8 | set_software_as_template |
| 12 | 9 | |
| 13 | 10 | @community = Community.new(params[:community]) |
| ... | ... | @@ -25,9 +22,6 @@ class SoftwareCommunitiesPluginMyprofileController < MyProfileController |
| 25 | 22 | end |
| 26 | 23 | |
| 27 | 24 | def edit_software |
| 28 | - @licenses = LicenseHelper.getListLicenses | |
| 29 | - @license_another = LicenseHelper.getAnotherLicense | |
| 30 | - | |
| 31 | 25 | update_software_atributes |
| 32 | 26 | |
| 33 | 27 | return unless request.post? | ... | ... |
lib/license_helper.rb
| 1 | 1 | module LicenseHelper |
| 2 | - def self.getListLicenses | |
| 3 | - licenses = LicenseInfo.select{|license| license.version != "Another"} | |
| 4 | - licenses | |
| 5 | - end | |
| 6 | - | |
| 7 | - def self.getAnotherLicense | |
| 2 | + def self.find_licenses query | |
| 3 | + licenses = LicenseInfo.where("version ILIKE ?", "%#{query}%").select("id, version") | |
| 4 | + licenses.reject!{|license| license.version == "Another"} | |
| 8 | 5 | license_another = LicenseInfo.find_by_version("Another") |
| 9 | - license_another | |
| 6 | + licenses << license_another if license_another | |
| 7 | + licenses | |
| 10 | 8 | end |
| 11 | 9 | end | ... | ... |
views/software_communities_plugin_myprofile/_license_info_fields.html.erb
| 1 | -<% @licenses.each do | license | %> | |
| 2 | - <input type="hidden" id = "version_<%=license.id %>" value = "<%=license.link%>"> | |
| 3 | -<% end %> | |
| 4 | - | |
| 5 | -<% if @license_another %> | |
| 6 | - <input type="hidden" id = "version_<%=_("Another") %>" value = "<%=@license_another.link%>"> | |
| 7 | -<% end %> | |
| 8 | - | |
| 9 | 1 | <%= text_field_tag "license_info[version]", license_version, :id=>"license_info_version", :class=>"license_info_version", :placeholder=>_('Autocomplete field, type some license') %> |
| 10 | 2 | <%= hidden_field_tag "license[license_infos_id]", license_id, :id=>"license_info_id", :class=>"license_info_id", :data => {:label=>license_version} %> |
| 11 | 3 | ... | ... |