From 30e39dd95746ea2fb303e5730e3e975708b77b22 Mon Sep 17 00:00:00 2001 From: Luciano Prestes Cavalcanti Date: Mon, 9 Feb 2015 14:45:43 -0200 Subject: [PATCH] Change dynamically link of license in create and edit software --- controllers/mpog_software_plugin_myprofile_controller.rb | 4 +--- public/mpog-software-validations.js | 7 ++++--- views/mpog_software_plugin_myprofile/_main_software_editor_extras.html.erb | 3 +-- views/mpog_software_plugin_myprofile/new_software.html.erb | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/controllers/mpog_software_plugin_myprofile_controller.rb b/controllers/mpog_software_plugin_myprofile_controller.rb index 70a50b1..2a05e4f 100644 --- a/controllers/mpog_software_plugin_myprofile_controller.rb +++ b/controllers/mpog_software_plugin_myprofile_controller.rb @@ -22,9 +22,7 @@ class MpogSoftwarePluginMyprofileController < MyProfileController @license_info = if params[:license_info].nil? LicenseInfo.new else - LicenseInfo.find(:first, - :conditions => ["version = ?", - "#{params[:license_info][:version]}"]) + LicenseInfo.find(params[:license_info][:version]) end control_software_creation diff --git a/public/mpog-software-validations.js b/public/mpog-software-validations.js index a6c2fbe..859576f 100644 --- a/public/mpog-software-validations.js +++ b/public/mpog-software-validations.js @@ -89,9 +89,8 @@ Element.insert(element_id, {bottom: content}); } - function get_license_link(select_id){ - var selected = jQuery('#'+select_id).selected().val(); - var link = jQuery("#version_" + selected).val(); + function get_license_link(){ + var link = jQuery("#version_" + this.value).val(); jQuery("#version_link") .attr("href", link) @@ -208,5 +207,7 @@ jQuery("#software_public_software").click(hide_show_public_software_fields); replace_software_creations_step(); + + jQuery("#license_info_version").change(get_license_link); }); })(); 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 d9eb0fb..87d7ba0 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,14 +12,13 @@

<%= _("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), :onchange => "get_license_link('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") %>

<% LicenseHelper.getListLicenses.each do | license | %> <% end %> - <%= @profile.software_info.license_info.link %>
diff --git a/views/mpog_software_plugin_myprofile/new_software.html.erb b/views/mpog_software_plugin_myprofile/new_software.html.erb index aff9f34..c4eb254 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.version]}, {:selected=>1}, :onchange => "get_license_link('license_info_version')") %> + <%= lcv.select(:version, LicenseInfo.all.map {|l| [l.version, l.id]}, {:selected => 1}) %>

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

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