function pTbpti(){ var fields_tbpti = RH.storeFields('kdptitbpti','nmptitbpti','tgenttbpti','tgtuptbpti','kotaatbpti','kdstatbpti','nmstatbpti','kdkabtbpti','nmkabtbpti'); var pageSize = 18; var ds_tbpti = RH.JsonStore({ url : BASE_URL + 'tbpti_controller/get_tbpti', fields : fields_tbpti, limit: pageSize, enableSearch: true, }); var ds_stptitbkod = new Ext.data.JsonStore({ //from database proxy: new Ext.data.HttpProxy({ url: BASE_URL + 'tbpti_controller/get_stptitbkod', method: 'POST' }), autoLoad: true, root: 'data', fields: [ { name: "kode", mapping: "kode" } , { name: "nama", mapping: "nama" } ] }); var storesObj = {stptitbkod:ds_stptitbkod}; //SEARCH COMPONENT var sb_tbpti = RH.searchComp({ id : 'sb_tbpti', fields : ['kdptitbpti:Kode Perguruan Tinggi','nmptitbpti:Nama Perguruan Tinggi'], selected : 'kdptitbpti', store : ds_tbpti }); // COLUMN MODEL var cm_tbpti = new Ext.grid.ColumnModel([ new Ext.grid.RowNumberer(), { header: RH.h3('Kode
Perguruan Tinggi'),width: 120, dataIndex: 'kdptitbpti', sortable: true }, { header: RH.h3('Nama Perguruan Tinggi'),width: 250, dataIndex: 'nmptitbpti', sortable: true }, { header: RH.h3('Tanggal Entry'), width: 100, dataIndex: 'tgenttbpti', sortable: true, xtype: 'datecolumn', format: 'd/m/Y' }, { header: RH.h3('Tanggal Update'), width: 100, dataIndex: 'tgtuptbpti', sortable: true, xtype: 'datecolumn', format: 'd/m/Y' }, { header: RH.h3('Kota'), width: 150, dataIndex: 'kotaatbpti', sortable: true }, { header: RH.h3('Status Perguruan Tinggi'), width: 150, dataIndex: 'nmstatbpti', sortable: true }, { header: RH.h3('Kabupaten'), width: 150, dataIndex: 'nmkabtbpti', sortable: true }, RH.EditColumn(), RH.DeleteColumn() ] ); /** THE GRID */ var gp_tbpti = RH.GridPanel_T1({ ds: ds_tbpti, cm: cm_tbpti, singleSelect: true, searchComp: sb_tbpti, allowAdd: true, fnAdd: fnAddTbpti, pageSize: pageSize, cellclick: onCellTbptiClick }); var fp_tbpti = RH.GPContainer1({ title: 'Ref. Perguruan Tinggi', iconCls:'silk-house', gridPanel: gp_tbpti, }); SET_PAGE_CONTENT(fp_tbpti); /** FUNCTIONS */ function onCellTbptiClick(grid, rowIndex, columnIndex, e) { var record = grid.getStore().getAt(rowIndex); // Get the Record RH.EditClick(e, function(){fnEditTbpti(grid, record)}); RH.DeleteClick(e, function(){fnDeleteTbpti(grid, record)}); } function reloadTbpti(){ ds_tbpti.reload(); } function fnAddTbpti(){ var grid = gp_tbpti; wEntryTbpti(false, grid, null, storesObj); } function fnEditTbpti(grid, record){ wEntryTbpti(true, grid, record, storesObj); } function fnDeleteTbpti(grid, record){ var url = BASE_URL + 'tbpti_controller/delete_tbpti'; var params = new Object({ kdptitbpti : record.data['kdptitbpti'] }); RH.deleteGridRecord(url, params, grid ); } } /** WIN - FORM ENTRY/EDIT KODE APLIKASI */ function wEntryTbpti(isUpdate, grid, record, storesObj){ var ds_stptitbkod = storesObj.stptitbkod; var winTitle = (isUpdate)?'Ref. Perguruan Tinggi (Edit)':'Ref. Perguruan Tinggi (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 tbpti_form = new Ext.form.FormPanel({ xtype:'form', id: 'frm.tbpti', 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.kdptitbpti', fieldLabel: 'Kode Perguruan Tinggi', width: 150, allowBlank: false, },{ id: 'tf.frm.nmptitbpti', fieldLabel: 'Nama Perguruan Tinggi', width: 300, allowBlank: false, },{ id: 'df.frm.tgenttbpti', xtype: 'datefield', fieldLabel: 'Tanggal Entry', value: new Date(), format: 'd/m/Y', width: 100, allowBlank: false, },{ id: 'df.frm.tgtuptbpti', xtype: 'datefield', fieldLabel: 'Tanggal Update', value: new Date(), format: 'd/m/Y', width: 100, allowBlank: true, },{ id: 'tf.frm.kotaatbpti', fieldLabel: 'Kota', width: 150, },{ xtype: 'combo', id: 'cb.frm.kdstatbpti', fieldLabel: 'Status Perguruan Tinggi', store: ds_stptitbkod, triggerAction: 'all', valueField: 'kode', displayField: 'nama', forceSelection: true, submitValue: true, mode: 'local', emptyText:'Pilih...', width: 150, }, RH.Lookup2Field({ id: 'lookupkotkab', label: 'Kota/Kabupaten', codeId:'tf.frm.kdkabtbpti', nameId:'tf.frm.nmkabtbpti', codeVisible: false, widths: [80,300], fnLookup: function(){ if (Ext.getCmp('cbfileimport').getValue()==true) { return; } wLookup(lu_kota, 'Kota/Kabupaten','tf.frm.kdkabtbpti','tf.frm.nmkabtbpti',500,350) } }),{ 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_pti', allowBlank: true, emptyText: 'Pilih File Excel', name: 'f_excel_import_pti', 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_tbpti.xls', '_self'); } },{ xtype:'checkbox', boxLabel: '', name: 'cbfileimport', id: 'cbfileimport', listeners: { check: function () { if (Ext.getCmp('cbfileimport').getValue()==true) { RH.disableComp('tf.frm.kdptitbpti'); RH.disableComp('tf.frm.nmptitbpti'); RH.disableComp('df.frm.tgenttbpti'); RH.disableComp('df.frm.tgtuptbpti'); RH.disableComp('tf.frm.kotaatbpti'); RH.disableComp('cb.frm.kdstatbpti'); RH.disableComp('tf.frm.kdkabtbpti'); RH.disableComp('tf.frm.nmkabtbpti'); RH.disableComp('lookupkotkab'); RH.setCompValue('tf.frm.kdptitbpti', ''); RH.setCompValue('tf.frm.nmptitbpti', ''); RH.setCompValue('df.frm.tgenttbpti', ''); RH.setCompValue('df.frm.tgtuptbpti', ''); RH.setCompValue('tf.frm.kotaatbpti', ''); RH.setCompValue('cb.frm.kdstatbpti', ''); RH.setCompValue('tf.frm.kdkabtbpti', ''); RH.setCompValue('tf.frm.nmkabtbpti', ''); } else { RH.enableComp('tf.frm.kdptitbpti'); RH.enableComp('tf.frm.nmptitbpti'); RH.enableComp('df.frm.tgenttbpti'); RH.enableComp('df.frm.tgtuptbpti'); RH.enableComp('tf.frm.kotaatbpti'); RH.enableComp('cb.frm.kdstatbpti'); RH.enableComp('tf.frm.kdkabtbpti'); RH.enableComp('tf.frm.nmkabtbpti'); RH.enableComp('lookupkotkab'); RH.setCompValue('f_excel_import_pti', null); } } } } ] }], buttons: [{ text: 'Simpan', iconCls:'silk-save', handler: function() { if (Ext.getCmp('cbfileimport').getValue()==true) { import_excel_tbpti('frm.tbpti'); } else { if (Ext.getCmp('f_excel_import_pti').getValue()) { Ext.MessageBox.alert('Informasi', 'Silahkan Ceklist Jika Melakukan Import'); } else { fnSaveTbpti(); } } } }, { text: 'Kembali', iconCls:'silk-arrow-undo', handler: function() { wTbpti.close(); } }] }); var wTbpti = new Ext.Window({ title: winTitle, height: 310, width: 620, modal: true, closable:false, items: [tbpti_form] }); /** CALL SET FORM AND SHOW THE FORM (WINDOW) */ setTbptiForm(isUpdate, record); wTbpti.show(); /** FORM FUNCTIONS */ function setTbptiForm(isUpdate, record){ if(isUpdate){ if(record != null){ RH.disableComp('tf.frm.kdptitbpti'); RH.setCompValue('tf.frm.kdptitbpti', record.data['kdptitbpti']); RH.setCompValue('tf.frm.nmptitbpti', record.data['nmptitbpti']); RH.setCompValue('df.frm.tgenttbpti', record.data['tgenttbpti']); RH.setCompValue('df.frm.tgtuptbpti', record.data['tgtuptbpti']); RH.setCompValue('tf.frm.kotaatbpti', record.data['kotaatbpti']); RH.setCompValue('cb.frm.kdstatbpti', record.data['kdstatbpti']); RH.setCompValue('tf.frm.kdkabtbpti', record.data['kdkabtbpti']); RH.setCompValue('tf.frm.nmkabtbpti', record.data['nmkabtbpti']); Ext.getCmp('comp_import_excel').disable(); return; } } } function fnSaveTbpti(){ var idForm = 'frm.tbpti'; var sUrl = BASE_URL +'tbpti_controller/insert_tbpti'; var sParams = new Object({ kdptitbpti : RH.getCompValue('tf.frm.kdptitbpti'), nmptitbpti : RH.getCompValue('tf.frm.nmptitbpti'), tgenttbpti : RH.getCompValue('df.frm.tgenttbpti'), tgtuptbpti : RH.getCompValue('df.frm.tgtuptbpti'), kotaatbpti : RH.getCompValue('tf.frm.kotaatbpti'), kdstatbpti : RH.getCompValue('cb.frm.kdstatbpti'), kdkabtbpti : RH.getCompValue('tf.frm.kdkabtbpti'), }); 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 +'tbpti_controller/update_tbpti'; msgSuccess = 'Update data berhasil'; msgFail = 'Update data gagal'; } //call form grid submit function (common function by RH) RH.submitGridForm(idForm, sUrl, sParams, grid, wTbpti, msgWait, msgSuccess, msgFail, msgInvalid); } function import_excel_tbpti(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_pti').getValue(),3); if (xls) { if (xls=="xls") { form_nya.getForm().submit({ url: BASE_URL + 'tbpti_controller/import_from_Excel', method: 'POST', params: { f_excel:Ext.getCmp('f_excel_import_pti').getValue() }, waitMsg: 'Proses Import Data Perguruan Tinggi...', success: function(form_nya, o) { Ext.MessageBox.alert('Informasi', 'Total Insert Data : ' + o.result.countinsert + ', Total Update Data : ' + o.result.countupdate); grid.getStore().reload(); wTbpti.close(); } , failure: function() { Ext.MessageBox.alert('Informasi', 'Import Data Perguruan Tinggi Gagal'); } }); } else { Ext.MessageBox.alert('Informasi', 'File Harus Berekstensi .xls'); } } else { Ext.MessageBox.alert('Informasi', 'Pilih File Excel'); } } }