Better IE support

This commit is contained in:
Matteo Gheza 2021-05-10 18:29:17 +02:00
parent cd3bfab8c0
commit 4963b34420
11 changed files with 193 additions and 162 deletions

View File

@ -163,107 +163,98 @@ echo("</div>");
?>
<script>
function init_modal() {
<?php if($orienation == "landscape"){ ?>$(".modal-dialog").css("max-width", "99%");<?php } ?>
var isMouseDown = false;
$(document)
.mouseup(function () {
isMouseDown = false;
});
$(".hour-cell")
.mousedown(function () {
isMouseDown = true;
$(this).toggleClass("highlighted");
return false; // prevent text selection
})
.mouseover(function () {
if (isMouseDown) {
$(this).toggleClass("highlighted");
}
});
function selectDay(id){
console.log("day selection " + id);
if ($(event.target).hasClass("highlighted_all")) {
$("#scheduler_body .day-" + id).toggleClass("highlighted");
$(event.target).toggleClass("highlighted_all");
} else {
$("#scheduler_body .day-" + id).addClass("highlighted");
$(event.target).addClass("highlighted_all");
}
<?php if($orienation == "landscape"){ ?>$(".modal-dialog").css("max-width", "99%");<?php } ?>
var isMouseDown = false;
$(document).mouseup(function () {
isMouseDown = false;
});
$(".hour-cell").mousedown(function () {
isMouseDown = true;
$(this).toggleClass("highlighted");
return false; // prevent text selection
}).mouseover(function () {
if (isMouseDown) {
$(this).toggleClass("highlighted");
}
});
function selectHour(id){
console.log("hour selection " + id);
if ($(event.target).hasClass("highlighted_all")) {
$("#scheduler_body .hour-" + id).toggleClass("highlighted");
$(event.target).toggleClass("highlighted_all");
} else {
$("#scheduler_body .hour-" + id).addClass("highlighted");
$(event.target).addClass("highlighted_all");
}
function selectDay(id) {
console.log("day selection " + id);
if ($(event.target).hasClass("highlighted_all")) {
$("#scheduler_body .day-" + id).toggleClass("highlighted");
$(event.target).toggleClass("highlighted_all");
} else {
$("#scheduler_body .day-" + id).addClass("highlighted");
$(event.target).addClass("highlighted_all");
}
}
$(".day")
.mousedown(function () {
isMouseDown = true;
let id = event.target.id;
selectDay(id);
return false; // prevent text selection
})
.mouseover(function () {
if (isMouseDown) {
let id = event.target.id;
selectDay(id);
}
});
function selectHour(id) {
console.log("hour selection " + id);
$(".hour")
.mousedown(function () {
isMouseDown = true;
let id = event.target.id.replace(":", "-");
selectHour(id);
return false; // prevent text selection
})
.mouseover(function () {
if (isMouseDown) {
let id = event.target.id.replace(":", "-");
selectHour(id);
}
});
if ($(event.target).hasClass("highlighted_all")) {
$("#scheduler_body .hour-" + id).toggleClass("highlighted");
$(event.target).toggleClass("highlighted_all");
} else {
$("#scheduler_body .hour-" + id).addClass("highlighted");
$(event.target).addClass("highlighted_all");
}
}
$("#submit_schedules_change")
.unbind()
.on("click", submit_changes);
$(".day").mousedown(function () {
isMouseDown = true;
var id = event.target.id;
selectDay(id);
return false; // prevent text selection
}).mouseover(function () {
if (isMouseDown) {
var id = event.target.id;
selectDay(id);
}
});
$(".hour").mousedown(function () {
isMouseDown = true;
var id = event.target.id.replace(":", "-");
selectHour(id);
return false; // prevent text selection
}).mouseover(function () {
if (isMouseDown) {
var id = event.target.id.replace(":", "-");
selectHour(id);
}
});
$("#submit_schedules_change").unbind().on("click", submit_changes);
}
function extractSelections(){
hours_list = [];
$("#scheduler_body td.highlighted").each((key, value) => {
let day = value.classList[1].replace("day-","");
let hour = value.classList[2].replace("hour-","").replace("-",":");
if(hour.length < 5) hour = "0" + hour;
console.log(day,hour,value);
hours_list.push([day,hour]);
});
return hours_list;
function extractSelections() {
hours_list = [];
$("#scheduler_body td.highlighted").each(function (key, value) {
var day = value.classList[1].replace("day-", "");
var hour = value.classList[2].replace("hour-", "").replace("-", ":");
if (hour.length < 5) hour = "0" + hour;
console.log(day, hour, value);
hours_list.push([day, hour]);
});
return hours_list;
}
function submit_changes(){
let hours = extractSelections();
let holidays = $.map($('input[name="holiday_check"]:checked'), function(c){return c.value; });
$.ajax({
url: "resources/ajax/ajax_availability_schedule.php",
method: "POST",
data: {
hours: hours,
holidays: holidays
},
success: function (data) {
console.log(data);
toastr.success('<?php t('Schedules updated successfully'); ?>');
}
});
function submit_changes() {
var hours = extractSelections();
var holidays = $.map($('input[name="holiday_check"]:checked'), function (c) {
return c.value;
});
$.ajax({
url: "resources/ajax/ajax_availability_schedule.php",
method: "POST",
data: {
hours: hours,
holidays: holidays
},
success: function success(data) {
console.log(data);
toastr.success('<?php t('Schedules updated successfully'); ?>');
}
});
}
</script>

View File

@ -4,6 +4,21 @@ init_class();
$user->requirelogin(false);
$user->online_time_update();
function generate_message($change_user, $action){
global $tools, $user;
if($action == "activate"){
$action_string = "Thanks, %s, you have given %s in case of alert.";
} else {
$action_string = "Thanks, %s, you have removed %s in case of alert.";
}
if($change_user == $user->auth->getUserId()){
$user_string = t("your availability", false);
} else {
$user_string = sprintf(t("%s availability", false), $user->nameById($change_user));
}
return sprintf(t($action_string, false), $user->nameById($user->auth->getUserId()), $user_string);
}
if(isset($_POST["change_id"]) && $_POST["dispo"] == 1 /* && $_POST["token_list"] == $_SESSION['token_list'] */){
$db->update(
DB_PREFIX."_profiles",
@ -11,6 +26,7 @@ if(isset($_POST["change_id"]) && $_POST["dispo"] == 1 /* && $_POST["token_list"]
["id" => $_POST["change_id"]]
);
$user->log("Status changed to 'available'", $_POST["change_id"], $user->auth->getUserId());
$message = generate_message($_POST["change_id"], "activate");
} else if(isset($_POST["change_id"]) && $_POST["dispo"] == 0 /* && $_POST["token_list"] == $_SESSION['token_list'] */){
$db->update(
DB_PREFIX."_profiles",
@ -18,5 +34,7 @@ if(isset($_POST["change_id"]) && $_POST["dispo"] == 1 /* && $_POST["token_list"]
["id" => $_POST["change_id"]]
);
$user->log("Status changed to 'not available'", $_POST["change_id"], $user->auth->getUserId());
$message = generate_message($_POST["change_id"], "deactivate");
}
echo(json_encode(["message" => $message]));
?>

View File

@ -12,10 +12,10 @@ foreach(!is_null($result) ? $result : [] as $row){
if($user->requireRole(Role::FULL_VIEWER)){
$name = $user->nameById($row["id"]);
$name_encoded = urlencode($user->name());
$functionName = $row["available"] ? "deactivate" : "activate";
$functionName = $row["available"] ? "allertaJS.main.deactivate" : "allertaJS.main.activate";
$helmet_colour = $row["chief"] ? "red" : "black";
$firstCell = "<a id='username-{$row['id']}' style='text-align: left;' onclick='$functionName(".$row["id"].");'><img alt='{$helmet_colour} helmet' src='./resources/images/{$helmet_colour}_helmet.png' width='20px'>$name</a>";
$secondCell = $row["available"] ? "<a onclick='$functionName(".$row["id"].");'><i class='fa fa-check' style='color:green'></i></a>" : "<a onclick='$functionName(".$row["id"].");'><i class='fa fa-times' style='color:red'></i></a>";
$firstCell = "<a style='text-align: left;' onclick='$functionName(".$row["id"].",0);'><img alt='{$helmet_colour} helmet' src='./resources/images/{$helmet_colour}_helmet.png' width='20px'>$name</a>";
$secondCell = $row["available"] ? "<a onclick='$functionName(".$row["id"].",0);'><i class='fa fa-check' style='color:green'></i></a>" : "<a onclick='$functionName(".$row["id"].",0);'><i class='fa fa-times' style='color:red'></i></a>";
$response[] = [
(time()-$row["online_time"])<=30 ? "<u>".$firstCell."</u>" : $firstCell,
$secondCell,

View File

@ -1,3 +0,0 @@
{
"sourceType": "unambiguous"
}

View File

@ -24,6 +24,7 @@
"clean-webpack-plugin": "^3.0.0",
"colors": "^1.4.0",
"copy-webpack-plugin": "^8.1.1",
"core-js": "^3.8.0",
"css-loader": "^5.2.4",
"datatables.net-bs4": "^1.10.23",
"datatables.net-buttons-bs4": "^1.6.5",
@ -1972,6 +1973,13 @@
"regenerator-runtime": "^0.11.0"
}
},
"node_modules/babel-runtime/node_modules/core-js": {
"version": "2.6.12",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.12.tgz",
"integrity": "sha512-Kb2wC0fvsWfQrgk8HU5lW6U/Lcs8+9aaYcy4ZFc6DDlo4nZ7n70dEgE5rtR0oG6ufKDUnrwfWL1mXR5ljDatrQ==",
"deprecated": "core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.",
"hasInstallScript": true
},
"node_modules/balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
@ -2372,11 +2380,14 @@
}
},
"node_modules/core-js": {
"version": "2.6.12",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.12.tgz",
"integrity": "sha512-Kb2wC0fvsWfQrgk8HU5lW6U/Lcs8+9aaYcy4ZFc6DDlo4nZ7n70dEgE5rtR0oG6ufKDUnrwfWL1mXR5ljDatrQ==",
"deprecated": "core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.",
"hasInstallScript": true
"version": "3.12.1",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.12.1.tgz",
"integrity": "sha512-Ne9DKPHTObRuB09Dru5AjwKjY4cJHVGu+y5f7coGn1E9Grkc3p2iBwE9AI/nJzsE29mQF7oq+mhYYRqOMFN1Bw==",
"hasInstallScript": true,
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/core-js"
}
},
"node_modules/core-js-compat": {
"version": "3.9.1",
@ -7699,6 +7710,13 @@
"requires": {
"core-js": "^2.4.0",
"regenerator-runtime": "^0.11.0"
},
"dependencies": {
"core-js": {
"version": "2.6.12",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.12.tgz",
"integrity": "sha512-Kb2wC0fvsWfQrgk8HU5lW6U/Lcs8+9aaYcy4ZFc6DDlo4nZ7n70dEgE5rtR0oG6ufKDUnrwfWL1mXR5ljDatrQ=="
}
}
},
"balanced-match": {
@ -8000,9 +8018,9 @@
}
},
"core-js": {
"version": "2.6.12",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.12.tgz",
"integrity": "sha512-Kb2wC0fvsWfQrgk8HU5lW6U/Lcs8+9aaYcy4ZFc6DDlo4nZ7n70dEgE5rtR0oG6ufKDUnrwfWL1mXR5ljDatrQ=="
"version": "3.12.1",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.12.1.tgz",
"integrity": "sha512-Ne9DKPHTObRuB09Dru5AjwKjY4cJHVGu+y5f7coGn1E9Grkc3p2iBwE9AI/nJzsE29mQF7oq+mhYYRqOMFN1Bw=="
},
"core-js-compat": {
"version": "3.9.1",

View File

@ -1,4 +1,7 @@
{
"browserslist": [
"ie 11"
],
"name": "allertavvf_webpack",
"version": "1.0.0",
"description": "",
@ -26,6 +29,7 @@
"clean-webpack-plugin": "^3.0.0",
"colors": "^1.4.0",
"copy-webpack-plugin": "^8.1.1",
"core-js": "^3.8.0",
"css-loader": "^5.2.4",
"datatables.net-bs4": "^1.10.23",
"datatables.net-buttons-bs4": "^1.6.5",

View File

@ -199,11 +199,13 @@ export async function loadTable ({ tablePage, setTableRefreshInterval = true, in
console.log(data);
if (data.length > 0) {
fillTableLoaded({ data, replaceLatLngWithMap, callback });
const headers = new Headers();
headers.append("date", Date.now());
caches.open("tables-1").then((cache) => {
cache.put("/table_" + tablePage + ".json", new Response(xhr.responseText, { headers: headers }));
});
if(typeof(Headers) == "function"){
const headers = new Headers();
headers.append("date", Date.now());
caches.open("tables-1").then((cache) => {
cache.put("/table_" + tablePage + ".json", new Response(xhr.responseText, { headers: headers }));
});
}
}
if (offline) { // if xhr request successful, client is online
console.log(onlineReload);
@ -246,3 +248,39 @@ export async function loadTable ({ tablePage, setTableRefreshInterval = true, in
}, interval);
}
}
export function activate(id, token_list) {
$.ajax({
url: "resources/ajax/ajax_change_availability.php",
method: "POST",
data: {
change_id: id,
dispo: 1,
token_list: token_list
},
dataType: "json",
success: function (data) {
console.log(data);
toastr.success(data.message);
allertaJS.main.loadTable({tablePage: "list", useCustomTableEngine: "default"});
}
});
}
export function deactivate(id, token_list) {
$.ajax({
url: "resources/ajax/ajax_change_availability.php",
method: "POST",
data: {
change_id: id,
dispo: 0,
token_list: token_list
},
dataType: "json",
success: function (data) {
console.log(data);
toastr.success(data.message);
allertaJS.main.loadTable({tablePage: "list", useCustomTableEngine: "default"});
}
});
}

View File

@ -61,8 +61,14 @@ var prodConfig = {
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"],
plugins: ["@babel/plugin-transform-runtime"]
presets: [
['@babel/preset-env', {
useBuiltIns: 'usage',
corejs: 3
}]
],
plugins: ["@babel/plugin-transform-runtime"],
sourceType: "unambiguous"
}
}
}

View File

@ -51,7 +51,7 @@
{% for user in service.crew %}
{% if user.driver == 1 and not user.hidden %}
<div class="form-check">
<input aria-label="{{ username(user.id) }}"id="drivers-{{ user.id }}" class="form-check-input drivers drivers-{{ user.id }}"
<input aria-label="{{ username(user.id) }}" id="drivers-{{ user.id }}" class="form-check-input drivers drivers-{{ user.id }}"
style="transform: scale(1.4); -webkit-transform: scale(1.4);" type="checkbox" name='drivers[]'
value='{{ user.id }}'>
<label class="form-check-label" for="drivers-{{ user.id }}">
@ -141,12 +141,12 @@
url: "resources/ajax/ajax_add_type.php",
method: "POST",
data: {
type: new_type
type: new_type
},
success: function (data) {
$('option:last-of-type').before($('<option>').val(new_type).text(new_type));
$('option[value='+new_type+']').prop('selected', 'selected').change();
toastr.success(`{{ "Type '%s' added successfully."|t|format('${new_type}') }}`);
$('option:last-of-type').before($('<option>').val(new_type).text(new_type));
$('option[value='+new_type+']').prop('selected', 'selected').change();
toastr.success('{{ "Type '%s' added successfully."|t|format('+new_type+')|raw }}');
}
});
}

View File

@ -51,6 +51,7 @@
</script>
{% endif %}
</div>
<br><br>
{% block footer %}
{% endblock %}

View File

@ -36,9 +36,9 @@
</div>
<div class="text-center">
<p>{{ 'Are you available in case of alert?'|t }}</p>
<button class="btn btn-lg btn-success" onclick="activate('{{ user.id }}')">{{ 'Activate'|t }}</button>
<button class="btn btn-lg btn-success" onclick="allertaJS.main.activate('{{ user.id }}', '')">{{ 'Activate'|t }}</button>
<button class="btn btn-lg btn-danger" style="background-color: red"
onclick="deactivate('{{ user.id }}')">{{ 'Deactivate'|t }}</button>
onclick="allertaJS.main.deactivate('{{ user.id }}', '')">{{ 'Deactivate'|t }}</button>
<br>
<button type="button" class="btn btn-lg" data-toggle="modal" data-target="#schedulesModal">
{{ 'Edit availability schedules'|t }}
@ -46,48 +46,6 @@
</div>
<br>
<br>
<script>
function generate_alert_string(id){
if(id == '{{ user.id }}'){
return '{{ "your availability"|t }}';
} else {
username = document.querySelector("#username-"+id).innerText;
return `{{ "%s availability"|t|format('${username}') }}`;
}
}
function activate(id) {
$.ajax({
url: "resources/ajax/ajax_change_availability.php",
method: "POST",
data: {
change_id: id,
dispo: 1,
token_list: "{{ token_list }}"
},
success: function (data) {
toastr.success(`{{ 'Thanks, %s, you have given %s in case of alert.'|t|format(user.name, '${generate_alert_string(id)}') }}`);
allertaJS.main.loadTable({tablePage: "list", useCustomTableEngine: "default"});
}
});
}
function deactivate(id) {
$.ajax({
url: "resources/ajax/ajax_change_availability.php",
method: "POST",
data: {
change_id: id,
dispo: 0,
token_list: "{{ token_list }}"
},
success: function (data) {
toastr.success(`{{ 'Thanks, %s, you have removed %s in case of alert.'|t|format(user.name, '${generate_alert_string(id)}') }}`);
allertaJS.main.loadTable({tablePage: "list", useCustomTableEngine: "default"});
}
});
}
</script>
<img alt="VVF" src="./resources/images/owner.png" width="150"
style="display: block; margin-left: auto; margin-right: auto;">
<br>