__('Label settings'), 'id' => 'tab-label', 'href' => $url.'&tabSelected=label', 'img' => 'zoom.png', ],[ 'name' => __('General settings'), 'id' => 'tab-general', 'href' => $url.'&tabSelected=general', 'img' => 'pencil.png', ],[ 'name' => __('Specific settings'), 'id' => 'tab-specific', 'href' => $url.'&tabSelected=specific', 'img' => 'event_responses_col.png', ], ]; $result = html_print_tabs($tabs); // TODO:Change other place. $js = ''; return $result.$js; } /** * Generates a form for you <3 * * @return string HTML code for Form. * * @throws \Exception On error. */ public function loadForm() { // Load desired form based on item type. $values = []; $item = null; $item_json = get_parameter('item', null); $item = json_decode(io_safe_output($item_json)); $type = null; if (isset($item) === true) { $values = $item->itemProps; $values->tabSelected = get_parameter('tabSelected', 'label'); $type = $values->type; } hd($values->tabSelected, true); $itemClass = VisualConsole::getItemClass($type); if (!isset($itemClass)) { throw new \Exception(__('Item type not valid ['.$type.']')); } if (\method_exists($itemClass, 'getFormInputs') === false) { throw new \Exception(__('Item type has no getFormInputs method ['.$type.']')); } $form = [ 'action' => '#', 'method' => 'POST', 'id' => 'itemForm-'.$values->tabSelected, 'class' => 'discovery modal', ]; // Retrieve inputs. $inputs = $itemClass::getFormInputs($values); // Generate Form. $form = $this->printForm( [ 'form' => $form, 'inputs' => $inputs, ], true ); return $form; } /** * Process a form. * * @return string JSON response. */ public function processForm() { hd($_POST, true); // Inserted data in new item. // $data = json_decode($_REQUEST['item'])->itemProps; $vCId = \get_parameter('vCId', 0); $data['type'] = 0; $data['label'] = \get_parameter('label', 'vacio'); $class = VisualConsole::getItemClass((int) $data['type']); try { // Save the new item. $data['id_layout'] = $vCId; hd($data, true); $result = $class::save($data); } catch (\Throwable $th) { // There is no item in the database. // hd($th, true); echo false; return; } /* // Extract data new item inserted. try { $item = VisualConsole::getItemFromDB($result); } catch (Throwable $e) { // Bad params. http_response_code(400); return; } */ return json_encode(['error' => obhd($item)]); } }