diff --git a/app/assets/javascripts/application/search.js b/app/assets/javascripts/application/search.js index 4046990f11b7b1b1a11f4595c8e0f47053419d08..17ccc41ff7eea2a44f688ff3ae4d2da77317ad1e 100644 --- a/app/assets/javascripts/application/search.js +++ b/app/assets/javascripts/application/search.js @@ -470,40 +470,28 @@ var runDropdown = function(element) { }; -var getElementsNumber = function(className) { - - $.ajax({ - url: '/search/get_class_size', - data: { class: className }, - dataType: "json", - success: function(data) { - switch(className) { - case 'LearningObject': - $('.search-input input').attr('placeholder', "Buscar em " + data.number + " conteúdos"); - break; - case 'Collection': - $('.search-input input').attr('placeholder', "Buscar em " + data.number + " coleções"); - break; - case 'User': - $('.search-input input').attr('placeholder', "Buscar em " + data.number + " usuários"); - break; - default: - $('.search-input input').attr('placeholder', "Buscar conteúdo"); - } - }, - error: function() { - $('.search-input input').attr('placeholder', "Buscar conteúdo"); - } - }); -}; - - $(document).ready (function(){ - getElementsNumber('LearningObject'); + var lo_num = $('.search-input input').attr("data-lo"); + var collection_num = $('.search-input input').attr("data-collection"); + var user_num = $('.search-input input').attr("data-user"); + + $('.search-input input').attr('placeholder', "Buscar em " + lo_num + " conteúdos"); $('.search-input select').change( function(){ - getElementsNumber( $(this).val()); + switch($(this).val()) { + case 'LearningObject': + $('.search-input input').attr('placeholder', "Buscar em " + lo_num + " conteúdos"); + break; + case 'Collection': + $('.search-input input').attr('placeholder', "Buscar em " + collection_num + " coleções"); + break; + case 'User': + $('.search-input input').attr('placeholder', "Buscar em " + user_num + " usuários"); + break; + default: + $('.search-input input').attr('placeholder', "Buscar conteúdo"); + } }) }); diff --git a/app/views/shared/application/_search.erb b/app/views/shared/application/_search.erb index 98bd06af1ea2bd07eb93300c5d9d383f0327aeb9..da844e70f8941b027f89828617add63475ed9553 100644 --- a/app/views/shared/application/_search.erb +++ b/app/views/shared/application/_search.erb @@ -1,7 +1,7 @@ <div class="search-input"> <form action="/search" method="get"> <div class="input-group" id="search"> - <input type="text" placeholder="" class="form-control" name="query" id="main_search"> + <input type="text" data-lo="<%=number_with_delimiter(LearningObject.count, delimiter: ".") %>" data-user="<%= number_with_delimiter(User.count, delimiter: ".") %>" data-collection="<%= number_with_delimiter(Collection.count, delimiter: ".") %>" placeholder="" class="form-control" name="query" id="main_search"> <select name="search_class" id="search_class" class="form-control"> <option value="LearningObject" selected>Conteúdos Educacionais</option> <option value="Collection">Coleções</option>