diff --git a/controllers/mpog_software_plugin_myprofile_controller.rb b/controllers/mpog_software_plugin_myprofile_controller.rb index d0717e0..009beae 100644 --- a/controllers/mpog_software_plugin_myprofile_controller.rb +++ b/controllers/mpog_software_plugin_myprofile_controller.rb @@ -23,7 +23,7 @@ class MpogSoftwarePluginMyprofileController < MyProfileController @license_info = if params[:license_info].nil? LicenseInfo.new else - LicenseInfo.find(params[:license_info][:version]) + LicenseInfo.find(params[:license_info][:id]) end control_software_creation @@ -123,8 +123,12 @@ class MpogSoftwarePluginMyprofileController < MyProfileController @software_info.license_info = @license @software_info.update_attributes(params[:software]) - another_license_version = params[:license][:version] - another_license_link = params[:license][:link] + another_license_version = nil + another_license_link = nil + if params[:license] + another_license_version = params[:license][:version] + another_license_link = params[:license][:link] + end @software_info.verify_license_info(another_license_version, another_license_link) @@ -141,13 +145,19 @@ class MpogSoftwarePluginMyprofileController < MyProfileController end def send_software_to_moderation + another_license_version = "" + another_license_link = "" + if params[:license] + another_license_version = params[:license][:version] + another_license_link = params[:license][:link] + end @software_info = SoftwareInfo.create_after_moderation(user, params[:software_info].merge({ :environment => environment, :name => params[:community][:name], :license_info => @license_info, - :another_license_version => params[:license][:version], - :another_license_link => params[:license][:link] })) + :another_license_version => another_license_version, + :another_license_link => another_license_link })) add_admin_to_community @@ -173,7 +183,8 @@ class MpogSoftwarePluginMyprofileController < MyProfileController @another_license_version = "" @another_license_link = "" - if @software_info.license_info_id == LicenseInfo.find_by_version("Another").id + license_another = LicenseInfo.find_by_version("Another") + if license_another && @software_info.license_info_id == license_another.id @another_license_version = @software_info.license_info.version @another_license_link = @software_info.license_info.link end diff --git a/lib/software_info.rb b/lib/software_info.rb index c5551a6..c972919 100644 --- a/lib/software_info.rb +++ b/lib/software_info.rb @@ -68,8 +68,9 @@ class SoftwareInfo < ActiveRecord::Base def license_info license = LicenseInfo.find_by_id self.license_info_id + license_another = LicenseInfo.find_by_version("Another") - if license == LicenseInfo.find_by_version("Another") + if license_another && license.id == license_another.id LicenseInfo.new( :version => self.another_license_version, :link => self.another_license_link @@ -80,10 +81,14 @@ class SoftwareInfo < ActiveRecord::Base end def another_license(version, link) - self.another_license_version = version - self.another_license_link = link - self.license_info = LicenseInfo.find_by_version("Another") - self.save! + license_another = LicenseInfo.find_by_version("Another") + + if license_another + self.another_license_version = version + self.another_license_link = link + self.license_info = license_another + self.save! + end end def validate_name_lenght @@ -137,7 +142,9 @@ class SoftwareInfo < ActiveRecord::Base end def verify_license_info another_license_version, another_license_link - if self.license_info_id == LicenseInfo.find_by_version("Another").id + license_another = LicenseInfo.find_by_version("Another") + + if license_another && self.license_info_id == license_another.id version = another_license_version link = another_license_link diff --git a/public/mpog-software-validations.js b/public/mpog-software-validations.js index 99778da..31f00b9 100644 --- a/public/mpog-software-validations.js +++ b/public/mpog-software-validations.js @@ -108,7 +108,7 @@ } function show_another_license_on_page_load() { - jQuery("#license_info_version").trigger("change"); + jQuery("#license_info_id").trigger("change"); } function hide_infos() { @@ -222,7 +222,7 @@ replace_software_creations_step(); - jQuery("#license_info_version").change(get_license_link); + jQuery("#license_info_id").change(get_license_link); show_another_license_on_page_load(); }); })(); diff --git a/test/helpers/software_test_helper.rb b/test/helpers/software_test_helper.rb index 93705c6..c35aa05 100644 --- a/test/helpers/software_test_helper.rb +++ b/test/helpers/software_test_helper.rb @@ -171,6 +171,7 @@ module SoftwareTestHelper #Fields for license info fields_license['version'] = LicenseInfo.last.version + fields_license['id'] = LicenseInfo.last.id hash_list << fields_license #Fields for community diff --git a/views/_main_software_editor_extras.html.erb b/views/_main_software_editor_extras.html.erb index ed561da..942256d 100644 --- a/views/_main_software_editor_extras.html.erb +++ b/views/_main_software_editor_extras.html.erb @@ -14,7 +14,7 @@

<%= _("Licenses") %>

- <%= select_tag(:version, options_for_select(LicenseHelper.getListLicenses.collect{|l| [l.version, l.id]}, :selected => context.profile.software_info.license_info.id), :onchange => "get_license_link('version')") %> + <%= select_tag(:id, options_for_select(LicenseHelper.getListLicenses.collect{|l| [l.version, l.id]}, :selected => context.profile.software_info.license_info.id), :onchange => "get_license_link('version')") %>

<%= _("License link") %>

diff --git a/views/mpog_software_plugin_myprofile/new_software.html.erb b/views/mpog_software_plugin_myprofile/new_software.html.erb index b90825c..16fa449 100644 --- a/views/mpog_software_plugin_myprofile/new_software.html.erb +++ b/views/mpog_software_plugin_myprofile/new_software.html.erb @@ -45,7 +45,7 @@ <%= fields_for @license_info do |lcv| %>

<%= lcv.label _("License Version: ") %>

- <%= lcv.select(:version, LicenseInfo.all.map {|l| [l.version, l.id]}, {:selected => 1}) %> + <%= lcv.select(:id, LicenseInfo.all.map {|l| [l.version, l.id]}, {:selected => 1}) %>

<%= _("License link") %>

<% LicenseHelper.getListLicenses.each do | license | %> -- libgit2 0.21.2