AG
FullCalendar exibe json na tela e não carrega calendário
Conforme imagem abaixo ao invés de atualizar os dados ele apresenta os dados na tela. Estou utilizando setChangeAction para filtrar o profissional no banco de dados.
Obrigado pela ajuda segue fonte abaixo:
Obrigado pela ajuda segue fonte abaixo:
- <?php
- /**
- * AgendamentoView Form
- * @author <your name here>
- */
- class AgendamentoView extends TPage
- {
- private $fc;
- /**
- * Page constructor
- */
- public function __construct()
- {
- parent::__construct();
- // creates the form
- $this->form = new BootstrapFormBuilder('form_Agendamento');
- $this->form->setFieldSizes('100%');
- $options = ['register_state' => 'false'];
- $profissional_id = new TDBCombo('profissional_id', 'clinica', 'Profissional', 'id', 'profissional');
- $profissional_id->setChangeAction(new TAction([$this, 'getEvents']));
- $row = $this->form->addFields( [ new TLabel('Profissional') , $profissional_id] );
- $row->layout = ['col-sm-6'];
- $this->fc = new TFullCalendar(date('Y-m-d'), 'month');
- $this->fc->setReloadAction(new TAction(array($this, 'getEvents')));
- $this->fc->setDayClickAction(new TAction(array('AgendamentoForm', 'onStartEdit'), $options));
- $this->fc->setEventClickAction(new TAction(array('AgendamentoForm', 'onEdit'), $options));
- $this->fc->setEventUpdateAction(new TAction(array('AgendamentoForm', 'onUpdateEvent'), $options));
- $this->fc->setOption('businessHours', [ [ 'dow' => [ 1, 2, 3, 4, 5 ], 'start' => '08:00', 'end' => '18:00' ]]);
- //$this->fc->setTimeRange('10:00', '18:00');
- //$this->fc->disableDragging();
- //$this->fc->disableResizing();
- $this->fc->style = 'width:100%';
- $this->form->addFields(array($this->fc));
- $container = new TVBox;
- $container->style = 'width: 100%';
- $container->add($this->form);
- //$container->add($this->fc);
- parent::add( $container );
- }
- /**
- * Output events as an json
- */
- public static function getEvents($param=NULL)
- {
- TApplication::postData('form_Agendamento',__CLASS__,'onReload');
- $return = array();
- try
- {
- TTransaction::open('clinica');
- $events = Agendamento::where('profissional_id', '=', $param['key'])->load();
- if ($events)
- {
- foreach ($events as $event)
- {
- //$event_array = $event->toArray();
- $event_array['id'] = $event->id;
- $event_array['start'] = str_replace( ' ', 'T', $event->horario_inicial );
- $event_array['end'] = str_replace( ' ', 'T', $event->horario_final );
- $event_array['color'] = '#3a87ad';
- //$event_array['id'] = $event_array['id'];
- //$event_array['start'] = str_replace( ' ', 'T', $event_array['horario_inicial'] );
- //$event_array['end'] = str_replace( ' ', 'T', $event_array['horario_final'] );
- //$event_array['color'] = '#3a87ad';
- //$event_array['start'] = str_replace( ' ', 'T', $event_array['horario_inicial']);
- //$event_array['end'] = str_replace( ' ', 'T', $event_array['horario_final']);
- $popover_content = $event->render("<b>Title</b>: {id} <br> <b>Description</b>: {descricao}");
- //$event_array['title'] = TFullCalendar::renderPopover($event_array['id'], 'Popover title', $popover_content);
- $event_array['title'] = TFullCalendar::renderPopover($event->id, 'Popover title', $popover_content);
- //$event_array['title'] = $event_array['title'] . ' - ' . $event->nome_paciente;
- $return[] = $event_array;
- }
- }
- TTransaction::close();
- echo json_encode($return);
- }
- catch (Exception $e)
- {
- new TMessage('error', $e->getMessage());
- }
- }
- /**
- * Reconfigure the callendar
- */
- public function onReload($param = null)
- {
- $this->form->setData($this->form->getData());
- if (isset($param['view']))
- {
- $this->fc->setCurrentView($param['view']);
- }
- if (isset($param['date']))
- {
- $this->fc->setCurrentDate($param['date']);
- }
- }
- }
Não chame a getEvents diretamente no evento change da combo. Crie uma outra função, faça os filtros e adicione-os à sessão. Nessa mesma função você pode chamar a onReload.
Dentro da getEvents verifique os dados da sessão para filtrar e retire a função postData.
Ola Nataniel bom dia obrigado pela ajuda funcionou perfeitamente. Vi um post seu para chamar o onReload dentro de uma function static.
TApplication::loadPage(__CLASS__,'onReload');
Ai foi de boa.
Obrigado
Boa noite Anderson!
Sou iniciante com o Adianti Studio, e pesquisando sobre o problema de calendário filtrando por usuário logado, ou pessoa específica encontrei o seu post.
É possível você postar o script dessa parte que vc enviou já com as correções sugeridas pelo colega?
Obrigado.
/**
* Reconfigure the callendar
*/
public function onReload($param = null)
{
if (isset($param['view']))
{
$this->fc->setCurrentView($param['view']);
}
if (isset($param['date']))
{
$this->fc->setCurrentDate($param['date']);
}
if ( (TSession::getValue('profissional_id') != '') )
{
$data = new stdClass;
$data->profissional_id = TSession::getValue('profissional_id');
$this->form->setData( $data );
}
}