Merge branch 'ent-3661-poder-elegir-dataserver-en-vmware-a-traves-de-discovery' into 'develop'

Ent 3661 poder elegir dataserver en vmware a traves de discovery

See merge request artica/pandorafms!3683
This commit is contained in:
Daniel Rodriguez 2021-01-11 15:43:18 +01:00
commit ed50126b1b
4 changed files with 68 additions and 499 deletions

View File

@ -27,7 +27,12 @@
*/
// Begin.
global $config;
require_once $config['homedir'].'/vendor/autoload.php';
require_once $config['homedir'].'/include/class/HTML.class.php';
use \HTML;
/**
* Global Wizard generic class. Needs to be inherited.
@ -423,281 +428,6 @@ class Wizard
}
/**
* Print a block of inputs.
* Example, using direct to 'anidate' inputs directly to wrapper:
* [
* 'wrapper' => 'div',
* 'block_id' => 'example_id',
* 'class' => 'your class',
* 'direct' => 1,
* 'block_content' => [
* [
* 'arguments' => [
* 'label' => __('Sugesstion'),
* 'type' => 'button',
* 'attributes' => 'class="sub ok btn_sug"',
* 'name' => 'option_1',
* 'id' => 'option_1',
* 'script' => 'change_option1()',
* ],
* ],
* [
* 'arguments' => [
* 'label' => __('Something is not quite right'),
* 'type' => 'button',
* 'attributes' => 'class="sub ok btn_something"',
* 'name' => 'option_2',
* 'id' => 'option_2',
* 'script' => 'change_option2()',
* ],
* ],
* ],
* ].
*
* @param array $input Definition of target block to be printed.
* @param boolean $return Return as string or direct output.
* @param boolean $direct Avoid encapsulation if input print is direct.
*
* @return string HTML content.
*/
public function printBlock(
array $input,
bool $return=false,
bool $direct=false
) {
$output = '';
if ($input['hidden'] == 1) {
$class = ' hidden';
} else {
$class = '';
}
if (isset($input['class']) === true) {
$class = $input['class'].$class;
}
if (is_array($input['block_content']) === true) {
$direct = (bool) $input['direct'];
$toggle = (bool) $input['toggle'];
// Print independent block of inputs.
$output .= '<li id="li-'.$input['block_id'].'" class="'.$class.'">';
if ($input['wrapper']) {
$output .= '<'.$input['wrapper'].' id="'.$input['block_id'].'" class="'.$class.'">';
}
if (!$direct) {
// Avoid encapsulation if input is direct => 1.
$output .= '<ul class="wizard '.$input['block_class'].'">';
}
$html = '';
foreach ($input['block_content'] as $in) {
$html .= $this->printBlock(
$in,
$return,
(bool) $direct
);
}
if ($toggle === true) {
$output .= ui_print_toggle(
[
'name' => (isset($input['toggle_name']) ? $input['toggle_name'] : 'toggle_'.uniqid()),
'content' => $html,
'title' => $input['toggle_title'],
'id' => $input['toggle_id'],
'hidden_default' => $input['toggle_hidden_default'],
'return' => (isset($input['toggle_return']) ? $input['toggle_return'] : true),
'toggle_class' => $input['toggle_toggle_class'],
'main_class' => $input['toggle_main_class'],
'container_class' => $input['toggle_container_class'],
'img_a' => $input['toggle_img_a'],
'img_b' => $input['toggle_img_b'],
'clean' => (isset($input['toggle_clean']) ? $input['toggle_clean'] : true),
]
);
} else {
$output .= $html;
}
// Close block.
if (!$direct) {
$output .= '</ul>';
}
if ($input['wrapper']) {
$output .= '</'.$input['wrapper'].'>';
}
$output .= '</li>';
} else {
if ($input['arguments']['type'] != 'hidden'
&& $input['arguments']['type'] != 'hidden_extended'
) {
if (!$direct) {
$output .= '<li id="'.$input['id'].'" class="'.$class.'">';
}
$output .= '<label>'.$input['label'].'</label>';
$output .= $this->printInput($input['arguments']);
// Allow dynamic content.
$output .= $input['extra'];
if (!$direct) {
$output .= '</li>';
}
} else {
$output .= $this->printInput($input['arguments']);
// Allow dynamic content.
$output .= $input['extra'];
}
}
if ($return === false) {
echo $output;
}
return $output;
}
/**
* Print a block of inputs with grid format.
*
* @param array $input Definition of target block to be printed.
* @param boolean $return Return as string or direct output.
*
* @return string HTML content.
*/
public function printBlockAsGrid(array $input, bool $return=false)
{
$output = '';
if ($input['hidden'] == 1) {
$class = ' hidden';
} else {
$class = '';
}
if (isset($input['class']) === true) {
$class = $input['class'].$class;
}
if (is_array($input['block_content']) === true) {
// Print independent block of inputs.
$output .= '<div id="'.$input['block_id'].'" class="wizard '.$class.'">';
$output .= '<ul class="wizard '.$input['block_class'].'">';
foreach ($input['block_content'] as $input) {
$output .= $this->printBlockAsGrid($input, $return);
}
$output .= '</ul></div>';
} else {
if ($input['arguments']['type'] != 'hidden'
&& $input['arguments']['type'] != 'hidden_extended'
) {
$id = '';
if ($input['id']) {
$id = $input['id'];
}
if ($input['arguments']['inline'] != 'true') {
$output .= '<div id="'.$id.'" class="std_input '.$class.'">';
} else {
$output .= '<div id="'.$id.'" class="inline_input '.$class.'">';
}
$output .= '<div class="label_select">';
$output .= $input['label'];
$output .= '</div>';
if ($input['arguments']['type'] == 'text' || $input['arguments']['type'] == 'text_extended') {
$output .= '<div class="discovery_text_input">';
$output .= $this->printInput($input['arguments']);
$output .= '</div>';
} else if ($input['arguments']['inline'] == 'true') {
$output .= '<div class="discovery_inline_input">';
$output .= $this->printInput($input['arguments']);
$output .= '</div>';
} else {
$output .= $this->printInput($input['arguments']);
}
// Allow dynamic content.
$output .= $input['extra'];
$output .= '</div>';
} else {
$output .= $this->printInput($input['arguments']);
// Allow dynamic content.
$output .= $input['extra'];
}
}
if ($return === false) {
echo $output;
}
return $output;
}
/**
* Print a block of inputs as a list element.
*
* @param array $input Definition of target block to be printed.
* @param boolean $return Return as string or direct output.
*
* @return string HTML content.
*/
public function printBlockAsList(array $input, bool $return=false)
{
$output = '';
if ($input['hidden'] == 1) {
$class = ' hidden';
} else {
$class = '';
}
if (isset($input['class']) === true) {
$class = $input['class'].$class;
}
if (is_array($input['block_content']) === true) {
// Print independent block of inputs.
$output .= '<li id="'.$input['block_id'].'" class="'.$class.'">';
$output .= '<ul class="wizard '.$input['block_class'].'">';
foreach ($input['block_content'] as $input) {
$output .= $this->printBlockAsList($input, $return);
}
$output .= '</ul></li>';
} else {
if ($input['arguments']['type'] != 'hidden'
&& $input['arguments']['type'] != 'hidden_extended'
) {
$output .= '<li id="'.$input['id'].'" class="'.$class.'">';
$output .= '<label>'.$input['label'].'</label>';
$output .= $this->printInput($input['arguments']);
// Allow dynamic content.
$output .= $input['extra'];
$output .= '</li>';
} else {
$output .= $this->printInput($input['arguments']);
// Allow dynamic content.
$output .= $input['extra'];
}
}
if ($return === false) {
echo $output;
}
return $output;
}
/**
* Print a form.
*
@ -712,67 +442,7 @@ class Wizard
bool $return=false,
bool $print_white_box=false
) {
$form = $data['form'];
$inputs = $data['inputs'];
$js = $data['js'];
$rawjs = $data['js_block'];
$cb_function = $data['cb_function'];
$cb_args = $data['cb_args'];
$output_head = '<form id="'.$form['id'].'" class="discovery '.$form['class'].'" onsubmit="'.$form['onsubmit'].'" enctype="'.$form['enctype'].'" action="'.$form['action'].'" method="'.$form['method'];
$output_head .= '" '.$form['extra'].'>';
if ($return === false) {
echo $output_head;
}
try {
if (isset($cb_function) === true) {
call_user_func_array(
$cb_function,
(isset($cb_args) === true) ? $cb_args : []
);
}
} catch (Exception $e) {
error_log('Error executing wizard callback: ', $e->getMessage());
}
$output_submit = '';
$output = '';
if ($print_white_box === true) {
$output .= '<div class="white_box">';
}
$output .= '<ul class="wizard">';
foreach ($inputs as $input) {
if ($input['arguments']['type'] != 'submit') {
$output .= $this->printBlock($input, true);
} else {
$output_submit .= $this->printBlock($input, true);
}
}
$output .= '</ul>';
if ($print_white_box === true) {
$output .= '</div>';
}
$output .= '<ul class="wizard">'.$output_submit.'</ul>';
$output .= '</form>';
$output .= '<script>'.$js.'</script>';
if ($rawjs) {
$output .= $rawjs;
}
if ($return === false) {
echo $output;
}
return $output_head.$output;
return HTML::printForm($data, $return, $print_white_box);
}
@ -786,112 +456,7 @@ class Wizard
*/
public function printFormAsGrid(array $data, bool $return=false)
{
$form = $data['form'];
$rows = $data['rows'];
$js = $data['js'];
$rawjs = $data['js_block'];
$cb_function = $data['cb_function'];
$cb_args = $data['cb_args'];
$output_head = '<form class="discovery wizard" onsubmit="'.$form['onsubmit'].'" enctype="'.$form['enctype'].'" action="'.$form['action'].'" method="'.$form['method'];
$output_head .= '" '.$form['extra'].'>';
if ($return === false) {
echo $output_head;
}
try {
if (isset($cb_function) === true) {
call_user_func_array(
$cb_function,
(isset($cb_args) === true) ? $cb_args : []
);
}
} catch (Exception $e) {
error_log('Error executing wizard callback: ', $e->getMessage());
}
$output_submit = '';
$output = '';
$first_block_printed = false;
if (is_array($rows)) {
foreach ($rows as $row) {
if ($row['new_form_block'] == true) {
if ($first_block_printed === true) {
// If first form block has been placed, then close it before starting a new one.
$output .= '</div>';
$output .= '<div class="white_box" style="margin-top: 30px;">';
} else {
$output .= '<div class="white_box">';
}
$first_block_printed = true;
}
$row_output = '<div class="edit_discovery_info '.$row['class'].'" style="'.$row['style'].'">';
foreach ($row['columns'] as $column) {
$width = isset($column['width']) ? 'width: '.$column['width'].';' : 'width: 100%;';
$padding_left = isset($column['padding-left']) ? 'padding-left: '.$column['padding-left'].';' : 'padding-left: 0;';
$padding_right = isset($column['padding-right']) ? 'padding-right: '.$column['padding-right'].';' : 'padding-right: 0;';
$extra_styles = isset($column['style']) ? $column['style'] : '';
$class = isset($column['class']) ? $column['class'] : '';
$row_output .= '<div class="'.$class.'" ';
$row_output .= ' style="'.$width.$padding_left.$padding_right;
$row_output .= $extra_styles.'">';
foreach ($column['inputs'] as $input) {
if (is_array($input)) {
if ($input['arguments']['type'] != 'submit') {
$row_output .= $this->printBlockAsGrid($input, true);
} else {
$output_submit .= $this->printBlockAsGrid($input, true);
}
} else {
$row_output .= $input;
}
}
$row_output .= '</div>';
}
if (isset($row['toggle'])) {
$output .= ui_print_toggle(
[
'content' => $row_output,
'name' => $row['toggle_label'],
'hidden_default' => ! (bool) $row['toggle'],
'return' => true,
]
);
} else {
$output .= $row_output;
}
$output .= '</div>';
}
}
$output .= '</div>';
$output .= '<ul class="wizard">'.$output_submit.'</ul>';
$output .= '</form>';
$output .= '<script>'.$js.'</script>';
if ($rawjs) {
$output .= $rawjs;
}
if ($return === false) {
echo $output;
}
return $output_head.$output;
return HTML::printFormAsGrid($data, $return);
}
@ -905,57 +470,7 @@ class Wizard
*/
public function printFormAsList(array $data, bool $return=false)
{
$form = $data['form'];
$inputs = $data['inputs'];
$js = $data['js'];
$rawjs = $data['js_block'];
$cb_function = $data['cb_function'];
$cb_args = $data['cb_args'];
$output_head = '<form class="discovery" onsubmit="'.$form['onsubmit'].'" enctype="'.$form['enctype'].'" action="'.$form['action'].'" method="'.$form['method'];
$output_head .= '" '.$form['extra'].'>';
if ($return === false) {
echo $output_head;
}
try {
if (isset($cb_function) === true) {
call_user_func_array(
$cb_function,
(isset($cb_args) === true) ? $cb_args : []
);
}
} catch (Exception $e) {
error_log('Error executing wizard callback: ', $e->getMessage());
}
$output = '<div class="white_box">';
$output .= '<ul class="wizard">';
foreach ($inputs as $input) {
if ($input['arguments']['type'] != 'submit') {
$output .= $this->printBlockAsList($input, true);
} else {
$output_submit .= $this->printBlockAsList($input, true);
}
}
$output .= '</ul>';
$output .= '</div>';
$output .= '<ul class="wizard">'.$output_submit.'</ul>';
$output .= '</form>';
$output .= '<script>'.$js.'</script>';
if ($rawjs) {
$output .= $rawjs;
}
if ($return === false) {
echo $output;
}
return $output_head.$output;
return HTML::printFormAsList($data, $return);
}

