RA
Editar calendário a partir da list - Erro VIEW
Pessoal, bom dia. Criei um agenda (form e view), até aí tudo 100%. Pensei em criar uma list e a partir dela editar informação no form do calendário. A list até chama a form mas dá um erro, e quando faço a alteração ele limpa o campos e mostra essa informação abaixo.
Notice: Undefined index: view in C:xampphtdocsprojeto_postgresappcontrolAgendaAgendaSala1Form.php on line 158
Informação:
O campo Paciente é obrigatório.
O campo Horário inicial é obrigatório.
O campo Horário final é obrigatório.
Notice: Undefined index: view in C:xampphtdocsprojeto_postgresappcontrolAgendaAgendaSala1Form.php on line 158
Informação:
O campo Paciente é obrigatório.
O campo Horário inicial é obrigatório.
O campo Horário final é obrigatório.
- <?php
- class AgendaSala1Form extends TWindow
- {
- protected $form; // form
- private $formFields = [];
- /**
- * Form constructor
- * @param $param Request
- */
- public function __construct( $param )
- {
- parent::__construct();
- parent::setSize(800, null);
- parent::setTitle('Lembrete');
- parent::setProperty('class', 'window_modal');
- $this->form = new BootstrapFormBuilder('form_AgendaSala1');
- $this->form->setFormTitle('Agenda Sala 1');
- $view = new THidden('view');
- $id = new TEntry('id');
- $id_cadastro = new TDBUniqueSearch( 'id_cadastro', 'projeto', 'Cadastro', 'id', 'nome', 'nome asc' );
- $horario_inicial = new TDateTime('horario_inicial');
- $horario_final = new TDateTime('horario_final');
- $titulo = new TEntry('titulo');
- $cor = new TColor('cor');
- $observacao = new TText('observacao');
- $id_cadastro->addValidation('Paciente', new TRequiredValidator());
- $horario_inicial->addValidation('Horário inicial', new TRequiredValidator());
- $horario_final->addValidation('Horário final', new TRequiredValidator());
- $id->setEditable(false);
- $id_cadastro->setMinLength(2);
- $horario_final->setMask('dd/mm/yyyy hh:ii');
- $horario_inicial->setMask('dd/mm/yyyy hh:ii');
- $horario_final->setDatabaseMask('yyyy-mm-dd hh:ii');
- $horario_inicial->setDatabaseMask('yyyy-mm-dd hh:ii');
- $id->setSize(100);
- $cor->setSize(100);
- $titulo->setSize('72%');
- $id_cadastro->setSize('76%');
- $horario_final->setSize(150);
- $horario_inicial->setSize(150);
- $observacao->setSize('76%', 68);
- $id->setEditable(FALSE);
- $this->form->addFields([$view]);
- $this->form->addFields([new TLabel('Id:')],[$id]);
- $this->form->addFields([new TLabel('Paciente:', '#ff0000')],[$id_cadastro]);
- $this->form->addFields([new TLabel('Horário inicial:', '#ff0000')],[$horario_inicial],[new TLabel('Horário final:', '#ff0000')],[$horario_final]);
- $this->form->addFields([new TLabel('Título:')],[$titulo],[new TLabel('Cor:')],[$cor]);
- $this->form->addFields([new TLabel('Observação:')],[$observacao]);
- // create the form actions
- $this->form->addAction('Salvar', new TAction([$this, 'onSave']), 'fa:floppy-o')->addStyleClass('btn-primary');
- $this->form->addAction('Limpar formulário', new TAction([$this, 'onClear']), 'fa:eraser #dd5a43');
- $this->form->addAction('Excluir', new TAction([$this, 'onDelete']), 'fa:trash-o #dd5a43');
- parent::add($this->form);
- }
- public function onSave($param = null)
- {
- try
- {
- TTransaction::open('projeto');
- $this->form->validate();
- $data = $this->form->getData();
- $object = new AgendaSala1();
- $object->fromArray( (array) $data);
- $object->store();
- // get the generated {PRIMARY_KEY}
- $data->id = $object->id;
- $this->form->setData($data);
- TTransaction::close();
- $action = new TAction(['AgendaSala1FormView', 'onReload']);
- $action->setParameter('view', $data->view);
- $action->setParameter('date', explode(' ', $data->horario_inicial)[0]);
- new TMessage('info', AdiantiCoreTranslator::translate('Record saved'), $action);
- }
- catch (Exception $e)
- {
- new TMessage('error', $e->getMessage());
- $this->form->setData( $this->form->getData() );
- TTransaction::rollback();
- }
- }
- public function onDelete($param = null)
- {
- if (isset($param['delete']) && $param['delete'] == 1)
- {
- try
- {
- $key = $param['id'];
- TTransaction::open('projeto');
- $object = new AgendaSala1($key, FALSE);
- $object->delete();
- TTransaction::close();
- $action = new TAction(array('AgendaSala1FormView', 'onReload'));
- $action->setParameter('view', $param['view']);
- $action->setParameter('date', explode(' ', $param['horario_inicial'])[0]);
- // shows the success message
- new TMessage('info', AdiantiCoreTranslator::translate('Record deleted'), $action);
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage());
- TTransaction::rollback();
- }
- }
- else
- {
- // define the delete action
- $action = new TAction(array($this, 'onDelete'));
- $action->setParameters((array) $this->form->getData()); // pass the key paramsseter ahead
- $action->setParameter('delete', 1);
- // shows a dialog to the user
- new TQuestion(AdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
- }
- }
- /**
- * Clear form data
- * @param $param Request
- */
- public function onClear( $param )
- {
- $this->form->clear();
- }
- public function onEdit( $param )
- {
- try
- {
- if (isset($param['key']))
- {
- $key = $param['key']; // get the parameter $key
- TTransaction::open('projeto'); // open a transaction
- $object = new AgendaSala1($key); // instantiates the Active Record
- $object->view = $param['view'];
- $this->form->setData($object); // fill the form
- TTransaction::close(); // close the transaction
- }
- else
- {
- $this->form->clear();
- }
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- public function onStartEdit($param)
- {
- $this->form->clear();
- $data = new stdClass;
- $data->view = $param['view']; // calendar view
- $data->cor = '#3a87ad';
- if ($param['date'])
- {
- if(strlen($param['date']) == '10')
- {
- $param['date'].= ' 09:00';
- }
- $data->horario_inicial = str_replace('T', ' ', $param['date']);
- $horario_final = new DateTime($data->horario_inicial);
- $horario_final->add(new DateInterval('PT1H'));
- $data->horario_final = $horario_final->format('Y-m-d H:i:s');
- $this->form->setData( $data );
- }
- }
- public static function onUpdateEvent($param)
- {
- try
- {
- if (isset($param['id']))
- {
- // open a transaction with database 'samples'
- TTransaction::open('projeto');
- $object = new AgendaSala1($param['id']);
- $object->horario_inicial = str_replace('T', ' ', $param['start_time']);
- $object->horario_final = str_replace('T', ' ', $param['end_time']);
- $object->store();
- // close the transaction
- TTransaction::close();
- }
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage());
- TTransaction::rollback();
- }
- }
- }?>
- <?php
- class AgendaSala1FormView extends TPage
- {
- private $fc;
- /**
- * Page constructor
- */
- public function __construct()
- {
- parent::__construct();
- $this->fc = new TFullCalendar(date('Y-m-d'), 'month');
- $this->fc->enableDays([1,2,3,4,5,6]);
- $this->fc->setReloadAction(new TAction(array($this, 'getEvents')));
- $this->fc->setDayClickAction(new TAction(array('AgendaSala1Form', 'onStartEdit')));
- $this->fc->setEventClickAction(new TAction(array('AgendaSala1Form', 'onEdit')));
- $this->fc->setEventUpdateAction(new TAction(array('AgendaSala1Form', 'onUpdateEvent')));
- $this->fc->setTimeRange('07:00', '19:00');
- parent::add( $this->fc );
- }
- /**
- * Output events as an json
- */
- public static function getEvents($param=NULL)
- {
- $return = array();
- try
- {
- TTransaction::open('projeto');
- $events = AgendaSala1::where('horario_inicial', '>=', $param['start'] . ' 00:00:00')
- ->where('horario_final', '<=', $param['end'] . ' 23:59:59')
- ->load();
- if ($events)
- {
- foreach ($events as $event)
- {
- $event_array = $event->toArray();
- $event_array['start'] = str_replace( ' ', 'T', $event_array['horario_inicial']);
- $event_array['end'] = str_replace( ' ', 'T', $event_array['horario_final']);
- $event_array['color'] = $event_array['cor'];
- $event_array['title'] = $event_array['titulo'] . ' - ' . $event->cadastro->nome;
- $return[] = $event_array;
- }
- }
- TTransaction::close();
- echo json_encode($return);
- }
- catch (Exception $e)
- {
- new TMessage('error', $e->getMessage());
- }
- }
- /**
- * Reconfigure the calendar
- */
- public function onReload($param = null)
- {
- if (isset($param['view']))
- {
- $this->fc->setCurrentView($param['view']);
- }
- if (isset($param['date']))
- {
- $this->fc->setCurrentDate($param['date']);
- }
- }
- }?>
- <?php
- /**
- * AgendaSala1List Listing
- * @author <your name here>
- */
- class AgendaSala1List extends TPage
- {
- private $form; // form
- private $datagrid; // listing
- private $pageNavigation;
- private $formgrid;
- private $loaded;
- private $deleteButton;
- /**
- * Class constructor
- * Creates the page, the form and the listing
- */
- public function __construct()
- {
- parent::__construct();
- // creates the form
- $this->form = new BootstrapFormBuilder('form_AgendaSala1');
- $this->form->setFormTitle('AgendaSala1');
- // create the form fields
- $id = new TEntry('id');
- $id_cadastro = new TDBUniqueSearch('id_cadastro', 'projeto', 'Cadastro', 'id', 'nome');
- $horario_inicial = new TEntry('horario_inicial');
- $horario_final = new TEntry('horario_final');
- $titulo = new TEntry('titulo');
- $cor = new TEntry('cor');
- $observacao = new TEntry('observacao');
- // add the fields
- $this->form->addFields( [ new TLabel('Id') ], [ $id ] );
- $this->form->addFields( [ new TLabel('Id Cadastro') ], [ $id_cadastro ] );
- $this->form->addFields( [ new TLabel('Horario Inicial') ], [ $horario_inicial ] );
- $this->form->addFields( [ new TLabel('Horario Final') ], [ $horario_final ] );
- $this->form->addFields( [ new TLabel('Titulo') ], [ $titulo ] );
- $this->form->addFields( [ new TLabel('Cor') ], [ $cor ] );
- $this->form->addFields( [ new TLabel('Observacao') ], [ $observacao ] );
- // set sizes
- $id->setSize('100%');
- $id_cadastro->setSize('100%');
- $horario_inicial->setSize('100%');
- $horario_final->setSize('100%');
- $titulo->setSize('100%');
- $cor->setSize('100%');
- $observacao->setSize('100%');
- // keep the form filled during navigation with session data
- $this->form->setData( TSession::getValue('AgendaSala1_filter_data') );
- // add the search form actions
- $btn = $this->form->addAction(_t('Find'), new TAction([$this, 'onSearch']), 'fa:search');
- $btn->class = 'btn btn-sm btn-primary';
- $this->form->addActionLink(_t('New'), new TAction(['AgendaSala1Form', 'onEdit']), 'fa:plus green');
- // creates a Datagrid
- $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
- $this->datagrid->style = 'width: 100%';
- $this->datagrid->datatable = 'true';
- // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
- // creates the datagrid columns
- $column_id = new TDataGridColumn('id', 'Id', 'right');
- $column_id_cadastro = new TDataGridColumn('id_cadastro', 'Id Cadastro', 'right');
- $column_horario_inicial = new TDataGridColumn('horario_inicial', 'Horario Inicial', 'left');
- $column_horario_final = new TDataGridColumn('horario_final', 'Horario Final', 'left');
- $column_titulo = new TDataGridColumn('titulo', 'Titulo', 'left');
- $column_cor = new TDataGridColumn('cor', 'Cor', 'left');
- $column_observacao = new TDataGridColumn('observacao', 'Observacao', 'left');
- // add the columns to the DataGrid
- $this->datagrid->addColumn($column_id);
- $this->datagrid->addColumn($column_id_cadastro);
- $this->datagrid->addColumn($column_horario_inicial);
- $this->datagrid->addColumn($column_horario_final);
- $this->datagrid->addColumn($column_titulo);
- $this->datagrid->addColumn($column_cor);
- $this->datagrid->addColumn($column_observacao);
- // create EDIT action
- $action_edit = new TDataGridAction(['AgendaSala1Form', 'onEdit']);
- //$action_edit->setUseButton(TRUE);
- //$action_edit->setButtonClass('btn btn-default');
- $action_edit->setLabel(_t('Edit'));
- $action_edit->setImage('fa:pencil-square-o blue fa-lg');
- $action_edit->setField('id');
- $this->datagrid->addAction($action_edit);
- // create DELETE action
- $action_del = new TDataGridAction(array($this, 'onDelete'));
- //$action_del->setUseButton(TRUE);
- //$action_del->setButtonClass('btn btn-default');
- $action_del->setLabel(_t('Delete'));
- $action_del->setImage('fa:trash-o red fa-lg');
- $action_del->setField('id');
- $this->datagrid->addAction($action_del);
- // create the datagrid model
- $this->datagrid->createModel();
- // creates the page navigation
- $this->pageNavigation = new TPageNavigation;
- $this->pageNavigation->setAction(new TAction([$this, 'onReload']));
- $this->pageNavigation->setWidth($this->datagrid->getWidth());
- // vertical box container
- $container = new TVBox;
- $container->style = 'width: 90%';
- // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $container->add($this->form);
- $container->add(TPanelGroup::pack('', $this->datagrid, $this->pageNavigation));
- parent::add($container);
- }
- /**
- * Inline record editing
- * @param $param Array containing:
- * key: object ID value
- * field name: object attribute to be updated
- * value: new attribute content
- */
- public function onInlineEdit($param)
- {
- try
- {
- // get the parameter $key
- $field = $param['field'];
- $key = $param['key'];
- $value = $param['value'];
- TTransaction::open('projeto'); // open a transaction with database
- $object = new AgendaSala1($key); // instantiates the Active Record
- $object->{$field} = $value;
- $object->store(); // update the object in the database
- TTransaction::close(); // close the transaction
- $this->onReload($param); // reload the listing
- new TMessage('info', "Record Updated");
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- /**
- * Register the filter in the session
- */
- public function onSearch()
- {
- // get the search form data
- $data = $this->form->getData();
- // clear session filters
- TSession::setValue('AgendaSala1List_filter_id', NULL);
- TSession::setValue('AgendaSala1List_filter_id_cadastro', NULL);
- TSession::setValue('AgendaSala1List_filter_horario_inicial', NULL);
- TSession::setValue('AgendaSala1List_filter_horario_final', NULL);
- TSession::setValue('AgendaSala1List_filter_titulo', NULL);
- TSession::setValue('AgendaSala1List_filter_cor', NULL);
- TSession::setValue('AgendaSala1List_filter_observacao', NULL);
- if (isset($data->id) AND ($data->id)) {
- $filter = new TFilter('id', '=', "$data->id"); // create the filter
- TSession::setValue('AgendaSala1List_filter_id', $filter); // stores the filter in the session
- }
- if (isset($data->id_cadastro) AND ($data->id_cadastro)) {
- $filter = new TFilter('id_cadastro', '=', "$data->id_cadastro"); // create the filter
- TSession::setValue('AgendaSala1List_filter_id_cadastro', $filter); // stores the filter in the session
- }
- if (isset($data->horario_inicial) AND ($data->horario_inicial)) {
- $filter = new TFilter('horario_inicial', 'like', "%{$data->horario_inicial}%"); // create the filter
- TSession::setValue('AgendaSala1List_filter_horario_inicial', $filter); // stores the filter in the session
- }
- if (isset($data->horario_final) AND ($data->horario_final)) {
- $filter = new TFilter('horario_final', 'like', "%{$data->horario_final}%"); // create the filter
- TSession::setValue('AgendaSala1List_filter_horario_final', $filter); // stores the filter in the session
- }
- if (isset($data->titulo) AND ($data->titulo)) {
- $filter = new TFilter('titulo', 'like', "%{$data->titulo}%"); // create the filter
- TSession::setValue('AgendaSala1List_filter_titulo', $filter); // stores the filter in the session
- }
- if (isset($data->cor) AND ($data->cor)) {
- $filter = new TFilter('cor', 'like', "%{$data->cor}%"); // create the filter
- TSession::setValue('AgendaSala1List_filter_cor', $filter); // stores the filter in the session
- }
- if (isset($data->observacao) AND ($data->observacao)) {
- $filter = new TFilter('observacao', 'like', "%{$data->observacao}%"); // create the filter
- TSession::setValue('AgendaSala1List_filter_observacao', $filter); // stores the filter in the session
- }
- // fill the form with data again
- $this->form->setData($data);
- // keep the search data in the session
- TSession::setValue('AgendaSala1_filter_data', $data);
- $param = array();
- $param['offset'] =0;
- $param['first_page']=1;
- $this->onReload($param);
- }
- /**
- * Load the datagrid with data
- */
- public function onReload($param = NULL)
- {
- try
- {
- // open a transaction with database 'projeto'
- TTransaction::open('projeto');
- // creates a repository for AgendaSala1
- $repository = new TRepository('AgendaSala1');
- $limit = 10;
- // creates a criteria
- $criteria = new TCriteria;
- // default order
- if (empty($param['order']))
- {
- $param['order'] = 'id';
- $param['direction'] = 'asc';
- }
- $criteria->setProperties($param); // order, offset
- $criteria->setProperty('limit', $limit);
- if (TSession::getValue('AgendaSala1List_filter_id')) {
- $criteria->add(TSession::getValue('AgendaSala1List_filter_id')); // add the session filter
- }
- if (TSession::getValue('AgendaSala1List_filter_id_cadastro')) {
- $criteria->add(TSession::getValue('AgendaSala1List_filter_id_cadastro')); // add the session filter
- }
- if (TSession::getValue('AgendaSala1List_filter_horario_inicial')) {
- $criteria->add(TSession::getValue('AgendaSala1List_filter_horario_inicial')); // add the session filter
- }
- if (TSession::getValue('AgendaSala1List_filter_horario_final')) {
- $criteria->add(TSession::getValue('AgendaSala1List_filter_horario_final')); // add the session filter
- }
- if (TSession::getValue('AgendaSala1List_filter_titulo')) {
- $criteria->add(TSession::getValue('AgendaSala1List_filter_titulo')); // add the session filter
- }
- if (TSession::getValue('AgendaSala1List_filter_cor')) {
- $criteria->add(TSession::getValue('AgendaSala1List_filter_cor')); // add the session filter
- }
- if (TSession::getValue('AgendaSala1List_filter_observacao')) {
- $criteria->add(TSession::getValue('AgendaSala1List_filter_observacao')); // add the session filter
- }
- // load the objects according to criteria
- $objects = $repository->load($criteria, FALSE);
- if (is_callable($this->transformCallback))
- {
- call_user_func($this->transformCallback, $objects, $param);
- }
- $this->datagrid->clear();
- if ($objects)
- {
- // iterate the collection of active records
- foreach ($objects as $object)
- {
- // add the object inside the datagrid
- $this->datagrid->addItem($object);
- }
- }
- // reset the criteria for record count
- $criteria->resetProperties();
- $count= $repository->count($criteria);
- $this->pageNavigation->setCount($count); // count of records
- $this->pageNavigation->setProperties($param); // order, page
- $this->pageNavigation->setLimit($limit); // limit
- // close the transaction
- TTransaction::close();
- $this->loaded = true;
- }
- catch (Exception $e) // in case of exception
- {
- // shows the exception error message
- new TMessage('error', $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- /**
- * Ask before deletion
- */
- public static function onDelete($param)
- {
- // define the delete action
- $action = new TAction([__CLASS__, 'Delete']);
- $action->setParameters($param); // pass the key parameter ahead
- // shows a dialog to the user
- new TQuestion(TAdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
- }
- /**
- * Delete a record
- */
- public static function Delete($param)
- {
- try
- {
- $key=$param['key']; // get the parameter $key
- TTransaction::open('projeto'); // open a transaction with database
- $object = new AgendaSala1($key, FALSE); // instantiates the Active Record
- $object->delete(); // deletes the object from the database
- TTransaction::close(); // close the transaction
- $pos_action = new TAction([__CLASS__, 'onReload']);
- new TMessage('info', TAdiantiCoreTranslator::translate('Record deleted'), $pos_action); // success message
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- /**
- * method show()
- * Shows the page
- */
- public function show()
- {
- // check if the datagrid is already loaded
- if (!$this->loaded AND (!isset($_GET['method']) OR !(in_array($_GET['method'], array('onReload', 'onSearch')))) )
- {
- if (func_num_args() > 0)
- {
- $this->onReload( func_get_arg(0) );
- }
- else
- {
- $this->onReload();
- }
- }
- parent::show();
- }
- }?>
Você está usando o mesmo nome para os formulários:
Sempre use nomes diferentes
Nataniel, desculpe minha falta de informações, mas deixa ver se eu entendi.
Minha FORM está: $this->form = new BootstrapFormBuilder('form_AgendaSala1');
Minha LIST está: $this->form = new BootstrapFormBuilder('form_AgendaSala1');
Esses formulários foram criado pelo studio automaticamente. Eu preciso alterar no código?
Sim, você precisa alterar o nome de um dos formulários:
O que acontece é que a TWindow "abre" sobre um html já existente. Como os 2 formulários possuem o mesmo nome, ao executar uma ação provavelmente vai pegar as informações do primeiro form criado, que no caso é o form da tela escondida sob a TWindow.