Esempio n. 1
0
 /**
  * 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} ) ");
 }
Esempio n. 2
0
 /**
  * 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);
     $actions_count = count($this->actions) + count($this->action_groups);
     if ($actions_count > 0) {
         for ($n = 0; $n < $actions_count; $n++) {
             $cell = new TElement('td');
             $row->add($cell);
             $cell->add('&nbsp;');
             $cell->{'class'} = 'tdatagrid_action';
             $cell->width = '16px';
         }
         $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 + 8 . 'px';
             }
             // verify if the column has an attached action
             if ($column->getAction()) {
                 $url = $column->getAction();
                 $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;
 }
Esempio n. 3
0
 /**
  * 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>';
 }
Esempio n. 4
0
 /**
  * Creates the DataGrid Structure
  */
 public function createModel()
 {
     if (!$this->columns) {
         return;
     }
     $this->thead = new TElement('thead');
     $this->thead->{'class'} = 'tdatagrid_head';
     parent::add($this->thead);
     $row = new TElement('tr');
     if ($this->scrollable) {
         $this->thead->{'style'} = 'display:block';
     }
     $this->thead->add($row);
     $actions_count = count($this->actions) + count($this->action_groups);
     if ($actions_count > 0) {
         for ($n = 0; $n < $actions_count; $n++) {
             $cell = new TElement('th');
             $row->add($cell);
             $cell->add('&nbsp;');
             $cell->{'class'} = 'tdatagrid_action';
             $cell->width = $this->actionWidth;
         }
         $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) {
                     if (isset($_GET['direction']) and $_GET['direction'] == 'asc') {
                         $label .= '<span class="glyphicon glyphicon-chevron-down blue" aria-hidden="true"></span>';
                     } else {
                         $label .= '<span class="glyphicon glyphicon-chevron-up blue" aria-hidden="true"></span>';
                     }
                 }
             }
             // add a cell with the columns label
             $cell = new TElement('th');
             $row->add($cell);
             $cell->add($label);
             $cell->{'class'} = 'tdatagrid_col';
             $cell->{'style'} = "text-align:{$align}";
             if ($width) {
                 $cell->width = $width + 8 . 'px';
             }
             // verify if the column has an attached action
             if ($column->getAction()) {
                 $action = $column->getAction();
                 if (isset($_GET['direction']) and $_GET['direction'] == 'asc' and isset($_GET['order']) and $_GET['order'] == $name) {
                     $action->setParameter('direction', 'desc');
                 } else {
                     $action->setParameter('direction', 'asc');
                 }
                 $url = $action->serialize();
                 $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;
 }