Commit 526afc86795c7be79e5482289edc15bde058a9f5

Authored by Fabio Teixeira
Committed by David Silva
1 parent 9655e48f

Set lincense to use the same ajax as software's dynamic tables

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
controllers/mpog_software_plugin_myprofile_controller.rb
@@ -180,11 +180,14 @@ class MpogSoftwarePluginMyprofileController &lt; MyProfileController @@ -180,11 +180,14 @@ class MpogSoftwarePluginMyprofileController &lt; MyProfileController
180 @list_operating_systems = @software_info.operating_systems 180 @list_operating_systems = @software_info.operating_systems
181 @disabled_public_software_field = disabled_public_software_field 181 @disabled_public_software_field = disabled_public_software_field
182 182
  183 + @license_version = @software_info.license_info.version
  184 + @license_id = @software_info.license_info.id
183 @another_license_version = "" 185 @another_license_version = ""
184 @another_license_link = "" 186 @another_license_link = ""
185 187
186 license_another = LicenseInfo.find_by_version("Another") 188 license_another = LicenseInfo.find_by_version("Another")
187 if license_another && @software_info.license_info_id == license_another.id 189 if license_another && @software_info.license_info_id == license_another.id
  190 + @license_version = "Another"
188 @another_license_version = @software_info.license_info.version 191 @another_license_version = @software_info.license_info.version
189 @another_license_link = @software_info.license_info.link 192 @another_license_link = @software_info.license_info.link
190 end 193 end
public/mpog-software-validations.js
@@ -21,7 +21,7 @@ @@ -21,7 +21,7 @@
21 21
22 if( field.length === 0 || selected.val().length === 0 ) { 22 if( field.length === 0 || selected.val().length === 0 ) {
23 message_error.removeClass("hide-field"); 23 message_error.removeClass("hide-field");
24 - selected_value.val(""); 24 + selected.val("");
25 25
26 message_error.show(); 26 message_error.show();
27 } else { 27 } else {
@@ -32,21 +32,21 @@ @@ -32,21 +32,21 @@
32 32
33 33
34 function database_autocomplete() { 34 function database_autocomplete() {
35 - enable_autocomplete("database", ".database_description_id", ".database_autocomplete"); 35 + enable_autocomplete("database", ".database_description_id", ".database_autocomplete", AJAX_URL.get_field_data);
36 } 36 }
37 37
38 38
39 function language_autocomplete() { 39 function language_autocomplete() {
40 - enable_autocomplete("software_language", ".programming_language_id", ".language_autocomplete"); 40 + enable_autocomplete("software_language", ".programming_language_id", ".language_autocomplete", AJAX_URL.get_field_data);
41 } 41 }
42 42
43 43
44 - function enable_autocomplete(field_name, field_value_class, autocomplete_class) { 44 + function enable_autocomplete(field_name, field_value_class, autocomplete_class, ajax_url, select_callback) {
45 $(autocomplete_class).autocomplete({ 45 $(autocomplete_class).autocomplete({
46 source : function(request, response){ 46 source : function(request, response){
47 $.ajax({ 47 $.ajax({
48 type: "GET", 48 type: "GET",
49 - url: AJAX_URL.get_field_data, 49 + url: ajax_url,
50 data: {query: request.term, field: field_name}, 50 data: {query: request.term, field: field_name},
51 success: function(result){ 51 success: function(result){
52 response(result); 52 response(result);
@@ -60,6 +60,10 @@ @@ -60,6 +60,10 @@
60 var description = get_hidden_description_field(this, field_value_class); 60 var description = get_hidden_description_field(this, field_value_class);
61 description.val(selected.item.id); 61 description.val(selected.item.id);
62 description.attr("data-label", selected.item.label); 62 description.attr("data-label", selected.item.label);
  63 +
  64 + if( select_callback !== undefined ) {
  65 + select_callback(selected);
  66 + }
63 } 67 }
64 }).blur(function(){ 68 }).blur(function(){
65 verify_autocomplete(this, field_value_class); 69 verify_autocomplete(this, field_value_class);
@@ -135,39 +139,27 @@ @@ -135,39 +139,27 @@
135 if( selected == "Another" ) { 139 if( selected == "Another" ) {
136 $("#another_license").removeClass("hide-field"); 140 $("#another_license").removeClass("hide-field");
137 $("#version_link").addClass("hide-field"); 141 $("#version_link").addClass("hide-field");
  142 + console.log($("#version_link"));
138 } else { 143 } else {
139 $("#another_license").addClass("hide-field"); 144 $("#another_license").addClass("hide-field");
140 $("#version_link").removeClass("hide-field"); 145 $("#version_link").removeClass("hide-field");
141 } 146 }
142 } 147 }
143 148
144 - function trigger_license_info_events() {  
145 - $("#license_info_version").autocomplete({  
146 - source : function(request, response){  
147 - $.ajax({  
148 - type: "GET",  
149 - url: AJAX_URL.get_license_data,  
150 - data: {query: request.term},  
151 - success: function(result){  
152 - response(result);  
153 - }  
154 - });  
155 - },  
156 149
157 - minLength: 0, 150 + function display_license_link_on_autocomplete(selected) {
  151 + var link = $("#version_" + selected.item.id).val();
  152 + $("#version_link").attr("href", link);
158 153
159 - select : function (event, selected) {  
160 - $("#license_info_id").val(selected.item.id);  
161 - var link = $("#version_" + selected.item.id).val(); 154 + display_another_license_fields(selected.item.label);
  155 + }
162 156
163 - console.log(link);  
164 157
165 - display_another_license_fields(selected.item.label);  
166 - $("#version_link").attr("href", link).text(link);  
167 - }  
168 - }).click(function(){  
169 - $(this).autocomplete("search", this.value);  
170 - }); 158 + function license_info_autocomplete() {
  159 + enable_autocomplete(
  160 + "license_info", ".license_info_id", ".license_info_version",
  161 + AJAX_URL.get_license_data, display_license_link_on_autocomplete
  162 + );
171 } 163 }
172 164
173 165
@@ -196,6 +188,7 @@ @@ -196,6 +188,7 @@
196 return false; 188 return false;
197 }); 189 });
198 190
  191 +
199 $(".language-button-hide").click(function(event){ 192 $(".language-button-hide").click(function(event){
200 event.preventDefault(); 193 event.preventDefault();
201 $(".language-info").hide(); 194 $(".language-info").hide();
@@ -257,6 +250,6 @@ @@ -257,6 +250,6 @@
257 250
258 replace_software_creations_step(); 251 replace_software_creations_step();
259 252
260 - trigger_license_info_events(); 253 + license_info_autocomplete();
261 }); 254 });
262 })(jQuery); 255 })(jQuery);
views/mpog_software_plugin_myprofile/_license_info_fields.html.erb 0 → 100644
@@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
  1 +<% LicenseHelper.getListLicenses.each do | license | %>
  2 + <input type="hidden" id = "version_<%=license.id %>" value = "<%=license.link%>">
  3 +<% end %>
  4 +
  5 +<h3><%= _("License Version: ") %></h3>
  6 +<%= text_field_tag "license_info[version]", license_version, :id=>"license_info_version", :class=>"license_info_version", :placeholder=>_('Autocomplete field, type some license') %>
  7 +<%= hidden_field_tag "license[license_infos_id]", license_id, :id=>"license_info_id", :class=>"license_info_id", :data => {:label=>license_version} %>
  8 +
  9 +<a id = "version_link" href="#" target="_BLANK" class="hide-field"><%= _("Read license") %></a>
  10 +
  11 +<div id="another_license" class="<%= 'hide-field' if license_version != 'Another' %>">
  12 + <%= labelled_text_field "Licence version", "license[version]", another_version, :id=>"licence_version" %>
  13 + <br />
  14 + <%= labelled_text_field "Licence link", "license[link]", another_link, :id=>"licence_link" %>
  15 +</div>
views/mpog_software_plugin_myprofile/_main_software_editor_extras.html.erb
@@ -10,24 +10,14 @@ @@ -10,24 +10,14 @@
10 <%= text_area_tag "software[finality]", @profile.software_info.finality, :placeholder => _("It is a software of..."), :cols => 40, :rows => 5, :maxlength => 140%> 10 <%= text_area_tag "software[finality]", @profile.software_info.finality, :placeholder => _("It is a software of..."), :cols => 40, :rows => 5, :maxlength => 140%>
11 </div> 11 </div>
12 12
13 -<h3> <%= _("Licenses") %> </h3>  
14 <div id='licenses'> 13 <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_id") %>  
16 -  
17 - <%= labelled_text_field _("License Version: "), "license_info[version]", @profile.software_info.license_info.version, :id=>"license_info_version" %>  
18 - <%= hidden_field_tag "license[license_infos_id]", @profile.software_info.license_info_id, :id=>"license_info_id" %>  
19 - <br />  
20 -  
21 - <h4> <%= _("License link") %> </h4>  
22 - <% LicenseHelper.getListLicenses.each do | license | %>  
23 - <input type="hidden" id = "version_<%=license.id %>" value = "<%=license.link%>">  
24 - <% end %>  
25 - <a id = "version_link" href="<%= @profile.software_info.license_info.link %>" target="BLANK"> <%= @profile.software_info.license_info.link %> </a>  
26 - <div id="another_license" class="hide-field">  
27 - <%= labelled_text_field "Licence version", "license[version]", "#{@another_license_version}", :id=>"licence_version" %>  
28 - <br />  
29 - <%= labelled_text_field "Licence link", "license[link]", "#{@another_license_link}", :id=>"licence_link" %>  
30 - </div> 14 + <%= render :partial => "license_info_fields", :locals => {
  15 + :license_version => @license_version,
  16 + :license_id => @license_id,
  17 + :another_version => @another_license_version,
  18 + :another_link => @another_license_link
  19 + }
  20 + %>
31 </div> 21 </div>
32 22
33 <h3> <%= _("Link to Repository") %> </h3> 23 <h3> <%= _("Link to Repository") %> </h3>
views/mpog_software_plugin_myprofile/new_software.html.erb
@@ -42,25 +42,14 @@ @@ -42,25 +42,14 @@
42 </div> 42 </div>
43 <% end %> 43 <% end %>
44 44
45 - <%= fields_for @license_info do |lcv| %>  
46 <div class="formfieldline"> 45 <div class="formfieldline">
47 - <%= labelled_text_field _("License Version: "), "license_info[version]", "", :id=>"license_info_version" %>  
48 - <%= hidden_field_tag "license[license_infos_id]", "", :id=>"license_info_id" %>  
49 -  
50 - <h4> <%= _("License link") %> </h4>  
51 - <% LicenseHelper.getListLicenses.each do | license | %>  
52 - <input type="hidden" id = "version_<%=license.id %>" value = "<%=license.link%>">  
53 - <% end %>  
54 - <a id = "version_link" href="<%= LicenseInfo.first.link %>" target="_BLANK"> <%=LicenseInfo.first.link %> </a>  
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> 46 + <%= render :partial => "license_info_fields", :locals => {
  47 + :license_version => "",
  48 + :license_id => "",
  49 + :another_version=>"",
  50 + :another_link=>""
  51 + } %>
61 </div> 52 </div>
62 - <% end %>  
63 -  
64 53
65 <%= fields_for @software_info do |swf| %> 54 <%= fields_for @software_info do |swf| %>
66 <div class="formfieldline formfield type-text"> 55 <div class="formfieldline formfield type-text">