function pTbkod(){ var fields_tbkod = RH.storeFields('kdapltbkod','ketertbkod','kdkodtbkod','nmkodtbkod','nmdata','',''); var pageSize = 18; var ds_tbkod = RH.JsonStore({ url : BASE_URL + 'tbkod_controller/get_tbkod', fields : fields_tbkod, limit: pageSize, enableSearch: true, }); //SEARCH COMPONENT var sb_tbkod = RH.searchComp({ id : 'sb_tbkod', fields : ['kdapltbkod:Kode Aplikasi','kdkodtbkod:Kode','nmkodtbkod:Nama'], selected : 'kdapltbkod', store : ds_tbkod }); // COLUMN MODEL var cm_tbkod = new Ext.grid.ColumnModel([ new Ext.grid.RowNumberer(), { header: RH.h3('Kode Aplikasi'),width: 150, dataIndex: 'kdapltbkod', sortable: true }, { header: RH.h3('Keterangan'),width: 200, dataIndex: 'ketertbkod', sortable: true }, { header: RH.h3('Kode'), width: 100, dataIndex: 'kdkodtbkod', sortable: true }, { header: RH.h3('Nama'), width: 200, dataIndex: 'nmkodtbkod', sortable: true }, { header: RH.h3('Nama Data'), width: 200, dataIndex: 'nmdata', sortable: true }, RH.EditColumn(), RH.DeleteColumn() ] ); /** THE GRID */ var gp_tbkod = RH.GridPanel_T1({ ds: ds_tbkod, cm: cm_tbkod, singleSelect: true, searchComp: sb_tbkod, allowAdd: true, fnAdd: fnAddTbkod, pageSize: pageSize, cellclick: onCellTbkodClick }); var fp_tbkod = RH.GPContainer1({ title: 'Kode Aplikasi', iconCls:'silk-house', gridPanel: gp_tbkod, }); SET_PAGE_CONTENT(fp_tbkod); /** FUNCTIONS */ function onCellTbkodClick(grid, rowIndex, columnIndex, e) { var record = grid.getStore().getAt(rowIndex); // Get the Record RH.EditClick(e, function(){fnEditTbkod(grid, record)}); RH.DeleteClick(e, function(){fnDeleteTbkod(grid, record)}); } function reloadTbkod(){ ds_tbkod.reload(); } function fnAddTbkod(){ var grid = gp_tbkod; wEntryTbkod(false, grid, null); } function fnEditTbkod(grid, record){ wEntryTbkod(true, grid, record); } function fnDeleteTbkod(grid, record){ var url = BASE_URL + 'tbkod_controller/delete_tbkod'; var params = new Object({ kdapltbkod : record.data['kdapltbkod'], kdkodtbkod : record.data['kdkodtbkod'] }); RH.deleteGridRecord(url, params, grid ); } } /** WIN - FORM ENTRY/EDIT KODE APLIKASI */ function wEntryTbkod(isUpdate, grid, record){ var winTitle = (isUpdate)?'Kode Aplikasi (Edit)':'Kode Aplikasi (Entry)'; /** DATA SOURCE GRUP KODE APLIKASI */ /*var ds_grup = new Ext.data.JsonStore({ //static data fields: [{ name:'kode' }, { name:'nama' }], data: [ { "kode":"1","nama":"test1"}, { "kode":"2","nama":"test2"} ] });*/ /** FORM ENTRY/EDIT MATA-KULIAH */ var tbkod_form = new Ext.form.FormPanel({ xtype:'form', id: 'frm.tbkod', fileUpload: true, buttonAlign: 'left', labelWidth: 170, labelAlign: 'right', bodyStyle: 'padding:10px 3px 3px 5px', // atas, kanan, bawah, kiri autoHeight: true, autoWidth: true, layout: 'form', frame: false, defaultType:'textfield', items: [ { id: 'tf.frm.kdapltbkod', fieldLabel: 'Kode Aplikasi', width: 150, allowBlank: false, },{ id: 'tf.frm.ketertbkod', fieldLabel: 'Keterangan', width: 300, allowBlank: false, },{ id: 'tf.frm.kdkodtbkod', fieldLabel: 'Kode', width: 150, allowBlank: false, },{ id: 'tf.frm.nmkodtbkod', fieldLabel: 'Nama', width: 300, },{ id: 'tf.frm.nmdata', fieldLabel: 'Nama Data', width: 300, },{ xtype: 'compositefield', hidden: false, name: 'comp_import_excel', fieldLabel: '* Khusus Import Excel', labelStyle: 'font-weight:bold;font-color:blue', id: 'comp_import_excel', items: [{ xtype: 'fileuploadfield', id: 'f_excel_import_kod', allowBlank: true, emptyText: 'Pilih File Excel', name: 'f_excel_import_kod', width: 200, buttonText: '', buttonCfg: { iconCls: 'silk-page-copy' }, listeners: { valid: function() { } } },{ xtype:'button', id: 'bdownloadtempl', text: 'Download Template', iconCls:'silk-page-edit', handler: function() { window.open(BASE_URL + 'resources/temp_files/template_tbkod.xls', '_self'); } },{ xtype:'checkbox', boxLabel: '', name: 'cbfileimport', id: 'cbfileimport', listeners: { check: function () { if (Ext.getCmp('cbfileimport').getValue()==true) { RH.disableComp('tf.frm.kdapltbkod'); RH.disableComp('tf.frm.ketertbkod'); RH.disableComp('tf.frm.kdkodtbkod'); RH.disableComp('tf.frm.nmkodtbkod'); RH.disableComp('tf.frm.nmdata'); RH.setCompValue('tf.frm.kdapltbkod', ''); RH.setCompValue('tf.frm.ketertbkod', ''); RH.setCompValue('tf.frm.kdkodtbkod', ''); RH.setCompValue('tf.frm.nmkodtbkod', ''); RH.setCompValue('tf.frm.nmdata', ''); } else { RH.enableComp('tf.frm.kdapltbkod'); RH.enableComp('tf.frm.ketertbkod'); RH.enableComp('tf.frm.kdkodtbkod'); RH.enableComp('tf.frm.nmkodtbkod'); RH.enableComp('tf.frm.nmdata'); RH.setCompValue('f_excel_import_kod', null); } } } } ] }], buttons: [{ text: 'Simpan', iconCls:'silk-save', handler: function() { if (Ext.getCmp('cbfileimport').getValue()==true) { import_excel_tbkod('frm.tbkod'); } else { if (Ext.getCmp('f_excel_import_kod').getValue()) { Ext.MessageBox.alert('Informasi', 'Silahkan Ceklist Jika Melakukan Import'); } else { fnSaveTbkod(); } } } }, { text: 'Kembali', iconCls:'silk-arrow-undo', handler: function() { wTbkod.close(); } }] }); var wTbkod = new Ext.Window({ title: winTitle, height: 250, width: 550, modal: true, closable:false, items: [tbkod_form] }); /** CALL SET FORM AND SHOW THE FORM (WINDOW) */ setTbkodForm(isUpdate, record); wTbkod.show(); /** FORM FUNCTIONS */ function setTbkodForm(isUpdate, record){ var kdprodi = RH.getCompValue('cb.prodi-matkul', true); if(isUpdate){ if(record != null){ RH.disableComp('tf.frm.kdapltbkod'); RH.disableComp('tf.frm.kdkodtbkod'); RH.setCompValue('tf.frm.kdapltbkod', record.data['kdapltbkod']); RH.setCompValue('tf.frm.ketertbkod', record.data['ketertbkod']); RH.setCompValue('tf.frm.kdkodtbkod', record.data['kdkodtbkod']); RH.setCompValue('tf.frm.nmkodtbkod', record.data['nmkodtbkod']); RH.setCompValue('tf.frm.nmdata', record.data['nmdata']); Ext.getCmp('comp_import_excel').disable(); return; } } } function fnSaveTbkod(){ var idForm = 'frm.tbkod'; var sUrl = BASE_URL +'tbkod_controller/insert_tbkod'; var sParams = new Object({ kdapltbkod : RH.getCompValue('tf.frm.kdapltbkod'), ketertbkod : RH.getCompValue('tf.frm.ketertbkod'), kdkodtbkod : RH.getCompValue('tf.frm.kdkodtbkod'), nmkodtbkod : RH.getCompValue('tf.frm.nmkodtbkod'), nmdata : RH.getCompValue('tf.frm.nmdata'), }); var msgWait = 'Tunggu, sedang proses menyimpan...'; var msgSuccess = 'Tambah data berhasil'; var msgFail = 'Tambah data gagal'; var msgInvalid = 'Data belum valid (data primer belum terisi)!'; if(isUpdate){ sUrl = BASE_URL +'tbkod_controller/update_tbkod'; msgSuccess = 'Update data berhasil'; msgFail = 'Update data gagal'; } //call form grid submit function (common function by RH) RH.submitGridForm(idForm, sUrl, sParams, grid, wTbkod, msgWait, msgSuccess, msgFail, msgInvalid); } function import_excel_tbkod(namaForm) { function Right(str, n){ if (n <= 0) return ""; else if (n > String(str).length) return str; else { var iLen = String(str).length; return String(str).substring(iLen, iLen - n); } } var form_nya = Ext.getCmp(namaForm); var xls = Right(Ext.getCmp('f_excel_import_kod').getValue(),3); if (xls) { if (xls=="xls") { form_nya.getForm().submit({ url: BASE_URL + 'tbkod_controller/import_from_Excel', method: 'POST', params: { f_excel:Ext.getCmp('f_excel_import_kod').getValue() }, waitMsg: 'Proses Import Data Kode Aplikasi...', success: function(form_nya, o) { Ext.MessageBox.alert('Informasi', 'Total Insert Data : ' + o.result.countinsert + ', Total Update Data : ' + o.result.countupdate); grid.getStore().reload(); wTbkod.close(); } , failure: function() { Ext.MessageBox.alert('Informasi', 'Import Data Kode Aplikasi Gagal'); } }); } else { Ext.MessageBox.alert('Informasi', 'File Harus Berekstensi .xls'); } } else { Ext.MessageBox.alert('Informasi', 'Pilih File Excel'); } } }