Commit a490ebe755a4762f1bab493a29178967090eb60c
Committed by
David Silva
1 parent
71f29e1e
Exists in
master
and in
5 other branches
Add fields for another_license_version and another_license_link on create and edit software_info
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
Showing
5 changed files
with
60 additions
and
3 deletions
Show diff stats
controllers/mpog_software_plugin_myprofile_controller.rb
| @@ -19,6 +19,7 @@ class MpogSoftwarePluginMyprofileController < MyProfileController | @@ -19,6 +19,7 @@ class MpogSoftwarePluginMyprofileController < MyProfileController | ||
| 19 | @community = Community.new(params[:community]) | 19 | @community = Community.new(params[:community]) |
| 20 | @community.environment = environment | 20 | @community.environment = environment |
| 21 | @software_info = SoftwareInfo.new(params[:software_info]) | 21 | @software_info = SoftwareInfo.new(params[:software_info]) |
| 22 | + | ||
| 22 | @license_info = if params[:license_info].nil? | 23 | @license_info = if params[:license_info].nil? |
| 23 | LicenseInfo.new | 24 | LicenseInfo.new |
| 24 | else | 25 | else |
| @@ -122,6 +123,11 @@ class MpogSoftwarePluginMyprofileController < MyProfileController | @@ -122,6 +123,11 @@ class MpogSoftwarePluginMyprofileController < MyProfileController | ||
| 122 | @software_info.license_info = @license | 123 | @software_info.license_info = @license |
| 123 | @software_info.update_attributes(params[:software]) | 124 | @software_info.update_attributes(params[:software]) |
| 124 | 125 | ||
| 126 | + another_license_version = params[:license][:version] | ||
| 127 | + another_license_link = params[:license][:link] | ||
| 128 | + | ||
| 129 | + @software_info.verify_license_info(another_license_version, another_license_link) | ||
| 130 | + | ||
| 125 | create_list_model_helpers | 131 | create_list_model_helpers |
| 126 | 132 | ||
| 127 | @software_info | 133 | @software_info |
| @@ -139,7 +145,9 @@ class MpogSoftwarePluginMyprofileController < MyProfileController | @@ -139,7 +145,9 @@ class MpogSoftwarePluginMyprofileController < MyProfileController | ||
| 139 | params[:software_info].merge({ | 145 | params[:software_info].merge({ |
| 140 | :environment => environment, | 146 | :environment => environment, |
| 141 | :name => params[:community][:name], | 147 | :name => params[:community][:name], |
| 142 | - :license_info => @license_info })) | 148 | + :license_info => @license_info, |
| 149 | + :another_license_version => params[:license][:version], | ||
| 150 | + :another_license_link => params[:license][:link] })) | ||
| 143 | 151 | ||
| 144 | add_admin_to_community | 152 | add_admin_to_community |
| 145 | 153 | ||
| @@ -161,6 +169,14 @@ class MpogSoftwarePluginMyprofileController < MyProfileController | @@ -161,6 +169,14 @@ class MpogSoftwarePluginMyprofileController < MyProfileController | ||
| 161 | @list_languages = @software_info.software_languages | 169 | @list_languages = @software_info.software_languages |
| 162 | @list_operating_systems = @software_info.operating_systems | 170 | @list_operating_systems = @software_info.operating_systems |
| 163 | @disabled_public_software_field = disabled_public_software_field | 171 | @disabled_public_software_field = disabled_public_software_field |
| 172 | + | ||
| 173 | + @another_license_version = "" | ||
| 174 | + @another_license_link = "" | ||
| 175 | + | ||
| 176 | + if @software_info.license_info_id == LicenseInfo.find_by_version("Another").id | ||
| 177 | + @another_license_version = @software_info.license_info.version | ||
| 178 | + @another_license_link = @software_info.license_info.link | ||
| 179 | + end | ||
| 164 | end | 180 | end |
| 165 | 181 | ||
| 166 | def set_software_as_template | 182 | def set_software_as_template |
lib/software_info.rb
| 1 | class SoftwareInfo < ActiveRecord::Base | 1 | class SoftwareInfo < ActiveRecord::Base |
| 2 | - acts_as_having_settings :field => :setting | 2 | + acts_as_having_settings :field => :settings |
| 3 | 3 | ||
| 4 | SEARCH_FILTERS = [] | 4 | SEARCH_FILTERS = [] |
| 5 | SEARCH_DISPLAYS = %w[full] | 5 | SEARCH_DISPLAYS = %w[full] |
| @@ -83,6 +83,7 @@ class SoftwareInfo < ActiveRecord::Base | @@ -83,6 +83,7 @@ class SoftwareInfo < ActiveRecord::Base | ||
| 83 | self.another_license_version = version | 83 | self.another_license_version = version |
| 84 | self.another_license_link = link | 84 | self.another_license_link = link |
| 85 | self.license_info = LicenseInfo.find_by_version("Another") | 85 | self.license_info = LicenseInfo.find_by_version("Another") |
| 86 | + self.save! | ||
| 86 | end | 87 | end |
| 87 | 88 | ||
| 88 | def validate_name_lenght | 89 | def validate_name_lenght |
| @@ -101,6 +102,9 @@ class SoftwareInfo < ActiveRecord::Base | @@ -101,6 +102,9 @@ class SoftwareInfo < ActiveRecord::Base | ||
| 101 | environment = attributes.delete(:environment) | 102 | environment = attributes.delete(:environment) |
| 102 | name = attributes.delete(:name) | 103 | name = attributes.delete(:name) |
| 103 | license_info = attributes.delete(:license_info) | 104 | license_info = attributes.delete(:license_info) |
| 105 | + another_license_version = attributes.delete(:another_license_version) | ||
| 106 | + another_license_link = attributes.delete(:another_license_link) | ||
| 107 | + | ||
| 104 | software_info = SoftwareInfo.new(attributes) | 108 | software_info = SoftwareInfo.new(attributes) |
| 105 | if !environment.admins.include? requestor | 109 | if !environment.admins.include? requestor |
| 106 | CreateSoftware.create!( | 110 | CreateSoftware.create!( |
| @@ -126,8 +130,20 @@ class SoftwareInfo < ActiveRecord::Base | @@ -126,8 +130,20 @@ class SoftwareInfo < ActiveRecord::Base | ||
| 126 | community.save! | 130 | community.save! |
| 127 | community.add_admin(requestor) | 131 | community.add_admin(requestor) |
| 128 | end | 132 | end |
| 133 | + | ||
| 134 | + software_info.verify_license_info(another_license_version, another_license_link) | ||
| 135 | + software_info.save! | ||
| 136 | + software_info | ||
| 129 | end | 137 | end |
| 130 | 138 | ||
| 139 | + def verify_license_info another_license_version, another_license_link | ||
| 140 | + if self.license_info_id == LicenseInfo.find_by_version("Another").id | ||
| 141 | + version = another_license_version | ||
| 142 | + link = another_license_link | ||
| 143 | + | ||
| 144 | + self.another_license(version, link) | ||
| 145 | + end | ||
| 146 | + end | ||
| 131 | 147 | ||
| 132 | 148 | ||
| 133 | def validate_acronym | 149 | def validate_acronym |
public/mpog-software-validations.js
| @@ -90,13 +90,27 @@ | @@ -90,13 +90,27 @@ | ||
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | function get_license_link(){ | 92 | function get_license_link(){ |
| 93 | + var selected_index = this.options.selectedIndex; | ||
| 94 | + var selected = this.options[selected_index]; | ||
| 93 | var link = jQuery("#version_" + this.value).val(); | 95 | var link = jQuery("#version_" + this.value).val(); |
| 94 | 96 | ||
| 97 | + if( selected.textContent == "Another" ) { | ||
| 98 | + jQuery("#another_license").removeClass("hide-field"); | ||
| 99 | + jQuery("#version_link").addClass("hide-field"); | ||
| 100 | + } else { | ||
| 101 | + jQuery("#another_license").addClass("hide-field"); | ||
| 102 | + jQuery("#version_link").removeClass("hide-field"); | ||
| 103 | + } | ||
| 104 | + | ||
| 95 | jQuery("#version_link") | 105 | jQuery("#version_link") |
| 96 | .attr("href", link) | 106 | .attr("href", link) |
| 97 | .text(link); | 107 | .text(link); |
| 98 | } | 108 | } |
| 99 | 109 | ||
| 110 | + function show_another_license_on_page_load() { | ||
| 111 | + jQuery("#license_info_version").trigger("change"); | ||
| 112 | + } | ||
| 113 | + | ||
| 100 | function hide_infos() { | 114 | function hide_infos() { |
| 101 | jQuery(".language-info").hide(); | 115 | jQuery(".language-info").hide(); |
| 102 | jQuery(".database-info").hide(); | 116 | jQuery(".database-info").hide(); |
| @@ -209,5 +223,6 @@ | @@ -209,5 +223,6 @@ | ||
| 209 | replace_software_creations_step(); | 223 | replace_software_creations_step(); |
| 210 | 224 | ||
| 211 | jQuery("#license_info_version").change(get_license_link); | 225 | jQuery("#license_info_version").change(get_license_link); |
| 226 | + show_another_license_on_page_load(); | ||
| 212 | }); | 227 | }); |
| 213 | })(); | 228 | })(); |
views/mpog_software_plugin_myprofile/_main_software_editor_extras.html.erb
| @@ -12,7 +12,7 @@ | @@ -12,7 +12,7 @@ | ||
| 12 | 12 | ||
| 13 | <h3> <%= _("Licenses") %> </h3> | 13 | <h3> <%= _("Licenses") %> </h3> |
| 14 | <div id='licenses'> | 14 | <div id='licenses'> |
| 15 | - <%= 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") %> | 15 | + <%= 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") %> |
| 16 | <br /> | 16 | <br /> |
| 17 | 17 | ||
| 18 | <h4> <%= _("License link") %> </h4> | 18 | <h4> <%= _("License link") %> </h4> |
| @@ -20,6 +20,11 @@ | @@ -20,6 +20,11 @@ | ||
| 20 | <input type="hidden" id = "version_<%=license.id %>" value = "<%=license.link%>"> | 20 | <input type="hidden" id = "version_<%=license.id %>" value = "<%=license.link%>"> |
| 21 | <% end %> | 21 | <% end %> |
| 22 | <a id = "version_link" href="<%= @profile.software_info.license_info.link %>" target="BLANK"> <%= @profile.software_info.license_info.link %> </a> | 22 | <a id = "version_link" href="<%= @profile.software_info.license_info.link %>" target="BLANK"> <%= @profile.software_info.license_info.link %> </a> |
| 23 | + <div id="another_license" class="hide-field"> | ||
| 24 | + <%= labelled_text_field "Licence version", "license[version]", "#{@another_license_version}", :id=>"licence_version" %> | ||
| 25 | + <br /> | ||
| 26 | + <%= labelled_text_field "Licence link", "license[link]", "#{@another_license_link}", :id=>"licence_link" %> | ||
| 27 | + </div> | ||
| 23 | </div> | 28 | </div> |
| 24 | 29 | ||
| 25 | <h3> <%= _("Link to Repository") %> </h3> | 30 | <h3> <%= _("Link to Repository") %> </h3> |
views/mpog_software_plugin_myprofile/new_software.html.erb
| @@ -53,6 +53,11 @@ | @@ -53,6 +53,11 @@ | ||
| 53 | <% end %> | 53 | <% end %> |
| 54 | <a id = "version_link" href="<%= LicenseInfo.first.link %>" target="_BLANK"> <%=LicenseInfo.first.link %> </a> | 54 | <a id = "version_link" href="<%= LicenseInfo.first.link %>" target="_BLANK"> <%=LicenseInfo.first.link %> </a> |
| 55 | 55 | ||
| 56 | + <div id="another_license" class="hide-field"> | ||
| 57 | + <%= labelled_text_field "Licence version", "license[version]", "", :id=>"licence_version" %> | ||
| 58 | + <br /> | ||
| 59 | + <%= labelled_text_field "Licence link", "license[link]", "", :id=>"licence_link" %> | ||
| 60 | + </div> | ||
| 56 | </div> | 61 | </div> |
| 57 | <% end %> | 62 | <% end %> |
| 58 | 63 |