Merge remote-tracking branch 'origin/ent-4774-welcome-to-pandorafms' into ent-EDF

Conflicts:
	pandora_console/include/javascript/pandora.js

	modified:   pandora_console/general/register.php
	modified:   pandora_console/godmode/agentes/configurar_agente.php
	modified:   pandora_console/godmode/agentes/module_manager_editor.php
	new file:   pandora_console/include/ajax/welcome_window.php
	new file:   pandora_console/include/class/WelcomeWindow.class.php
	modified:   pandora_console/include/constants.php
	modified:   pandora_console/include/functions_config.php
	modified:   pandora_console/include/javascript/pandora.js
	new file:   pandora_console/include/styles/new_installation_welcome_window.css
This commit is contained in:
fbsanchez 2019-10-30 16:56:44 +01:00
commit 72b1fb2b16
9 changed files with 1113 additions and 90 deletions

View File

@ -30,6 +30,7 @@
global $config;
require_once $config['homedir'].'/include/functions_update_manager.php';
require_once $config['homedir'].'/include/class/WelcomeWindow.class.php';
if (is_ajax()) {
@ -122,6 +123,8 @@ if (is_ajax()) {
exit();
}
ui_require_css_file('register');
$initial = isset($config['initial_wizard']) !== true
@ -170,6 +173,16 @@ if (!$config['disabled_newsletter']) {
}
}
$welcome = !$registration && !$show_newsletter && !$initial;
try {
$welcome_window = new WelcomeWindow($welcome);
if ($welcome_window !== null) {
$welcome_window->run();
}
} catch (Exception $e) {
$welcome = false;
}
$newsletter = null;
?>

View File

