Commit 92d962e0 authored by Mateus Ravedutti's avatar Mateus Ravedutti

Update reports search forms

parent 8eaf92b2
load_professionals = (app_root_url, service_place_id = '', city_hall_id = 0) ->
$('select#report_professional_performer_id_eq').attr('disabled', 'disabled').html('<option value="">Carregando profissionais...</option>')
load_professionals = (app_root_url, field, service_place_id = '', city_hall_id = 0) ->
$(field).attr('disabled', 'disabled').html('<option value="">Carregando profissionais...</option>')
# get service_place's professionals
select = ['<option value="">Todos</option>']
if service_place_id == ''
......@@ -15,15 +15,15 @@ load_professionals = (app_root_url, service_place_id = '', city_hall_id = 0) ->
select.push('<option value="' + item.id + '">' + item.name + '</option>')
)
if select.length > 1
$('select#report_professional_performer_id_eq').html(select)
$(field).html(select)
.removeAttr('disabled')
else
$('select#report_professional_performer_id_eq').attr('disabled', 'disabled')
$(field).attr('disabled', 'disabled')
.html('<option value="">Nenhum profissional cadastrado neste local!</option>')
)
load_service_types = (app_root_url, service_place_id = '', city_hall_id = 0) ->
$('select#report_service_type_id_eq').attr('disabled', 'disabled').html('<option value="">Carregando tipos de atendimento...</option>')
load_service_types = (app_root_url, field, service_place_id = '', city_hall_id = 0) ->
$(field).attr('disabled', 'disabled').html('<option value="">Carregando tipos de atendimento...</option>')
# get service_place's service_types
select = ['<option value="">Todos</option>']
if service_place_id == ''
......@@ -39,16 +39,16 @@ load_service_types = (app_root_url, service_place_id = '', city_hall_id = 0) ->
select.push('<option value="' + item.id + '">' + item.description + '</option>')
)
if select.length > 1
$('select#report_service_type_id_eq').html(select)
$(field).html(select)
.removeAttr('disabled')
else
$('select#report_service_type_id_eq').attr('disabled', 'disabled')
$(field).attr('disabled', 'disabled')
.html('<option value="">Nenhum tipo de atendimento cadastrado neste local!</option>')
)
load_service_places = (app_root_url, city_hall_id) ->
$('select#report_service_place_id_eq').attr('disabled', 'disabled').html('<option value="">Carregando locais de atendimento...</option>')
# get city_hall's service_palces
load_service_places = (app_root_url, field, city_hall_id) ->
$(field).attr('disabled', 'disabled').html('<option value="">Carregando locais de atendimento...</option>')
# get city_hall's service_places
select = ['<option value="">Todos</option>']
$.getJSON(app_root_url + 'city_halls/' + parseInt(city_hall_id) + '/service_places')
.done((dados) ->
......@@ -56,10 +56,10 @@ load_service_places = (app_root_url, city_hall_id) ->
select.push('<option value="' + item.id + '">' + item.name + '</option>')
)
if select.length > 1
$('select#report_service_place_id_eq').html(select)
$(field).html(select)
.removeAttr('disabled')
else
$('select#report_service_place_id_eq').attr('disabled', 'disabled')
$(field).attr('disabled', 'disabled')
.html('<option value="">Nenhum local de atendimento cadastrado nesta prefeitura!</option>')
)
......@@ -981,32 +981,51 @@ $(document).ready ->
app_root_url = $("input#app_root_url").val()
city_hall_id = $("select#city_hall_id").val()
current_report = window.location.pathname.split('/').pop()
service_place_field = 'select#q_service_places_id_eq'
if(current_report == 'schedules_report')
professional_field = 'select#report_shift_professional_performer_id_eq'
service_place_field = 'select#report_service_place_id_eq'
service_type_field = 'select#report_shift_service_type_id_eq'
else if(current_report == 'services_report')
professional_field = 'select#services_shift_professional_performer_id_eq'
service_place_field = 'select#services_service_place_id_eq'
service_type_field = 'select#services_shift_service_type_id_eq'
else
professional_field = 'select#report_professional_performer_id_eq'
service_place_field = 'select#report_service_place_id_eq'
service_type_field = 'select#report_service_type_id_eq'
if city_hall_id == undefined
if $('select#report_service_place_id_eq').val() != undefined
if $(service_place_field).val() != undefined
# adm_prefeitura
load_professionals(app_root_url)
load_service_types(app_root_url)
$('select#report_service_place_id_eq').on('change', () ->
service_place_id = $("select#report_service_place_id_eq").val()
load_professionals(app_root_url, service_place_id)
load_service_types(app_root_url, service_place_id)
load_professionals(app_root_url, professional_field)
load_service_types(app_root_url, service_type_field)
$(service_place_field).on('change', () ->
service_place_id = $(service_place_field).val()
load_professionals(app_root_url, professional_field, service_place_id)
load_service_types(app_root_url, service_type_field, service_place_id)
)
else
# adm_c3sl
city_id = $('select#city_hall_id').val()
load_service_places(app_root_url, city_id)
load_professionals(app_root_url,'',city_id)
load_service_types(app_root_url,'',city_id)
load_service_places(app_root_url, service_place_field, city_id)
load_professionals(app_root_url, professional_field, '',city_id)
load_service_types(app_root_url, service_type_field,'',city_id)
$('select#city_hall_id').on('change', () ->
city_id = $('select#city_hall_id').val()
load_service_places(app_root_url, city_id)
load_professionals(app_root_url,'',city_id)
load_service_types(app_root_url,'',city_id)
load_service_places(app_root_url,service_place_field,city_id)
load_professionals(app_root_url,professional_field,'',city_id)
load_service_types(app_root_url,service_type_field,'',city_id)
)
$('select#report_service_place_id_eq').on('change', () ->
service_place_id = $("select#report_service_place_id_eq").val()
load_professionals(app_root_url, service_place_id)
load_service_types(app_root_url, service_place_id)
$(service_place_field).on('change', () ->
service_place_id = $(service_place_field).val()
load_professionals(app_root_url, professional_field, service_place_id)
load_service_types(app_root_url, service_type_field, service_place_id)
)
translate_weekday = (div, index) ->
switch index%7
......@@ -1026,4 +1045,4 @@ translate_weekday = (div, index) ->
day = 'SAB'
# error
$(div).html day
return
\ No newline at end of file
return
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