function pRuangan(){ /** DATA STORES */ var ds_jruangan = new Ext.data.JsonStore({ //from database proxy: new Ext.data.HttpProxy({ url: BASE_URL + 'data_controller/get_jruangan ', method: 'POST' }), root: 'data', autoLoad: true, fields: [{ name: "idjnsruangan" }, { name: "nmjnsruangan" }] }); var ds_truangan = new Ext.data.JsonStore({ //from database proxy: new Ext.data.HttpProxy({ url: BASE_URL + 'data_controller/get_truangan ', method: 'POST' }), root: 'data', autoLoad: true, fields: [{ name: "idtiperuangan" }, { name: "nmtiperuangan" }] }); var ds_status = new Ext.data.JsonStore({ //from database proxy: new Ext.data.HttpProxy({ url: BASE_URL + 'data_controller/get_status ', method: 'POST' }), root: 'data', autoLoad: true, fields: [{ name: "idstatus" }, { name: "nmstatus" }] }); var ds_klpruangan = new Ext.data.JsonStore({ //from database proxy: new Ext.data.HttpProxy({ url: BASE_URL + 'data_controller/get_klpruangan ', method: 'POST' }), root: 'data', autoLoad: true, fields: [{ name: "idklpruangan" }, { name: "nmklpruangan" }] }); var wFormStoresObj = new Object({ jnruang: ds_jruangan, tpruang:ds_truangan, struang: ds_status,klpruangan:ds_klpruangan }); var fields_ruangan = RH.storeFields('idruangan', 'kdruangan', 'nmruangan', 'deskripsi', 'kapasitas', 'idjnsruangan','idtiperuangan','nmtiperuangan','idsubruangan','nmsubruangan','idstatus','idklpruangan'); var pageSize = 18; var ds_ruangan = RH.JsonStore({ url : BASE_URL + 'ruangan_controller/get_ruangan', fields : fields_ruangan, limit: pageSize, enableSearch: true, }); //SEARCH COMPONENT var sb_ruangan = RH.searchComp({ id : 'sb_ruangan', fields : ['kdruangan:Kode','nmruangan:Nama Ruangan'], selected : 'nmruangan', store : ds_ruangan }); /** COLUMN MODEL & RENDERER */ function renderJruangan(value) { return RH.getRecordFieldValue(ds_jruangan, 'nmjnsruangan', 'idjnsruangan', value); } function renderStruangan(value) { return RH.getRecordFieldValue(ds_status, 'nmstatus', 'idstatus', value); } function renderKlpruangan(value) { return RH.getRecordFieldValue(ds_klpruangan, 'nmklpruangan', 'idklpruangan', value); } var cm_ruangan = new Ext.grid.ColumnModel([ new Ext.grid.RowNumberer(), { header: 'Kode',width: 80, dataIndex: 'kdruangan', sortable: true }, { header: 'Nama', width: 200, dataIndex: 'nmruangan', sortable: true }, { header: 'Deskripsi', width: 300, dataIndex: 'deskripsi', sortable: true, hidden: true }, { header: 'Jenis Ruangan', width: 120, dataIndex: 'idjnsruangan', renderer: renderJruangan, sortable: true }, { header: 'Tipe Ruangan', width: 120, dataIndex: 'nmtiperuangan', sortable: true }, { header: 'Kelompok Ruangan', width: 120, dataIndex: 'idklpruangan', renderer: renderKlpruangan, sortable: true }, { header: 'Parent', width: 120, dataIndex: 'nmsubruangan', sortable: true }, { header: 'Kapasitas', width: 120, dataIndex: 'kapasitas', sortable: true }, { header: 'Status', width: 120, dataIndex: 'idstatus', renderer: renderStruangan, sortable: true }, RH.EditColumn(), RH.DeleteColumn() ] ); /** THE GRID */ var gp_ruangan = RH.GridPanel_T1({ ds: ds_ruangan, cm: cm_ruangan, singleSelect: true, searchComp: sb_ruangan, allowAdd: true, fnAdd: fnAddRuangan, pageSize: pageSize, cellclick: onCellRuanganClick }); var fp_ruangan = RH.GPContainer1({ title: 'Ruangan', iconCls:'silk-house', gridPanel: gp_ruangan, }); SET_PAGE_CONTENT(fp_ruangan); /** FUNCTIONS */ function onCellRuanganClick(grid, rowIndex, columnIndex, e) { var record = grid.getStore().getAt(rowIndex); // Get the Record RH.EditClick(e, function(){fnEditRuangan(grid, record)}); RH.DeleteClick(e, function(){fnDeleteRuangan(grid, record)}); } function reloadRuangan(){ ds_ruangan.reload(); } function fnAddRuangan(){ var grid = gp_ruangan; wform_ruangan(false, grid, null, wFormStoresObj); } function fnEditRuangan(grid, record){ wform_ruangan(true, grid, record, wFormStoresObj); } function fnDeleteRuangan(grid, record){ var url = BASE_URL + 'ruangan_controller/delete_ruangan'; var params = new Object({ idruangan : record.data['idruangan'] }); RH.deleteGridRecord(url, params, grid ); } } /** WIN - FORM ENTRY/EDIT RUANGAN */ function wform_ruangan(isEdit, grid, record, storesObj){ var winTitle = (isEdit)?'Ruangan (Edit)':'Ruangan (Entry)'; /** DATA STORES */ var ds_jruangan = storesObj.jnruang; var ds_truangan = storesObj.tpruang; var ds_status = storesObj.struang; var ds_klpruangan = storesObj.klpruangan; /** THE FORM */ var ruangan_form = new Ext.form.FormPanel({ xtype:'form', id: 'frm.ruangan', buttonAlign: 'left', labelWidth: 150, labelAlign: 'right', bodyStyle: 'padding:10px 3px 3px 5px', // atas, kanan, bawah, kiri monitorValid: true, height: 350, width: 500, layout: 'form', frame: false, defaultType:'textfield', items: [ { id: 'tf.frm.kdruangan', fieldLabel: 'Kode', width: 150, allowBlank: false, },{ id: 'tf.frm.nmruangan', fieldLabel: 'Nama', width: 300, allowBlank: false, },{ xtype: 'textarea', id: 'ta.frm.deskripsi', fieldLabel: 'Deskripsi', width: 300, },{ xtype: 'numberfield', id:'nf.frm.kapasitas', fieldLabel:'Kapasitas', width:80,allowBlank: false },{ xtype: 'combo', id: 'cb.frm.idjnsruangan', fieldLabel: 'Jenis Ruangan', store: ds_jruangan, triggerAction: 'all', valueField: 'idjnsruangan', displayField: 'nmjnsruangan', forceSelection: true, submitValue: true, mode: 'local', emptyText:'Pilih...', width: 300, allowBlank: false, editable:false, },{ xtype: 'combo', id: 'cb.frm.idtiperuangan', fieldLabel: 'Tipe Ruangan', store: ds_truangan, triggerAction: 'all', valueField: 'idtiperuangan', displayField: 'nmtiperuangan', forceSelection: true, submitValue: true, mode: 'local', emptyText:'Pilih...', width: 300, allowBlank: false, editable:false, },{ xtype: 'combo', id: 'cb.frm.idklpruangan', fieldLabel: 'Kelompok Ruangan', store: ds_klpruangan, triggerAction: 'all', valueField: 'idklpruangan', displayField: 'nmklpruangan', forceSelection: true, submitValue: true, mode: 'local', emptyText:'Pilih...', width: 300, allowBlank: false, editable:false, }, RH.Lookup2Field({ label: 'Parent', codeId:'lu.idruangan', nameId:'lu.nmruangan', widths: [80,185], codeVisible: false, fnLookup: function(){wLookup(lu_ruangan, 'Daftar Ruangan','lu.idruangan','lu.nmruangan') } }),{ xtype: 'combo', id: 'cb.frm.idstatus', fieldLabel: 'Status', store: ds_status, triggerAction: 'all', valueField: 'idstatus', displayField: 'nmstatus', forceSelection: true, submitValue: true, mode: 'local', emptyText:'Pilih...', width: 300, allowBlank: false, editable:false, }], buttons: [{ text: 'Simpan', iconCls:'silk-save', handler: function() { fnSaveRuangan(); } }, { text: 'Kembali', iconCls:'silk-arrow-undo', handler: function() { wRuangan.close(); } }] }); var wRuangan = new Ext.Window({ title: winTitle, modal: true, closable:false, items: [ruangan_form] }); /** CALL SET FORM AND SHOW THE FORM (WINDOW) */ setRuanganForm(isEdit, record); wRuangan.show(); /** FORM FUNCTIONS */ function setRuanganForm(isEdit, record){ var kdprodi = RH.getCompValue('cb.prodi-matkul', true); if(isEdit){ if(record != null){ Ext.getCmp('tf.frm.kdruangan').disable(); RH.setCompValue('tf.frm.kdruangan', record.data['kdruangan']); RH.setCompValue('tf.frm.nmruangan', record.data['nmruangan']); RH.setCompValue('ta.frm.deskripsi', record.data['deskripsi']); RH.setCompValue('cb.frm.idjnsruangan', record.data['idjnsruangan']); RH.setCompValue('cb.frm.idtiperuangan', record.data['idtiperuangan']); RH.setCompValue('nf.frm.kapasitas', record.data['kapasitas']); RH.setCompValue('lu.idruangan', record.data['idsubruangan']); RH.setCompValue('lu.nmruangan', record.data['nmsubruangan']); RH.setCompValue('cb.frm.idstatus', record.data['idstatus']) RH.setCompValue('cb.frm.idklpruangan', record.data['idklpruangan']); return; } } } function fnSaveRuangan(){ var idForm = 'frm.ruangan'; var sUrl = BASE_URL +'ruangan_controller/insert_ruangan'; var sParams = getInsertRuanganParams(); 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(isEdit){ sUrl = BASE_URL +'ruangan_controller/update_ruangan'; sParams.idruangan = record.data['idruangan']; msgSuccess = 'Update data berhasil'; msgFail = 'Update data gagal'; } //call form grid submit function (common function by RH) RH.submitGridForm(idForm, sUrl, sParams, grid, wRuangan, msgWait, msgSuccess, msgFail, msgInvalid); //wRuangan.close(); } // GET PARAMETERS FOR INSERT/UPDATE function getInsertRuanganParams(){ return new Object({ kdruangan : RH.getCompValue('tf.frm.kdruangan'), nmruangan : RH.getCompValue('tf.frm.nmruangan'), deskripsi : RH.getCompValue('ta.frm.deskripsi'), idjnsruangan : RH.getCompValue('cb.frm.idjnsruangan'), idtiperuangan : RH.getCompValue('cb.frm.idtiperuangan'), idsubruangan : RH.getCompValue('lu.idruangan'), kapasitas : RH.getCompValue('nf.frm.kapasitas'), idstatus : RH.getCompValue('cb.frm.idstatus'), idklpruangan : RH.getCompValue('cb.frm.idklpruangan') }); } }