diff --git a/controllers/mpog_software_plugin_myprofile_controller.rb b/controllers/mpog_software_plugin_myprofile_controller.rb index 2a05e4f..d0717e0 100644 --- a/controllers/mpog_software_plugin_myprofile_controller.rb +++ b/controllers/mpog_software_plugin_myprofile_controller.rb @@ -19,6 +19,7 @@ class MpogSoftwarePluginMyprofileController < MyProfileController @community = Community.new(params[:community]) @community.environment = environment @software_info = SoftwareInfo.new(params[:software_info]) + @license_info = if params[:license_info].nil? LicenseInfo.new else @@ -122,6 +123,11 @@ 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] + + @software_info.verify_license_info(another_license_version, another_license_link) + create_list_model_helpers @software_info @@ -139,7 +145,9 @@ class MpogSoftwarePluginMyprofileController < MyProfileController params[:software_info].merge({ :environment => environment, :name => params[:community][:name], - :license_info => @license_info })) + :license_info => @license_info, + :another_license_version => params[:license][:version], + :another_license_link => params[:license][:link] })) add_admin_to_community @@ -161,6 +169,14 @@ class MpogSoftwarePluginMyprofileController < MyProfileController @list_languages = @software_info.software_languages @list_operating_systems = @software_info.operating_systems @disabled_public_software_field = disabled_public_software_field + + @another_license_version = "" + @another_license_link = "" + + if @software_info.license_info_id == LicenseInfo.find_by_version("Another").id + @another_license_version = @software_info.license_info.version + @another_license_link = @software_info.license_info.link + end end def set_software_as_template diff --git a/lib/software_info.rb b/lib/software_info.rb index b4a69f3..c5551a6 100644 --- a/lib/software_info.rb +++ b/lib/software_info.rb @@ -1,5 +1,5 @@ class SoftwareInfo < ActiveRecord::Base - acts_as_having_settings :field => :setting + acts_as_having_settings :field => :settings SEARCH_FILTERS = [] SEARCH_DISPLAYS = %w[full] @@ -83,6 +83,7 @@ class SoftwareInfo < ActiveRecord::Base self.another_license_version = version self.another_license_link = link self.license_info = LicenseInfo.find_by_version("Another") + self.save! end def validate_name_lenght @@ -101,6 +102,9 @@ class SoftwareInfo < ActiveRecord::Base environment = attributes.delete(:environment) name = attributes.delete(:name) license_info = attributes.delete(:license_info) + another_license_version = attributes.delete(:another_license_version) + another_license_link = attributes.delete(:another_license_link) + software_info = SoftwareInfo.new(attributes) if !environment.admins.include? requestor CreateSoftware.create!( @@ -126,8 +130,20 @@ class SoftwareInfo < ActiveRecord::Base community.save! community.add_admin(requestor) end + + software_info.verify_license_info(another_license_version, another_license_link) + software_info.save! + software_info end + def verify_license_info another_license_version, another_license_link + if self.license_info_id == LicenseInfo.find_by_version("Another").id + version = another_license_version + link = another_license_link + + self.another_license(version, link) + end + end def validate_acronym diff --git a/public/mpog-software-validations.js b/public/mpog-software-validations.js index 859576f..99778da 100644 --- a/public/mpog-software-validations.js +++ b/public/mpog-software-validations.js @@ -90,13 +90,27 @@ } function get_license_link(){ + var selected_index = this.options.selectedIndex; + var selected = this.options[selected_index]; var link = jQuery("#version_" + this.value).val(); + if( selected.textContent == "Another" ) { + jQuery("#another_license").removeClass("hide-field"); + jQuery("#version_link").addClass("hide-field"); + } else { + jQuery("#another_license").addClass("hide-field"); + jQuery("#version_link").removeClass("hide-field"); + } + jQuery("#version_link") .attr("href", link) .text(link); } + function show_another_license_on_page_load() { + jQuery("#license_info_version").trigger("change"); + } + function hide_infos() { jQuery(".language-info").hide(); jQuery(".database-info").hide(); @@ -209,5 +223,6 @@ replace_software_creations_step(); jQuery("#license_info_version").change(get_license_link); + show_another_license_on_page_load(); }); })(); diff --git a/views/mpog_software_plugin_myprofile/_main_software_editor_extras.html.erb b/views/mpog_software_plugin_myprofile/_main_software_editor_extras.html.erb index 87d7ba0..3bfcd09 100644 --- a/views/mpog_software_plugin_myprofile/_main_software_editor_extras.html.erb +++ b/views/mpog_software_plugin_myprofile/_main_software_editor_extras.html.erb @@ -12,7 +12,7 @@

<%= _("Licenses") %>

- <%= select_tag("license[license_infos_id]", options_for_select(LicenseHelper.getListLicenses.collect{|l| [l.version, l.id]}, :selected => @profile.software_info.license_info.id), :id => "license_info_version") %> + <%= select_tag("license[license_infos_id]", options_for_select(LicenseHelper.getListLicenses.collect{|l| [l.version, l.id]}, :selected => @profile.software_info.license_info_id), :id => "license_info_version") %>

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

@@ -20,6 +20,11 @@ <% end %> <%= @profile.software_info.license_info.link %> +
+ <%= labelled_text_field "Licence version", "license[version]", "#{@another_license_version}", :id=>"licence_version" %> +
+ <%= labelled_text_field "Licence link", "license[link]", "#{@another_license_link}", :id=>"licence_link" %> +

<%= _("Link to Repository") %>

diff --git a/views/mpog_software_plugin_myprofile/new_software.html.erb b/views/mpog_software_plugin_myprofile/new_software.html.erb index c4eb254..b90825c 100644 --- a/views/mpog_software_plugin_myprofile/new_software.html.erb +++ b/views/mpog_software_plugin_myprofile/new_software.html.erb @@ -53,6 +53,11 @@ <% end %> <%=LicenseInfo.first.link %> +
+ <%= labelled_text_field "Licence version", "license[version]", "", :id=>"licence_version" %> +
+ <%= labelled_text_field "Licence link", "license[link]", "", :id=>"licence_link" %> +
<% end %> -- libgit2 0.21.2