@ -2278,6 +2278,10 @@ if ($updateGIS) {
// -----------------------------------
// Load page depending on tab selected
// -----------------------------------
if ($_SESSION['create_module'] && $config['welcome_state'] == 1) {
$edit_module = true;
}
switch ($tab) {
case 'main':
include 'agent_manager.php';

View File

@ -391,6 +391,9 @@ if ($id_agent_module) {
} else {
if (isset($moduletype) === false) {
$moduletype = (string) get_parameter('moduletype');
if ($_SESSION['create_module'] && $config['welcome_state'] == 1) {
$moduletype = 'networkserver';
}
// Clean up specific network modules fields.
$name = '';

View File

@ -0,0 +1,62 @@
<?php
/**
* Welcome window ajax controller.
*
* @category WelcomeWindow
* @package Pandora FMS
* @subpackage New Installation Welcome Window
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
* Please see http://pandorafms.org for full contribution list
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation for version 2.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* ============================================================================
*/
// Begin.
global $config;
require_once $config['homedir'].'/include/class/WelcomeWindow.class.php';
if (is_ajax() === false) {
exit;
}
$ajaxPage = 'include/ajax/welcome_window';
// Control call flow.
try {
// User access and validation is being processed on class constructor.
$welcome_actions = new WelcomeWindow(true, $ajaxPage);
} catch (Exception $e) {
exit;
}
// Ajax controller.
$method = get_parameter('method', '');
if (method_exists($welcome_actions, $method) === true) {
if ($welcome_actions->ajaxMethod($method) === true) {
$welcome_actions->{$method}();
} else {
$welcome_actions->error('Unavailable method.');
}
} else {
$welcome_actions->error('Method not found. ['.$method.']');
}
// Stop any execution.
exit;

View File

@ -0,0 +1,767 @@
<?php
/**
* Welcome to Pandora FMS feature.
*
* @category Class
* @package Pandora FMS
* @subpackage New Installation Welcome Window
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
* Please see http://pandorafms.org for full contribution list
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation for version 2.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* ============================================================================
*/
// Begin.
global $config;
require_once $config['homedir'].'/godmode/wizards/Wizard.main.php';
/**
* Class WelcomeWindow.
*/
class WelcomeWindow extends Wizard
{
/**
* Allowed methods to be called using AJAX request.
*
* @var array
*/
public $AJAXMethods = [
'loadWelcomeWindow',
'cancelWelcome',
];
/**
* Url of controller.
*
* @var string
*/
public $ajaxController;
/**
* Current step.
*
* @var integer
*/
public $step;
/**
* Current agent (created example).
*
* @var integer
*/
public $agent;
/**
* Generates a JSON error.
*
* @param string $msg Error message.
*
* @return void
*/
public function error($msg)
{
echo json_encode(
['error' => $msg]
);
}
/**
* Checks if target method is available to be called using AJAX.
*
* @param string $method Target method.
*
* @return boolean True allowed, false not.
*/
public function ajaxMethod($method)
{
global $config;
// Check access.
check_login();
return in_array($method, $this->AJAXMethods);
}
/**
* Constructor.
*
* @param boolean $must_run Must run or not.
* @param string $ajax_controller Controller.
*
* @return object
* @throws Exception On error.
*/
public function __construct(
bool $must_run=false,
$ajax_controller='include/ajax/welcome_window'
) {
$this->ajaxController = $ajax_controller;
if ($this->initialize($must_run) !== true) {
throw new Exception('Must not be shown');
}
return $this;
}
/**
* Main method.
*
* @return void
*/
public function run()
{
ui_require_css_file('new_installation_welcome_window');
echo '<div id="welcome_modal_window" style="display: none"; >';
?>
<script type="text/javascript">
load_modal({
target: $('#welcome_modal_window'),
url: '<?php echo ui_get_full_url('ajax.php', false, false, false); ?>',
modal: {
title: "<?php echo __('Welcome to Pandora FMS'); ?>",
cancel: '<?php echo __('Cancel'); ?>',
},
onshow: {
page: '<?php echo $this->ajaxController; ?>',
method: 'loadWelcomeWindow',
},
oncancel: {
page: '<?php echo $this->ajaxController; ?>',
title: "<?php echo __('Cancel Configuration Window'); ?>",
method: 'cancelWelcome',
confirm: function (fn) {
confirmDialog({
title: '<?php echo __('Are you sure?'); ?>',
message: '<?php echo __('Are you sure you want to cancel this tutorial?'); ?>',
ok: '<?php echo __('OK'); ?>',
cancel: '<?php echo __('Cancel'); ?>',
onAccept: function() {
// Continue execution.
fn();
}
})
}
}
});
</script>
<?php
echo '</div>';
}
/**
* Method to cancel welcome modal window.
*
* @return void
*/
public function cancelWelcome()
{
// Config update value.
$this->setStep(WELCOME_FINISHED);
}
/**
* Return current step.
*
* @return integer Step.
*/
public function getStep(): int
{
global $config;
$this->step = $config['welcome_state'];
return $this->step;
}
/**
* Sets current step.
*
* @param integer $step Current step.
*
* @return void
*/
public function setStep(int $step)
{
$this->step = $step;
config_update_value('welcome_state', $step);
}
/**
* Retrieve current welcome agent id.
*
* @return integer Agent id (created).
*/
public function getWelcomeAgent()
{
global $config;
return $config['welcome_id_agent'];
}
/**
* Saves current welcome agent (latest created).
*
* @param integer $id_agent Agent id.
*
* @return void
*/
public function setWelcomeAgent(int $id_agent)
{
config_update_value('welcome_id_agent', $id_agent);
}
/**
* Loads a welcome window form
*
* @return string HTML code for form.
*
* @return void Runs loadWelcomeWindow (AJAX).
*/
public function loadWelcomeWindow()
{
global $config;
$btn_configure_mail_class = '';
$btn_create_agent_class = '';
$btn_create_module_class = '';
$btn_create_alert_class = '';
$btn_create_discovery_class = '';
switch ($this->step) {
case W_CREATE_AGENT:
$btn_configure_mail_class = ' completed';
$btn_create_agent_class = ' pending';
break;
case W_CREATE_MODULE:
$btn_configure_mail_class = ' completed';
$btn_create_agent_class = ' completed';
$btn_create_module_class = ' pending';
break;
case W_CREATE_ALERT:
$btn_configure_mail_class = ' completed';
$btn_create_agent_class = ' completed';
$btn_create_module_class = ' completed';
$btn_create_alert_class = ' pending';
break;
case W_CREATE_TASK:
$btn_configure_mail_class = ' completed';
$btn_create_agent_class = ' completed';
$btn_create_module_class = ' completed';
$btn_create_alert_class = ' completed';
$btn_create_discovery_class = ' pending';
break;
case WELCOME_FINISHED:
// Nothing left to do.
$btn_configure_mail_class = ' completed';
$btn_create_agent_class = ' completed';
$btn_create_module_class = ' completed';
$btn_create_alert_class = ' completed';
$btn_create_discovery_class = ' completed';
break;
default:
case W_CONFIGURE_MAIL:
// Nothing done yet.
$btn_configure_mail_class = ' pending';
break;
}
$form = [
'action' => '#',
'id' => 'welcome_form',
'onsubmit' => 'this.dialog("close");',
'class' => 'modal',
];
$inputs = [
[
'wrapper' => 'div',
'block_id' => 'div_configure_mail',
'class' => 'flex-row w100p',
'direct' => 1,
'block_content' => [
[
'label' => __('Please ensure mail configuration matches your needs'),
'arguments' => [
'class' => 'first_lbl',
'name' => 'lbl_create_agent',
'id' => 'lbl_create_agent',
],
],
[
'arguments' => [
'label' => '',
'type' => 'button',
'attributes' => 'class="go '.$btn_configure_mail_class.'"',
'name' => 'btn_email_conf',
'id' => 'btn_email_conf',
],
],
],
],[
'wrapper' => 'div',
'block_id' => 'div_create_agent',
'class' => 'flex-row w100p',
'direct' => 1,
'block_content' => [
[
'label' => __('Create an agent'),
'arguments' => [
'class' => 'first_lbl',
'name' => 'lbl_create_agent',
'id' => 'lbl_create_agent',
],
],
[
'arguments' => [
'label' => '',
'type' => 'button',
'attributes' => 'class="go '.$btn_create_agent_class.'"',
'name' => 'btn_create_agent',
'id' => 'btn_create_agent',
],
],
],
],
[
'label' => 'Learn to monitor',
'arguments' => [
'class' => 'class="lbl_learn"',
'name' => 'lbl_learn',
'id' => 'lbl_learn',
],
],
[
'wrapper' => 'div',
'block_id' => 'div_monitor_actions',
'class' => 'learn_content_indented flex-row w100p',
'direct' => 1,
'block_content' => [
[
'label' => __('Create a module to check if an agent is online'),
'arguments' => [
'class' => 'second_lbl',
'name' => 'lbl_check_agent',
'id' => 'lbl_check_agent',
],
],
[
'arguments' => [
'label' => '',
'type' => 'button',
'attributes' => 'class="go '.$btn_create_module_class.'"',
'name' => 'btn_create_module',
'id' => 'btn_create_module',
],
],
],
],
[
'wrapper' => 'div',
'block_id' => 'div_monitor_actions',
'class' => 'learn_content_indented flex-row w100p',
'direct' => 1,
'block_content' => [
[
'label' => __('Be warned if something is wrong, create an alert on the module'),
'arguments' => [
'class' => 'second_lbl',
'name' => 'lbl_create_alert',
'id' => 'lbl_create_alert',
],
],
[
'arguments' => [
'label' => '',
'type' => 'button',
'attributes' => 'class="go '.$btn_create_alert_class.'"',
'name' => 'btn_create_alert',
'id' => 'btn_create_alert',
],
],
],
],
[
'wrapper' => 'div',
'block_id' => 'div_discover',
'class' => 'flex-row w100p',
'direct' => 1,
'block_content' => [
[
'label' => __('Discover hosts and devices in your network'),
'arguments' => [
'class' => 'first_lbl',
'name' => 'lbl_discover_devices',
'id' => 'lbl_discover_devices',
],
],
[
'arguments' => [
'label' => '',
'type' => 'button',
'attributes' => 'class="go '.$btn_create_discovery_class.'"',
'name' => 'btn_discover_devices',
'id' => 'btn_discover_devices',
],
],
],
],
[
'wrapper' => 'div',
'block_id' => 'div_not_working',
'class' => 'flex-row w100p',
'direct' => 1,
'block_content' => [
[
'label' => __('If something is not working as expected, look for this icon and report!'),
'arguments' => [
'class' => 'first_lbl',
'name' => 'lbl_not_working',
'id' => 'lbl_not_working',
],
],
[
'label' => html_print_image('images/feedback-header.png', true),
],
],
],
];
$output = $this->printForm(
[
'form' => $form,
'inputs' => $inputs,
],
true
);
$output .= $this->loadJS();
echo $output;
// Ajax methods does not continue.
exit();
}
/**
* This function acts as a constructor. Receive the condition to check with
* the global config (welcome_state) if continues
*
* @param boolean $must_run Must be run or not (check register.php).
*
* @return boolean True if initialized or false if must not run.
*/
public function initialize($must_run)
{
global $config;
if ($must_run === false
|| (isset($config['welcome_state']) === true
&& $config['welcome_state'] === WELCOME_FINISHED)
) {
// Do not start unless not finished.
return false;
}
$sec2 = get_parameter('sec2', '');
$this->step = $this->getStep();
$this->agent = $this->getWelcomeAgent();
if ($sec2 === '') {
// Unless finished.
if ($this->step !== WELCOME_FINISHED) {
return true;
}
}
/*
* Configure mail. Control current flow.
*
* On empty sec2: show current step.
* On setup page: do not show.
* After mail configuration: enable agent step.
*/
if ($this->step == W_CONFIGURE_MAIL) {
if ($sec2 === 'godmode/setup/setup'
&& get_parameter('section', '') == 'general'
&& get_parameter('update_config', false) !== false
) {
// Mail configuration have been processed.
$_SESSION['configured_mail'] = true;
$this->setStep(W_CREATE_AGENT);
} else if ($sec2 === 'godmode/setup/setup'
&& get_parameter('section', '') === 'general'
) {
// Mail configuration is being processed.
return false;
} else {
// Any other page, show welcome.
return true;
}
}
/*
* Create agent. Control current flow.
*
* On empty sec2: show current step.
* On agent creation page: do not show.
* After agent creation: enable module step.
*/
if ($this->step === W_CREATE_AGENT) {
// Create agent is pending.
if ($sec2 === 'godmode/agentes/configurar_agente'
&& get_parameter('create_agent', false) !== false
) {
// Agent have been created. Store.
$this->setWelcomeAgent(
db_get_value(
'MAX(id_agente)',
'tagente'
)
);
$this->setStep(W_CREATE_MODULE);
return true;
} else if ($sec2 === 'godmode/agentes/configurar_agente') {
// Agent is being created.
return false;
} else {
// Any other page, show welcome.
return true;
}
}
/*
* Create module. Control current flow.
*
* On empty sec2: show current step.
* On module creation page: do not show.
* After module creation: enable alert step.
*/
if ($this->step === W_CREATE_MODULE) {
// Create module is pending.
if ($sec2 === 'godmode/agentes/configurar_agente'
&& get_parameter('tab', '') === 'module'
&& get_parameter('create_module', false) !== false
) {
// Module have been created.
$this->setStep(W_CREATE_ALERT);
return true;
} else if ($sec2 === 'godmode/agentes/configurar_agente'
&& get_parameter('tab', '') === 'module'
) {
// Module is being created.
return false;
} else {
// Any other page, show welcome.
return true;
}
}
/*
* Create alert. Control current flow.
*
* On empty sec2: show current step.
* On alert creation page: do not show.
* After alert creation: enable discovery task step.
*/
if ($this->step === W_CREATE_ALERT) {
// Create alert is pending.
if ($sec2 === 'godmode/agentes/configurar_agente'
&& get_parameter('tab', '') === 'alert'
&& get_parameter('create_alert', false) !== false
) {
// Alert have been created.
$this->setStep(W_CREATE_TASK);
return true;
} else if ($sec2 === 'godmode/agentes/configurar_agente'
&& get_parameter('tab', '') === 'alert'
) {
// Alert is being created.
return false;
} else {
// Any other page, show welcome.
return true;
}
}
/*
* Create discovery task. Control current flow.
*
* On empty sec2: show current step.
* On discovery task creation page: do not show.
* After discovery task creation: finish.
*/
if ($this->step === W_CREATE_TASK) {
// Create Discovery task is pending.
// Host&Devices finishses on page 2.
if ($sec2 === 'godmode/servers/discovery'
&& get_parameter('page', 0) == 2
) {
// Discovery task have been created.
$this->setStep(WELCOME_FINISHED);
// Finished! do not show.
return false;
} else if ($sec2 == 'godmode/servers/discovery') {
// Discovery task is being created.
return false;
} else {
// Any other page, show welcome.
return true;
}
}
if ($this->step === WELCOME_FINISHED) {
// Welcome tutorial finished.
return false;
}
// Return a reference to the new object.
return false;
}
/**
* Load JS content.
* function that enables the functions to the buttons when its action is
* completed.
* Assign the url of each button.
*
* @return string HTML code for javascript functionality.
*/
public function loadJS()
{
ob_start();
?>
<script type="text/javascript">
<?php
switch ($this->step) {
case W_CONFIGURE_MAIL:
?>
document.getElementById("button-btn_email_conf").setAttribute(
'onclick',
'configureEmail()'
);
<?php
break;
case W_CREATE_AGENT:
?>
document.getElementById("button-btn_create_agent").setAttribute(
'onclick',
'createNewAgent()'
);
<?php
break;
case W_CREATE_MODULE:
?>
document.getElementById("button-btn_create_module").setAttribute(
'onclick',
'checkAgentOnline()'
);
<?php
break;
case W_CREATE_ALERT:
?>
document.getElementById("button-btn_create_alert").setAttribute(
'onclick',
'createAlertModule()'
);
<?php
break;
case W_CREATE_TASK:
?>
document.getElementById("button-btn_discover_devices").setAttribute(
'onclick',
'discoverDevicesNetwork()'
);
<?php
break;
case WELCOME_FINISHED:
default:
// Do not enable anything.
break;
}
?>
function configureEmail() {
window.location = '<?php echo ui_get_full_url('index.php?sec=general&sec2=godmode/setup/setup&section=general#table3'); ?>';
}
function createNewAgent() {
window.location = '<?php echo ui_get_full_url('index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&new_agent=1&crt-2=Create+agent'); ?>';
}
function checkAgentOnline() {
window.location = '<?php echo ui_get_full_url('index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=module&id_agente='.$this->getWelcomeAgent().''); ?>';
}
function createAlertModule() {
window.location = '<?php echo ui_get_full_url('index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=alert&id_agente='.$this->getWelcomeAgent().''); ?>';
}
function monitorRemoteCommands() {
window.location = '<?php echo ui_get_full_url(''); ?>';
}
function discoverDevicesNetwork() {
window.location = '<?php echo ui_get_full_url('index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=hd&mode=netscan'); ?>';
}
function reportIsNotWorking() {
}
function cierre_dialog(){
this.dialog("close");
}
</script>
<?php
return ob_get_clean();
}
}

View File

@ -648,3 +648,12 @@ define('HA_PENDING', 2);
define('HA_PROCESSING', 3);
define('HA_DISABLED', 4);
define('HA_FAILED', 5);
define('WELCOME_STARTED', 1);
define('W_CONFIGURE_MAIL', 1);
define('W_CREATE_AGENT', 2);
define('W_CREATE_MODULE', 3);
define('W_CREATE_ALERT', 4);
define('W_CREATE_TASK', 5);
define('WELCOME_FINISHED', -1);

View File

@ -1895,6 +1895,10 @@ function config_process_config()
config_update_value('unique_ip', 0);
}
if (!isset($config['welcome_state'])) {
config_update_value('welcome_state', WELCOME_STARTED);
}
/*
* Parse the ACL IP list for access API
*/

View File

@ -1900,6 +1900,139 @@ function load_modal(settings) {
buttons: []
})
.show();
var required_buttons = [];
if (settings.modal.cancel != undefined) {
//The variable contains a function
// that is responsible for executing the method it receives from settings
// which confirms the closure of a modal
var cancelModal = function() {
settings.target.dialog("close");
if (AJAX_RUNNING) return;
AJAX_RUNNING = 1;
var formdata = new FormData();
formdata.append("page", settings.oncancel.page);
formdata.append("method", settings.oncancel.method);
$.ajax({
method: "post",
url: settings.url,
processData: false,
contentType: false,
data: formdata,
success: function(data) {
if (typeof settings.oncancel.callback == "function") {
settings.oncancel.callback(data);
settings.target.dialog("close");
}
AJAX_RUNNING = 0;
},
error: function(data) {
// console.log(data);
AJAX_RUNNING = 0;
}
});
};
required_buttons.push({
class:
"ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd submit-cancel",
text: settings.modal.cancel,
click: function() {
if (settings.oncancel != undefined) {
if (typeof settings.oncancel.confirm == "function") {
//receive function
settings.oncancel.confirm(cancelModal);
} else if (settings.oncancel != undefined) {
cancelModal();
}
}
}
});
}
if (settings.modal.ok != undefined) {
required_buttons.push({
class:
"ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next",
text: settings.modal.ok,
click: function() {
if (AJAX_RUNNING) return;
AJAX_RUNNING = 1;
if (settings.onsubmit.preaction != undefined) {
settings.onsubmit.preaction();
}
if (settings.onsubmit.dataType == undefined) {
settings.onsubmit.dataType = "html";
}
var formdata = new FormData();
if (settings.extradata) {
settings.extradata.forEach(function(item) {
if (item.value != undefined) formdata.append(item.name, item.value);
});
}
formdata.append("page", settings.onsubmit.page);
formdata.append("method", settings.onsubmit.method);
var flagError = false;
$("#" + settings.form + " :input").each(function() {
if (this.checkValidity() === false) {
$(this).prop("title", this.validationMessage);
$(this).tooltip({
tooltipClass: "uitooltip",
position: { my: "right bottom", at: "right bottom" },
show: { duration: 200 }
});
$(this).tooltip("open");
flagError = true;
}
if (this.type == "file") {
if ($(this).prop("files")[0]) {
formdata.append(this.name, $(this).prop("files")[0]);
}
} else {
if ($(this).attr("type") == "checkbox") {
if (this.checked) {
formdata.append(this.name, "on");
}
} else {
formdata.append(this.name, $(this).val());
}
}
});
if (flagError === false) {
$.ajax({
method: "post",
url: settings.url,
processData: false,
contentType: false,
data: formdata,
dataType: settings.onsubmit.dataType,
success: function(data) {
if (settings.ajax_callback != undefined) {
if (settings.idMsgCallback != undefined) {
settings.ajax_callback(data, settings.idMsgCallback);
} else {
settings.ajax_callback(data);
}
}
AJAX_RUNNING = 0;
}
});
} else {
AJAX_RUNNING = 0;
}
},
error: function(data) {
// console.log(data);
AJAX_RUNNING = 0;
}
});
}
$.ajax({
method: "post",
@ -1922,105 +2055,63 @@ function load_modal(settings) {
opacity: 0.5,
background: "black"
},
buttons: [
{
class:
"ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd submit-cancel",
text: settings.modal.cancel,
click: function() {
$(this).dialog("close");
if (typeof settings.cleanup == "function") {
settings.cleanup();
}
}
},
{
class:
"ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next",
text: settings.modal.ok,
click: function() {
if (AJAX_RUNNING) return;
AJAX_RUNNING = 1;
if (settings.onsubmit.preaction != undefined) {
settings.onsubmit.preaction();
}
if (settings.onsubmit.dataType == undefined) {
settings.onsubmit.dataType = "html";
}
var formdata = new FormData();
if (settings.extradata) {
settings.extradata.forEach(function(item) {
if (item.value != undefined)
formdata.append(item.name, item.value);
});
}
formdata.append("page", settings.onsubmit.page);
formdata.append("method", settings.onsubmit.method);
var flagError = false;
$("#" + settings.form + " :input").each(function() {
if (this.checkValidity() === false) {
$(this).prop("title", this.validationMessage);
$(this).tooltip({
tooltipClass: "uitooltip",
position: { my: "right bottom", at: "right bottom" },
show: { duration: 200 }
});
$(this).tooltip("open");
flagError = true;
}
if (this.type == "file") {
if ($(this).prop("files")[0]) {
formdata.append(this.name, $(this).prop("files")[0]);
}
} else {
if ($(this).attr("type") == "checkbox") {
if (this.checked) {
formdata.append(this.name, "on");
}
} else {
formdata.append(this.name, $(this).val());
}
}
});
if (flagError === false) {
$.ajax({
method: "post",
url: settings.url,
processData: false,
contentType: false,
data: formdata,
dataType: settings.onsubmit.dataType,
success: function(data) {
if (settings.ajax_callback != undefined) {
if (settings.idMsgCallback != undefined) {
settings.ajax_callback(data, settings.idMsgCallback);
} else {
settings.ajax_callback(data);
}
}
AJAX_RUNNING = 0;
}
});
} else {
AJAX_RUNNING = 0;
}
}
}
],
buttons: required_buttons,
closeOnEscape: false,
open: function() {
$(".ui-dialog-titlebar-close").hide();
}
});
},
error: function(data) {
// console.log(data);
}
});
}
//Function that shows a dialog box to confirm closures of generic manners. The modal id is random
function confirmDialog(settings) {
var randomStr =
Math.random()
.toString(36)
.substring(2, 15) +
Math.random()
.toString(36)
.substring(2, 15);
$("body").append(
'<div id="confirm_' + randomStr + '">' + settings.message + "</div>"
);
$("#confirm_" + randomStr);
$("#confirm_" + randomStr)
.dialog({
title: settings.title,
close: false,
width: 350,
modal: true,
buttons: [
{
text: "Cancel",
class:
"ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd submit-cancel",
click: function() {
$(this).dialog("close");
if (typeof settings.onDeny == "function") settings.onDeny();
}
},
{
text: "Ok",
class:
"ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next",
click: function() {
$(this).dialog("close");
if (typeof settings.onAccept == "function") settings.onAccept();
}
}
]
})
.show();
}
/**
* Function to show modal with message Validation.
*

View File

@ -0,0 +1,70 @@
/*
// Pandora FMS - the Flexible Monitoring System
// =============================================
// Copyright (c) 2004-2009 Artica Soluciones Tecnológicas S.L
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; version 2
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
.modal {
overflow: hidden;
}
.welcome_modal_window {
overflow: hidden;
}
label {
font-family: "lato-lighter", "Open Sans", sans-serif;
letter-spacing: 0.03pt;
font-size: 8pt;
font-weight: 900;
}
.content_position {
display: flex;
margin-top: 5px;
font-family: "lato-lighter", "Open Sans", sans-serif;
letter-spacing: 0.03pt;
font-size: 8pt;
font-weight: 800;
}
.learn_content_indented {
margin-top: 0.5em;
text-indent: 2em;
font-family: "lato-lighter", "Open Sans", sans-serif;
letter-spacing: 0.03pt;
font-size: 8pt;
font-weight: 800;
}
#lbl_learn {
font-family: "lato-lighter", "Open Sans", sans-serif;
letter-spacing: 0.03pt;
font-size: 8pt;
font-weight: 800;
}
.go {
background-repeat: no-repeat;
width: 25px;
height: 25px;
border: none;
}
.pending {
background-image: url(../../images/darrowright.png);
}
.completed {
background-image: url(../../images/input_tick.png);
}