Commit 8f54d03e7abb2090645d20fea688dc7c11d5d608
Committed by
Luciano Prestes
1 parent
8a9d6bad
Exists in
master
and in
5 other branches
fixes_software: Change dynamic table database name to autocomplete
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Showing
3 changed files
with
55 additions
and
3 deletions
Show diff stats
controllers/mpog_software_plugin_controller.rb
... | ... | @@ -148,6 +148,22 @@ class MpogSoftwarePluginController < ApplicationController |
148 | 148 | render :json=>state_list.collect {|state| state.name }.to_json |
149 | 149 | end |
150 | 150 | |
151 | + def get_databases | |
152 | + return render :json=>{} unless request.xhr? and params[:query] | |
153 | + | |
154 | + data = DatabaseDescription.where("name ILIKE ?", "%#{params[:query]}%").collect {|db| | |
155 | + {:id=>db.id, :label=>db.name} | |
156 | + } | |
157 | + other = [DatabaseDescription.last].collect { |db| | |
158 | + {:id=>db.id, :label=>db.name} | |
159 | + } | |
160 | + | |
161 | + # Always has other in the list | |
162 | + data |= other | |
163 | + | |
164 | + render :json=> data | |
165 | + end | |
166 | + | |
151 | 167 | protected |
152 | 168 | |
153 | 169 | def private_create_institution | ... | ... |
lib/database_helper.rb
... | ... | @@ -36,7 +36,7 @@ module DatabaseHelper |
36 | 36 | ApplicationHelper |
37 | 37 | ) |
38 | 38 | |
39 | - return database_html_structure({:database_description_id => 1, :version => "", :operating_system => ""}) if list_databases.nil? | |
39 | + return database_html_structure({:database_description_id => "", :version => "", :operating_system => ""}) if list_databases.nil? | |
40 | 40 | |
41 | 41 | lambdas_list = [] |
42 | 42 | |
... | ... | @@ -52,8 +52,8 @@ module DatabaseHelper |
52 | 52 | content_tag('table', |
53 | 53 | content_tag('tr', |
54 | 54 | content_tag('td', label_tag(_("database Name: ")))+ |
55 | - content_tag('td', select_tag("database[][database_description_id]", SoftwareHelper.select_options(DatabaseDescription.all, database_data[:database_description_id]) ))+ | |
56 | - content_tag('td') | |
55 | + content_tag('td', text_field_tag("database_autocomplete", "", :class=>"database_autocomplete"))+ | |
56 | + content_tag('td', hidden_field_tag("database[][database_description_id]", database_data[:database_description_id], :class=>"database_description_id")) | |
57 | 57 | )+ |
58 | 58 | |
59 | 59 | content_tag('tr', | ... | ... |
public/mpog-software-validations.js
1 | 1 | (function(){ |
2 | + function database_autocomplete() { | |
3 | + jQuery(".database_autocomplete").autocomplete({ | |
4 | + source : function(request, response){ | |
5 | + jQuery.ajax({ | |
6 | + type: "GET", | |
7 | + url: "/plugin/mpog_software/get_databases", | |
8 | + data: {query: request.term}, | |
9 | + success: function(result){ | |
10 | + response(result); | |
11 | + | |
12 | + /*if( result.length == 0 ) { | |
13 | + jQuery('#institution_empty_ajax_message').switchClass("hide-field", "show-field"); | |
14 | + } else { | |
15 | + jQuery('#institution_empty_ajax_message').switchClass("show-field", "hide-field"); | |
16 | + }*/ | |
17 | + }, | |
18 | + error: function(ajax, stat, errorThrown) { | |
19 | + console.log('Link not found : ' + errorThrown); | |
20 | + } | |
21 | + }); | |
22 | + }, | |
23 | + | |
24 | + minLength: 1, | |
25 | + | |
26 | + select : function (event, selected) { | |
27 | + jQuery(this) | |
28 | + .parent().parent() | |
29 | + .find(".database_description_id") | |
30 | + .val(selected.item.id); | |
31 | + } | |
32 | + }); | |
33 | + } | |
34 | + | |
35 | + | |
2 | 36 | function delete_dynamic_table() { |
3 | 37 | var button = jQuery(".delete-dynamic-table"); |
4 | 38 | |
... | ... | @@ -49,6 +83,7 @@ |
49 | 83 | var dynamic_tables = ["dynamic-databases", "dynamic-languages", "dynamic-libraries","dynamic-operating_systems"]; |
50 | 84 | |
51 | 85 | delete_dynamic_table(); |
86 | + database_autocomplete(); | |
52 | 87 | |
53 | 88 | jQuery(".new-dynamic-table").click(function(){ |
54 | 89 | var link = jQuery(this); |
... | ... | @@ -63,6 +98,7 @@ |
63 | 98 | }); |
64 | 99 | |
65 | 100 | delete_dynamic_table(); |
101 | + database_autocomplete(); | |
66 | 102 | return false; |
67 | 103 | }); |
68 | 104 | ... | ... |