Commit 8511e492b5f73fd6428573aa714c9fd43ac02cbf
1 parent
66411419
Exists in
master
and in
79 other branches
Change software language select field to autocomplete
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
Showing
4 changed files
with
56 additions
and
9 deletions
Show diff stats
controllers/mpog_software_plugin_controller.rb
... | ... | @@ -141,6 +141,22 @@ class MpogSoftwarePluginController < ApplicationController |
141 | 141 | render :json=> data |
142 | 142 | end |
143 | 143 | |
144 | + def get_languages | |
145 | + return render :json=>{} unless request.xhr? and params[:query] | |
146 | + | |
147 | + data = ProgrammingLanguage.where("name ILIKE ?", "%#{params[:query]}%").select("id, name").collect {|db| | |
148 | + {:id=>db.id, :label=>db.name} | |
149 | + } | |
150 | + other = [ProgrammingLanguage.select("id, name").last].collect { |db| | |
151 | + {:id=>db.id, :label=>db.name} | |
152 | + } | |
153 | + | |
154 | + # Always has other in the list | |
155 | + data |= other | |
156 | + | |
157 | + render :json=> data | |
158 | + end | |
159 | + | |
144 | 160 | protected |
145 | 161 | |
146 | 162 | def private_create_institution | ... | ... |
lib/database_helper.rb
1 | 1 | module DatabaseHelper |
2 | 2 | |
3 | - def self.isValidDatabase? database | |
3 | + def self.valid_database? database | |
4 | 4 | return false if SoftwareHelper.all_table_is_empty?(database) |
5 | 5 | |
6 | 6 | database_description_id_list = DatabaseDescription.select(:id).collect {|dd| dd.id } |
... | ... | @@ -15,7 +15,7 @@ module DatabaseHelper |
15 | 15 | list_databases = [] |
16 | 16 | |
17 | 17 | new_databases.each do |new_database| |
18 | - if isValidDatabase? new_database | |
18 | + if valid_database? new_database | |
19 | 19 | database = SoftwareDatabase.new |
20 | 20 | database.database_description_id = new_database[:database_description_id] |
21 | 21 | database.version = new_database[:version] | ... | ... |
lib/software_language_helper.rb
... | ... | @@ -39,7 +39,7 @@ module SoftwareLanguageHelper |
39 | 39 | lambdas_list = [] |
40 | 40 | |
41 | 41 | if not show_information |
42 | - return language_html_structure({:programming_language_id => 1, :version => "", :operating_system => ""}) if list_languages.nil? | |
42 | + return language_html_structure({:programming_language_id => "", :version => "", :operating_system => ""}) if list_languages.nil? | |
43 | 43 | |
44 | 44 | list_languages.each do |language| |
45 | 45 | lambdas_list << language_html_structure(language) |
... | ... | @@ -52,17 +52,24 @@ module SoftwareLanguageHelper |
52 | 52 | |
53 | 53 | end |
54 | 54 | |
55 | - | |
56 | 55 | lambdas_list |
57 | 56 | end |
58 | 57 | |
59 | 58 | def self.language_html_structure(language_data) |
59 | + language_name = if language_data[:programming_language_id].blank? | |
60 | + "" | |
61 | + else | |
62 | + ProgrammingLanguage.find(language_data[:programming_language_id], :select=>"name").name | |
63 | + end | |
64 | + | |
60 | 65 | Proc::new do |
61 | 66 | content_tag('table', |
62 | 67 | content_tag('tr', |
63 | 68 | content_tag('td', label_tag(_("Language Name: ")))+ |
64 | - content_tag('td', select_tag("language[][programming_language_id]", SoftwareHelper.select_options(ProgrammingLanguage.all, language_data[:programming_language_id]) ))+ | |
65 | - content_tag('td') | |
69 | + content_tag('td', | |
70 | + text_field_tag("language_autocomplete", language_name, :class=>"language_autocomplete") + | |
71 | + content_tag('div', _("Pick an item on the list"), :class=>"autocomplete_validation_message hide-field") ) + | |
72 | + content_tag('td', hidden_field_tag("language[][programming_language_id]", language_data[:programming_language_id], :class=>"programming_language_id", data:{label:language_name})) | |
66 | 73 | )+ |
67 | 74 | |
68 | 75 | content_tag('tr', | ... | ... |
public/mpog-software-validations.js
... | ... | @@ -30,9 +30,6 @@ |
30 | 30 | data: {query: request.term}, |
31 | 31 | success: function(result){ |
32 | 32 | response(result); |
33 | - }, | |
34 | - error: function(ajax, stat, errorThrown) { | |
35 | - console.log('Link not found : ' + errorThrown); | |
36 | 33 | } |
37 | 34 | }); |
38 | 35 | }, |
... | ... | @@ -50,6 +47,31 @@ |
50 | 47 | } |
51 | 48 | |
52 | 49 | |
50 | + function language_autocomplete() { | |
51 | + jQuery(".language_autocomplete").autocomplete({ | |
52 | + source : function(request, response){ | |
53 | + jQuery.ajax({ | |
54 | + type: "GET", | |
55 | + url: "/plugin/mpog_software/get_languages", | |
56 | + data: {query: request.term}, | |
57 | + success: function(result){ | |
58 | + response(result); | |
59 | + } | |
60 | + }); | |
61 | + }, | |
62 | + | |
63 | + minLength: 0, | |
64 | + | |
65 | + select : function (event, selected) { | |
66 | + var description = get_hidden_description_field(this, ".programming_language_id"); | |
67 | + description.val(selected.item.id); | |
68 | + description.attr("data-label", selected.item.label); | |
69 | + } | |
70 | + }).blur(function(){ | |
71 | + verify_autocomplete(this, ".programming_language_id"); | |
72 | + }); | |
73 | + } | |
74 | + | |
53 | 75 | function delete_dynamic_table() { |
54 | 76 | var button = jQuery(".delete-dynamic-table"); |
55 | 77 | |
... | ... | @@ -101,6 +123,7 @@ |
101 | 123 | |
102 | 124 | delete_dynamic_table(); |
103 | 125 | database_autocomplete(); |
126 | + language_autocomplete(); | |
104 | 127 | |
105 | 128 | jQuery(".new-dynamic-table").click(function(){ |
106 | 129 | var link = jQuery(this); |
... | ... | @@ -116,6 +139,7 @@ |
116 | 139 | |
117 | 140 | delete_dynamic_table(); |
118 | 141 | database_autocomplete(); |
142 | + language_autocomplete(); | |
119 | 143 | return false; |
120 | 144 | }); |
121 | 145 | ... | ... |