View File

@ -610,9 +610,15 @@ class HTML
}
if (is_array($input['block_content']) === true) {
if (empty($input['label']) === false) {
$output .= '<div class="label_select">';
$output .= $input['label'];
$output .= '</div>';
}
// Print independent block of inputs.
$output .= '<li id="'.$input['block_id'].'" class="'.$class.'">';
$output .= '<ul class="wizard '.$input['block_class'].'">';
$output .= '<li id="'.$input['block_id'].'" class="'.$class.'">';
foreach ($input['block_content'] as $input) {
$output .= self::printBlockAsGrid($input, $return);
}
@ -717,7 +723,7 @@ class HTML
if (is_array($input['block_content']) === true) {
// Print independent block of inputs.
$output .= '<li id="'.$input['block_id'].'" class="'.$class.'">';
$output .= '<ul class="wizard '.$input['block_class'].'">';
$output .= '<ul class="wizard list '.$input['block_class'].'">';
foreach ($input['block_content'] as $input) {
$output .= self::printBlockAsList($input, $return);
}
@ -908,10 +914,34 @@ class HTML
$output .= ' style="'.$width.$padding_left.$padding_right;
$output .= $extra_styles.'">';
// Toggle option.
foreach ($column['inputs'] as $input) {
if (is_array($input)) {
if ($input['arguments']['type'] != 'submit') {
if ($input['toggle'] === true) {
$output .= ui_print_toggle(
[
'name' => (isset($input['toggle_name']) ? $input['toggle_name'] : 'toggle_'.uniqid()),
'title' => $input['toggle_title'],
'id' => $input['toggle_id'],
'hidden_default' => $input['toggle_hidden_default'],
'content' => self::printBlockAsGrid(
$input,
true
),
'return' => true,
'name' => (isset($input['toggle_name']) ? $input['toggle_name'] : 'toggle_'.uniqid()),
'toggle_class' => $input['toggle_toggle_class'],
'main_class' => $input['toggle_main_class'],
'container_class' => $input['toggle_container_class'],
'img_a' => $input['toggle_img_a'],
'img_b' => $input['toggle_img_b'],
'clean' => (isset($input['toggle_clean']) ? $input['toggle_clean'] : true),
]
);
} else {
$output .= self::printBlockAsGrid($input, true);
}
} else {
$output_submit .= self::printBlockAsGrid($input, true);
}

View File

@ -3808,7 +3808,11 @@ function ui_toggle(
if ($clean === false) {
$header_class = 'white_table_graph_header';
} else {
if ($main_class == 'box-shadow white_table_graph') {
// Default value, clean class.
$main_class = '';
}
$container_class = 'white-box-content-clean';
}
@ -3837,14 +3841,14 @@ function ui_toggle(
$original,
true,
[
'style' => 'object-fit: contain; float:right; margin-right:10px;',
'class' => 'float-left',
'style' => 'object-fit: contain; margin-right:10px;',
'title' => $title,
'id' => 'image_'.$uniqid,
]
);
}
$output .= '&nbsp;&nbsp';
$output .= '<b>'.$name.'</b>';
} else {
$output .= $name;

View File

@ -11,8 +11,24 @@ ul.wizard {
ul.wizard li {
padding-bottom: 10px;
padding-top: 10px;
}
ul.wizard.inline li {
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-start;
}
.list .edit_discovery_input {
display: flex;
align-items: center;
flex-direction: row;
justify-content: space-between;
}
.list .label_select {
margin-bottom: 0;
}
ul.wizard li > label:not(.p-switch) {
@ -32,6 +48,10 @@ ul.wizard li > textarea {
display: none;
}
.indented {
margin-left: 1em;
}
.wizard .indented {
margin-left: 1em;
}