diff --git a/web/ajax/controlcaps.php b/web/ajax/controlcaps.php new file mode 100644 index 000000000..9e655c128 --- /dev/null +++ b/web/ajax/controlcaps.php @@ -0,0 +1,33 @@ + diff --git a/web/skins/classic/views/controlcaps.php b/web/skins/classic/views/controlcaps.php index 3fa04a600..705459afe 100644 --- a/web/skins/classic/views/controlcaps.php +++ b/web/skins/classic/views/controlcaps.php @@ -32,32 +32,45 @@ xhtmlHeaders(__FILE__, translate('ControlCaps'));
-
-
- - -
-
-

-
+ + +
+ + + + +
+
-
- - - +
- - - - - - - - - - + + + + + + + + + + + @@ -65,7 +78,9 @@ xhtmlHeaders(__FILE__, translate('ControlCaps')); foreach( $controls as $control ) { ?> - + + + @@ -74,18 +89,12 @@ foreach( $controls as $control ) { -
disabled="disabled"/>
-
- - -
-
diff --git a/web/skins/classic/views/js/controlcaps.js b/web/skins/classic/views/js/controlcaps.js index 6cedf1c3a..1631e58bc 100644 --- a/web/skins/classic/views/js/controlcaps.js +++ b/web/skins/classic/views/js/controlcaps.js @@ -1,10 +1,85 @@ +var table = $j('#controlTable'); +var addNewBtn = $j('#addNewBtn'); +var editBtn = $j('#editBtn'); +var deleteBtn = $j('#deleteBtn'); + // Manage the Add New Control button function AddNewControl(el) { url = el.getAttribute('data-url'); window.location.assign(url); } +// 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(); + + 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) { + if ( $j('#deleteConfirm').length ) { + $j('#deleteConfirm').replaceWith(data.html); + } else { + $j("body").append(data.html); + } + manageDelConfirmModalBtns(); + }) + .fail(logAjaxFail); +} + +// Manage the DELETE CONFIRMATION modal button +function manageDelConfirmModalBtns() { + document.getElementById("delConfirmBtn").addEventListener("click", function onDelConfirmClick(evt) { + if ( ! canEditControl ) { + 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); + }); +} + function initPage() { + + // 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'); + + addNewBtn.prop('disabled', (selections.length || !canEditControl)); + editBtn.prop('disabled', !((selections.length == 1) && canEditControl)); + deleteBtn.prop('disabled', !(selections.length && canEditControl)); + }); + + // Init the bootstrap-table + table.bootstrapTable({icons: icons}); + // Manage the BACK button document.getElementById("backBtn").addEventListener("click", function onBackClick(evt) { evt.preventDefault(); @@ -19,6 +94,25 @@ function initPage() { evt.preventDefault(); window.location.reload(true); }); + + // Manage the DELETE button + document.getElementById("deleteBtn").addEventListener("click", function onDeleteClick(evt) { + if ( ! canEditControl ) { + 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'); + } } $j(document).ready(function() { diff --git a/web/skins/classic/views/js/controlcaps.js.php b/web/skins/classic/views/js/controlcaps.js.php new file mode 100644 index 000000000..6db74d130 --- /dev/null +++ b/web/skins/classic/views/js/controlcaps.js.php @@ -0,0 +1 @@ +var canEditControl = ;