EVOLUTION-NINJA
Edit File: departments.php
<?php echo view('includes/header');?> <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'); ?>" /> <!-- The link to the CSS that the grid needs --> <link rel="stylesheet" type="text/css" media="screen" href="<?php echo base_url('public/jqgrid/css/ui.jqgrid.css'); ?>" /> <script src="<?php echo base_url('public/assets/js/jquery-ui.js'); ?>" type="text/javascript"></script> <section class="content-header"> <h1> Cost Centre-Departments </h1> </section> <!--- section 1 --> <section class="content"> <button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#myModal"> Add Department </button> <!-- Modal --> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="myModalLabel">Add CC-Department</h4> </div> <div class="modal-body"> <form id="land_owner" class="form-inline usertype_form" enctype="multipart/form-data"> <div class="row land_owner_a"> <div class="form-group col-sm-12 col-md-8"> <label class="col-sm-4">CC-Department</label> <input type="text" class="form-control col-sm-8" name="department" required="required"> </div> </div> <!-- row 1--> <div class="row land_owner_a"> <div class="col-sm-4 col-md-4"></div> <div class="col-sm-4 col-md-4"> <button type="submit" class="btn btn-primary center-block submit_button submit">Submit</button> </div> <div class="col-sm-4 col-md-4"></div> </div> <!-- row 6--> </form> </div> </div> </div> </div> <div class="row" style=""> <div class="col-md-3"></div> <div class="col-md-7"> <div id = "jaytab3" style="margin-top:3%;margin-left: -28px;" class="grid"> <div class="grid_div"></div><table id="list3"></table> <div id="pager3"></div> <div id="dialogSelectRow3" title="Warning" style="display:none"> <p>Please select row</p> </div> </div> </div> </div> </div> <!--- col-sm-8 --> --> <div class="col-sm-0 col-md-1"></div> </section> <!--- section 2 --> <!-- Modal --> <div class="modal fade" id="edit_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="myModalLabel">Update CC-Department</h4> </div> <div class="modal-body"> <form id="land_owner" class="form-inline update_form" enctype="multipart/form-data"> <input type="hidden" class="form-control col-sm-8 user_type_id_pk" name="user_type_id" required="required"> <div class="row land_owner_a"> <div class="form-group col-sm-12 col-md-8"> <label class="col-sm-4">CC-Department</label> <input type="text" class="form-control col-sm-8 department" name="department" required="required"> </div> </div> <!-- row 1--> <div class="row land_owner_a"> <div class="col-sm-4 col-md-4"></div> <div class="col-sm-4 col-md-4"> <button type="submit" class="btn btn-primary center-block update_button submit">Update</button> </div> <div class="col-sm-4 col-md-4"></div> </div> <!-- row 5--> </form> </div> </div> </div> </div> <style type="text/css"> .content-wrapper, .right-side { //min-height:900px !important; } a { color: inherit; } .form-control:focus, input[type="Submit"]:focus, input[type="button"]:focus { border-color: #FF0000; box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(255, 0, 0, 0.6); } #FrmGrid_list2 { width: 100% !important; } .ui-jqdialog .ui-jqdialog-titlebar { height: 29px !important; background-color: #001a00; color: white; padding-left: 10px; } .fm-button { height: 21px !important; padding: 1px; margin-right: 10px !important; height: 21px !important; width: 50%; margin-top: -7px !important; } .ui-jqdialog-content td.navButton { padding-top: 12px !important; } .ui-jqgrid .ui-jqgrid-titlebar { height: 27px !important; background:#AF0100 !important; color:white !important; } .ui-jqgrid-bdiv { height: 232px !important; } .ui-widget-overlay { z-index:0 !important; } .ui-widget-header { background: #1e7ad7 !important; } .ui-jqgrid-hdiv ui-state-default { width: 873px !important; cursor: default!important } ui-state-highlight, .ui-widget-content .ui-state-highlight, .ui-widget-header .ui-state-highlight { border: 1px solid #fed22f; background: #ffe45c; } .ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { font-weight: bold; color: black; } .ui-jqgrid .ui-jqgrid-bdiv { overflow-y: scroll; //overflow-x: hidden; } .agr_appr { font-weight:bold !important; color:#AF0100; cursor: pointer; } </style> <script type="text/javascript"> $(document).ready(function (){ jQuery("#list3").jqGrid({ url:"<?php echo site_url('department-list')?>", mtype : "post", datatype: "json", colNames:['SI','Cost Centre-Department Name','Edit','Delete'], colModel:[ {name:'user_type_id',index:'user_type_id', width:50, hidden:true,editable:false,key:true}, {name:'user_type',index:'user_type', width:250, editable:false}, {name:' ',index:' ',editable:false,align: "center",editrules:{required: true}, width:150,cellattr: function (rowId, tv, rawObject, cm, rdata) { return ' onclick="reg_fun($(this))" '; },formatter:function (cellvalue, options, rowObject) { return "<input type='button' value='EDIT' \>"; }}, {name:'delete',index:'delete',align: "center",editable:false,editrules:{required: true}, width:150,cellattr: function (rowId, tv, rawObject, cm, rdata) { return ' onclick="fun_delete($(this))" '; },formatter:function (cellvalue, options, rowObject) { return "<input type='button' value='DELETE' \>"; }}, ], rowNum:20, rowTotal: 2000, rowList : [10,20,30,50,100,500,1000], rownumbers: true, rownumWidth: 40, pager:"#pager3", sortname:'owner_id', viewrecords: true, gridview: true, autowidth: true, sortorder:"asc", shrinkToFit: false, emptyrecords: 'No records to display', // multiselect: true, // multiboxonly: true, loadonce:true, caption:" CC-Department List", }); $("#list3").jqGrid("setLabel", "rn", "SL"); $("#list3").jqGrid('filterToolbar',{searchOperators : false}); //for multisearch code,remove if not required $("#list3").jqGrid('navGrid','#pager3', {edit:true,add:false,del:false,search:true,refreshstate:"current"}, { }, { }, { }, { sopt:['eq', 'ne', 'lt', 'gt', 'cn', 'bw', 'ew'], closeOnEscape: true, multipleSearch: true, closeAfterSearch: true } ); }); function reg_fun(rowId) { var user_type_id = rowId.closest('tr').attr('id'); var app = $("#list3").jqGrid('getRowData',user_type_id); app=app.user_type; $(".user_type_id_pk").val(user_type_id); $(".department").val(app); $("#edit_modal").modal("show"); } function fun_delete(rowId) { var user_type_id = rowId.closest('tr').attr('id'); swal({ title: "Are you sure?", text: "You will not be able to recover this data!", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "Yes, delete it!", cancelButtonText: "No, cancel plz!", closeOnConfirm: false, closeOnCancel: false }, function(isConfirm){ if (isConfirm) { $(".sweet-alert").hide(); $(".sweet-overlay").hide(); // test.attr('disabled', 'disabled'); // test.text("Deleting..."); $.ajax({ type : 'post', url : '<?php echo site_url("delete-usertype")?>', data : {user_type_id:user_type_id}, success:function(response) { // response=jQuery.parseJSON(response); console.log(response); if(response.result == 1) { toastr["success"](response.message); $("#list3").jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid'); location.reload(); } } }); } else { $(".sweet-alert").hide(); $(".sweet-overlay").hide(); } }); } $('.usertype_form').submit(function(e){ e.preventDefault(); formdata = new FormData($(this)[0]); $(".submit_button").attr('disabled', 'disabled'); $(".submit_button").text("Submitting..."); $.ajax({ type : 'post', url : '<?php echo site_url("add-department")?>', data : formdata, contentType: false, processData: false, success:function(response){ // response=jQuery.parseJSON(response); console.log(response); if(response.result == 1) { $("#myModal").modal("hide"); toastr["success"](response.message); $('.usertype_form')[0].reset(); $(".submit_button").text("Submit"); $(".submit_button").removeAttr('disabled'); $("#list3").jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid'); } else if(response.result == 2) { toastr["error"](response.message); $(".submit_button").text("Submit"); $(".submit_button").removeAttr('disabled'); } else { toastr["error"](response.message); $(".submit_button").text("Submit"); $(".submit_button").removeAttr('disabled'); } } }); }); $('.update_form').submit(function(e){ e.preventDefault(); formdata = new FormData($(this)[0]); $(".update_button").attr('disabled', 'disabled'); $(".update_button").text("Updating..."); $.ajax({ type : 'post', url : '<?php echo site_url("update-department")?>', data : formdata, contentType: false, processData: false, success:function(response){ // response=jQuery.parseJSON(response); console.log(response); if(response.result==1) { $("#edit_modal").modal("hide"); toastr["success"](response.message); $('.update_form')[0].reset(); $(".update_button").text("Submit"); $(".update_button").removeAttr('disabled'); $("#list3").jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid'); } else if(response.result==2) { toastr["error"](response.message); $(".update_button").text("Submit"); $(".update_button").removeAttr('disabled'); } else { toastr["error"](response.message); $(".update_button").text("Submit"); $(".update_button").removeAttr('disabled'); } } }); }); </script> <?php echo view('includes/footer');?>