/** * Add a column * @param $label Field Label * @param $object Field Object * @param $size Field Size */ public function addQuickColumn($label, $name, $align = 'left', $size = 200, TAction $action = NULL, $param = NULL) { // creates a new column $object = new TDataGridColumn($name, $label, $align, $size); if ($action instanceof TAction) { // create ordering $action->setParameter($param[0], $param[1]); $object->setAction($action); } // add the column to the datagrid parent::addColumn($object); return $object; }
/** * Class Constructor * @param $type Type of the message (info, error) * @param $message Message to be shown * @param $action Action to be processed when closing the dialog * @param $title_msg Dialog Title */ public function __construct($type, $message, TAction $action = NULL, $title_msg = '') { $this->id = 'tmessage_' . mt_rand(1000000000, 1999999999); $modal_wrapper = new TElement('div'); $modal_wrapper->{'class'} = 'modal'; $modal_wrapper->{'id'} = $this->id; $modal_wrapper->{'style'} = 'padding-top: 10%; z-index:4000'; $modal_wrapper->{'tabindex'} = '-1'; $modal_dialog = new TElement('div'); $modal_dialog->{'class'} = 'modal-dialog'; $modal_content = new TElement('div'); $modal_content->{'class'} = 'modal-content'; $modal_header = new TElement('div'); $modal_header->{'class'} = 'modal-header'; if ($type == 'info') { $image = new TImage("fa:fa fa-info-circle fa-5x blue"); } else { $image = new TImage("fa:fa fa-exclamation-circle fa-5x red"); } $image->{'style'} = 'float:left; margin-right: 10px;'; $close = new TElement('button'); $close->{'type'} = 'button'; $close->{'class'} = 'close'; $close->{'data-dismiss'} = 'modal'; $close->{'aria-hidden'} = 'true'; $close->add('×'); $title = new TElement('h4'); $title->{'class'} = 'modal-title'; $title->{'style'} = 'display:inline'; $title->add($title_msg ? $title_msg : ($type == 'info' ? AdiantiCoreTranslator::translate('Information') : AdiantiCoreTranslator::translate('Error'))); $body = new TElement('div'); $body->{'style'} = 'text-align:left'; $body->{'class'} = 'modal-body'; $body->add($image); $span = new TElement('span'); $span->add($message); $body->add($span); $button = new TElement('button'); $button->{'class'} = 'btn btn-default'; $button->{'data-dismiss'} = 'modal'; $button->{'onclick'} = "\$( '.modal-backdrop' ).last().remove(); \$('#{$this->id}').modal('hide'); \$('body').removeClass('modal-open');"; $button->add('OK'); if ($action) { $button->{'onclick'} .= "__adianti_load_page('{$action->serialize()}');"; $button->{'data-toggle'} = "modal"; } $footer = new TElement('div'); $footer->{'class'} = 'modal-footer'; $modal_wrapper->add($modal_dialog); $modal_dialog->add($modal_content); $modal_content->add($modal_header); $modal_header->add($close); $modal_header->add($title); $modal_content->add($body); $modal_content->add($footer); $footer->add($button); $modal_wrapper->show(); $callback = 'function () {' . $button->{'onclick'} . '}'; TScript::create("tdialog_start( '#{$this->id}', {$callback} );"); }
/** * Class Constructor * @param $name name of the form field * @param $database name of the database connection * @param $form name of the parent form * @param $model name of the Active Record to be searched * @param $display_field name of the field to be searched and shown * @param $receive_key name of the form field to receive the primary key * @param $receive_display_field name of the form field to receive the "display field" * @param $display_field2 name of the #2 field to be searched and shown */ public function __construct($name, $database, $form, $model, $display_field, $receive_key, $receive_display_field, TCriteria $criteria = NULL, $display_field2 = NULL) { parent::__construct($name); if (empty($database)) { throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'database', __CLASS__)); } if (empty($model)) { throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'model', __CLASS__)); } if (empty($display_field)) { throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'display_field', __CLASS__)); } $obj = new TStandardSeek2(); // define the action parameters $action = new TAction(array($obj, 'onSetup')); $action->setParameter('database', $database); $action->setParameter('parent', $form); $action->setParameter('model', $model); $action->setParameter('display_field', $display_field); $action->setParameter('receive_key', $receive_key); $action->setParameter('receive_field', $receive_display_field); $action->setParameter('criteria', base64_encode(serialize($criteria))); $action->setParameter('display_field2', $display_field2); parent::setAction($action); }
/** * Define the action to be executed when the user leaves the form field * @param $action TAction object */ function setExitAction(TAction $action) { if ($action->isStatic()) { $this->exitAction = $action; } else { $string_action = $action->toString(); throw new Exception(AdiantiCoreTranslator::translate('Action (^1) must be static to be used in ^2', $string_action, __METHOD__)); } }
/** * Class Constructor * @param $message A string containint the question * @param $action_yes Action taken for YES response * @param $action_no Action taken for NO response */ public function __construct($message, TAction $action_yes, TAction $action_no = NULL) { $buttons = array(Gtk::STOCK_YES, Gtk::RESPONSE_YES); if ($action_no instanceof TAction) { $buttons[] = Gtk::STOCK_NO; $buttons[] = Gtk::RESPONSE_NO; } $buttons[] = Gtk::STOCK_CANCEL; $buttons[] = Gtk::RESPONSE_CANCEL; parent::__construct('', NULL, Gtk::DIALOG_MODAL, $buttons); parent::set_position(Gtk::WIN_POS_CENTER); parent::set_size_request(500, 300); $textview = new GtkTextView(); $textview->set_wrap_mode(Gtk::WRAP_WORD); $textview->set_border_width(12); $textbuffer = $textview->get_buffer(); $tagtable = $textbuffer->get_tag_table(); $customTag = new GtkTextTag(); $tagtable->add($customTag); $customTag->set_property('foreground', '#525252'); $tagBegin = $textbuffer->create_mark('tagBegin', $textbuffer->get_end_iter(), true); $textbuffer->insert_at_cursor("\n " . $message); $tagEnd = $textbuffer->create_mark('tagEnd', $textbuffer->get_end_iter(), true); $start = $textbuffer->get_iter_at_mark($tagBegin); $end = $textbuffer->get_iter_at_mark($tagEnd); $textbuffer->apply_tag($customTag, $start, $end); $textview->set_editable(FALSE); $textview->set_cursor_visible(FALSE); $pango = new PangoFontDescription('Sans 14'); $textview->modify_font($pango); $image = GtkImage::new_from_stock(Gtk::STOCK_DIALOG_QUESTION, Gtk::ICON_SIZE_DIALOG); $scroll = new GtkScrolledWindow(); $scroll->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_ALWAYS); $scroll->add($textview); $hbox = new GtkHBox(); $this->vbox->pack_start($hbox); $hbox->pack_start($image, FALSE, FALSE); $hbox->pack_start($scroll, TRUE, TRUE); $this->show_all(); $result = parent::run(); if ($result == Gtk::RESPONSE_YES) { parent::destroy(); call_user_func_array($action_yes->getAction(), array($action_yes->getParameters())); } else { if ($result == Gtk::RESPONSE_NO) { parent::destroy(); call_user_func_array($action_no->getAction(), array($action_no->getParameters())); } else { parent::destroy(); } } }
/** * Class Constructor * @param $type Type of the message (info, error) * @param $message Message to be shown * @param $action Action to be processed when closing the dialog */ public function __construct($type, $message, TAction $action = NULL) { parent::__construct('', NULL, Gtk::DIALOG_MODAL, array(Gtk::STOCK_OK, Gtk::RESPONSE_OK)); parent::set_position(Gtk::WIN_POS_CENTER); parent::set_size_request(500, 300); $textview = new GtkTextView(); $textview->set_wrap_mode(Gtk::WRAP_WORD); $textview->set_border_width(12); $textbuffer = $textview->get_buffer(); $tagtable = $textbuffer->get_tag_table(); $customTag = new GtkTextTag(); $tagtable->add($customTag); $customTag->set_property('foreground', '#525252'); $message = "\n " . str_replace('<br>', "\n ", $message); $tagBegin = $textbuffer->create_mark('tagBegin', $textbuffer->get_end_iter(), true); $textbuffer->insert_at_cursor(strip_tags($message)); $tagEnd = $textbuffer->create_mark('tagEnd', $textbuffer->get_end_iter(), true); $start = $textbuffer->get_iter_at_mark($tagBegin); $end = $textbuffer->get_iter_at_mark($tagEnd); $textbuffer->apply_tag($customTag, $start, $end); $textview->set_editable(FALSE); $textview->set_cursor_visible(FALSE); $pango = new PangoFontDescription('Sans 14'); $textview->modify_font($pango); $image = $type == 'info' ? GtkImage::new_from_stock(Gtk::STOCK_DIALOG_INFO, Gtk::ICON_SIZE_DIALOG) : GtkImage::new_from_stock(Gtk::STOCK_DIALOG_ERROR, Gtk::ICON_SIZE_DIALOG); $scroll = new GtkScrolledWindow(); $scroll->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_ALWAYS); $scroll->add($textview); $hbox = new GtkHBox(); $this->vbox->pack_start($hbox); $hbox->pack_start($image, FALSE, FALSE); $hbox->pack_start($scroll, TRUE, TRUE); $this->show_all(); parent::connect('key_press_event', array($this, 'onClose')); $result = parent::run(); if ($result == Gtk::RESPONSE_OK) { if ($action) { $parameters = $action->getParameters(); parent::destroy(); call_user_func_array($action->getAction(), array($parameters)); return; } } parent::destroy(); }
/** * Add an action * @param $title Title * @param $action Action * @param $icon Icon */ public function addAction($title, TAction $action, $icon = NULL) { $li = new TElement('li'); $link = new TElement('a'); // if ($action instanceof TScriptAction) => don't __load_page... $link->{'onclick'} = "__adianti_load_page('{$action->serialize()}');"; $link->{'style'} = 'cursor: pointer'; if ($icon) { $image = new TImage($icon); $image->{'style'} = 'padding: 4px'; $link->add($image); } $span = new TElement('span'); $span->add($title); $link->add($span); $li->add($link); $this->elements->add($li); }
/** * Class Constructor * @param $message A string containint the question * @param $action_yes Action taken for YES response * @param $action_no Action taken for NO response * @param $title_msg Dialog Title */ public function __construct($message, TAction $action_yes = NULL, TAction $action_no = NULL, $title_msg = '') { $this->id = uniqid(); $modal_wrapper = new TElement('div'); $modal_wrapper->{'class'} = 'modal'; $modal_wrapper->{'id'} = $this->id; $modal_wrapper->{'style'} = 'padding-top: 10%; z-index:4000'; $modal_wrapper->{'tabindex'} = '-1'; $modal_dialog = new TElement('div'); $modal_dialog->{'class'} = 'modal-dialog'; $modal_content = new TElement('div'); $modal_content->{'class'} = 'modal-content'; $modal_header = new TElement('div'); $modal_header->{'class'} = 'modal-header'; $image = new TImage("lib/adianti/images/question.png"); $image->{'style'} = 'float:left'; $close = new TElement('button'); $close->{'type'} = 'button'; $close->{'class'} = 'close'; $close->{'data-dismiss'} = 'modal'; $close->{'aria-hidden'} = 'true'; $close->add('×'); $title = new TElement('h4'); $title->{'class'} = 'modal-title'; $title->{'style'} = 'display:inline'; $title->add($title_msg ? $title_msg : AdiantiCoreTranslator::translate('Question')); $body = new TElement('div'); $body->{'class'} = 'modal-body'; $body->add($image); $span = new TElement('span'); $span->{'style'} = 'margin-left:20px;float:left; display:inline-block'; $span->add($message); $body->add($span); $footer = new TElement('div'); $footer->{'class'} = 'modal-footer'; if ($action_yes) { $button = new TElement('button'); $button->{'class'} = 'btn btn-default'; $button->{'data-toggle'} = "modal"; $button->{'data-dismiss'} = 'modal'; $button->add(AdiantiCoreTranslator::translate('Yes')); $button->{'onclick'} = '__adianti_load_page(\'' . $action_yes->serialize() . '\')'; $footer->add($button); } if ($action_no) { $button = new TElement('button'); $button->{'class'} = 'btn btn-default'; $button->{'data-toggle'} = "modal"; $button->{'data-dismiss'} = 'modal'; $button->add(AdiantiCoreTranslator::translate('No')); $button->{'onclick'} = '__adianti_load_page(\'' . $action_no->serialize() . '\')'; $footer->add($button); } else { $button = new TElement('button'); $button->{'class'} = 'btn btn-default'; $button->{'data-dismiss'} = 'modal'; $button->add(AdiantiCoreTranslator::translate('No')); $footer->add($button); } $button = new TElement('button'); $button->{'class'} = 'btn btn-default'; $button->{'data-dismiss'} = 'modal'; $button->add(AdiantiCoreTranslator::translate('Cancel')); $footer->add($button); $modal_wrapper->add($modal_dialog); $modal_dialog->add($modal_content); $modal_content->add($modal_header); $modal_header->add($close); $modal_header->add($title); $modal_content->add($body); $modal_content->add($footer); $modal_wrapper->show(); TScript::create("tdialog_start( '#{$this->id}' );"); }
/** * Converts the action into an URL * @param $format_action = format action with document or javascript (ajax=no) */ public function serialize($format_action = TRUE) { if (is_array($this->action) and is_object($this->action[0])) { if (isset($_REQUEST['offset'])) { $this->setParameter('offset', $_REQUEST['offset']); } if (isset($_REQUEST['limit'])) { $this->setParameter('limit', $_REQUEST['limit']); } if (isset($_REQUEST['page'])) { $this->setParameter('page', $_REQUEST['page']); } if (isset($_REQUEST['first_page'])) { $this->setParameter('first_page', $_REQUEST['first_page']); } if (isset($_REQUEST['order'])) { $this->setParameter('order', $_REQUEST['order']); } if (parent::isStatic()) { $this->setParameter('static', '1'); } } return parent::serialize($format_action); }
/** * Define the action to be executed when * the user clicks over the column header * @param $action A TAction object */ public function setAction(TAction $action) { $this->set_clickable(TRUE); $this->connect_simple('clicked', array($this, 'onExecuteAction'), $action->getAction(), $action->getParameters()); }
/** * method onDelete() * executada quando o usuario clica no botao delete * Ask if the user really wants to delete the record */ function onDelete($param) { // define the delete action $action = new TAction(array($this, 'Delete')); $action->setParameters($param); // pass the key parameter ahead // mostra o dialogo para o usuario new TQuestion('Deseja realmente excluir ?', $action); }
/** * Class constructor * Creates the page, the form and the listing */ public function __construct() { parent::__construct(); parent::include_css('app/resources/custom-table.css'); // creates the form $this->form = new TForm('form_search_Subelemento'); $this->form->class = 'tform'; // CSS class // creates a table $table = new TTable(); $table->width = '100%'; $this->form->add($table); // add a row for the form title $row = $table->addRow(); $row->class = 'tformtitle'; $row->addCell(new TLabel('Consulta SubElemento'))->colspan = 2; //$table->addRowSet( new TLabel('Consulta SubElemento') ,'')->class = 'tformtitle'; // CSS class // create the form fields $descricao = new TEntry('descricao'); // define the sizes $descricao->setSize(350); // add one row for each form field $table->addRowSet(new TLabel('Descrição:'), $descricao); $this->form->setFields(array($descricao)); // keep the form filled during navigation with session data $this->form->setData(TSession::getValue('Subelemento_filter_data')); // create two action buttons to the form $find_button = TButton::create('find', array($this, 'onSearch'), _t('Find'), 'ico_find.png'); $this->form->addField($find_button); $buttons_box = new THBox(); $buttons_box->add($find_button); // add a row for the form action $row = $table->addRow(); $row->class = 'tformaction'; // CSS class $row->addCell($buttons_box)->colspan = 2; // creates a Datagrid $this->datagrid = new TDataGrid(); $this->datagrid->style = 'width: 100%'; $this->datagrid->class = 'tdatagrid_table customized-table'; $this->datagrid->setHeight(320); // creates the datagrid columns $id = new TDataGridColumn('id', 'ID', 'right', 100); $descricao = new TDataGridColumn('descricao', 'Descrição', 'left'); // add the columns to the DataGrid $this->datagrid->addColumn($id); $this->datagrid->addColumn($descricao); // creates the datagrid column actions $order_id = new TAction(array($this, 'onReload')); $order_id->setParameter('order', 'id'); $id->setAction($order_id); $order_descricao = new TAction(array($this, 'onReload')); $order_descricao->setParameter('order', 'descricao'); $descricao->setAction($order_descricao); // create the datagrid model $this->datagrid->createModel(); // creates the page navigation $this->pageNavigation = new TPageNavigation(); $this->pageNavigation->setAction(new TAction(array($this, 'onReload'))); $this->pageNavigation->setWidth($this->datagrid->getWidth()); // create the page container $container = new TTable(); //$container->style = 'width: 80%'; $container->addRow()->addCell(new TXMLBreadCrumb('menu.xml', __CLASS__)); $container->addRow()->addCell($this->form); $container->addRow()->addCell($this->datagrid); $container->addRow()->addCell($this->pageNavigation); parent::add($container); }
/** * method onDelete() * executed whenever the user clicks at the delete button * Ask if the user really wants to delete the record */ function onDelete($param) { // define the delete action $action = new TAction(array($this, 'Delete')); $action->setParameters($param); // pass the key parameter ahead // shows a dialog to the user new TQuestion('Deseja realmente excluir ?', $action); }
/** * */ public function makeTSeekButton($properties) { $widget = new TSeekButton((string) $properties->{'name'}); $widget->setSize((int) $properties->{'width'}); if ($properties->{'database'} and $properties->{'model'}) { $obj = new TStandardSeek(); $action = new TAction(array($obj, 'onSetup')); $action->setParameter('database', (string) $properties->{'database'}); if (isset($this->form)) { if ($this->form instanceof TForm) { $action->setParameter('parent', $this->form->getName()); } } $action->setParameter('model', (string) $properties->{'model'}); $action->setParameter('display_field', (string) $properties->{'display'}); $action->setParameter('receive_key', (string) $properties->{'name'}); $action->setParameter('receive_field', (string) $properties->{'receiver'}); $widget->setAction($action); } $this->fields[] = $widget; $this->fieldsByName[(string) $properties->{'name'}] = $widget; return $widget; }
/** * Define the action to be executed when the user leaves the form field * @param $action TAction object */ function setExitAction(TAction $action) { if ($action->isStatic()) { $this->exitAction = $action; } else { $string_action = $action->toString(); throw new Exception(AdiantiCoreTranslator::translate('Action (^1) must be static to be used in ^2', $string_action, __METHOD__)); } $this->textview->connect_after('focus-out-event', array($this, 'onExecuteExitAction')); }
/** * Prepare action for use * @param $action TAction * @param $object Data Object */ private function prepareAction(TAction $action, $object) { $field = $action->getField(); if (is_null($field)) { throw new Exception(AdiantiCoreTranslator::translate('Field for action ^1 not defined', $label) . '.<br>' . AdiantiCoreTranslator::translate('Use the ^1 method', 'setField' . '()') . '.'); } if (!isset($object->{$field})) { throw new Exception(AdiantiCoreTranslator::translate('Field ^1 not exists', $field)); } // get the object property that will be passed ahead $key = isset($object->{$field}) ? $object->{$field} : NULL; $action->setParameter('key', $key); }
function onQuestionGerarPlanilha($param) { if (!isset($param)) { return; } $key = $param['key']; if (!isset($key) || !$key) { return; } try { TTransaction::open('saciq'); $Requisicao = new Requisicao($key); if ($Requisicao->srp->estaVencida()) { new TMessage('error', 'SRP já está vencida!'); return; } $pergunta = 'Voce realmente deseja gerar a planilha da seguinte Requisição?<br>' . 'SRP: ' . $Requisicao->srp->numeroSRP . '<br>' . 'Nº Processo: ' . $Requisicao->numeroProcesso . '<br>' . 'Emissão: ' . TDate::date2br($Requisicao->emissao); TTransaction::close(); } catch (Exception $e) { if ($e->getCode() == 23000) { new TMessage('error', '<b>Registro duplicado</b><br>Verifique os campos inseridos e tente novamente'); } else { if ($e->getCode() == 0) { new TMessage('error', '<b>Error</b> <br>' . $e->getMessage()); } else { new TMessage('error', '<b>Error Desconhecido</b> <br>Código: ' . $e->getCode()); } } // desfazer todas as operacoes pendentes TTransaction::rollback(); return; } if (!isset($pergunta) || !$pergunta) { return; } $sim = new TAction(array($this, 'onGerar')); //$nao = new TAction(array($this, 'onAction2')); // define os parâmetros de cada ação $sim->setParameter('requisicao', $key); // shows the question dialog new TQuestion($pergunta, $sim); }
private function checkDatabase($file) { try { TTransaction::open('saciq'); $criteria = new TCriteria(); $criteria->add(new TFilter('numeroSRP', '=', $this->importacao->getNroSRP())); $criteria->add(new TFilter('numeroIRP', '=', $this->importacao->getNroIRP())); $criteria->add(new TFilter('numeroProcesso', '=', $this->importacao->getNumeroProcesso())); $criteria->add(new TFilter('uasg', '=', $this->importacao->getUasgGerenciadora())); $criteria->add(new TFilter('validade', '=', $this->importacao->getValidadeAta())); $repository = new TRepository('Srp'); $count = $repository->count($criteria); if ($count > 0) { $continua = new TAction(array($this, 'onContinua')); // define os parâmetros de cada ação $continua->setParameter('confirma', 1); $continua->setParameter('file', $file); new TQuestion('Essa SRP já foi importada, reimportar a planilha <br>irá excluir os dados anteriores, Confirma?', $continua); TTransaction::close(); return false; } TTransaction::close(); return true; } catch (Exception $e) { if ($e->getCode() == 23000) { new TMessage('error', '<b>Registro duplicado</b><br>Verifique os campos inseridos e tente novamente'); } else { if ($e->getCode() == 0) { new TMessage('error', '<b>Error</b> <br>' . $e->getMessage()); } else { new TMessage('error', '<b>Error Desconhecido</b> <br>Código: ' . $e->getCode()); } } // desfazer todas as operacoes pendentes TTransaction::rollback(); } }
/** * Show the widget */ public function show() { // check if it's not editable if (parent::getEditable()) { if (!TForm::getFormByName($this->formName) instanceof TForm) { throw new Exception(AdiantiCoreTranslator::translate('You must pass the ^1 (^2) as a parameter to ^3', __CLASS__, $this->name, 'TForm::setFields()')); } $serialized_action = ''; if ($this->action) { // get the action class name if (is_array($callback = $this->action->getAction())) { if (is_object($callback[0])) { $rc = new ReflectionClass($callback[0]); $classname = $rc->getShortName(); } else { $classname = $callback[0]; } $inst = new $classname(); $ajaxAction = new TAction(array($inst, 'onSelect')); if (in_array($classname, array('TStandardSeek2'))) { $ajaxAction->setParameter('parent', $this->action->getParameter('parent')); $ajaxAction->setParameter('database', $this->action->getParameter('database')); $ajaxAction->setParameter('model', $this->action->getParameter('model')); $ajaxAction->setParameter('display_field', $this->action->getParameter('display_field')); $ajaxAction->setParameter('receive_key', $this->action->getParameter('receive_key')); $ajaxAction->setParameter('receive_field', $this->action->getParameter('receive_field')); $ajaxAction->setParameter('criteria', $this->action->getParameter('criteria')); $ajaxAction->setParameter('display_field2', $this->action->getParameter('display_field2')); } else { if ($actionParameters = $this->action->getParameters()) { foreach ($actionParameters as $key => $value) { $ajaxAction->setParameter($key, $value); } } } $ajaxAction->setParameter('form_name', $this->formName); $string_action = $ajaxAction->serialize(FALSE); if ($this->useOutEvent) { $this->setProperty('seekaction', "__adianti_post_lookup('{$this->formName}', '{$string_action}', document.{$this->formName}.{$this->name})"); $this->setProperty('onBlur', $this->getProperty('seekaction'), FALSE); } } $this->action->setParameter('form_name', $this->formName); $serialized_action = $this->action->serialize(FALSE); } parent::show(); $this->button->onclick = "javascript:serialform=(\$('#{$this->formName}').serialize());\n __adianti_append_page('engine.php?{$serialized_action}&'+serialform)"; $this->button->show(); if ($this->auxiliar) { echo ' '; $this->auxiliar->show(); } } else { parent::show(); } }
/** * method deleteCollection() * Delete many records */ public function deleteCollection($param) { // decode json with record id's $selected = json_decode($param['selected']); try { TTransaction::open($this->database); if ($selected) { // delete each record from collection foreach ($selected as $id) { $class = $this->activeRecord; $object = new $class(); $object->delete($id); } $posAction = new TAction(array($this, 'onReload')); $posAction->setParameters($param); new TMessage('info', AdiantiCoreTranslator::translate('Records deleted'), $posAction); } TTransaction::close(); } catch (Exception $e) { new TMessage('error', $e->getMessage()); TTransaction::rollback(); } }
/** * method onDelete() * executed whenever the user clicks at the delete button * Ask if the user really wants to delete the record */ function onDelete($param) { // define the delete action $action = new TAction(array($this, '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); }
/** * Class Constructor * @param $title_msg Dialog Title * @param $form Dialog form body * @param $action Action to be processed when closing the dialog * @param $caption Button caption */ public function __construct($title_msg, AdiantiFormInterface $form, TAction $action = NULL, $caption = '') { $this->id = 'tinputdialog_' . mt_rand(1000000000, 1999999999); $modal_wrapper = new TElement('div'); $modal_wrapper->{'class'} = 'modal'; $modal_wrapper->{'id'} = $this->id; $modal_wrapper->{'style'} = 'padding-top: 10%; z-index:2000'; $modal_wrapper->{'tabindex'} = '-1'; $modal_dialog = new TElement('div'); $modal_dialog->{'class'} = 'modal-dialog'; $modal_content = new TElement('div'); $modal_content->{'class'} = 'modal-content'; $modal_header = new TElement('div'); $modal_header->{'class'} = 'modal-header'; $close = new TElement('button'); $close->{'type'} = 'button'; $close->{'class'} = 'close'; $close->{'data-dismiss'} = 'modal'; $close->{'aria-hidden'} = 'true'; $close->add('×'); $title = new TElement('h4'); $title->{'class'} = 'modal-title'; $title->{'style'} = 'display:inline'; $title->add($title_msg ? $title_msg : AdiantiCoreTranslator::translate('Input')); $form_name = $form->getName(); $wait_message = AdiantiCoreTranslator::translate('Loading'); if ($form instanceof TQuickForm) { $actionButtons = $form->getActionButtons(); $form->delActions(); if ($actionButtons) { foreach ($actionButtons as $key => $button) { if ($button->getAction()->getParameter('stay-open') !== 1) { $button->addFunction("tdialog_close('{$this->id}')"); $button->{'data-toggle'} = "modal"; $button->{'data-dismiss'} = 'modal'; } $buttons[] = $button; } } } else { $button = new TButton(strtolower(str_replace(' ', '_', $caption))); if ($action->getParameter('stay-open') !== 1) { $button->{'data-toggle'} = "modal"; $button->{'data-dismiss'} = 'modal'; $button->addFunction("tdialog_close('{$this->id}')"); } $button->setAction($action); $button->setLabel($caption); $buttons[] = $button; $form->addField($button); } $footer = new TElement('div'); $footer->{'class'} = 'modal-footer'; $modal_wrapper->add($modal_dialog); $modal_dialog->add($modal_content); $modal_content->add($modal_header); $modal_header->add($close); $modal_header->add($title); $modal_content->add($form); $modal_content->add($footer); if (isset($buttons) and $buttons) { foreach ($buttons as $button) { $footer->add($button); } } $modal_wrapper->show(); TScript::create("tdialog_start( '#{$this->id}' );"); }
/** * Define the action to be executed when the user changes the combo * @param $action TAction object */ function setChangeAction(TAction $action) { if ($action->isStatic()) { $this->changeAction = $action; } else { $string_action = $action->toString(); throw new Exception(AdiantiCoreTranslator::translate('Action (^1) must be static to be used in ^2', $string_action, __METHOD__)); } $this->widget->connect('changed', array($this, 'onExecuteExitAction')); }
/** * Define the action to be executed when the user changes the combo * @param $action TAction object */ function setChangeAction(TAction $action) { if ($action->isStatic()) { $this->changeAction = $action; } else { $string_action = $action->toString(); throw new Exception(AdiantiCoreTranslator::translate('Action (^1) must be static to be used in ^2', $string_action, __METHOD__)); } if ($this->radios) { foreach ($this->radios as $key => $radio) { $radio->connect('clicked', array($this, 'onExecuteExitAction')); } } }