Commit a490ebe755a4762f1bab493a29178967090eb60c

Authored by Luciano Prestes
Committed by David Silva
1 parent 71f29e1e

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>
controllers/mpog_software_plugin_myprofile_controller.rb
... ... @@ -19,6 +19,7 @@ class MpogSoftwarePluginMyprofileController &lt; MyProfileController
19 19 @community = Community.new(params[:community])
20 20 @community.environment = environment
21 21 @software_info = SoftwareInfo.new(params[:software_info])
  22 +
22 23 @license_info = if params[:license_info].nil?
23 24 LicenseInfo.new
24 25 else
... ... @@ -122,6 +123,11 @@ class MpogSoftwarePluginMyprofileController &lt; MyProfileController
122 123 @software_info.license_info = @license
123 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 131 create_list_model_helpers
126 132  
127 133 @software_info
... ... @@ -139,7 +145,9 @@ class MpogSoftwarePluginMyprofileController &lt; MyProfileController
139 145 params[:software_info].merge({
140 146 :environment => environment,
141 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 152 add_admin_to_community
145 153  
... ... @@ -161,6 +169,14 @@ class MpogSoftwarePluginMyprofileController &lt; MyProfileController
161 169 @list_languages = @software_info.software_languages
162 170 @list_operating_systems = @software_info.operating_systems
163 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 180 end
165 181  
166 182 def set_software_as_template
... ...
lib/software_info.rb
1 1 class SoftwareInfo < ActiveRecord::Base
2   - acts_as_having_settings :field => :setting
  2 + acts_as_having_settings :field => :settings
3 3  
4 4 SEARCH_FILTERS = []
5 5 SEARCH_DISPLAYS = %w[full]
... ... @@ -83,6 +83,7 @@ class SoftwareInfo &lt; ActiveRecord::Base
83 83 self.another_license_version = version
84 84 self.another_license_link = link
85 85 self.license_info = LicenseInfo.find_by_version("Another")
  86 + self.save!
86 87 end
87 88  
88 89 def validate_name_lenght
... ... @@ -101,6 +102,9 @@ class SoftwareInfo &lt; ActiveRecord::Base
101 102 environment = attributes.delete(:environment)
102 103 name = attributes.delete(:name)
103 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 108 software_info = SoftwareInfo.new(attributes)
105 109 if !environment.admins.include? requestor
106 110 CreateSoftware.create!(
... ... @@ -126,8 +130,20 @@ class SoftwareInfo &lt; ActiveRecord::Base
126 130 community.save!
127 131 community.add_admin(requestor)
128 132 end
  133 +
  134 + software_info.verify_license_info(another_license_version, another_license_link)
  135 + software_info.save!
  136 + software_info
129 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 149 def validate_acronym
... ...
public/mpog-software-validations.js
... ... @@ -90,13 +90,27 @@
90 90 }
91 91  
92 92 function get_license_link(){
  93 + var selected_index = this.options.selectedIndex;
  94 + var selected = this.options[selected_index];
93 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 105 jQuery("#version_link")
96 106 .attr("href", link)
97 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 114 function hide_infos() {
101 115 jQuery(".language-info").hide();
102 116 jQuery(".database-info").hide();
... ... @@ -209,5 +223,6 @@
209 223 replace_software_creations_step();
210 224  
211 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 12  
13 13 <h3> <%= _("Licenses") %> </h3>
14 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 16 <br />
17 17  
18 18 <h4> <%= _("License link") %> </h4>
... ... @@ -20,6 +20,11 @@
20 20 <input type="hidden" id = "version_<%=license.id %>" value = "<%=license.link%>">
21 21 <% end %>
22 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 28 </div>
24 29  
25 30 <h3> <%= _("Link to Repository") %> </h3>
... ...
views/mpog_software_plugin_myprofile/new_software.html.erb
... ... @@ -53,6 +53,11 @@
53 53 <% end %>
54 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 61 </div>
57 62 <% end %>
58 63  
... ...