add modal confirmation window

This commit is contained in:
marcos 2019-10-28 18:57:10 +01:00
parent e725a0185b
commit 57bfc364ae
5 changed files with 151 additions and 24 deletions

View File

@ -175,7 +175,7 @@ if (!$config['disabled_newsletter']) {
$welcome = !$registration && !$show_newsletter && !$initial; $welcome = !$registration && !$show_newsletter && !$initial;
$welcome_window = WelcomeWindow::initialize($welcome); $welcome_window = WelcomeWindow::initialize($welcome);
if ($welcome_window && $config['welcome_started'] === 1) { if ($welcome_window) {
$welcome_window->run(); $welcome_window->run();
} }

View File

@ -2266,7 +2266,7 @@ if ($updateGIS) {
// ----------------------------------- // -----------------------------------
// Load page depending on tab selected // Load page depending on tab selected
// ----------------------------------- // -----------------------------------
if (!$_SESSION['create_module']) { if ($_SESSION['create_module'] && $config['welcome_started'] == 1) {
$edit_module = true; $edit_module = true;
} }

View File

@ -321,7 +321,7 @@ if ($id_agent_module) {
} else { } else {
if (!isset($moduletype)) { if (!isset($moduletype)) {
$moduletype = (string) get_parameter('moduletype'); $moduletype = (string) get_parameter('moduletype');
if (!$_SESSION['create_module']) { if ($_SESSION['create_module'] && $config['welcome_started'] == 1) {
$moduletype = 'networkserver'; $moduletype = 'networkserver';
} }

View File

@ -48,7 +48,10 @@ class WelcomeWindow extends Wizard
* *
* @var array * @var array
*/ */
public $AJAXMethods = ['loadWelcomeWindow']; public $AJAXMethods = [
'loadWelcomeWindow',
'cancelWelcome',
];
/** /**
* Url of controller. * Url of controller.
@ -65,6 +68,21 @@ class WelcomeWindow extends Wizard
public $step; public $step;
/**
* 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. * Checks if target method is available to be called using AJAX.
* *
@ -137,9 +155,30 @@ class WelcomeWindow extends Wizard
}, },
onshow: { onshow: {
page: '<?php echo $this->ajaxController; ?>', page: '<?php echo $this->ajaxController; ?>',
method: 'loadWelcomeWindow' 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();
}
})
},
callback: function(data) {
console.log(data);
}
}
}); });
</script> </script>
<?php <?php
@ -147,6 +186,16 @@ class WelcomeWindow extends Wizard
} }
/**
* cancelWelcome is method to cancel welcome modal window
*/
public function cancelWelcome()
{
// config update value.
config_update_value('welcome_started', WELCOME_FINISHED);
}
/** /**
* Loads a welcome window form * Loads a welcome window form
* *
@ -162,10 +211,9 @@ class WelcomeWindow extends Wizard
$btn_create_module_class = ''; $btn_create_module_class = '';
$btn_create_alert_class = ''; $btn_create_alert_class = '';
$btn_create_discovery_class = ''; $btn_create_discovery_class = '';
$action = '';
if (($_SESSION['step'] === 'create_mail') || $_SESSION['step'] === null) { if (($_SESSION['step'] === null )) {
// Pending mail. // Nothing done yet
$btn_configure_mail_class = ' pending'; $btn_configure_mail_class = ' pending';
} else if ($_SESSION['step'] === 'create_agent') { } else if ($_SESSION['step'] === 'create_agent') {
$this->step = 'create_agent'; $this->step = 'create_agent';
@ -406,18 +454,16 @@ class WelcomeWindow extends Wizard
/** /**
* Esto es un constructor realmente... * This function acts as a constructor.
* se llama desde la navegación normal , no ajax * Receive the condition to check with the global config (welcome_started) if continues
*/ */
public static function initialize($must_run) public static function initialize($must_run)
{ {
global $config; global $config;
if ($must_run === false) { if ($must_run === false || $config['welcome_started'] != WELCOME_STARTED) {
// Do not start unless already started. // Do not start unless already started.
if ($config['welcome_started'] != WELCOME_STARTED) {
return false; return false;
}
} }
// Calculate steps. // Calculate steps.
@ -515,25 +561,22 @@ class WelcomeWindow extends Wizard
/** /**
* DOCUMENTA!!! * function that enables the functions to the buttons when its action is completed.
* * Assign the url of each button
*/ */
public function loadJS() public function loadJS()
{ {
ob_start(); ob_start();
?> ?>
<script type="text/javascript"> <script type="text/javascript">
console.log('vale');
if('.<?php echo $_SESSION['step'] == 'create_mail'; ?>.'){ if('.<?php echo $_SESSION['step'] == 'create_mail'; ?>.'){
document.getElementById("button-btn_email_conf").setAttribute('onclick', 'configureEmail()'); document.getElementById("button-btn_email_conf").setAttribute('onclick', 'configureEmail()');
console.log('mail');
} }
if( '.<?php echo $_SESSION['step'] == 'create_agent'; ?>.') { if( '.<?php echo $_SESSION['step'] == 'create_agent'; ?>.') {
document.getElementById("button-btn_create_agent").setAttribute('onclick', 'createNewAgent()'); document.getElementById("button-btn_create_agent").setAttribute('onclick', 'createNewAgent()');
console.log('agente true');
} }
if( '.<?php echo $_SESSION['step'] == 'create_module'; ?>.') { if( '.<?php echo $_SESSION['step'] == 'create_module'; ?>.') {
document.getElementById("button-btn_create_module").setAttribute('onclick', 'checkAgentOnline()'); document.getElementById("button-btn_create_module").setAttribute('onclick', 'checkAgentOnline()');
console.log('modulo entra true');
} }
if( '.<?php echo $_SESSION['step'] == 'create_alert'; ?>.') { if( '.<?php echo $_SESSION['step'] == 'create_alert'; ?>.') {
@ -572,7 +615,9 @@ class WelcomeWindow extends Wizard
function reportIsNotWorking() { function reportIsNotWorking() {
} }
function cierre_dialog(){
this.dialog("close");
}
</script> </script>
<?php <?php
return ob_get_clean(); return ob_get_clean();

View File

@ -1899,17 +1899,48 @@ function load_modal(settings) {
buttons: [] buttons: []
}) })
.show(); .show();
var required_buttons = []; var required_buttons = [];
if (settings.modal.cancel != undefined) { 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() {
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);
}
AJAX_RUNNING = 0;
},
error: function(data) {
console.log(data);
AJAX_RUNNING = 0;
}
});
};
required_buttons.push({ required_buttons.push({
class: class:
"ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd submit-cancel", "ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd submit-cancel",
text: settings.modal.cancel, text: settings.modal.cancel,
click: function() { click: function() {
$(this).dialog("close"); if (typeof settings.oncancel.confirm == "function") {
if (typeof settings.cleanup == "function") { //receive function
settings.cleanup(); settings.oncancel.confirm(cancelModal);
} else if (settings.oncancel != undefined) {
cancelModal();
} }
} }
}); });
@ -1958,10 +1989,14 @@ function load_modal(settings) {
contentType: false, contentType: false,
data: formdata, data: formdata,
success: function(data) { success: function(data) {
if (settings.ajax_callback != undefined) { if (typeof settings.ajax_callback == "function") {
settings.ajax_callback(data); settings.ajax_callback(data);
} }
AJAX_RUNNING = 0; AJAX_RUNNING = 0;
},
error: function(data) {
console.log(data);
AJAX_RUNNING = 0;
} }
}); });
} }
@ -1995,6 +2030,53 @@ function load_modal(settings) {
$(".ui-dialog-titlebar-close").hide(); $(".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();
}