Skip to content

Commit

Permalink
Refine license modal JS and conditions.
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-unwin committed Nov 4, 2024
1 parent 063f1cf commit 8a3b997
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 115 deletions.
14 changes: 11 additions & 3 deletions app/Views/shared/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ function my_comparison($asort, $bsort)
let html = document.querySelector('html');
html.classList.add(prefers);
html.setAttribute('data-bs-theme', prefers);

var license_string_id = <?= $config->license_string_id ?>;
var oae_prompt_id = <?= $config->oae_prompt_id ?>;
</script>
</head>
<!-- Need d-flex flex-column h-100 to hold footer in place -->
Expand Down Expand Up @@ -679,6 +680,13 @@ function my_comparison($asort, $bsort)
<?php } ?>

<!-- Toasts -->
<?php
$extra = 'Please download Open-AudIT from <a target="_blank" href="https://firstwave.com">FirstWave</a> to access a free license and additional functionality.';
$license = (!empty($config->license)) ? strtolower($config->license) : 'none';
if ($license !== 'commercial' and (is_file(ROOTPATH . 'other/enterprise.bin') or is_file(ROOTPATH . 'other/enterprise.exe'))) {
$extra = 'For a free license, click <a href="#" data-bs-toggle="modal" data-bs-target="#modalCompareLicense">here</a>.';
}
?>
<div aria-live="polite" aria-atomic="true" class="position-relative">
<div class="toast-container top-0 end-0 p-3">
<div class="toast toast-ent" role="alert" aria-live="assertive" aria-atomic="true" id="liveToastEnterprise">
Expand All @@ -687,7 +695,7 @@ function my_comparison($asort, $bsort)
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close" style="padding-top:34px; padding-right:50px;"></button>
</div>
<div class="toast-body">
This feature is limited to Enterprise licenses only. Please contact <a href="https://firstwave.com" target="_blank">FirstWave</a> for a license.
This feature is limited to Enterprise licenses only. <?= $extra ?>
</div>
</div>
<div class="toast toast-pro" role="alert" aria-live="assertive" aria-atomic="true" id="liveToastProfessional">
Expand All @@ -696,7 +704,7 @@ function my_comparison($asort, $bsort)
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close" style="padding-top:34px; padding-right:50px;"></button>
</div>
<div class="toast-body">
This feature is limited to Professional licenses only. Please contact <a href="https://firstwave.com" target="_blank">FirstWave</a> for a license.
This feature is limited to Professional licenses only. <?= $extra ?>
</div>
</div>
<div class="toast toast-perm" role="alert" aria-live="assertive" aria-atomic="true" id="liveToastPermission">
Expand Down
121 changes: 9 additions & 112 deletions app/Views/shared/modalCompareLicense.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
$button_prompt_never = '';
$button_prompt_later = '';
if (($meta->collection === 'summaries' or $meta->collection === 'groups') and $config->oae_prompt <= date('Y-m-d') and $license !== 'commercial') {
$button_prompt_never = '<span id="button_prompt_never"><a data-bs-dismiss="modal" class="btn btn-default btn-sm dismiss_modal_button" href="#" data-value="2100-01-01">' . __('Do not show me again') . '</a></span>';
$button_prompt_later = '<span id="button_prompt_later"><a data-bs-dismiss="modal" class="btn btn-default btn-sm dismiss_modal_button" href="#" data-value="' . date('Y-m-d', strtotime(date('Y-m-d') . ' + 1 day')) . '">' . __('Ask me later') . '</a></span>';
// $button_prompt_never = '<span id="button_prompt_never"><a data-bs-dismiss="modal" class="btn btn-default btn-sm dismiss_modal_button" href="#" data-value="2100-01-01">' . __('Do not show me again') . '</a></span>';
$button_prompt_later = '<span id="button_prompt_later"><a data-bs-dismiss="modal" class="btn btn-default btn-sm dismiss_modal_button" href="#" data-value="' . date('Y-m-d', strtotime(date('Y-m-d') . ' + 30 day')) . '">' . __('Ask me later') . '</a></span>';
}
$countries = array(
"Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa", "Andorra",
Expand Down Expand Up @@ -280,13 +280,13 @@

<div class="row">
<div class="col-6 clearfix pull-left">
<?php if (($meta->collection === 'summaries' or $meta->collection === 'groups') and $config->oae_prompt <= date('Y-m-d') and $license !== 'commercial') {
<?php if (($meta->collection === 'summaries' or $meta->collection === 'groups' or $meta->collection === 'help') and $config->oae_prompt <= date('Y-m-d') and $license !== 'commercial' and (file_exists(ROOTPATH . 'other/enterprise.bin') or file_exists(ROOTPATH . 'other/enterprise.exe'))) {
echo $button_prompt_later;
} ?>
</div>
<div class="col-6 clearfix pull-right">
<div class="float-end">
<?php if (($meta->collection === 'summaries' or $meta->collection === 'groups') and $config->oae_prompt <= date('Y-m-d') and $license !== 'commercial') {
<?php if (($meta->collection === 'summaries' or $meta->collection === 'groups' or $meta->collection === 'help') and $config->oae_prompt <= date('Y-m-d') and $license !== 'commercial' and (file_exists(ROOTPATH . 'other/enterprise.bin') or file_exists(ROOTPATH . 'other/enterprise.exe'))) {
echo $button_prompt_never;
} ?>
</div>
Expand All @@ -302,117 +302,14 @@
$(window).on("load", function() {
$(document).ready(function () {
<?php
if (($meta->collection === 'summaries' or $meta->collection === 'groups') and $config->oae_prompt <= date('Y-m-d') and $license !== 'commercial') {
if (($meta->collection === 'summaries' or $meta->collection === 'groups' or $meta->collection === 'help') and $config->oae_prompt <= date('Y-m-d') and $license !== 'commercial' and (file_exists(ROOTPATH . 'other/enterprise.bin') or file_exists(ROOTPATH . 'other/enterprise.exe'))) {
echo "\n $('#modalCompareLicense').modal('show');\n";
}
?>

$(document).on('click', '.dismiss_modal_button', function (e) {
$('*').css('cursor','wait');
var value = $(this).attr("data-value");
updatePrompt(value);
$('*').css('cursor','auto');
});


function updatePrompt(value) {
var data = {};
data["data"] = {};
data["data"]["id"] = "<?= $config->oae_prompt_id ?>";
data["data"]["type"] = "configuration";
data["data"]["attributes"] = {};
data["data"]["attributes"]["value"] = value;
data = JSON.stringify(data);
$.ajax({
async: false,
type: "PATCH",
url: "<?= base_url() ?>index.php/configuration/<?= $config->oae_prompt_id ?>",
contentType: "application/json",
data: {data : data},
success: function (data) {
/* alert( 'success' ); */
console.log(data);
},
error: function (data) {
console.log(data.responseText);
data = JSON.parse(data.responseText);
alert(data.errors[0].code + "\n" + data.errors[0].title + "\n" + data.errors[0].detail);
}
});
}

function validateEmail($email) {
var emailReg = /^([\w-\.\+]+@([\w-]+\.)+[\w-]{2,4})?$/;
return emailReg.test( $email );
}

$("#createFree").click(function (e) {
console.log("createFree clicked");

$("#data\\[attributes\\]\\[first_name\\]").removeClass('border-danger');
$("#data\\[attributes\\]\\[last_name\\]").removeClass('border-danger');
$("#data\\[attributes\\]\\[email\\]").removeClass('border-danger');
$("#data\\[attributes\\]\\[company\\]").removeClass('border-danger');
$("#data\\[attributes\\]\\[country\\]").removeClass('border-danger');

if ($("#data\\[attributes\\]\\[first_name\\]").val() == '') {
$("#data\\[attributes\\]\\[first_name\\]").addClass('border-danger');
$("#data\\[attributes\\]\\[first_name\\]").focus();
return;
}
if ($("#data\\[attributes\\]\\[last_name\\]").val() == '') {
$("#data\\[attributes\\]\\[last_name\\]").addClass('border-danger');
$("#data\\[attributes\\]\\[last_name\\]").focus();
return;
}
if ($("#data\\[attributes\\]\\[email\\]").val() == '' || !validateEmail($("#data\\[attributes\\]\\[email\\]").val())) {
$("#data\\[attributes\\]\\[email\\]").addClass('border-danger');
$("#data\\[attributes\\]\\[email\\]").focus();
return;
}
if ($("#data\\[attributes\\]\\[company\\]").val() == '') {
$("#data\\[attributes\\]\\[company\\]").addClass('border-danger');
$("#data\\[attributes\\]\\[company\\]").focus();
return;
}
if ($("#data\\[attributes\\]\\[country\\]").val() == '') {
$("#data\\[attributes\\]\\[country\\]").addClass('border-danger');
$("#data\\[attributes\\]\\[country\\]").focus();
return;
}

$('*').css('cursor','wait');

var data = {};
data["data"] = {};
data["data"]["id"] = <?= $config->license_string_id ?>;
data["data"]["type"] = "configuration";
data["data"]["attributes"] = {};
data["data"]["attributes"]["value"] = {};
data["data"]["attributes"]["value"]["country"] = $("#data\\[attributes\\]\\[country\\]").val();
data["data"]["attributes"]["value"]["first_name"] = $("#data\\[attributes\\]\\[first_name\\]").val();
data["data"]["attributes"]["value"]["last_name"] = $("#data\\[attributes\\]\\[last_name\\]").val();
data["data"]["attributes"]["value"]["email"] = $("#data\\[attributes\\]\\[email\\]").val();
data["data"]["attributes"]["value"]["company"] = $("#data\\[attributes\\]\\[company\\]").val();
data = JSON.stringify(data);
$.ajax({
type: "PATCH",
url: '<?= base_url() ?>index.php/configuration/<?= $config->license_string_id ?>',
contentType: "application/json",
data: {data : data},
success: function(data, textStatus) {
updatePrompt('2101-01-01');
location.reload();
},
error: function (jqXHR, textStatus, errorThrown) {
console.log("Status: " + textStatus);
console.log("errorThrown: " + errorThrown);
console.log(JSON.stringify(jqXHR));
alert(jqXHR.responseJSON.errors[0].code + ": " + jqXHR.responseJSON.errors[0].detail);
return false;
}
});
});
// console.log("Collection: <?= $meta->collection ?>");
// console.log("OAE Prompt: <?= $config->oae_prompt ?>");
// console.log("Date: <?= date('Y-m-d') ?>");
// console.log("License: <?= $license ?>");
});
});
</script>
108 changes: 108 additions & 0 deletions public/js/open-audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,112 @@ $(document).ready(function () {
$('.debug').click(function (e) {
$('#json_response').css('display', 'block');
});

/* Modal for Licensing */
$(document).on('click', '.dismiss_modal_button', function (e) {
$('*').css('cursor','wait');
var value = $(this).attr("data-value");
updatePrompt(value);
$('*').css('cursor','auto');
});


/* Remind me later */
function updatePrompt(value) {
var data = {};
data["data"] = {};
data["data"]["id"] = oae_prompt_id;
data["data"]["type"] = "configuration";
data["data"]["attributes"] = {};
data["data"]["attributes"]["value"] = value;
data = JSON.stringify(data);
$.ajax({
async: false,
type: "PATCH",
url: baseurl + "/configuration/" + oae_prompt_id,
contentType: "application/json",
data: {data : data},
success: function (data) {
/* alert( 'success' ); */
console.log(data);
},
error: function (data) {
console.log(data.responseText);
data = JSON.parse(data.responseText);
alert(data.errors[0].code + "\n" + data.errors[0].title + "\n" + data.errors[0].detail);
}
});
}

function validateEmail($email) {
var emailReg = /^([\w-\.\+]+@([\w-]+\.)+[\w-]{2,4})?$/;
return emailReg.test( $email );
}

/* Create a free license */
$("#createFree").click(function (e) {
$("#data\\[attributes\\]\\[first_name\\]").removeClass('border-danger');
$("#data\\[attributes\\]\\[last_name\\]").removeClass('border-danger');
$("#data\\[attributes\\]\\[email\\]").removeClass('border-danger');
$("#data\\[attributes\\]\\[company\\]").removeClass('border-danger');
$("#data\\[attributes\\]\\[country\\]").removeClass('border-danger');

if ($("#data\\[attributes\\]\\[first_name\\]").val() == '') {
$("#data\\[attributes\\]\\[first_name\\]").addClass('border-danger');
$("#data\\[attributes\\]\\[first_name\\]").focus();
return;
}
if ($("#data\\[attributes\\]\\[last_name\\]").val() == '') {
$("#data\\[attributes\\]\\[last_name\\]").addClass('border-danger');
$("#data\\[attributes\\]\\[last_name\\]").focus();
return;
}
if ($("#data\\[attributes\\]\\[email\\]").val() == '' || !validateEmail($("#data\\[attributes\\]\\[email\\]").val())) {
$("#data\\[attributes\\]\\[email\\]").addClass('border-danger');
$("#data\\[attributes\\]\\[email\\]").focus();
return;
}
if ($("#data\\[attributes\\]\\[company\\]").val() == '') {
$("#data\\[attributes\\]\\[company\\]").addClass('border-danger');
$("#data\\[attributes\\]\\[company\\]").focus();
return;
}
if ($("#data\\[attributes\\]\\[country\\]").val() == '') {
$("#data\\[attributes\\]\\[country\\]").addClass('border-danger');
$("#data\\[attributes\\]\\[country\\]").focus();
return;
}

$('*').css('cursor','wait');

var data = {};
data["data"] = {};
data["data"]["id"] = license_string_id;
data["data"]["type"] = "configuration";
data["data"]["attributes"] = {};
data["data"]["attributes"]["value"] = {};
data["data"]["attributes"]["value"]["country"] = $("#data\\[attributes\\]\\[country\\]").val();
data["data"]["attributes"]["value"]["first_name"] = $("#data\\[attributes\\]\\[first_name\\]").val();
data["data"]["attributes"]["value"]["last_name"] = $("#data\\[attributes\\]\\[last_name\\]").val();
data["data"]["attributes"]["value"]["email"] = $("#data\\[attributes\\]\\[email\\]").val();
data["data"]["attributes"]["value"]["company"] = $("#data\\[attributes\\]\\[company\\]").val();
data = JSON.stringify(data);
$.ajax({
type: "PATCH",
url: baseurl + '/configuration/' + license_string_id,
contentType: "application/json",
data: {data : data},
success: function(data, textStatus) {
updatePrompt('2101-01-01');
location.reload();
},
error: function (jqXHR, textStatus, errorThrown) {
console.log("Status: " + textStatus);
console.log("errorThrown: " + errorThrown);
console.log(JSON.stringify(jqXHR));
alert(jqXHR.responseJSON.errors[0].code + ": " + jqXHR.responseJSON.errors[0].detail);
return false;
}
});
});
});

0 comments on commit 8a3b997

Please sign in to comment.