| |
| $(document).ready(function(){ |
| |
| $("#kode").keyup(function(e){ |
| var isi = $(e.target).val(); |
| $(e.target).val(isi.toUpperCase()); |
| }); |
| |
| $("#nomortelpon").keypress(function(data){ |
| if (data.which!=8 && data.which!=0 && (data.which<48 || data.which>57)) { |
| return false; |
| } |
| }); |
| $("#nomorfax").keypress(function(data){ |
| if (data.which!=8 && data.which!=0 && (data.which<48 || data.which>57)) { |
| return false; |
| } |
| }); |
| |
| |
| |
| $(".data").flexigrid({ |
| url : 'pages/master/post-json-supplier.php', |
| dataType : 'json', |
| colModel : [{display : 'No',name : 'no',width : 40,sortable : false,align : 'center'}, |
| {display : 'Kode',name : 'kode_supplier',width : 60,sortable : true,align : 'center'}, |
| {display : 'Nama supplier',name : 'nama_supplier',width : 200,sortable : true,align : 'left'}, |
| {display : 'Alamat Supplier',name : 'alamat_supplier',width : 220,sortable : true,align : 'left'}, |
| {display : 'Nomor Telpon',name : 'telp_supplier',width : 80,sortable : true,align : 'left'}, |
| {display : 'Nomor fax',name : 'fax_supplier',width : 80,sortable : true,align : 'left'}, |
| {display : 'Email',name : 'email_supplier',width : 230,sortable : true,align : 'left'} |
| ], |
| buttons : [{name : 'Add',bclass : 'add',onpress : test}, |
| {name : 'Edit',bclass : 'edit',onpress : test}, |
| {name : 'Delete',bclass : 'delete',onpress : test}, |
| {separator : true} , |
| {name : 'Refresh',bclass : 'refresh',onpress : test} |
| ], |
| searchitems : [ |
| {display : 'Kode',name : 'kode_supplier',isdefault : true}, |
| {display : 'Nama Supplier',name : 'nama_supplier' } |
| ], |
| sortname : "kode_supplier", |
| sortorder : "asc", |
| singleSelect : true, |
| usepager : true, |
| title : 'Daftar Supplier', |
| useRp : true, |
| rp : 10, |
| showTableToggleBtn : false, |
| height : 350, |
| width : 1000, |
| pagetext: 'Hal ', |
| outof: 's.d' |
| }); |
| function test(com, grid) { |
| if (com == 'Delete') { |
| |
| if ($('.trSelected',grid).length == 1) { |
| $('.trSelected',grid).each(function() { |
| var id = $(this).attr('id'); |
| id = id.substring(id.lastIndexOf('row')+3); |
| var pilih = confirm('Data yang akan dihapus = '+id+ '?'); |
| if (pilih==true) { |
| HapusData(id); |
| } |
| }); |
| } else { |
| alert('Silahkan pilih salah satu baris yang ingin di Hapus'); |
| return false; |
| } |
| } else if (com == 'Add') { |
| |
| Tambah(); |
| $('#form').dialog('open'); |
| }else if (com == 'Edit') { |
| |
| if ($('.trSelected',grid).length == 1) { |
| $('.trSelected',grid).each(function() { |
| var id = $(this).attr('id'); |
| id = id.substring(id.lastIndexOf('row')+3); |
| EditData(id); |
| }); |
| } else { |
| alert('Silahkan pilih salah satu baris yang ingin di edit'); |
| return false; |
| } |
| }else if (com == 'Refresh') { |
| window.location.replace('dashboard.php?cat=master&page=data_supplier_tambah'); |
| } |
| } |
| |
| $('#form').dialog({ |
| autoOpen: false, |
| width: 600, |
| buttons: { |
| "Simpan": function() { |
| simpan(); |
| }, |
| "Tambah": function() { |
| Tambah(); |
| }, |
| "Kembali": function() { |
| $(this).dialog("close"); |
| $('.data').flexReload(); |
| } |
| } |
| }); |
| |
| |
| function Tambah(){ |
| $(".input").val(''); |
| $("#kode").attr("disabled",false); |
| $("#kode").val(''); |
| $("#kode").focus(); |
| |
| } |
| |
| function EditData(e){ |
| var id = e; |
| $.ajax({ |
| type : "POST", |
| url : "pages/master/cari_supplier.php", |
| data : "id="+id, |
| dataType : "json", |
| success : function(data){ |
| $("#kode").val(id); |
| $("#namasupplier").val(data.namasupplier); |
| $("#alamatsupplier").val(data.alamatsupplier); |
| $("#nomortelpon").val(data.nomortelpon); |
| $("#nomorfax").val(data.nomorfax); |
| $("#email").val(data.email); |
| |
| |
| $("#kode").attr("disabled",true); |
| |
| $('#form').dialog('open'); |
| } |
| }); |
| } |
| |
| function HapusData(e){ |
| var id = e; |
| $.ajax({ |
| type : "POST", |
| url : "pages/master/hapus_supplier.php", |
| data : "id="+id, |
| success : function(data){ |
| alert(data); |
| $('.data').flexReload(); |
| } |
| }); |
| } |
| |
| function simpan(){ |
| |
| var kode = $("#kode").val(); |
| var namasupplier = $("#namasupplier").val(); |
| var alamatsupplier = $("#alamatsupplier").val(); |
| var nomortelpon = $("#nomortelpon").val(); |
| var nomorfax = $("#nomorfax").val(); |
| var email = $("#email").val(); |
| |
| |
| |
| |
| |
| |
| if(namasupplier.length==0){ |
| alert('Maaf, Nama supplier tidak boleh kosong'); |
| $("#namasupplier").focus(); |
| return false(); |
| } |
| if(alamatsupplier.length==0){ |
| alert('Maaf, Anda belum mengisi alamat supplier'); |
| $("#alamatsupplier").focus(); |
| return false(); |
| } |
| if(nomortelpon.length==0){ |
| alert('Maaf, Anda belum mengisi nomor telpon'); |
| $("#nomortelpon").focus(); |
| return false(); |
| } |
| if(nomorfax.length==0){ |
| alert('Maaf, Anda belum mengisi nomor fax'); |
| $("#nomorfax").focus(); |
| return false(); |
| } |
| |
| if(email.length==0){ |
| alert('Maaf, Anda belum mengisi email'); |
| $("#email").focus(); |
| return false(); |
| } |
| |
| $.ajax({ |
| type : "POST", |
| url : "pages/master/simpan_supplier.php", |
| data : "kode="+kode+"&namasupplier="+namasupplier+"&alamatsupplier="+alamatsupplier+"&nomortelpon="+nomortelpon+"&nomorfax="+nomorfax+"&email="+email, |
| success : function(data){ |
| alert(data); |
| $('.data').flexReload(); |
| } |
| }); |
| } |
| }); |