/**
  * Show the widget at the screen
  */
 public function show()
 {
     $wrapper = new TElement('div');
     $wrapper->{'mtf_name'} = $this->getName();
     // include the needed libraries and styles
     if ($this->fields) {
         $table = new TTable();
         $mandatories = array();
         // mandatory
         $fields = array();
         $i = 0;
         if ($this->orientation == 'horizontal') {
             $row_label = $table->addRow();
             $row_field = $table->addRow();
         }
         foreach ($this->fields as $name => $obj) {
             if ($this->orientation == 'vertical') {
                 $row = $table->addRow();
                 $row_label = $row;
                 $row_field = $row;
             }
             $label = new TLabel($obj->text);
             if ($obj->mandatory) {
                 $label->setFontColor('red');
             }
             $row_label->addCell($label);
             $row_field->addCell($obj->field);
             $mandatories[] = $obj->mandatory;
             $fields[] = $name;
             $post_fields[$name] = 1;
             $sizes[$name] = $obj->size;
             $obj->field->setName($this->name . '_' . $name);
             if (in_array(get_class($obj->field), array('TComboCombined', 'Adianti\\Widget\\Form\\TComboCombined'))) {
                 $aux_name = $obj->field->getTextName();
                 $aux_full_name = $this->name . '_' . $aux_name;
                 $mandatories[] = 0;
                 $obj->field->setTextName($aux_full_name);
                 $fields[] = $aux_name;
                 $post_fields[$aux_name] = 1;
                 // invert sizes
                 $sizes[$aux_name] = $obj->size;
                 $sizes[$name] = 20;
                 $i++;
             }
             $i++;
         }
         $wrapper->add($table);
     }
     // check whether the widget is non-editable
     if (parent::getEditable()) {
         // create three buttons to control the MultiField
         $add = new TButton("{$this->name}btnStore");
         $add->setLabel(AdiantiCoreTranslator::translate('Register'));
         $add->setImage('fa:angle-double-down');
         $add->addFunction("multifields['{$this->name}'].addRowFromFormFields()");
         $del = new TButton("{$this->name}btnDelete");
         $del->setLabel(AdiantiCoreTranslator::translate('Delete'));
         $del->setImage('fa:trash');
         $can = new TButton("{$this->name}btnCancel");
         $can->setLabel(AdiantiCoreTranslator::translate('Cancel'));
         $can->setImage('fa:times-circle');
         $hbox_buttons = new THBox();
         $hbox_buttons->{'style'} = 'margin-top:3px;margin-bottom:3px';
         $hbox_buttons->add($add);
         $hbox_buttons->add($del);
         $hbox_buttons->add($can);
         $wrapper->add($hbox_buttons);
     }
     // create the MultiField Panel
     $panel = new TElement('div');
     $panel->{'class'} = "multifieldDiv";
     $input = new THidden($this->name);
     $panel->add($input);
     // create the MultiField DataGrid Header
     $table = new TTable();
     $table->{'class'} = 'multifield';
     $table->{'id'} = "{$this->name}mfTable";
     $head = new TElement('thead');
     $table->add($head);
     $row = new TTableRow();
     $head->add($row);
     // fill the MultiField DataGrid
     if ($this->fields) {
         foreach ($this->fields as $obj) {
             $c = $obj->text;
             if (in_array(get_class($obj->field), array('TComboCombined', 'Adianti\\Widget\\Form\\TComboCombined'))) {
                 $cell = $row->addCell('ID');
                 $cell->{'width'} = '20px';
                 $cell->{'class'} = 'multifield_header';
             }
             $cell = $row->addCell($c);
             $cell->{'width'} = $obj->size . 'px';
             $cell->{'class'} = 'multifield_header';
         }
     }
     $body_height = $this->height - 34;
     $body = new TElement('tbody');
     $body->{'style'} = "height: {$body_height}px";
     $body->{'class'} = 'tmultifield_scrolling';
     $table->add($body);
     if ($this->objects) {
         foreach ($this->objects as $obj) {
             if (isset($obj->id)) {
                 $row = new TTableRow();
                 $row->dbId = $obj->id;
                 $body->add($row);
             } else {
                 $row = new TTableRow();
                 $body->add($row);
             }
             if ($fields) {
                 foreach ($fields as $name) {
                     $cellValue = is_null($obj->{$name}) ? '' : $obj->{$name};
                     $original = $cellValue;
                     if (is_array(json_decode($cellValue))) {
                         $content = json_decode($cellValue);
                         $rows = array();
                         foreach ($content as $_row) {
                             $rows[] = implode(':', array_values(get_object_vars($_row)));
                         }
                         $cellValue = implode(',', $rows);
                         $cell = $row->addCell($cellValue);
                         $cell->{'data'} = htmlspecialchars($original);
                     } else {
                         $cell = $row->addCell($cellValue);
                         $cell->{'data'} = $cellValue;
                     }
                     if (isset($sizes[$name])) {
                         $cell->style = 'width:' . $sizes[$name] . 'px;';
                     }
                 }
             }
         }
     }
     $panel->add($table);
     $wrapper->add($panel);
     $wrapper->show();
     $fields_json = json_encode($fields);
     $mandatories_json = json_encode($mandatories);
     TScript::create(" tmultifield_start( '{$this->name}', {$fields_json}, {$mandatories_json}, {$this->width},{$this->height} ) ");
 }
