diff --git a/controllers/mpog_software_plugin_controller.rb b/controllers/mpog_software_plugin_controller.rb index ea42484..d6414e2 100644 --- a/controllers/mpog_software_plugin_controller.rb +++ b/controllers/mpog_software_plugin_controller.rb @@ -148,6 +148,22 @@ class MpogSoftwarePluginController < ApplicationController render :json=>state_list.collect {|state| state.name }.to_json end + def get_databases + return render :json=>{} unless request.xhr? and params[:query] + + data = DatabaseDescription.where("name ILIKE ?", "%#{params[:query]}%").collect {|db| + {:id=>db.id, :label=>db.name} + } + other = [DatabaseDescription.last].collect { |db| + {:id=>db.id, :label=>db.name} + } + + # Always has other in the list + data |= other + + render :json=> data + end + protected def private_create_institution diff --git a/lib/database_helper.rb b/lib/database_helper.rb index 8d5e746..933d1f1 100644 --- a/lib/database_helper.rb +++ b/lib/database_helper.rb @@ -36,7 +36,7 @@ module DatabaseHelper ApplicationHelper ) - return database_html_structure({:database_description_id => 1, :version => "", :operating_system => ""}) if list_databases.nil? + return database_html_structure({:database_description_id => "", :version => "", :operating_system => ""}) if list_databases.nil? lambdas_list = [] @@ -52,8 +52,8 @@ module DatabaseHelper content_tag('table', content_tag('tr', content_tag('td', label_tag(_("database Name: ")))+ - content_tag('td', select_tag("database[][database_description_id]", SoftwareHelper.select_options(DatabaseDescription.all, database_data[:database_description_id]) ))+ - content_tag('td') + content_tag('td', text_field_tag("database_autocomplete", "", :class=>"database_autocomplete"))+ + content_tag('td', hidden_field_tag("database[][database_description_id]", database_data[:database_description_id], :class=>"database_description_id")) )+ content_tag('tr', diff --git a/public/mpog-software-validations.js b/public/mpog-software-validations.js index d3b5cbf..51f810d 100644 --- a/public/mpog-software-validations.js +++ b/public/mpog-software-validations.js @@ -1,4 +1,38 @@ (function(){ + function database_autocomplete() { + jQuery(".database_autocomplete").autocomplete({ + source : function(request, response){ + jQuery.ajax({ + type: "GET", + url: "/plugin/mpog_software/get_databases", + data: {query: request.term}, + success: function(result){ + response(result); + + /*if( result.length == 0 ) { + jQuery('#institution_empty_ajax_message').switchClass("hide-field", "show-field"); + } else { + jQuery('#institution_empty_ajax_message').switchClass("show-field", "hide-field"); + }*/ + }, + error: function(ajax, stat, errorThrown) { + console.log('Link not found : ' + errorThrown); + } + }); + }, + + minLength: 1, + + select : function (event, selected) { + jQuery(this) + .parent().parent() + .find(".database_description_id") + .val(selected.item.id); + } + }); + } + + function delete_dynamic_table() { var button = jQuery(".delete-dynamic-table"); @@ -49,6 +83,7 @@ var dynamic_tables = ["dynamic-databases", "dynamic-languages", "dynamic-libraries","dynamic-operating_systems"]; delete_dynamic_table(); + database_autocomplete(); jQuery(".new-dynamic-table").click(function(){ var link = jQuery(this); @@ -63,6 +98,7 @@ }); delete_dynamic_table(); + database_autocomplete(); return false; }); -- libgit2 0.21.2