reformat dashboard js code to subfunctions
This commit is contained in:
parent
e5d579e9d0
commit
02e6f96a3a
@ -1,159 +1,30 @@
|
||||
$(document).ready(function () {
|
||||
//load total collections
|
||||
$.post('/senddata/wastedata', 'action=getStartHeaderData', function (data) {
|
||||
console.log(data);
|
||||
$("#total-connection-labels").html(data.collectionnumber);
|
||||
|
||||
$("#planed-collection-label").html(data.futurecollections);
|
||||
|
||||
$("#finished-collection-label").html(data.finshedcollections);
|
||||
|
||||
$("#total-city-number-label").html(data.citynumber);
|
||||
}, 'json');
|
||||
|
||||
//load version footer
|
||||
//
|
||||
$.post('/senddata/wastedata', 'action=getversionandbuildtime', function (data) {
|
||||
$("#version-footer-label").html("<b>Version</b> " + data.version + " <b>Build</b> " + data.buildtime);
|
||||
}, 'json');
|
||||
|
||||
|
||||
/* Constants */
|
||||
var citytable;
|
||||
var datetable;
|
||||
|
||||
function reloadtable() {
|
||||
$.post('/senddata/wastedata', 'action=getAllCities', function (data) {
|
||||
if (citytable != null) {
|
||||
citytable.destroy(); //delete table if already created
|
||||
}
|
||||
//load header data
|
||||
loadHeaderData();
|
||||
|
||||
console.log(data);
|
||||
if (data.query == "ok") {
|
||||
$('#location-table-data').html("");
|
||||
$(".delbtn").off();
|
||||
//load footer
|
||||
loadVersionFooter();
|
||||
|
||||
for (var i = 0; i < data.data.length; i++) {
|
||||
$('#location-table-data').append("<tr>" +
|
||||
"<td>" + data.data[i].cityname + "</td>" +
|
||||
"<td>" + data.data[i].zone + "</td>" +
|
||||
"<td>" + data.data[i].wastetype + "</td>" +
|
||||
"<td>" + "<button dataid='" + data.data[i].id + "' type='button' class='delbtn btn btn-danger'>X</button>" + "</td>" +
|
||||
"</tr>");
|
||||
}
|
||||
|
||||
$(".delbtn").click(function (event) {
|
||||
var id = event.target.getAttribute("dataid");
|
||||
console.log("clicked btn data " + id);
|
||||
$.post('/senddata/wastedata', 'action=deletecity&id=' + id, function (data) {
|
||||
console.log(data);
|
||||
if (data.status == "success") {
|
||||
Swal.fire({
|
||||
type: "success",
|
||||
title: 'Successfully deleted city!',
|
||||
html: 'This alert closes automatically.',
|
||||
timer: 1000,
|
||||
}).then((result) => {
|
||||
console.log('Popup closed. ')
|
||||
|
||||
});
|
||||
//reload city table
|
||||
reloadtable();
|
||||
} else if (data.status == "dependenciesnotdeleted") {
|
||||
Swal.fire({
|
||||
type: "warning",
|
||||
title: 'This city is a dependency of a date',
|
||||
html: 'Do you want do delete it anyway with all dependencies?',
|
||||
}).then((result) => {
|
||||
console.log('Popup closed. ')
|
||||
|
||||
});
|
||||
//todo set yes no button here
|
||||
}
|
||||
|
||||
}, "json");
|
||||
});
|
||||
|
||||
citytable = $("#example2").DataTable();
|
||||
} else if (data.query == "nodbconn") {
|
||||
Swal.fire({
|
||||
type: "error",
|
||||
title: 'No connection to Database',
|
||||
html: 'Setup DB here --> <a href="index.html">click<a/>.',
|
||||
}).then((result) => {
|
||||
console.log('Popup closed. ')
|
||||
|
||||
});
|
||||
} else {
|
||||
console.log("Error: " + data.query);
|
||||
}
|
||||
|
||||
}, 'json');
|
||||
}
|
||||
|
||||
|
||||
function reloadDateTable() {
|
||||
$.post('/senddata/wastedata', 'action=getAllDates', function (data) {
|
||||
if (datetable != null) {
|
||||
datetable.destroy(); //delete table if already created
|
||||
}
|
||||
console.log(data);
|
||||
|
||||
if (data.query == "ok") {
|
||||
$('#picupdates-tablebody').html("");
|
||||
$(".delbtndate").off();
|
||||
|
||||
for (var i = 0; i < data.data.length; i++) {
|
||||
$('#picupdates-tablebody').append("<tr>" +
|
||||
"<td>" + data.data[i].cityname + "</td>" +
|
||||
"<td>" + data.data[i].zone + "</td>" +
|
||||
"<td>" + data.data[i].wastetype + "</td>" +
|
||||
"<td>" + data.data[i].date + "</td>" +
|
||||
"<td>" + "<button dataid='" + data.data[i].id + "' type='button' class='delbtndate btn btn-danger'>X</button>" + "</td>" +
|
||||
"</tr>");
|
||||
}
|
||||
|
||||
$(".delbtndate").click(function (event) {
|
||||
var id = event.target.getAttribute("dataid");
|
||||
console.log("clicked btn data " + id);
|
||||
$.post('/senddata/wastedata', 'action=deletedate&id=' + id, function (data) {
|
||||
console.log(data);
|
||||
if (data.status == "success") {
|
||||
Swal.fire({
|
||||
type: "success",
|
||||
title: 'Successfully deleted city!',
|
||||
html: 'This alert closes automatically.',
|
||||
timer: 1000,
|
||||
}).then((result) => {
|
||||
console.log('Popup closed. ')
|
||||
|
||||
});
|
||||
reloadDateTable();
|
||||
} else if (data.status == "dependenciesnotdeleted") {
|
||||
Swal.fire({
|
||||
type: "warning",
|
||||
title: 'This city is a dependency of a date',
|
||||
html: 'Do you want do delete it anyway with all dependencies?',
|
||||
}).then((result) => {
|
||||
console.log('Popup closed. ')
|
||||
|
||||
});
|
||||
//todo set yes no button here
|
||||
}
|
||||
|
||||
}, "json");
|
||||
});
|
||||
}
|
||||
datetable = $("#table-pickupdates").DataTable({
|
||||
"order": [[3, "asc"]]
|
||||
});
|
||||
|
||||
//todo picupdates-tablebody
|
||||
}, "json");
|
||||
}
|
||||
|
||||
reloadtable();
|
||||
//reload Date table
|
||||
reloadDateTable();
|
||||
|
||||
//init time picker
|
||||
initDatePicker();
|
||||
|
||||
//add click listeners to all buttons
|
||||
addClickListeners();
|
||||
|
||||
|
||||
/* Btn Action Listeners */
|
||||
|
||||
function addClickListeners() {
|
||||
//btn listeners
|
||||
$('#logoutbtn').click(function () {
|
||||
$.post('/senddata/checkloginstate', 'action=logout', function (data) {
|
||||
@ -320,8 +191,12 @@ $(document).ready(function () {
|
||||
console.log(data)
|
||||
}, "json");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/* Functions */
|
||||
|
||||
function initDatePicker() {
|
||||
//Date picker pop up actions...
|
||||
var date_input = $('input[name="date"]'); //our date input has the name "date"
|
||||
var container = $('.bootstrap-iso form').length > 0 ? $('.bootstrap-iso form').parent() : "body";
|
||||
@ -332,4 +207,156 @@ $(document).ready(function () {
|
||||
autoclose: true,
|
||||
};
|
||||
date_input.datepicker(options);
|
||||
}
|
||||
|
||||
function loadHeaderData() {
|
||||
$.post('/senddata/wastedata', 'action=getStartHeaderData', function (data) {
|
||||
console.log(data);
|
||||
$("#total-connection-labels").html(data.collectionnumber);
|
||||
|
||||
$("#planed-collection-label").html(data.futurecollections);
|
||||
|
||||
$("#finished-collection-label").html(data.finshedcollections);
|
||||
|
||||
$("#total-city-number-label").html(data.citynumber);
|
||||
}, 'json');
|
||||
}
|
||||
|
||||
function loadVersionFooter() {
|
||||
$.post('/senddata/wastedata', 'action=getversionandbuildtime', function (data) {
|
||||
$("#version-footer-label").html("<b>Version</b> " + data.version + " <b>Build</b> " + data.buildtime);
|
||||
}, 'json');
|
||||
}
|
||||
|
||||
function reloadtable() {
|
||||
$.post('/senddata/wastedata', 'action=getAllCities', function (data) {
|
||||
if (citytable != null) {
|
||||
citytable.destroy(); //delete table if already created
|
||||
}
|
||||
|
||||
console.log(data);
|
||||
if (data.query == "ok") {
|
||||
var tabledata = $('#location-table-data');
|
||||
|
||||
|
||||
tabledata.html("");
|
||||
//todo in variable
|
||||
$(".delbtn").off();
|
||||
|
||||
for (var i = 0; i < data.data.length; i++) {
|
||||
tabledata.append("<tr>" +
|
||||
"<td>" + data.data[i].cityname + "</td>" +
|
||||
"<td>" + data.data[i].zone + "</td>" +
|
||||
"<td>" + data.data[i].wastetype + "</td>" +
|
||||
"<td>" + "<button dataid='" + data.data[i].id + "' type='button' class='delbtn btn btn-danger'>X</button>" + "</td>" +
|
||||
"</tr>");
|
||||
}
|
||||
|
||||
$(".delbtn").click(function (event) {
|
||||
var id = event.target.getAttribute("dataid");
|
||||
console.log("clicked btn data " + id);
|
||||
$.post('/senddata/wastedata', 'action=deletecity&id=' + id, function (data) {
|
||||
console.log(data);
|
||||
if (data.status === "success") {
|
||||
Swal.fire({
|
||||
type: "success",
|
||||
title: 'Successfully deleted city!',
|
||||
html: 'This alert closes automatically.',
|
||||
timer: 1000,
|
||||
}).then((result) => {
|
||||
console.log('Popup closed. ')
|
||||
|
||||
});
|
||||
reloadtable();
|
||||
} else if (data.status === "dependenciesnotdeleted") {
|
||||
Swal.fire({
|
||||
type: "warning",
|
||||
title: 'This city is a dependency of a date',
|
||||
html: 'Do you want do delete it anyway with all dependencies?',
|
||||
}).then((result) => {
|
||||
console.log('Popup closed. ')
|
||||
|
||||
});
|
||||
//todo set yes no button here
|
||||
}
|
||||
|
||||
}, "json");
|
||||
});
|
||||
|
||||
citytable = $("#example2").DataTable();
|
||||
} else if (data.query == "nodbconn") {
|
||||
Swal.fire({
|
||||
type: "error",
|
||||
title: 'No connection to Database',
|
||||
html: 'Setup DB here --> <a href="index.html">click<a/>.',
|
||||
}).then((result) => {
|
||||
console.log('Popup closed. ')
|
||||
|
||||
});
|
||||
} else {
|
||||
console.log("Error: " + data.query);
|
||||
}
|
||||
|
||||
}, 'json');
|
||||
}
|
||||
|
||||
function reloadDateTable() {
|
||||
$.post('/senddata/wastedata', 'action=getAllDates', function (data) {
|
||||
if (datetable != null) {
|
||||
datetable.destroy(); //delete table if already created
|
||||
}
|
||||
console.log(data);
|
||||
|
||||
if (data.query == "ok") {
|
||||
$('#picupdates-tablebody').html("");
|
||||
$(".delbtndate").off();
|
||||
|
||||
for (var i = 0; i < data.data.length; i++) {
|
||||
$('#picupdates-tablebody').append("<tr>" +
|
||||
"<td>" + data.data[i].cityname + "</td>" +
|
||||
"<td>" + data.data[i].zone + "</td>" +
|
||||
"<td>" + data.data[i].wastetype + "</td>" +
|
||||
"<td>" + data.data[i].date + "</td>" +
|
||||
"<td>" + "<button dataid='" + data.data[i].id + "' type='button' class='delbtndate btn btn-danger'>X</button>" + "</td>" +
|
||||
"</tr>");
|
||||
}
|
||||
|
||||
$(".delbtndate").click(function (event) {
|
||||
var id = event.target.getAttribute("dataid");
|
||||
console.log("clicked btn data " + id);
|
||||
$.post('/senddata/wastedata', 'action=deletedate&id=' + id, function (data) {
|
||||
console.log(data);
|
||||
if (data.status == "success") {
|
||||
Swal.fire({
|
||||
type: "success",
|
||||
title: 'Successfully deleted city!',
|
||||
html: 'This alert closes automatically.',
|
||||
timer: 1000,
|
||||
}).then((result) => {
|
||||
console.log('Popup closed. ')
|
||||
|
||||
});
|
||||
reloadDateTable();
|
||||
} else if (data.status == "dependenciesnotdeleted") {
|
||||
Swal.fire({
|
||||
type: "warning",
|
||||
title: 'This city is a dependency of a date',
|
||||
html: 'Do you want do delete it anyway with all dependencies?',
|
||||
}).then((result) => {
|
||||
console.log('Popup closed. ')
|
||||
|
||||
});
|
||||
//todo set yes no button here
|
||||
}
|
||||
|
||||
}, "json");
|
||||
});
|
||||
}
|
||||
datetable = $("#table-pickupdates").DataTable({
|
||||
"order": [[3, "asc"]]
|
||||
});
|
||||
|
||||
//todo picupdates-tablebody
|
||||
}, "json");
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user