Commit 3b50d8e8 authored by mateus ravedutti's avatar mateus ravedutti

Update professionals index search form

parent 873d0ff9
......@@ -78,9 +78,50 @@ carrega_cep = ->
$("select#citizen_city_id").val("")
)
update_city_hall_child_selects = (city_hall_id) ->
if city_hall_id || city_hall_id != ""
app_root_url = $("input#app_root_url").val()
$.getJSON(app_root_url + 'city_halls/' + city_hall_id + '/service_places.json')
.done((dados) ->
if dados.length > 0
select = []
select.push('<option value=\"\">Todos </option>')
$.each(dados, (i, service_place) ->
select.push('<option value="' + service_place['id'] + '">' + service_place['name'] + '</option>')
)
$('select#q_service_places_id_eq').html(select)
else
$('select#q_service_places_id_eq').html('<option value="">Todos </option>')
)
$.getJSON(app_root_url + 'city_halls/' + city_hall_id + '/occupations.json')
.done((dados) ->
if dados.length > 0
select = []
select.push('<option value=\"\">Todos </option>')
$.each(dados, (i, occupation) ->
select.push('<option value="' + occupation['id'] + '">' + occupation['name'] + '</option>')
)
$('select#q_occupation_id_eq').html(select)
else
$('select#q_occupation_id_eq').html('<option value="">Todos </option>')
)
desabilita_selects_from_city_hall = () ->
$('select#q_service_places_id_eq').html('<option value="">Todos </option>')
$('select#q_occupation_id_eq').html('<option value="">Todos </option>')
$(document).ready(->
$('#service_places__id').material_select();
$('select#q_service_places_city_hall_id_eq').on('change', () ->
city_hall_id = $("select#q_service_places_city_hall_id_eq").val()
update_city_hall_child_selects(city_hall_id)
desabilita_selects_from_city_hall()
)
$('.multiple-select-dropdown li').hide ->
id = $(".multiple-select-dropdown").attr("id")
$('#service_places__id').material_select();
......@@ -89,6 +130,8 @@ $(document).ready(->
);
$(document).ready(->
$('#reset_button').click ->
$('.search-field').val('')
$('.cpf').val('')
......
......@@ -233,4 +233,17 @@ class CityHallsController < ApplicationController
end
end
def occupations
c = CityHall.find(params[:city_hall_id])
occupations = []
c.occupations.pluck(:id,:name).each do |s|
occupations.push({:id => s[0], :name => s[1]})
end
respond_to do |format|
format.json { render json: occupations }
end
end
end
......@@ -55,7 +55,7 @@ class CitizenAbility
can [:professionals, :service_types], ServicePlace
can :manage, [Professional, Report]
can [:schedule_select_escalas_report, :generate_escalas_report], Report
can [:service_types, :professionals], CityHall
can [:service_types, :professionals, :occupations, :service_places], CityHall
end
if ['adm_prefeitura',
'adm_c3sl'].include?(profServPlace.role)
......
......@@ -14,11 +14,42 @@
</div>
<div class="field-h col s12 m6 l3">
<%= f.label :occupation_id, t(:Occupation)+": " %>
<%= f.collection_select :occupation_id_eq, Occupation.all.order(:description), :id, :description, {
:include_blank => "Todos"}, { :class => "search-field" } %>
<%= f.label :service_places_city_hall_id, t(:city_hall) %><br />
<% if @currentProfessionalServicePlace.role == "adm_c3sl" %>
<%= f.collection_select :service_places_city_hall_id_eq, CityHall.active.order(:name),
:id, :name, { :include_blank => "Todos" }, { :class => "search-field" } %>
<% else %>
<%= f.collection_select :service_places_city_hall_id_eq, CityHall.where(id: @currentCityHall.id),
:id, :name, { disabled: true }, { :class => "search-field" } %>
<% end %>
</div>
<div class="field-h col s12 m6 l3">
<%= f.label :occupation_id, t(:Occupation)+": " %><br />
<% if @currentProfessionalServicePlace.role == "adm_c3sl" %>
<%= f.select :occupation_id_eq,
options_from_collection_for_select([],"id","name"),
{:include_blank => "Todos"}, {:class => "search-field"} %>
<% else %>
<%= f.select :occupation_id_eq,
options_from_collection_for_select(Occupation.where(city_hall_id: @currentCityHall.id),"id","name"),
{:include_blank => "Todos"}, {:class => "search-field"} %>
<% end %>
</div>
<div class="field-h col s12 m6 l3">
<%= f.label :service_places_id, t(:service_places)+": " %><br />
<% if @currentProfessionalServicePlace.role == "adm_c3sl" %>
<%= f.select :service_places_id_eq,
options_from_collection_for_select([],"id","name"),
{:include_blank => "Todos"}, {:class => "search-field"} %>
<% else %>
<%= f.select :service_places_id_eq,
options_from_collection_for_select(ServicePlace.where(city_hall_id: @currentCityHall.id),"id","name"),
{:include_blank => "Todos"}, {:class => "search-field"} %>
<% end %>
</div>
<div class="field-h col s12 m6 l3">
<%= f.label :active, t(:Situation)+":" %>
<%= f.select :active_eq,
......@@ -26,22 +57,6 @@
{:include_blank => "Todos"},{:class => "search-field"} %>
</div>
<% if @currentProfessionalServicePlace.role != "adm_local" %>
<div class="field-h col s12 m6 l3 truncate">
<%= f.label :service_places_id, t(:service_place) + ":" %>
<br />
<%= f.collection_select :service_places_id_eq, @serviceplaces, :id, :name,
{:include_blank => "Todos"}, {:class => "search-field"} %>
</div>
<% else %>
<div class="field-h col s12 m6 l3 truncate">
<%= f.label :service_places_id, t(:service_place) + ":" %>
<br />
<%= f.text_field :service_places_id_eq, :class => 'search-field', :value => @current_place.name, :disabled => true %>
</div>
<% end %>
<div class="field-h col s12 m6 l3">
<%= f.label :name, t(:Name)+": " %>
<%= f.text_field :citizen_name_cont, :class => "search-field" %>
......
......@@ -192,6 +192,7 @@ Agendador::Application.routes.draw do
get "/city_halls/:city_hall_id/service_types" => "city_halls#service_types", :format => :json
get "/city_halls/:city_hall_id/service_places" => "city_halls#service_places", :format => :json
get "/city_halls/:city_hall_id/sectors", :to => "city_halls#sectors", :format => :json
get "/city_halls/:city_hall_id/occupations" => "city_halls#occupations", :format => :json
# Sectors
get "/sectors/:sector_id/service_types", :to => "sectors#service_types", :format => :json
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment