/**
  * Show the widget at the screen
  */
 public function show()
 {
     // include the needed libraries and styles
     if ($this->fields) {
         $table = new TTable();
         $mdr = array();
         // mandatory
         $fields = array();
         $i = 0;
         foreach ($this->fields as $name => $obj) {
             $row = $table->addRow();
             $label = new TLabel($obj->text);
             if ($obj->inform) {
                 $row->addCell($label);
                 $row->addCell($obj->field);
             }
             $fields[] = $name;
             $post_fields[$name] = 1;
             $obj->field->setName($this->name . '_' . $name);
             if (get_class($obj->field) == 'TComboCombined') {
                 $fields[] = $obj->field->getTextName();
                 $obj->field->setTextName($this->name . '_' . $obj->field->getTextName());
                 $i++;
             }
             $i++;
         }
         $table->show();
     }
     // 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(TAdiantiCoreTranslator::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(TAdiantiCoreTranslator::translate('Delete'));
         $del->setImage('ico_delete.png');
         $can = new TButton("{$this->name}btnCancel");
         $can->setLabel(TAdiantiCoreTranslator::translate('Cancel'));
         $can->setImage('ico_close.png');
         $table = new TTable();
         $row = $table->addRow();
         $row->addCell($add);
         $row->addCell($del);
         $row->addCell($can);
         $table->show();
     }
     // 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->id = "{$this->name}mfTable";
     $head = new TElement('thead');
     $table->add($head);
     $row = new TTableRow();
     $head->add($row);
     // fill the MultiField DataGrid
     foreach ($this->fields as $obj) {
         $c = $obj->text;
         if (get_class($obj->field) == 'TComboCombined') {
             $row->addCell('ID');
         }
         $cell = $row->addCell($c);
         $cell->width = $obj->size . 'px';
     }
     $body = new TElement('tbody');
     $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);
             }
             foreach ($fields as $name) {
                 $cell = $row->addCell(is_null($obj->{$name}) ? '' : $obj->{$name});
                 if (isset($this->fields[$name]->size)) {
                     $cell->style = 'width:' . $this->fields[$name]->size . 'px';
                 }
             }
         }
     }
     $panel->add($table);
     $panel->show();
     echo '<script type="text/javascript">';
     echo "var mtf{$this->name};";
     //echo '$(document).ready(function() {';
     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";
     $fields = implode("','{$this->name}_", $fields);
     echo "mtf{$this->name}.formFieldsName = Array('{$this->name}_{$fields}');\n";
     echo "mtf{$this->name}.formPostFields = Array();\n";
     foreach ($post_fields as $col => $value) {
         echo "mtf{$this->name}.formPostFields['{$col}'] = '{$value}';\n";
     }
     $mdr = implode(',', $mdr);
     echo "mtf{$this->name}.formFieldsMandatory = Array({$mdr});\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 '});';
     echo '</script>';
 }
 /**
  * Creates the DataGrid Structure
  */
 public function createModel()
 {
     if (!$this->columns) {
         return;
     }
     $thead = new TElement('thead');
     $thead->{'class'} = 'tdatagrid_head';
     parent::add($thead);
     $row = new TElement('tr');
     if ($this->scrollable) {
         $row->{'style'} = 'display:block';
     }
     $thead->add($row);
     // add some cells for the actions
     if ($this->actions) {
         foreach ($this->actions as $action) {
             $cell = new TElement('td');
             $row->add($cell);
             $cell->add('&nbsp;');
             $cell->{'class'} = 'tdatagrid_action';
             $cell->width = '16px';
         }
         // the last one has right border
         $cell->{'class'} = 'tdatagrid_col';
     }
     // add some cells for the data
     if ($this->columns) {
         // iterate the DataGrid columns
         foreach ($this->columns as $column) {
             // get the column properties
             $name = $column->getName();
             $label = '&nbsp;' . $column->getLabel() . '&nbsp;';
             $align = $column->getAlign();
             $width = $column->getWidth();
             if (isset($_GET['order'])) {
                 if ($_GET['order'] == $name) {
                     $label .= '<img src="lib/adianti/images/ico_down.png">';
                 }
             }
             // add a cell with the columns label
             $cell = new TElement('td');
             $row->add($cell);
             $cell->add($label);
             $cell->{'class'} = 'tdatagrid_col';
             $cell->align = $align;
             if ($width) {
                 //$cell-> width = $width.'px';
                 $cell->width = $width + 8 . 'px';
             }
             // verify if the column has an attached action
             if ($column->getAction()) {
                 $url = $column->getAction();
                 $cell->onmouseover = "this.className='tdatagrid_col_over';";
                 $cell->onmouseout = "this.className='tdatagrid_col'";
                 $cell->href = $url;
                 $cell->generator = 'adianti';
             }
         }
         if ($this->scrollable) {
             $cell = new TElement('td');
             $cell->{'class'} = 'tdatagrid_col';
             $row->add($cell);
             $cell->add('&nbsp;');
             $cell->width = '12px';
         }
     }
     // add one row to the DataGrid
     $this->tbody = new TElement('tbody');
     $this->tbody->{'class'} = 'tdatagrid_body';
     if ($this->scrollable) {
         $this->tbody->{'style'} = "height: {$this->height}px; display: block; overflow-y:scroll; overflow-x:hidden;";
     }
     parent::add($this->tbody);
     $this->modelCreated = TRUE;
 }