';
+ if (!isset($input['extra'])) {
+ $output .= '
';
+ }
+
+ if (isset($input['extra'])) {
+ $output .= '
';
+ }
+ }
+
+ if ($input['arguments']['inline'] == 'true' && isset($input['extra'])) {
+ $output .= '
';
+ }
+
+ $output .= '
';
+ $output .= $input['label'];
+ $output .= '
';
+
+ if ($input['arguments']['inline'] == 'true' && isset($input['extra'])) {
+ $output .= '
';
+ }
+
+ if ($input['arguments']['inline'] == 'true' && !isset($input['extra'])) {
+ $output .= '
';
+ }
+
+ if ($input['arguments']['type'] == 'text' || $input['arguments']['type'] == 'text_extended') {
+ $output .= '
';
+ $output .= $this->printInput($input['arguments']);
+ $output .= '
';
+ } else if ($input['arguments']['inline'] == 'true') {
+ if (isset($input['extra'])) {
+ $output .= '
';
+ $output .= '
';
+ } else {
+ $output .= '
';
+ $output .= '
';
+ }
+
+ $output .= $this->printInput($input['arguments']);
+ $output .= '
';
+ $output .= '
';
+
+ if (isset($input['extra'])) {
+ $output .= '
';
+ }
+ } else {
+ $output .= $this->printInput($input['arguments']);
+ }
+
+ // Allow dynamic content.
+ $output .= $input['extra'];
+ $output .= '
';
+ } 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 .= '
';
+ $output .= '';
+ } else {
+ if ($input['arguments']['type'] != 'hidden') {
+ $output .= '
';
+ $output .= '';
+ $output .= $this->printInput($input['arguments']);
+ // Allow dynamic content.
+ $output .= $input['extra'];
+ $output .= '';
+ } else {
+ $output .= $this->printInput($input['arguments']);
+ // Allow dynamic content.
+ $output .= $input['extra'];
+ }
+ }
+
+ if ($return === false) {
+ echo $output;
+ }
+
+ return $output;
+ }
+
+
+ /**
+ * Print a form as a grid of inputs.
+ *
+ * @param array $data Definition of target form to be printed.
+ * @param boolean $return Return as string or direct output.
+ *
+ * @return string HTML code.
+ */
+ 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 = '
';
+ } else {
+ $output .= '
';
+ }
+
+ $first_block_printed = true;
+ }
+
+ $output .= '
';
+
+ 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'] : '';
+
+ $output .= '
';
+
+ foreach ($column['inputs'] as $input) {
+ if (is_array($input)) {
+ if ($input['arguments']['type'] != 'submit') {
+ $output .= $this->printBlockAsGrid($input, true);
+ } else {
+ $output_submit .= $this->printBlockAsGrid($input, true);
+ }
+ } else {
+ $output .= $input;
+ }
+ }
+
+ $output .= '
';
+ }
+
+ $output .= '
';
+ }
+ }
+
+ $output .= '
';
+
+ $output .= '
';
+ $output .= '';
+ $output .= '';
+ if ($rawjs) {
+ $output .= $rawjs;
+ }
+
+ if ($return === false) {
+ echo $output;
+ }
+
+ return $output_head.$output;
+
+ }
+
+
+ /**
+ * Print a form as a list.
+ *
+ * @param array $data Definition of target form to be printed.
+ * @param boolean $return Return as string or direct output.
+ *
+ * @return string HTML code.
+ */
+ 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 = '
';
+ $output .= '';
+ if ($rawjs) {
+ $output .= $rawjs;
+ }
+
+ if ($return === false) {
+ echo $output;
+ }
+
+ return $output_head.$output;
+
+ }
+
+
+ /**
+ * Dumps html string to output.
+ *
+ * @param mixed $html HTML content to be printed.
+ *
+ * @return void
+ */
+ public function render($html)
+ {
+ echo $html;
+ }
+
+
+}
diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js
index 33ab956a1f..7c42e2c38b 100644
--- a/pandora_console/include/javascript/pandora.js
+++ b/pandora_console/include/javascript/pandora.js
@@ -1879,7 +1879,13 @@ function load_modal(settings) {
var data = new FormData();
if (settings.extradata) {
settings.extradata.forEach(function(item) {
- if (item.value != undefined) data.append(item.name, item.value);
+ if (item.value != undefined) {
+ if (item.value instanceof Object || item.value instanceof Array) {
+ data.append(item.name, JSON.stringify(item.value));
+ } else {
+ data.append(item.name, item.value);
+ }
+ }
});
}
data.append("page", settings.onshow.page);
@@ -1946,8 +1952,16 @@ function load_modal(settings) {
var formdata = new FormData();
if (settings.extradata) {
settings.extradata.forEach(function(item) {
- if (item.value != undefined)
- formdata.append(item.name, item.value);
+ if (item.value != undefined) {
+ if (
+ item.value instanceof Object ||
+ item.value instanceof Array
+ ) {
+ formdata.append(item.name, JSON.stringify(item.value));
+ } else {
+ formdata.append(item.name, item.value);
+ }
+ }
});
}
formdata.append("page", settings.onsubmit.page);
diff --git a/pandora_console/include/javascript/pandora_visual_console.js b/pandora_console/include/javascript/pandora_visual_console.js
index 053555f20c..9708739bc0 100755
--- a/pandora_console/include/javascript/pandora_visual_console.js
+++ b/pandora_console/include/javascript/pandora_visual_console.js
@@ -160,8 +160,6 @@ function createVisualConsole(
e.nativeEvent.stopPropagation();
var item = e.item || {};
- var props = item.props || {};
-
var meta = item.meta || {};
if (meta.editMode && !meta.isUpdating) {
@@ -169,7 +167,6 @@ function createVisualConsole(
visualConsole,
asyncTaskManager,
baseUrl,
- props,
item
);
}
@@ -421,8 +418,7 @@ function createVisualConsole(
visualConsole,
asyncTaskManager,
baseUrl,
- { type: type },
- {}
+ { itemProps: { type: type } }
);
},
deleteItem: function(item) {
@@ -1407,14 +1403,49 @@ function copyVisualConsoleItem(baseUrl, vcId, vcItemId, callback) {
};
}
+/* Defined in operations/visual_console/view.php */
+/* global showMsg,cleanupDOM,$,load_modal */
function createOrUpdateVisualConsoleItem(
visualConsole,
asyncTaskManager,
baseUrl,
- props,
item
) {
+ var title = "Create item";
+ if (item.itemProps.id) {
+ title = "Update item";
+ }
+ // var props = item.props || {};
+ load_modal({
+ target: $("#modalVCItemForm"),
+ form: "itemForm",
+ url: baseUrl + "ajax.php",
+ ajax_callback: showMsg,
+ cleanup: cleanupDOM,
+ modal: {
+ title: title,
+ ok: "OK",
+ cancel: "Cancel"
+ },
+ extradata: [
+ {
+ name: "item",
+ value: item
+ }
+ ],
+ onshow: {
+ page: "include/rest-api/index",
+ method: "loadForm"
+ },
+ onsubmit: {
+ page: "include/rest-api/index",
+ method: "processForm"
+ }
+ });
+
+ /*
var formContainer = {};
+
if (props.id) {
// Item selection.
visualConsole.selectItem(props.id, true);
@@ -2081,6 +2112,8 @@ function createOrUpdateVisualConsoleItem(
]
});
// TODO: Add submit and reset button.
+
+ */
}
// TODO: Delete the functions below when you can.
diff --git a/pandora_console/include/rest-api/index.php b/pandora_console/include/rest-api/index.php
index 5f4b2b9eee..ee352f5100 100644
--- a/pandora_console/include/rest-api/index.php
+++ b/pandora_console/include/rest-api/index.php
@@ -10,6 +10,22 @@ if (!is_ajax()) {
require_once $config['homedir'].'/vendor/autoload.php';
use Models\VisualConsole\Container as VisualConsole;
+use Models\VisualConsole\View as Viewer;
+
+$method = get_parameter('method');
+if ($method) {
+ $viewer = new Viewer();
+ try {
+ if (method_exists($viewer, $method)) {
+ echo $viewer->{$method}();
+ }
+ } catch (Exception $e) {
+ echo json_encode(['error' => $e->msg()]);
+ return;
+ }
+
+ return;
+}
$visualConsoleId = (int) get_parameter('visualConsoleId');
$getVisualConsole = (bool) get_parameter('getVisualConsole');
diff --git a/pandora_console/include/rest-api/models/VisualConsole/Item.php b/pandora_console/include/rest-api/models/VisualConsole/Item.php
index 55b6387946..9f0c9f75bd 100644
--- a/pandora_console/include/rest-api/models/VisualConsole/Item.php
+++ b/pandora_console/include/rest-api/models/VisualConsole/Item.php
@@ -1887,4 +1887,43 @@ class Item extends CachedModel
}
+ /**
+ * Generates inputs for form (global, common).
+ *
+ * @param object $values Default values.
+ *
+ * @return array Of inputs.
+ */
+ public static function getFormInputs(object $values): array
+ {
+ $inputs = [];
+
+ // Label.
+ $inputs[] = [
+ 'label' => __('Label'),
+ 'id' => 'div-label',
+ 'arguments' => [
+ 'name' => 'Label',
+ 'type' => 'text',
+ 'value' => $values->label,
+ 'return' => true,
+ ],
+ ];
+
+ // Position.
+ $inputs[] = [
+ 'label' => __('Position'),
+ 'id' => 'div-label',
+ 'arguments' => [
+ 'name' => 'position-x',
+ 'type' => 'text',
+ 'value' => $values->posX,
+ 'return' => true,
+ ],
+ ];
+
+ return $inputs;
+ }
+
+
}
diff --git a/pandora_console/include/rest-api/models/VisualConsole/Items/StaticGraph.php b/pandora_console/include/rest-api/models/VisualConsole/Items/StaticGraph.php
index 1e5be69603..87c23794c6 100644
--- a/pandora_console/include/rest-api/models/VisualConsole/Items/StaticGraph.php
+++ b/pandora_console/include/rest-api/models/VisualConsole/Items/StaticGraph.php
@@ -241,4 +241,26 @@ final class StaticGraph extends Item
}
+ /**
+ * Generates inputs for form (specific).
+ *
+ * @param object $values Default values.
+ *
+ * @return array Of inputs.
+ *
+ * @throws Exception On error.
+ */
+ public static function getFormInputs(object $values): array
+ {
+ // Retrieve global - common inputs.
+ $inputs = Item::getFormInputs($values);
+
+ if (is_array($inputs) !== true) {
+ throw new Exception('[StaticGraph]::getFormInputs parent class return is not an array');
+ }
+
+ return $inputs;
+ }
+
+
}
diff --git a/pandora_console/include/rest-api/models/VisualConsole/View.php b/pandora_console/include/rest-api/models/VisualConsole/View.php
new file mode 100644
index 0000000000..973744d098
--- /dev/null
+++ b/pandora_console/include/rest-api/models/VisualConsole/View.php
@@ -0,0 +1,105 @@
+itemProps;
+ $type = $values->type;
+ }
+
+ $itemClass = VisualConsole::getItemClass($type);
+
+ if (!isset($itemClass)) {
+ throw new Exception(__('Item type not valid ['.$type.']'));
+ }
+
+ $form = [
+ 'action' => '#',
+ 'id' => 'modal_form',
+ 'onsubmit' => 'return false;',
+ 'class' => 'discovery modal',
+ 'extra' => 'autocomplete="new-password"',
+ ];
+
+ // Retrieve inputs.
+ $inputs = $itemClass::getFormInputs($values);
+
+ // Generate Form.
+ return $this->printForm(
+ [
+ 'form' => $form,
+ 'inputs' => $inputs,
+ ],
+ true
+ );
+
+ }
+
+
+ /**
+ * Process a form.
+ *
+ * @return string JSON response.
+ */
+ public function processForm()
+ {
+ $item = json_decode($_REQUEST['item'])->itemProps;
+ return json_encode(['error' => obhd($item)]);
+ }
+
+
+}
diff --git a/pandora_console/include/styles/form.css b/pandora_console/include/styles/form.css
new file mode 100644
index 0000000000..374b8525c0
--- /dev/null
+++ b/pandora_console/include/styles/form.css
@@ -0,0 +1,331 @@
+/*
+ * Discovery css global
+ */
+
+ul.bigbuttonlist {
+ min-height: 200px;
+}
+
+li.discovery {
+ display: inline-block;
+ float: left;
+ width: 250px;
+ margin: 15px;
+ padding-bottom: 50px;
+}
+
+li.discovery > a {
+ text-decoration: none;
+ color: #333;
+}
+li.discovery > a:hover {
+ color: #000;
+}
+
+li.discovery img {
+ height: 90px;
+}
+
+li.discovery > a label {
+ cursor: pointer;
+}
+
+div.data_container > label {
+ font-family: "lato-bolder", "Open Sans", sans-serif;
+ font-weight: lighter;
+}
+
+div.data_container {
+ width: 100%;
+ height: 100%;
+ text-align: center;
+ padding-top: 30px;
+ padding-bottom: 30px;
+}
+
+div.data_container:hover {
+ box-shadow: 2px 2px 10px #ddd;
+}
+
+/*
+ * TODO: This may be at hostdevices.css
+ */
+.texto {
+ height: auto;
+ text-align: center;
+}
+h1.wizard {
+ padding: 0;
+ margin: 0;
+}
+h1.wizard a {
+ margin-left: -20px;
+}
+h1.wizard a:hover {
+ color: #fff;
+}
+#text_wizard {
+ font-weight: bolder;
+ text-decoration: none;
+ font-size: 24px;
+}
+div.arrow_box {
+ display: inline-block;
+ position: relative;
+ color: #888;
+ padding: 1.3em;
+ margin-left: 20px;
+ margin-bottom: 10px;
+ padding-left: 3em;
+}
+
+.arrow_box.selected {
+ background: #424242;
+ color: #ccc;
+}
+
+.arrow_box:after {
+ left: 0%;
+ border-left-color: white;
+ border-width: 20px;
+ margin-top: -20px;
+}
+
+div.arrow_box:before {
+ left: 100%;
+ border-left-color: #ccc;
+ border-width: 20px;
+ margin-top: -20px;
+}
+.arrow_box.selected:before {
+ border-left-color: #424242;
+}
+
+.arrow_box.selected:hover {
+ color: #fff;
+}
+.arrow_box:hover {
+ color: #000;
+}
+
+/*
+ * Breadcrum
+ */
+
+#menu_tab_frame_view_bc {
+ display: flex;
+ justify-content: space-between;
+ border-bottom: 2px solid #82b92e;
+ max-height: 70px;
+ min-height: 55px;
+ width: 100%;
+ padding-right: 0px;
+ margin-left: 0px;
+ margin-bottom: 20px;
+ height: 55px;
+ box-sizing: border-box;
+ background-color: #fafafa;
+ border-top-right-radius: 7px;
+ border-top-left-radius: 7px;
+ box-shadow: 0px 0px 2px rgba(0, 0, 0, 0.1);
+}
+
+#menu_tab_frame_view_bc .breadcrumbs_container {
+ align-self: flex-start;
+}
+
+.breadcrumbs_container {
+ padding-top: 4px;
+ text-indent: 0.25em;
+ padding-left: 2.5em;
+}
+
+.breadcrumb_link {
+ color: #848484;
+ font-size: 10pt;
+ font-family: "lato-bolder", "Open Sans", sans-serif;
+ text-decoration: none;
+}
+
+span.breadcrumb_link {
+ color: #d0d0d0;
+ font-size: 12pt;
+}
+
+.breadcrumb_link.selected {
+ color: #95b750;
+}
+
+.breadcrumb_link.selected:hover {
+ color: #95b750;
+}
+.breadcrumb_link:hover {
+ color: #95b750;
+}
+
+/*
+ * Discovery forms structure
+ */
+
+form.discovery * {
+ font-size: 10pt;
+}
+
+form.discovery .label_select b {
+ font-family: "lato", "Open Sans", sans-serif;
+ font-weight: bolder;
+}
+
+.edit_discovery_info {
+ display: flex;
+ align-items: flex-start;
+ padding-top: 25px;
+}
+
+.edit_discovery_input {
+ align-items: center;
+ margin-bottom: 25px;
+}
+
+/*
+ * Discovery text inputs
+ */
+
+.discovery_label_hint {
+ display: flex;
+}
+
+label {
+ color: #343434;
+ font-weight: bold;
+}
+
+.discovery_full_width_input {
+ width: 100%;
+}
+
+li > input[type="text"],
+li > input[type="password"],
+.discovery_text_input > input[type="password"],
+.discovery_text_input > input[type="text"],
+#interval_manual > input[type="text"] {
+ background-color: transparent;
+ border: none;
+ border-radius: 0;
+ border-bottom: 1px solid #ccc;
+ font-family: "lato-bolder", "Open Sans", sans-serif;
+ font-weight: lighter;
+ padding: 0px 0px 2px 0px;
+ box-sizing: border-box;
+ margin-bottom: 4px;
+}
+
+#interval_manual > input[type="text"] {
+ width: 50px;
+ margin-left: 10px;
+ margin-right: 10px;
+}
+
+.discovery_list_input {
+ width: 100%;
+ border: 1px solid #cbcbcb;
+ overflow-y: auto;
+}
+
+.discovery_list_input option {
+ text-align: left;
+}
+
+.discovery_list_input option:checked {
+ background: #1aab8e -webkit-linear-gradient(bottom, #7db742 0%, #7db742 100%);
+ color: #fff;
+}
+
+.discovery_textarea_input {
+ background-color: #fbfbfb;
+ padding-left: 10px;
+ width: 100%;
+ height: 100px;
+ max-height: 100px;
+ max-width: 100%;
+ -webkit-box-sizing: border-box;
+ -moz-box-sizing: border-box;
+ box-sizing: border-box;
+ resize: none;
+}
+
+a.tip {
+ margin-left: 8px;
+}
+
+.inline_switch > label {
+ float: right;
+}
+
+.discovery_interval_select_width {
+ width: 90%;
+}
+
+a.ext_link {
+ margin-left: 1em;
+ font-size: 8pt;
+}
+
+/*
+ * Discovery > Wizard css global style
+ */
+
+ul.wizard {
+}
+
+ul.wizard li {
+ padding-bottom: 10px;
+ padding-top: 10px;
+}
+
+ul.wizard li > label:not(.p-switch) {
+ width: 250px;
+ vertical-align: top;
+ display: inline-block;
+}
+
+ul.wizard li > textarea {
+ width: 600px;
+ height: 15em;
+ display: inline-block;
+ font-family: monospace;
+}
+
+.hidden {
+ display: none;
+}
+
+ul.wizard li > label:not(.p-switch) {
+ width: auto;
+}
+
+form.top-action-buttons ul.wizard {
+ display: flex;
+ flex-direction: row;
+}
+
+ul.wizard li {
+ margin-right: 1em;
+}
+
+form.modal ul.wizard li {
+ display: flex;
+ flex-direction: row;
+ width: 90%;
+ margin: 0.5em auto;
+ justify-items: center;
+}
+
+form.modal ul.wizard li * {
+ flex: 1;
+}
+
+ul.wizard li.flex-indep {
+ flex: 1;
+ margin: 0;
+}
diff --git a/pandora_console/operation/visual_console/view.php b/pandora_console/operation/visual_console/view.php
index 23bfafc777..2d80441ca2 100644
--- a/pandora_console/operation/visual_console/view.php
+++ b/pandora_console/operation/visual_console/view.php
@@ -387,7 +387,11 @@ $visualConsoleItems = VisualConsole::getItemsFromDB(
$visualConsoleId,
$aclUserGroups
);
+ui_require_css_file('modal');
+ui_require_css_file('form');
?>
+
+