/**
  * 
  * @param \Centreon\Internal\Form $formHandler
  * @param type $formComponents
  * @return string
  */
 public static function genForm($formHandler, $formComponents)
 {
     $formElements = $formHandler->toSmarty();
     $htmlRendering = '<div class="row">';
     $htmlRendering .= '<div ' . 'class="bs-callout bs-callout-success" ' . 'id="formSuccess" ' . 'style="display: none;">' . 'The object has been successfully updated' . '</div>';
     $htmlRendering .= '<div ' . 'class="bs-callout bs-callout-danger" ' . 'id="formError" ' . 'style="display: none;">' . 'An error occured' . '</div>';
     $htmlRendering .= '<form class="form-horizontal" role="form" ' . $formElements['attributes'] . '>';
     $formRendering = '';
     $tabRendering = '<div class="form-tabs-header">' . '<div class="inline-block">' . '<ul class="nav nav-tabs" id="formHeader">';
     $first = true;
     foreach ($formComponents as $sectionLabel => $sectionComponents) {
         if ($first) {
             $active = 'active';
             $first = false;
         } else {
             $active = '';
         }
         $tabRendering .= '<li class="' . $active . '">' . '<a ' . 'href="#' . str_replace(' ', '', $sectionLabel) . '" ' . 'data-toggle="tab">' . $sectionLabel . '</a>' . '</li>';
     }
     $formRendering .= '</ul></div></div>';
     $formRendering .= '<div class="tab-content">';
     $first = true;
     foreach ($formComponents as $sectionLabel => $sectionComponents) {
         if ($first) {
             $active = 'active';
             $first = false;
         } else {
             $active = '';
         }
         $formRendering .= '<div class="tab-pane ' . $active . '" id="' . str_replace(' ', '', $sectionLabel) . '">';
         foreach ($sectionComponents as $blockLabel => $blockComponents) {
             $formRendering .= '<h4 class="page-header" style="padding-top:0px;">' . ucwords($blockLabel) . '</h4>';
             $formRendering .= '<div class="panel-body">';
             foreach ($blockComponents as $component) {
                 if (isset($formElements[$component]['html'])) {
                     $formRendering .= $formElements[$component]['html'];
                 }
             }
             $formRendering .= '</div>';
         }
         $formRendering .= '</div>';
     }
     $formRendering .= '</div>';
     $formRendering .= '<div>' . $formElements['save_form']['html'] . '</div>';
     $formRendering .= $formElements['hidden'];
     $htmlRendering .= $tabRendering . $formRendering;
     return $htmlRendering;
 }
Example #2
0
 /**
  * Get field HTML
  *
  * Response HTML
  *
  * @method get
  * @route /{object}/mc_fields/[i:id]
  */
 public function getMcFieldAction()
 {
     $requestParam = $this->getParams('named');
     $stmt = $this->db->prepare("SELECT name, label, default_value, attributes, type, help\n            FROM cfg_forms_fields\n            WHERE field_id = :id");
     $stmt->bindValue(':id', $requestParam['id'], \PDO::PARAM_INT);
     $stmt->execute();
     $row = $stmt->fetch();
     $row['validators'] = Form::getValidatorsByField($requestParam['id']);
     $extraParams['id'] = 0;
     $form = new Form('default');
     $form->add($row, $extraParams);
     $formElements = $form->toSmarty();
     $this->tpl->assign('field', $formElements[$row['name']]['html']);
     $this->tpl->assign('formName', "massive_change");
     $this->tpl->assign('typeField', $row['type']);
     $this->tpl->display('tools/mcField.tpl');
 }
Example #3
0
 public function testAddTextarea()
 {
     $tpl = Di::getDefault()->get('template');
     $form = new Form('testForm');
     $arr = array('type' => 'textarea', 'label' => 'Test', 'name' => 'testTextarea', 'mandatory' => false);
     $form->addStatic($arr);
     $sm = $form->toSmarty();
     $tpl->assign('form', $sm['testTextarea']['html']);
     $printedResult = $tpl->fetch($this->formTpl);
     $this->assertContains('<div class="form-group "><div class="col-sm-2" style="text-align:right">' . '<label class="label-controller" for="testTextarea">Test</label></div>' . '<div class="col-sm-9">' . '<textarea id="testTextarea" ' . 'name="testTextarea" class="form-control " rows="3" placeholder="testTextarea" >' . ' </textarea></div></div>', $printedResult);
 }
Example #4
0
 /**
  * 
  * @param array $step
  * @param array $fName
  * @param array $value List of default values
  * @return array
  */
 private function buildFormComponents($step, &$fName, $values)
 {
     $myForm = new Form('pollerTemplate');
     foreach ($step as $field) {
         $fName[] = $field['name'];
         $attributes = array();
         if (isset($field['attributes'])) {
             $attributes = json_encode($field['attributes']);
         }
         $mandatory = 1;
         if (isset($field['require']) && false === $field['require']) {
             $mandatory = 0;
         }
         $formField = array('name' => $field['name'], 'label' => $field['label'], 'type' => $field['type'], 'mandatory' => $mandatory, 'attributes' => $attributes);
         $myForm->addStatic($formField);
     }
     $myForm->setDefaults($values);
     $formComponents = $myForm->toSmarty();
     unset($myForm);
     return $formComponents;
 }