Beispiel #2
0
 /**
  * Add a form field
  * @param $label     Field Label
  * @param $objects   Array of Objects
  * @param $required  Boolean TRUE if required
  */
 public function addQuickFields($label, $objects, $required = FALSE)
 {
     if (empty($this->currentRow) or $this->fieldPositions % $this->fieldsByRow == 0) {
         // add the field to the container
         $this->currentRow = $this->table->addRow();
     }
     $row = $this->currentRow;
     if ($required) {
         $label_field = new TLabel($label . '(*)');
         $label_field->setFontColor('#FF0000');
     } else {
         $label_field = new TLabel($label);
     }
     $row->addCell($label_field);
     $hbox = new THBox();
     foreach ($objects as $object) {
         parent::addField($object);
         $object->setLabel($label);
         $hbox->add($object);
     }
     $row->addCell($hbox);
     $this->fieldPositions++;
     return $row;
 }
 /**
  * Show the widget at the screen
  */
 public function show()
 {
     $wrapper = new TElement('div');
     $wrapper->{'mtf_name'} = $this->getName();
     // include the needed libraries and styles
     if ($this->fields) {
         $table = new TTable();
         $mandatory = array();
         // mandatory
         $fields = array();
         $i = 0;
         if ($this->orientation == 'horizontal') {
             $row_label = $table->addRow();
             $row_field = $table->addRow();
         }
         foreach ($this->fields as $name => $obj) {
             if ($this->orientation == 'vertical') {
                 $row = $table->addRow();
                 $row_label = $row;
                 $row_field = $row;
             }
             $label = new TLabel($obj->text);
             if ($obj->mandatory) {
                 $label->setFontColor('red');
             }
             $row_label->addCell($label);
             $row_field->addCell($obj->field);
             $mandatory[] = $obj->mandatory;
             $fields[] = $name;
             $post_fields[$name] = 1;
             $sizes[$name] = $obj->size;
             $obj->field->setName($this->name . '_' . $name);
             if (in_array(get_class($obj->field), array('TComboCombined', 'Adianti\\Widget\\Form\\TComboCombined'))) {
                 $aux_name = $obj->field->getTextName();
                 $aux_full_name = $this->name . '_' . $aux_name;
                 $mandatory[] = 0;
                 $obj->field->setTextName($aux_full_name);
                 $fields[] = $aux_name;
                 $post_fields[$aux_name] = 1;
                 // invert sizes
                 $sizes[$aux_name] = $obj->size;
                 $sizes[$name] = 20;
                 $i++;
             }
             $i++;
         }
         $wrapper->add($table);
     }
     // check whether the widget is non-editable
     if (parent::getEditable()) {
         // create three buttons to control the MultiField
         $add = new TButton("{$this->name}btnStore");
         $add->setLabel(AdiantiCoreTranslator::translate('Register'));
         //$add->setName("{$this->name}btnStore");
         $add->setImage('ico_save.png');
         $add->addFunction("mtf{$this->name}.addRowFromFormFields()");
         $del = new TButton("{$this->name}btnDelete");
         $del->setLabel(AdiantiCoreTranslator::translate('Delete'));
         $del->setImage('ico_delete.png');
         $can = new TButton("{$this->name}btnCancel");
         $can->setLabel(AdiantiCoreTranslator::translate('Cancel'));
         $can->setImage('ico_close.png');
         $hbox_buttons = new THBox();
         $hbox_buttons->{'style'} = 'margin-top:3px;margin-bottom:3px';
         $hbox_buttons->add($add);
         $hbox_buttons->add($del);
         $hbox_buttons->add($can);
         $wrapper->add($hbox_buttons);
     }
     // create the MultiField Panel
     $panel = new TElement('div');
     $panel->{'class'} = "multifieldDiv";
     $input = new THidden($this->name);
     $panel->add($input);
     // create the MultiField DataGrid Header
     $table = new TTable();
     $table->{'class'} = 'multifield';
     $table->{'id'} = "{$this->name}mfTable";
     $head = new TElement('thead');
     $table->add($head);
     $row = new TTableRow();
     $head->add($row);
     // fill the MultiField DataGrid
     if ($this->fields) {
         foreach ($this->fields as $obj) {
             $c = $obj->text;
             if (in_array(get_class($obj->field), array('TComboCombined', 'Adianti\\Widget\\Form\\TComboCombined'))) {
                 $cell = $row->addCell('ID');
                 $cell->{'width'} = '20px';
                 $cell->{'class'} = 'multifield_header';
             }
             $cell = $row->addCell($c);
             $cell->{'width'} = $obj->size . 'px';
             $cell->{'class'} = 'multifield_header';
         }
     }
     $body_height = $this->height - 34;
     $body = new TElement('tbody');
     $body->{'style'} = "height: {$body_height}px";
     $body->{'class'} = 'tmultifield_scrolling';
     $table->add($body);
     if ($this->objects) {
         foreach ($this->objects as $obj) {
             if (isset($obj->id)) {
                 $row = new TTableRow();
                 $row->dbId = $obj->id;
                 $body->add($row);
             } else {
                 $row = new TTableRow();
                 $body->add($row);
             }
             if ($fields) {
                 foreach ($fields as $name) {
                     $cellValue = is_null($obj->{$name}) ? '' : $obj->{$name};
                     $original = $cellValue;
                     if (is_array(json_decode($cellValue))) {
                         $content = json_decode($cellValue);
                         $rows = array();
                         foreach ($content as $_row) {
                             $rows[] = implode(':', array_values(get_object_vars($_row)));
                         }
                         $cellValue = implode(',', $rows);
                         $cell = $row->addCell($cellValue);
                         $cell->{'data'} = htmlspecialchars($original);
                     } else {
                         $cell = $row->addCell($cellValue);
                         $cell->{'data'} = $cellValue;
                     }
                     if (isset($sizes[$name])) {
                         $cell->style = 'width:' . $sizes[$name] . 'px;';
                     }
                 }
             }
         }
     }
     $panel->add($table);
     $wrapper->add($panel);
     $wrapper->show();
     echo '<script type="text/javascript">';
     echo "var mtf{$this->name};";
     echo "mtf{$this->name} = new MultiField('{$this->name}mfTable',{$this->width},{$this->height});\n";
     $s = implode("','", $fields);
     echo "mtf{$this->name}.formFieldsAlias = Array('{$s}');\n";
     $sfields = implode("','{$this->name}_", $fields);
     echo "mtf{$this->name}.formFieldsName = Array('{$this->name}_{$sfields}');\n";
     echo "mtf{$this->name}.formPostFields = Array();\n";
     if ($post_fields) {
         foreach ($post_fields as $col => $value) {
             echo "mtf{$this->name}.formPostFields['{$col}'] = '{$value}';\n";
         }
     }
     $mdr_array = implode(',', $mandatory);
     echo "mtf{$this->name}.formFieldsMandatory = [{$mdr_array}];\n";
     echo "mtf{$this->name}.mandatoryMessage = '" . AdiantiCoreTranslator::translate('The field ^1 is required') . "';\n";
     echo "mtf{$this->name}.storeButton  = document.getElementsByName('{$this->name}btnStore')[0];\n";
     echo "mtf{$this->name}.deleteButton = document.getElementsByName('{$this->name}btnDelete')[0];\n";
     echo "mtf{$this->name}.cancelButton = document.getElementsByName('{$this->name}btnCancel')[0];\n";
     echo "mtf{$this->name}.inputResult  = document.getElementsByName('{$this->name}')[0];\n";
     echo '</script>';
 }
