EVOLUTION-NINJA
Edit File: employee_list.php
<?php echo view('includes/home_sidebar');?> <!DOCTYPE html> <html> <head> <title>Employee List</title> <script type="text/javascript" src="<?php echo base_url('public/assets/js/jquery-3.6.0.min.js'); ?>"></script> <script type="text/ecmascript" src="<?php echo base_url('public/jqgrid/js/jquery.jqGrid.min.js'); ?>"></script> <script type="text/ecmascript" src="<?php echo base_url('public/jqgrid/js/i18n/grid.locale-en.js'); ?>"></script> <link rel="stylesheet" type="text/css" media="screen" href="<?php echo base_url('public/assets/css/jquery-ui.css'); ?>" /> <link rel="stylesheet" type="text/css" media="screen" href="<?php echo base_url('public/jqgrid/css/ui.jqgrid.css'); ?>" /> <link rel="stylesheet" type="text/css" media="screen" href="<?php echo base_url('public/jqgrid/css/ui.jqgrid-bootstrap.css'); ?>" /> <script src="<?php echo base_url('public/assets/js/jquery-ui.js'); ?>" type="text/javascript"></script> <script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script> <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script> </head> <!-- <body> --> <div style="padding-inline:3%"> <div > <div class="row fee-collection"> <div class="col-sm-4"> <h4 class="user-tag">Employee List</h4> </div> <div class="col-sm-6"> </div> <div class="col-sm-2"> <button class="btn back-butt" onclick="goBack()"><i class="fa fa-arrow-left" aria-hidden="true"></i> Back</button> </div> </div> <!-- <h4 class="user-tag">Employee List</h4> --> </div> <div class="grid_div mt-4"> <table id="employeeList"></table> </div> <div id="pager3"></div> </div> <script> $(document).ready(function () { $("#employeeList").jqGrid({ url: '<?php echo site_url('fetch-emp-list');?>', datatype: 'json', colNames: ['ID','id','Employee ID' ,'Full Name','Title','Department', 'Phone', 'Email', 'Date','Action'], colModel: [ { name: 'id', index: 'id', hidden: true }, { name: 'emp_id', index: 'emp_id', hidden: true }, { name: 'employee_id', index: 'id',width:200 }, // { name: 'first_name', index: 'first_name', width: 100 }, // { name: 'last_name', index: 'lastname', width: 100 }, { name: 'full_name', index: 'full_name', width: 200, formatter: function (cellvalue, options, rowObject) { var firstName = rowObject.first_name; // Assuming first_name is available in rowObject var lastName = rowObject.last_name; // Assuming last_name is available in rowObject var fullName = firstName + " " + lastName; return fullName; } }, { name: 'title', index: 'title' ,width:200}, { name: 'department', index: 'department', width: 150 }, // { name: 'title', index: 'title', width: 150 }, { name: 'work_phone', index: 'phone', width: 200 }, { name: 'email', index: 'email', width: 200 }, { name: 'date_of_joining', index: 'date', width: 200 }, // { name: 'action', width: 200, align: 'center', sortable: false, formatter: function (cellValue, options, rowObject) { // // console.log(rowObject.employee_id); // var editButton = '<button class="btn btn-primary editButton" data-id="' + rowObject.employee_id + '">Edit</button>'; // var deleteButton = '<button class="btn btn-danger deleteButton" data-id="' + rowObject.employee_id + '">Delete</button>'; // var make = `<button class="btn btn-success " onclick="promote(${rowObject.emp_id})" >Promote</button>`; // return editButton + ' | ' + deleteButton +' | ' + make; // }} { name: 'action', width: 300, align: 'center', sortable: false, formatter: function (cellValue, options, rowObject) { var editButton = '<button class="btn btn-primary editButton" data-id="' + rowObject.employee_id + '">Edit</button>'; var deleteButton = '<button class="btn btn-danger deleteButton" data-id="' + rowObject.employee_id + '">Delete</button>'; var make = `<button class="btn btn-success " onclick="promote(${rowObject.emp_id})" >Promote</button>`; return editButton + ' | ' + deleteButton+' | ' + make; }, cellattr: function (rowId, value, rawObject, cm, rdata) { return 'id="action-' + rowId + '"'; } } ], pager: '#pager3', rownumbers: true, // rowNum: 10, rowList: [50, 100, 200, 300], viewrecords: true, gridview: true, height: 'auto', shrinkToFit: true, autowidth: true, caption: "Employee List", onInitGrid: function () { $(this).jqGrid('filterToolbar', { stringResult: true, searchOperators: true }); } }); $("#employeeList").jqGrid('navGrid','#pager3', {edit:false, add:false, del:false, search:true, refresh:true}, { }, { }, { }, { sopt:['eq', 'ne', 'lt', 'gt', 'cn', 'bw', 'ew'], closeOnEscape: true, multipleSearch: true, closeAfterSearch: true } ); }); // $(document).ready(function() { // $(document).on('click', '.deleteButton', function () { // var $deleteButton = $(this); // var rowId = $deleteButton.closest('tr').attr('id'); // Extracting ID from the table row // Swal.fire({ // title: 'Are you sure?', // text: 'You are about to delete this data!', // icon: 'warning', // showCancelButton: true, // confirmButtonColor: '#dc3545', // cancelButtonColor: '#007bff', // confirmButtonText: 'Yes, delete it!' // }).then((result) => { // if (result.isConfirmed) { // $.ajax({ // url: '<?= site_url('delete-employee') ?>', // type: 'POST', // data: { id: rowId }, // success: function (response) { // if (response.status === 'success') { // $("#employeeList").jqGrid('delRowData', rowId); // Swal.fire('Deleted!', 'Your data has been deleted.', 'success'); // } else { // Swal.fire('Error', 'Failed to delete data.', 'error'); // } // }, // error: function () { // Swal.fire('Error', 'Failed to send AJAX request.', 'error'); // } // }); // } // }); // }); // }); $(document).ready(function() { $(document).on('click', '.deleteButton', function () { var $deleteButton = $(this); var rowId = $deleteButton.closest('tr').attr('id'); // Extracting ID from the table row var employeeId = $deleteButton.data('id'); // Extracting employee ID from the button data attribute Swal.fire({ title: 'Are you sure?', text: 'You are about to delete this data!', icon: 'warning', showCancelButton: true, confirmButtonColor: '#dc3545', cancelButtonColor: '#007bff', confirmButtonText: 'Yes, delete it!' }).then((result) => { if (result.isConfirmed) { // AJAX request to delete employee $.ajax({ url: '<?php echo site_url('delete-employee'); ?>', // Adjusted endpoint URL method: 'POST', // Use POST method for compatibility with CodeIgniter's CSRF protection data: { employee_id: employeeId, // Add CSRF token for CSRF protection '<?php echo csrf_token(); ?>': '<?php echo csrf_hash(); ?>' }, success: function (response) { // Assuming success response indicates successful deletion if (response.status === 'success') { $("#" + rowId).remove(); // Remove the row from the table Swal.fire('Deleted!', 'Your data has been deleted.', 'success'); } else { Swal.fire('Error', 'Failed to delete data.', 'error'); } }, error: function (xhr, status, error) { console.error('Error deleting employee:', error); Swal.fire('Error', 'Failed to delete data.', 'error'); } }); } }); }); }); $(document).on('click', '.editButton', function() { var rowId = $(this).data('id'); // Redirect to the edit_emp_list page with the employee_id parameter window.location.href = '<?php echo base_url('edit_emp_list');?>?employee_id=' + rowId; }); </script> <!-- BACK BUTTON SCRIPT --> <div class="modal fade" id="editModal" tabindex="-1" aria-labelledby="editModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="editModalLabel">Access Control</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <form id="promoteform"> <div class="modal-body fee-modal"> <input type="hidden" name="eid" id="eid" /> <label for="modepy">Promote</label> <select name="type" id="" class="form-control" required> <option value="" selected>Select</option> <option value="1">Admin</option> <option value="2">Trainer</option> </select> <br> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary-color" data-bs-dismiss="modal">Cancel</button> <button type="submit" id='collect-btn' class="btn btn-primary-color">SUBMIT</button> </div> </form> </div> </div> </div> <script> // promote function promote(id){ $('#eid').val(id); $('#editModal').modal('show'); } $(document).ready(function(){ $('#promoteform').submit(function(e){ e.preventDefault(); var formdata = new FormData($(this)[0]); $.ajax({ type: 'post', url: '<?php echo base_url("promote-employee");?>', data: formdata, contentType: false, processData: false, success: function (response) { if (response.result == 1) { Swal.fire({ icon: "success", title: response.message, showConfirmButton: false, timer: 2000 }); $('#editModal').modal('hide'); } else { Swal.fire({ icon: "error", title: response.message, showConfirmButton: false, timer: 1000 }); $('#editModal').modal('hide'); } }, error: function (xhr, textStatus, errorThrown) { console.error(xhr.responseText); Swal.fire({ icon: "error", title: "An error occurred", showConfirmButton: false, timer: 1000 }); }, }); }) }) function goBack() { window.location.href = 'dashboard'; } </script> <!-- </body> </html> --> <style> .btn-secondary-color{ color: white; background-image: linear-gradient(-60deg, #dda44f 0%, #f09819 100%); } .btn-primary-color{ background-color: cadetblue; color: white; } .btn-secondary-color:hover{ color: white; background-image: linear-gradient(-60deg, #dda44f 0%, #f09819 100%); } .btn-primary-color:hover{ background-color: cadetblue; color: white; } #editModal .modal-content{ background-color: #eff3f8; } .ui-jqgrid-sdiv { display: none !important; } .ui-jqgrid-titlebar { background-color: rgba(0, 72, 76, 1); } .ui-jqgrid-title { color: #fff; font-weight: 600; font-size: 18px; } .user-tag { color: rgba(0, 72, 76, 1); font-weight: 600; font-size: 24px; } .soptclass { display: none; } @media only screen and (max-width: 600px) { #mobile-div { padding: 20px; } .u_e { margin-bottom: 5px; } .u_s { margin-bottom: 5px; } } .ui-jqgrid { z-index: 1; } </style> <?php echo view('includes/footer'); ?>