2020-09-27 01:09:41 +08:00
|
|
|
var table = $j('#controlTable');
|
|
|
|
var addNewBtn = $j('#addNewBtn');
|
|
|
|
var editBtn = $j('#editBtn');
|
|
|
|
var deleteBtn = $j('#deleteBtn');
|
|
|
|
|
2020-09-26 05:12:05 +08:00
|
|
|
// Manage the Add New Control button
|
|
|
|
function AddNewControl(el) {
|
|
|
|
url = el.getAttribute('data-url');
|
|
|
|
window.location.assign(url);
|
|
|
|
}
|
|
|
|
|
2020-09-27 01:09:41 +08:00
|
|
|
// Manage the Add New Control button
|
|
|
|
function addNewControl(el) {
|
|
|
|
url = el.getAttribute('data-url');
|
|
|
|
window.location.assign(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Manage the Edit Control button
|
|
|
|
function editControl(el) {
|
|
|
|
var selection = getIdSelections();
|
2020-09-27 02:55:56 +08:00
|
|
|
|
2020-09-27 01:09:41 +08:00
|
|
|
url = el.getAttribute('data-url');
|
|
|
|
window.location.assign(url+selection);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the event id's of the selected rows
|
|
|
|
function getIdSelections() {
|
|
|
|
return $j.map(table.bootstrapTable('getSelections'), function(row) {
|
|
|
|
return row.Id.replace(/(<([^>]+)>)/gi, ''); // strip the html from the element before sending
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the Delete Confirmation Modal HTML via Ajax call
|
|
|
|
function getDelConfirmModal(key) {
|
|
|
|
$j.getJSON(thisUrl + '?request=modal&modal=delconfirm&key=' + key)
|
|
|
|
.done(function(data) {
|
2020-10-15 04:58:39 +08:00
|
|
|
insertModalHtml('deleteConfirm', data.html);
|
2020-09-27 01:09:41 +08:00
|
|
|
manageDelConfirmModalBtns();
|
|
|
|
})
|
|
|
|
.fail(logAjaxFail);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Manage the DELETE CONFIRMATION modal button
|
|
|
|
function manageDelConfirmModalBtns() {
|
|
|
|
document.getElementById("delConfirmBtn").addEventListener("click", function onDelConfirmClick(evt) {
|
2020-12-09 04:25:48 +08:00
|
|
|
if ( ! canEdit.Control ) {
|
2020-09-27 01:09:41 +08:00
|
|
|
enoperm();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var selections = getIdSelections();
|
|
|
|
|
|
|
|
evt.preventDefault();
|
|
|
|
$j.getJSON(thisUrl + '?request=controlcaps&action=delete&cids[]='+selections.join('&cids[]='))
|
|
|
|
.done( function(data) {
|
|
|
|
$j('#eventTable').bootstrapTable('refresh');
|
|
|
|
window.location.reload(true);
|
|
|
|
})
|
|
|
|
.fail(logAjaxFail);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-26 05:05:16 +08:00
|
|
|
function initPage() {
|
2020-09-27 01:09:41 +08:00
|
|
|
// enable or disable buttons based on current selection and user rights
|
|
|
|
table.on('check.bs.table uncheck.bs.table ' +
|
|
|
|
'check-all.bs.table uncheck-all.bs.table',
|
|
|
|
function() {
|
|
|
|
selections = table.bootstrapTable('getSelections');
|
|
|
|
|
2020-12-09 04:25:48 +08:00
|
|
|
addNewBtn.prop('disabled', (selections.length || !canEdit.Control));
|
|
|
|
editBtn.prop('disabled', !((selections.length == 1) && canEdit.Control));
|
|
|
|
deleteBtn.prop('disabled', !(selections.length && canEdit.Control));
|
2020-09-27 01:09:41 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
// Init the bootstrap-table
|
|
|
|
table.bootstrapTable({icons: icons});
|
|
|
|
|
2020-09-26 05:05:16 +08:00
|
|
|
// Manage the BACK button
|
|
|
|
document.getElementById("backBtn").addEventListener("click", function onBackClick(evt) {
|
|
|
|
evt.preventDefault();
|
|
|
|
window.history.back();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Disable the back button if there is nothing to go back to
|
|
|
|
$j('#backBtn').prop('disabled', !document.referrer.length);
|
|
|
|
|
|
|
|
// Manage the REFRESH Button
|
|
|
|
document.getElementById("refreshBtn").addEventListener("click", function onRefreshClick(evt) {
|
|
|
|
evt.preventDefault();
|
|
|
|
window.location.reload(true);
|
|
|
|
});
|
2020-09-27 01:09:41 +08:00
|
|
|
|
|
|
|
// Manage the DELETE button
|
|
|
|
document.getElementById("deleteBtn").addEventListener("click", function onDeleteClick(evt) {
|
2020-12-09 04:25:48 +08:00
|
|
|
if ( ! canEdit.Control ) {
|
2020-09-27 01:09:41 +08:00
|
|
|
enoperm();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
evt.preventDefault();
|
|
|
|
$j('#deleteConfirm').modal('show');
|
|
|
|
});
|
|
|
|
|
|
|
|
// Load the delete confirmation modal into the DOM
|
|
|
|
getDelConfirmModal('ConfirmDeleteControl');
|
|
|
|
|
|
|
|
// Hide these columns on first run when no cookie is saved
|
|
|
|
if ( !getCookie("zmControlTable.bs.table.columns") ) {
|
|
|
|
table.bootstrapTable('hideColumn', 'Id');
|
|
|
|
}
|
2020-09-26 05:05:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$j(document).ready(function() {
|
|
|
|
initPage();
|
|
|
|
});
|