| Server IP : 127.0.0.1 / Your IP : 192.168.99.1 Web Server : Apache/2.4.35 (Win64) OpenSSL/1.1.1b mod_fcgid/2.3.9 System : Windows NT WIN-JEJMB9EN0L0 10.0 build 14393 (Windows Server 2016) AMD64 User : Administrator ( 0) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /wamp/www/sipapbd_2019/application/modules/pejabat_daerah/views/ |
Upload File : |
<fieldset>
<legend><?php echo $breadcrumbs;?></legend>
</fieldset>
<div id="grid_container">
<div id="search" class="row">
</div>
<table id="grid"></table>
<div id="pager"></div>
<div id="loading" class="loading" style="margin-top:10px; margin: auto;"> </div>
</div>
<script>
<?php
$akses = isset($akses) ? $akses : 0;
$canEdit = $akses >= 3;
$canPrint = $akses >= 2;
?>
var grid = $('#grid'), id = last = 0, canEdit = <?php echo $canEdit ? 'true' : 'false'; ?>;
$(document).ready(function() {
params = {
container : $('#search'),
grid : grid,
cols : <?php echo json_encode($grid['fields']); ?>,
}
Search.init(params);
grid.jqGrid({
url:'<?php echo base_url().$modul?>/get_daftar',
editurl:'<?php echo base_url().$modul?>/proses',
datatype:'json',
mtype:'POST',
colNames:['','Nama Pejabat', 'NIP', 'Jabatan', 'Aktif','',''],
colModel:[
{name:'kd', hidden:true, editable:true},
{name:'nama', width:400, editable:true, edittype:'text', editoptions:{maxlength:100}},
{name:'nip', width:150,editable:true,edittype:'text',editoptions:{size:50}},
{name:'jab', width:200, editable:true, editoptions:{dataInit:initselect2_pejabat}},
{name:'aktif', width:40, editable:true, edittype:'checkbox', formatter:'checkbox', editoptions:{value:"1:0"}, align:'center'},
{name:'last_changed', width:150, editable:true, hidden:true},
{name:'param', width:50, editable:true, hidden:true},
],
pager:'#pager',
rowNum:1000000,
scroll:true,
rownumbers:true,
viewrecords:true,
gridview:true,
shrinkToFit:false,
autowidth:true,
height:'400',
recordtext:'{2} baris',
onSelectRow: function(id){
if(id && id!==last){
$(this).restoreRow(last);
last=id;
}
},
ondblClickRow:edit_row,
});
grid.jqGrid('bindKeys', {"onEnter": edit_row});
grid.jqGrid( 'navGrid', "#pager", {
add: canEdit,
addtext: 'Tambah',
addfunc: add_row,
edit: canEdit,
edittext: 'Ubah',
editfunc: edit_row,
del: canEdit,
deltext: 'Hapus',
delfunc: del_row,
search: false,
searchtext: 'Cari',
refresh: true,
refreshtext: 'Refresh',
},{},{},{},{});
<?php
if ($canPrint)
{
?>
grid.jqGrid().navSeparatorAdd('#pager')
.navButtonAdd('#pager',{
caption:'Cetak',
onClickButton: function(){ preview({"tipe":"daftar"}, grid)},
title:'Cetak Daftar',
buttonicon:'ui-icon-print',
position:'last'
});
<?php
}
?>
grid.gridResize();
});
function add_row(){
if (!canEdit) return;
addparam = {
rowID : --id,
initdata: {aktif: 1},
position :"last",
addRowParams : {
keys : true,
aftersavefunc: aftersave_pejabat,
beforeSaveRow: beforesave_pejabat,
oneditfunc: onedit_pejabat,
afterrestorefunc: afterrestore_pejabat,
successfunc: successfunc,
errorfunc: errorfunc,
restoreAfterError: false,
}
}
$(this).jqGrid('addRow', addparam);
}
function edit_row(id){
if (!canEdit) return;
pejabat_event = true;
editparam = {
keys : true,
aftersavefunc: aftersave_pejabat,
beforeSaveRow: beforesave_pejabat,
oneditfunc: onedit_pejabat,
afterrestorefunc: afterrestore_pejabat,
successfunc: successfunc,
errorfunc: errorfunc,
restoreAfterError: false,
}
$(this).jqGrid('editRow', id, editparam);
last = id;
return false;
}
function del_row(id){
if (!canEdit) return;
var grid = $(this),
question = 'Hapus Pejabat dari daftar ?';
confirmation(question).then(function(answer){
if (!answer) return;
$.ajax({
url: '<?php echo base_url().$modul?>/hapus',
type: "post",
dataType: "json",
data: { id: id},
success: function(res){
if(res.isSuccess == true) {
show_info(res.message, 'Sukses');
grid.jqGrid('delRowData', id);
}
else {
show_error(res.message, 'Gagal');
if(res.error=="exist") grid.trigger('reloadGrid');
}
},
});
});
}
function aftersave_pejabat(id, resp){
oresp = JSON.parse(resp.responseText);
newid = oresp.id;
grid.jqGrid('setCell', id, 'param', '0');
if (oresp.isSuccess){
show_info(oresp.message, 'Sukses');
grid.jqGrid('setCell', id, 'last_changed', oresp.last_changed);
if (newid !== id){
data = $(this).jqGrid('getRowData', id);
data.id = newid;
data.last_changed = oresp.last_changed;
$(this).jqGrid('addRowData', newid, data, 'after', id);
$(this).jqGrid('delRowData', id);
//$(this).jqGrid('resetSelection')
$(this).jqGrid('setSelection', newid)
last = id;
}
}
else {
show_error(oresp.message, 'Gagal');
}
$(this).focus();
}
function beforesave_pejabat(opt, id){
jab = $('#'+id+'_jab').select2('val');
nama = $('#'+id+'_nama').val();
if (jab == '' || nama == '') {
show_warning('Silahkan melengkapi semua isian Pejabat Daerah.', 'Perhatian');
return false;
}
/* remove select2 */
$('#'+id+'_jab').select2('destroy');
}
function onedit_pejabat(id){
// focus ke elemen pertama
$('#'+id+'_nama').focus();
}
function successfunc(resp){
oresp = JSON.parse(resp.responseText);
return oresp.isSuccess;
}
function errorfunc(id, resp){
$('#'+id+'_nip').keypress(function(e) {
if (e.which == '13' || e.keyCode == '13' ||e.charCode == '0') {
oresp = JSON.parse(resp.responseText);
respon(oresp,grid,modul,successfunc,aftersave_pejabat,errorfunc,afterrestore_pejabat);
}
});
$('#'+id+'_nama').keypress(function(e) {
if (e.which == '13' || e.keyCode == '13' ||e.charCode == '0') {
oresp = JSON.parse(resp.responseText);
respon(oresp,grid,modul,successfunc,aftersave_pejabat,errorfunc,afterrestore_pejabat);
}
});
}
function afterrestore_pejabat(id){
$(this).focus();
}
query_pejabat = function(option){
$.ajax({
url: "<?php echo base_url()?>pilih/jabatan",
type: 'POST',
dataType: 'json',
data: {
'q': option.term,
},
success: function (data) {
if(option.term.length > 0){
data.results.push({id: option.term, text: option.term });
}
option.callback({
results: data.results
});
}
});
}
function initselect2_pejabat(el){
var oid = el.id;
$(el).select2({
minimumInputLength: 0,
query: query_pejabat,
placeholder: 'Pilih Jabatan',
openOnEnter: false,
dropdownAutoWidth : true,
initSelection: function(element, callback){
var data = {'text': element.val()};
callback(data);
},
});
$(el).on('change', function(e){
idx = e.target.id;
pos = idx.indexOf('jab');
if ( pos > -1){
pre = idx.substring(0, pos);
$('#'+pre+'kd').val(e.added ? e.added.id : null);
$(e.target).val(e.added ? e.added.text : '');
return false;
}
e.stopPropagation();
});
$('#s2id_' + oid).on('keyup', function(e){
if (e.keyCode === 13) {
ev = $.Event('keydown');
ev.keyCode= 13;
$(el).trigger(ev);
}
});
}
</script>