Beispiel #4
0
 /**
  * 
  */
 public function makeTLabel($properties)
 {
     $widget = new TLabel((string) $properties->{'name'});
     $widget->setValue((string) $properties->{'value'});
     $widget->setFontColor((string) $properties->{'color'});
     $widget->setFontSize((string) $properties->{'size'});
     $widget->setFontStyle((string) $properties->{'style'});
     $this->fieldsByName[(string) $properties->{'name'}] = $widget;
     return $widget;
 }
Beispiel #5
0
 function __construct()
 {
     parent::__construct();
     // creates the form
     $this->form = new TForm('form_home');
     $this->form->class = 'tform';
     // CSS class
     $this->form->width = '100%';
     $this->form->style = "background-color:rgba(0,0,0,0)!important;";
     // creates a table
     $table = new TTable();
     $table->width = '100%';
     $this->form->add($table);
     $table->style = 'background-color:rgba(0, 0, 0, 0);box-shadow: none !important;border: none !important;';
     $row = $table->addRow();
     $lbUI = new TLabel('<B>Últimas importações</B>');
     $lbUR = new TLabel('<B>Últimas requisições</B>');
     $lbUC = new TLabel('<B>Últimas cessões</B>');
     $lbSV = new TLabel('<B>SRP à vencer</B>');
     $lbUI->setFontSize(16);
     $lbUR->setFontSize(16);
     $lbUC->setFontSize(16);
     $lbSV->setFontSize(16);
     $lbUI->style = "padding-top : 10px;";
     $lbUR->style = "padding-top : 10px;";
     $lbUC->style = "padding-top : 10px;";
     $lbSV->style = "padding-top : 10px;";
     $row->addCell($lbUI);
     $row->addCell(new TLabel('&nbsp;'));
     $row->addCell($lbUR);
     parent::include_css('app/resources/custom-table.css');
     $this->dg_UltImportacao = new TDataGrid();
     $this->dg_UltRequisicao = new TDataGrid();
     $this->dg_UltCesssao = new TDataGrid();
     $this->dg_SRPAVencer = new TDataGrid();
     $this->dg_UltImportacao->class = 'tdatagrid_table customized-table';
     $this->dg_UltRequisicao->class = 'tdatagrid_table customized-table';
     $this->dg_UltCesssao->class = 'tdatagrid_table customized-table';
     $this->dg_SRPAVencer->class = 'tdatagrid_table customized-table';
     //$this->dg_UltImportacao->style = 'width : 100%';
     //$this->dg_UltRequisicao->style = 'width : 100%';
     //$this->dg_UltCesssao->style = 'width : 100%';
     //$this->dg_AtasAVencer->style = 'width : 100%';
     $this->dg_UltImportacao->setHeight(320);
     $this->dg_UltRequisicao->setHeight(320);
     $this->dg_UltCesssao->setHeight(320);
     $this->dg_SRPAVencer->setHeight(320);
     $this->dg_UltImportacao->makeScrollable();
     $this->dg_UltRequisicao->makeScrollable();
     $this->dg_UltCesssao->makeScrollable();
     $this->dg_SRPAVencer->makeScrollable();
     //$this->dg_UltImportacao->disableDefaultClick();
     //$this->dg_UltRequisicao->disableDefaultClick();
     //$this->dg_UltCesssao->disableDefaultClick();
     //$this->dg_SRPAVencer->disableDefaultClick();
     //Ultimas Importações
     $numeroSRP = new TDataGridColumn('numeroSRP', 'Nº SRP', 'left', 70);
     $numeroIRP = new TDataGridColumn('numeroIRP', 'Nº IRP', 'left', 70);
     $numeroProcesso = new TDataGridColumn('numeroProcesso', 'Proc. Orig.', 'left', 150);
     $uasg = new TDataGridColumn('uasg', 'UASG', 'left', 50);
     $validade = new TDataGridColumn('validade', 'Validade', 'left', 100);
     $nome = new TDataGridColumn('nome', 'Nome', 'left', 300);
     $actUltImp = new TDataGridAction(array('SrpFormView', 'onViewSrp'));
     $actUltImp->setLabel('Visualizar');
     $actUltImp->setImage('fa:search fa-fw');
     $actUltImp->setField('id');
     $this->dg_UltImportacao->addAction($actUltImp);
     $this->dg_UltImportacao->addColumn($numeroSRP);
     $this->dg_UltImportacao->addColumn($numeroIRP);
     $this->dg_UltImportacao->addColumn($numeroProcesso);
     $this->dg_UltImportacao->addColumn($nome);
     $this->dg_UltImportacao->addColumn($uasg);
     $this->dg_UltImportacao->addColumn($validade);
     $this->dg_UltImportacao->createModel();
     //Ultimas Requisições
     $srp = new TDataGridColumn('numeroSRP', 'Nº SRP', 'left', 100);
     $numeroProcesso = new TDataGridColumn('numeroProcesso', 'Nº do processo', 'left', 250);
     $data = new TDataGridColumn('emissao', 'Data', 'left', 100);
     $aprovado = new TDataGridColumn('aprovado', 'Aprovado', 'left', 100);
     $actUltReq = new TDataGridAction(array('RequisicaoList', 'onReload'));
     $actUltReq->setLabel('Visualizar');
     $actUltReq->setImage('fa:search fa-fw');
     $actUltReq->setField('id');
     $this->dg_UltRequisicao->addAction($actUltReq);
     $this->dg_UltRequisicao->addColumn($srp);
     $this->dg_UltRequisicao->addColumn($numeroProcesso);
     $this->dg_UltRequisicao->addColumn($data);
     $this->dg_UltRequisicao->addColumn($aprovado);
     $this->dg_UltRequisicao->createModel();
     //Atas a Vencer
     $numeroSRP = new TDataGridColumn('numeroSRP', 'Nº SRP', 'left', 70);
     $numeroIRP = new TDataGridColumn('numeroIRP', 'Nº IRP', 'left', 70);
     $numeroProcesso = new TDataGridColumn('numeroProcesso', 'Proc. Orig.', 'left', 150);
     $uasg = new TDataGridColumn('uasg', 'UASG', 'left', 50);
     $validade = new TDataGridColumn('validade', 'Validade', 'left', 100);
     $nome = new TDataGridColumn('nome', 'Nome', 'left', 300);
     $actSrpVen = new TDataGridAction(array('SrpFormView', 'onViewSrp'));
     $actSrpVen->setLabel('Visualizar');
     $actSrpVen->setImage('fa:search fa-fw');
     $actSrpVen->setField('id');
     $this->dg_SRPAVencer->addAction($actSrpVen);
     $this->dg_SRPAVencer->addColumn($numeroSRP);
     $this->dg_SRPAVencer->addColumn($numeroIRP);
     $this->dg_SRPAVencer->addColumn($numeroProcesso);
     $this->dg_SRPAVencer->addColumn($nome);
     $this->dg_SRPAVencer->addColumn($uasg);
     $this->dg_SRPAVencer->addColumn($validade);
     $this->dg_SRPAVencer->createModel();
     //Ultimas Cessões
     $srp = new TDataGridColumn('numeroSRP', 'Nº SRP', 'left', 100);
     $numeroCessao = new TDataGridColumn('numeroCessao', 'Nº da Cessão', 'left', 250);
     $data = new TDataGridColumn('emissao', 'Data', 'left', 100);
     $aprovado = new TDataGridColumn('aprovado', 'Aprovado', 'left', 100);
     $actUltCes = new TDataGridAction(array('CessaoList', 'onReload'));
     $actUltCes->setLabel('Visualizar');
     $actUltCes->setImage('fa:search fa-fw');
     $actUltCes->setField('id');
     $this->dg_UltCesssao->addAction($actUltCes);
     $this->dg_UltCesssao->addColumn($srp);
     $this->dg_UltCesssao->addColumn($numeroCessao);
     $this->dg_UltCesssao->addColumn($data);
     $this->dg_UltCesssao->addColumn($aprovado);
     $this->dg_UltCesssao->createModel();
     $table->addRowSet($this->dg_UltImportacao, new TLabel('&nbsp;'), $this->dg_UltRequisicao);
     $row = $table->addRow();
     $row->addCell(new TLabel('&nbsp;'))->colspan = 3;
     $row = $table->addRow();
     $row->addCell($lbSV);
     $row->addCell(new TLabel('&nbsp;'));
     $row->addCell($lbUC);
     $table->addRowSet($this->dg_SRPAVencer, new TLabel('&nbsp;'), $this->dg_UltCesssao);
     $container = TVBox::pack($this->form);
     parent::add($container);
     //parent::add($this->form);
 }
 /**
  * Add a field to the MultiField
  * @param $name   Widget's name
  * @param $text   Widget's label
  * @param $object Widget
  * @param $size   Widget's size
  * @param $inform Show the Widget in the form
  */
 public function addField($name, $text, GtkObject $object, $size, $mandatory = FALSE)
 {
     if ($this->orientation == 'horizontal') {
         if (count($this->fields) == 0) {
             $this->row_label = $this->table_fields->addRow();
             $this->row_field = $this->table_fields->addRow();
         }
     } else {
         $row = $this->table_fields->addRow();
         $this->row_label = $row;
         $this->row_field = $row;
     }
     $label = new TLabel("<i>{$text}</i>");
     if ($mandatory) {
         $label->setFontColor('#FF0000');
     }
     $n = $this->count;
     $object->setName("{$this->name}_text{$n}");
     $this->row_label->addCell($label);
     $this->row_field->addCell($object);
     $this->fields[$name] = array($text, $object, $size, FALSE, $mandatory);
     $this->allfields[$name] = array($text, $object, $size, FALSE, $mandatory);
     if (in_array(get_class($object), array('TComboCombined', 'Adianti\\Widget\\Form\\TComboCombined'))) {
         $column = new GtkTreeViewColumn('ID');
     } else {
         $column = new GtkTreeViewColumn($text);
     }
     $cell_renderer = new GtkCellRendererText();
     $cell_renderer->set_property('width', $size);
     $column->set_fixed_width($size);
     $column->pack_start($cell_renderer, true);
     $column->add_attribute($cell_renderer, 'text', $this->count);
     $this->types[] = GObject::TYPE_STRING;
     $this->view->append_column($column);
     $this->columns[$name] = $this->count;
     $this->count++;
     // combocombined, need to add one more column and treat different
     if (in_array(get_class($object), array('TComboCombined', 'Adianti\\Widget\\Form\\TComboCombined'))) {
         $cell_renderer->set_property('width', 20);
         $column->set_fixed_width(20);
         $tname = $object->getTextName();
         $this->fields[$tname] = array($text, $object, $size, TRUE, $mandatory);
         $this->fields[$name][2] = 20;
         $this->allfields[$name][2] = 20;
         $column = new GtkTreeViewColumn($text);
         $cell_renderer = new GtkCellRendererText();
         $cell_renderer->set_property('width', $size);
         $column->set_fixed_width($size);
         $column->pack_start($cell_renderer, true);
         $column->add_attribute($cell_renderer, 'text', $this->count);
         $this->types[] = GObject::TYPE_STRING;
         $this->view->append_column($column);
         $this->allfields[$tname] = array($text, $object, $size, TRUE, $mandatory);
         $this->columns[$tname] = $this->count;
         $this->count++;
     }
 }