Commit 9655e48fa6d1908eda310d82e93d29748fd77141
Committed by
David Silva
1 parent
ec80627d
Exists in
master
and in
5 other branches
Set lincense link as an autocomplete field
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
Showing
4 changed files
with
136 additions
and
85 deletions
Show diff stats
controllers/mpog_software_plugin_controller.rb
... | ... | @@ -130,6 +130,20 @@ class MpogSoftwarePluginController < ApplicationController |
130 | 130 | render :json=> data |
131 | 131 | end |
132 | 132 | |
133 | + def get_license_data | |
134 | + return render :json=>{} if !request.xhr? || params[:query].nil? | |
135 | + | |
136 | + data = if params[:query].empty? | |
137 | + LicenseInfo.all | |
138 | + else | |
139 | + LicenseInfo.where("version ILIKE ?", "%#{params[:query]}%").select("id, version") | |
140 | + end | |
141 | + | |
142 | + render :json=> data.collect { |license| | |
143 | + {:id=>license.id, :label=>license.version} | |
144 | + } | |
145 | + end | |
146 | + | |
133 | 147 | protected |
134 | 148 | |
135 | 149 | def get_state_list | ... | ... |
public/mpog-software-validations.js
1 | -(function(){ | |
1 | +(function($){ | |
2 | 2 | var AJAX_URL = { |
3 | 3 | get_field_data: |
4 | - url_with_subdirectory("/plugin/mpog_software/get_field_data") | |
4 | + url_with_subdirectory("/plugin/mpog_software/get_field_data"), | |
5 | + get_license_data: | |
6 | + url_with_subdirectory("/plugin/mpog_software/get_license_data") | |
5 | 7 | }; |
6 | 8 | |
7 | 9 | |
8 | 10 | function get_hidden_description_field(autocomplete_field, klass) { |
9 | - var field = jQuery(autocomplete_field); | |
11 | + var field = $(autocomplete_field); | |
10 | 12 | field = field.parent().parent().find(klass); |
11 | 13 | return field; |
12 | 14 | } |
13 | 15 | |
16 | + | |
14 | 17 | function verify_autocomplete(field, klass) { |
15 | - var field = jQuery(field); | |
18 | + var field = $(field); | |
16 | 19 | var selected = get_hidden_description_field(field, klass); |
17 | - var message_error = jQuery(field).parent().find(".autocomplete_validation_message"); | |
20 | + var message_error = $(field).parent().find(".autocomplete_validation_message"); | |
18 | 21 | |
19 | 22 | if( field.length === 0 || selected.val().length === 0 ) { |
20 | 23 | message_error.removeClass("hide-field"); |
... | ... | @@ -27,6 +30,7 @@ |
27 | 30 | } |
28 | 31 | } |
29 | 32 | |
33 | + | |
30 | 34 | function database_autocomplete() { |
31 | 35 | enable_autocomplete("database", ".database_description_id", ".database_autocomplete"); |
32 | 36 | } |
... | ... | @@ -36,10 +40,11 @@ |
36 | 40 | enable_autocomplete("software_language", ".programming_language_id", ".language_autocomplete"); |
37 | 41 | } |
38 | 42 | |
43 | + | |
39 | 44 | function enable_autocomplete(field_name, field_value_class, autocomplete_class) { |
40 | - jQuery(autocomplete_class).autocomplete({ | |
45 | + $(autocomplete_class).autocomplete({ | |
41 | 46 | source : function(request, response){ |
42 | - jQuery.ajax({ | |
47 | + $.ajax({ | |
43 | 48 | type: "GET", |
44 | 49 | url: AJAX_URL.get_field_data, |
45 | 50 | data: {query: request.term, field: field_name}, |
... | ... | @@ -59,18 +64,19 @@ |
59 | 64 | }).blur(function(){ |
60 | 65 | verify_autocomplete(this, field_value_class); |
61 | 66 | }).click(function(){ |
62 | - jQuery(this).autocomplete("search", ""); | |
67 | + $(this).autocomplete("search", ""); | |
63 | 68 | }); |
64 | 69 | } |
65 | 70 | |
71 | + | |
66 | 72 | function delete_dynamic_table() { |
67 | - var button = jQuery(".delete-dynamic-table"); | |
73 | + var button = $(".delete-dynamic-table"); | |
68 | 74 | |
69 | 75 | button.each(function(){ |
70 | - var table = jQuery(this).parent().parent().parent().parent(); | |
76 | + var table = $(this).parent().parent().parent().parent(); | |
71 | 77 | var color = table.css("background-color"); |
72 | 78 | |
73 | - jQuery(this).click(function(){ | |
79 | + $(this).click(function(){ | |
74 | 80 | table.remove(); |
75 | 81 | return false; |
76 | 82 | }).mouseover(function(){ |
... | ... | @@ -81,77 +87,105 @@ |
81 | 87 | }); |
82 | 88 | } |
83 | 89 | |
90 | + | |
84 | 91 | function has_more_than_one(table_class) { |
85 | - return (jQuery("."+table_class).length > 2); // One is always added by defaul and its hidden | |
92 | + return ($("."+table_class).length > 2); // One is always added by defaul and its hidden | |
86 | 93 | } |
87 | 94 | |
95 | + | |
88 | 96 | function add_dynamic_table(element_id, content) { |
89 | 97 | Element.insert(element_id, {bottom: content}); |
90 | 98 | } |
91 | 99 | |
92 | - function get_license_link(){ | |
93 | - var selected_index = this.options.selectedIndex; | |
94 | - var selected = this.options[selected_index]; | |
95 | - var link = jQuery("#version_" + this.value).val(); | |
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 | - | |
105 | - jQuery("#version_link") | |
106 | - .attr("href", link) | |
107 | - .text(link); | |
108 | - } | |
109 | 100 | |
110 | 101 | function show_another_license_on_page_load() { |
111 | - jQuery("#license_info_id").trigger("change"); | |
102 | + $("#license_info_id").trigger("change"); | |
112 | 103 | } |
113 | 104 | |
105 | + | |
114 | 106 | function hide_infos() { |
115 | - jQuery(".language-info").hide(); | |
116 | - jQuery(".database-info").hide(); | |
117 | - jQuery(".libraries-info").hide(); | |
118 | - jQuery(".operating-system-info").hide(); | |
119 | - jQuery(".language-button-hide").hide(); | |
120 | - jQuery(".database-button-hide").hide(); | |
121 | - jQuery(".libraries-button-hide").hide(); | |
122 | - jQuery(".operating-system-button-hide").hide(); | |
107 | + $(".language-info").hide(); | |
108 | + $(".database-info").hide(); | |
109 | + $(".libraries-info").hide(); | |
110 | + $(".operating-system-info").hide(); | |
111 | + $(".language-button-hide").hide(); | |
112 | + $(".database-button-hide").hide(); | |
113 | + $(".libraries-button-hide").hide(); | |
114 | + $(".operating-system-button-hide").hide(); | |
123 | 115 | } |
124 | 116 | |
125 | 117 | function hide_show_public_software_fields() { |
126 | - if (jQuery("#software_public_software").prop("checked")) | |
127 | - jQuery(".public-software-fields").show(); | |
118 | + if ($("#software_public_software").prop("checked")) | |
119 | + $(".public-software-fields").show(); | |
128 | 120 | else |
129 | - jQuery(".public-software-fields").hide(); | |
121 | + $(".public-software-fields").hide(); | |
130 | 122 | } |
131 | 123 | |
124 | + | |
132 | 125 | function replace_software_creations_step() { |
133 | - var software_creation_step = jQuery("#software_creation_step").remove(); | |
126 | + var software_creation_step = $("#software_creation_step").remove(); | |
134 | 127 | |
135 | 128 | if( software_creation_step.size() > 0 ) { |
136 | - jQuery("#profile-data").parent().prepend(software_creation_step); | |
129 | + $("#profile-data").parent().prepend(software_creation_step); | |
137 | 130 | } |
138 | 131 | } |
139 | 132 | |
140 | - jQuery(document).ready(function(){ | |
133 | + | |
134 | + function display_another_license_fields(selected) { | |
135 | + if( selected == "Another" ) { | |
136 | + $("#another_license").removeClass("hide-field"); | |
137 | + $("#version_link").addClass("hide-field"); | |
138 | + } else { | |
139 | + $("#another_license").addClass("hide-field"); | |
140 | + $("#version_link").removeClass("hide-field"); | |
141 | + } | |
142 | + } | |
143 | + | |
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 | + | |
157 | + minLength: 0, | |
158 | + | |
159 | + select : function (event, selected) { | |
160 | + $("#license_info_id").val(selected.item.id); | |
161 | + var link = $("#version_" + selected.item.id).val(); | |
162 | + | |
163 | + console.log(link); | |
164 | + | |
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 | + }); | |
171 | + } | |
172 | + | |
173 | + | |
174 | + $(document).ready(function() { | |
141 | 175 | var dynamic_tables = ["dynamic-databases", "dynamic-languages", "dynamic-libraries","dynamic-operating_systems"]; |
142 | 176 | |
143 | 177 | delete_dynamic_table(); |
144 | 178 | database_autocomplete(); |
145 | 179 | language_autocomplete(); |
146 | 180 | |
147 | - jQuery(".new-dynamic-table").click(function(){ | |
148 | - var link = jQuery(this); | |
181 | + $(".new-dynamic-table").click(function(){ | |
182 | + var link = $(this); | |
149 | 183 | |
150 | 184 | dynamic_tables.each(function(value){ |
151 | 185 | if( link.hasClass(value) ) { |
152 | 186 | var table_id = value.split("-")[1]; |
153 | 187 | |
154 | - var table_html = jQuery("#table_structure_"+table_id).html(); | |
188 | + var table_html = $("#table_structure_"+table_id).html(); | |
155 | 189 | add_dynamic_table(table_id, table_html); |
156 | 190 | } |
157 | 191 | }); |
... | ... | @@ -162,67 +196,67 @@ |
162 | 196 | return false; |
163 | 197 | }); |
164 | 198 | |
165 | - jQuery(".language-button-hide").click(function(event){ | |
199 | + $(".language-button-hide").click(function(event){ | |
166 | 200 | event.preventDefault(); |
167 | - jQuery(".language-info").hide(); | |
168 | - jQuery(".language-button-show").show(); | |
169 | - jQuery(".language-button-hide").hide(); | |
201 | + $(".language-info").hide(); | |
202 | + $(".language-button-show").show(); | |
203 | + $(".language-button-hide").hide(); | |
170 | 204 | }); |
171 | 205 | |
172 | - jQuery(".language-button-show").click(function(event){ | |
206 | + $(".language-button-show").click(function(event){ | |
173 | 207 | event.preventDefault(); |
174 | - jQuery(".language-info").show(); | |
175 | - jQuery(".language-button-show").hide(); | |
176 | - jQuery(".language-button-hide").show(); | |
208 | + $(".language-info").show(); | |
209 | + $(".language-button-show").hide(); | |
210 | + $(".language-button-hide").show(); | |
177 | 211 | }); |
178 | 212 | |
179 | - jQuery(".operating-system-button-hide").click(function(event){ | |
213 | + $(".operating-system-button-hide").click(function(event){ | |
180 | 214 | event.preventDefault(); |
181 | - jQuery(".operating-system-info").hide(); | |
182 | - jQuery(".operating-system-button-show").show(); | |
183 | - jQuery(".operating-system-button-hide").hide(); | |
215 | + $(".operating-system-info").hide(); | |
216 | + $(".operating-system-button-show").show(); | |
217 | + $(".operating-system-button-hide").hide(); | |
184 | 218 | }); |
185 | 219 | |
186 | - jQuery(".operating-system-button-show").click(function(event){ | |
220 | + $(".operating-system-button-show").click(function(event){ | |
187 | 221 | event.preventDefault(); |
188 | - jQuery(".operating-system-info").show(); | |
189 | - jQuery(".operating-system-button-show").hide(); | |
190 | - jQuery(".operating-system-button-hide").show(); | |
222 | + $(".operating-system-info").show(); | |
223 | + $(".operating-system-button-show").hide(); | |
224 | + $(".operating-system-button-hide").show(); | |
191 | 225 | }); |
192 | 226 | |
193 | - jQuery(".database-button-hide").click(function(event){ | |
227 | + $(".database-button-hide").click(function(event){ | |
194 | 228 | event.preventDefault(); |
195 | - jQuery(".database-info").hide(); | |
196 | - jQuery(".database-button-show").show(); | |
197 | - jQuery(".database-button-hide").hide(); | |
229 | + $(".database-info").hide(); | |
230 | + $(".database-button-show").show(); | |
231 | + $(".database-button-hide").hide(); | |
198 | 232 | }); |
199 | 233 | |
200 | - jQuery(".database-button-show").click(function(event){ | |
234 | + $(".database-button-show").click(function(event){ | |
201 | 235 | event.preventDefault(); |
202 | - jQuery(".database-info").show(); | |
203 | - jQuery(".database-button-show").hide(); | |
204 | - jQuery(".database-button-hide").show(); | |
236 | + $(".database-info").show(); | |
237 | + $(".database-button-show").hide(); | |
238 | + $(".database-button-hide").show(); | |
205 | 239 | }); |
206 | 240 | |
207 | - jQuery(".libraries-button-hide").click(function(event){ | |
241 | + $(".libraries-button-hide").click(function(event){ | |
208 | 242 | event.preventDefault(); |
209 | - jQuery(".libraries-info").hide(); | |
210 | - jQuery(".libraries-button-show").show(); | |
211 | - jQuery(".libraries-button-hide").hide(); | |
243 | + $(".libraries-info").hide(); | |
244 | + $(".libraries-button-show").show(); | |
245 | + $(".libraries-button-hide").hide(); | |
212 | 246 | }); |
213 | 247 | |
214 | - jQuery(".libraries-button-show").click(function(event){ | |
248 | + $(".libraries-button-show").click(function(event){ | |
215 | 249 | event.preventDefault(); |
216 | - jQuery(".libraries-info").show(); | |
217 | - jQuery(".libraries-button-show").hide(); | |
218 | - jQuery(".libraries-button-hide").show(); | |
250 | + $(".libraries-info").show(); | |
251 | + $(".libraries-button-show").hide(); | |
252 | + $(".libraries-button-hide").show(); | |
219 | 253 | }); |
254 | + | |
220 | 255 | hide_show_public_software_fields(); |
221 | - jQuery("#software_public_software").click(hide_show_public_software_fields); | |
256 | + $("#software_public_software").click(hide_show_public_software_fields); | |
222 | 257 | |
223 | 258 | replace_software_creations_step(); |
224 | 259 | |
225 | - jQuery("#license_info_id").change(get_license_link); | |
226 | - show_another_license_on_page_load(); | |
260 | + trigger_license_info_events(); | |
227 | 261 | }); |
228 | -})(); | |
262 | +})(jQuery); | ... | ... |
views/mpog_software_plugin_myprofile/_main_software_editor_extras.html.erb
... | ... | @@ -13,6 +13,9 @@ |
13 | 13 | <h3> <%= _("Licenses") %> </h3> |
14 | 14 | <div id='licenses'> |
15 | 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" %> | |
16 | 19 | <br /> |
17 | 20 | |
18 | 21 | <h4> <%= _("License link") %> </h4> | ... | ... |
views/mpog_software_plugin_myprofile/new_software.html.erb
... | ... | @@ -44,8 +44,8 @@ |
44 | 44 | |
45 | 45 | <%= fields_for @license_info do |lcv| %> |
46 | 46 | <div class="formfieldline"> |
47 | - <h4> <%= lcv.label _("License Version: ") %> </h4> | |
48 | - <%= lcv.select(:id, LicenseInfo.all.map {|l| [l.version, l.id]}, {:selected => 1}) %> | |
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 | 49 | |
50 | 50 | <h4> <%= _("License link") %> </h4> |
51 | 51 | <% LicenseHelper.getListLicenses.each do | license | %> | ... | ... |