function pMatkul(){ var fields_matkul = new Object([ { name: "kdprodi" } , { name: "nmprodi" } //from mspst ,{ name: "kdmk" } , { name: "nmmkind" } , { name: "nmmkeng" } , { name: "nmmkalias" } , { name: "kdkelmk" } ]); /** COMMON DATA STORES */ var ds_prodireg = store_prodireg(); var ds_kelmk = store_kelmatkul(); var wAddEditStoresObj = new Object({ prodi: ds_prodireg, kelmk: ds_kelmk }); /** GRID MATA-KULIAH */ // COLUMN MODEL var cm_matkul = new Ext.grid.ColumnModel([ { header: 'kdprodi', dataIndex: 'kdprodi', hidden: true }, { header: 'Kode Mata Kuliah',width: 100, dataIndex: 'kdmk', sortable: true }, { header: 'Nama Mata Kuliah (Indonesia)', width: 300, dataIndex: 'nmmkind', sortable: true }, { header: 'Nama Mata Kuliah (English)', width: 300, dataIndex: 'nmmkeng', sortable: true }, { header: 'Program Studi', width: 200, dataIndex: 'nmprodi', sortable: true }, { id: 'col.edit', width: 30, sortable: false, renderer: RH.column_edit, }, { id: 'col.delete', width: 30, sortable: false, renderer: RH.column_delete, }] ); // Selection Model var sm_matkul = new Ext.grid.RowSelectionModel({ singleSelect: true }); // Grid View var gv_matkul = new Ext.grid.GridView({ emptyText: '< Belum ada Data >' }); //STORE var ds_matkul = new Ext.data.JsonStore({ proxy: new Ext.data.HttpProxy({ url: BASE_URL + 'matkul_controller/get_matkulByProdi', method: 'POST' }), baseParams: { start: 0, limit: 18 , kdprodi: RH.getCompValue('cb.prodi-matkul', true), key: RH.getKeyPar(), value: RH.getValPar(), }, listeners:{ beforeload : function(store) { //PARAMETERS FOR SEARCH BAR store.baseParams.kdprodi = RH.getCompValue('cb.prodi-matkul', true); store.baseParams.key = RH.getKeyPar(); store.baseParams.value = RH.getValPar(); } }, totalProperty: 'results', autoLoad : true, root: 'data', fields: fields_matkul }); //SEARCH OBJ var searchParObj = new Object([ { 'key': 'kdmk', 'name': 'Kode Mata Kuliah' } , { 'key': 'nmmkind', 'name': 'Nama Mata Kuliah (Ind)' } , { 'key': 'nmmkeng', 'name': 'Nama Mata Kuliah (Eng)' } ]); RH.searchObj_init(); // MUST to INITIALIZE RH.searchObj.textWidth = 250; RH.searchObj.params = searchParObj; // MUST OVR RH.searchObj.store = ds_matkul; // MUST OVR var gp_matkul = new Ext.grid.GridPanel({ ds: ds_matkul, //title: 'Mata Kuliah', iconCls: '', cm: cm_matkul, sm: sm_matkul, view: gv_matkul, forceFit: true, autoHeight: true, layout:'anchor', autoSizeColumns: true, //autoExpandColumn: 'nmmkind', autoScroll:true, enableColumnResize: true, enableColumnHide: false, enableColumnMove: false, enableHdaccess: false, columnLines: true, loadMask: true, tbar:[ RH.searchBar() ,{ text: 'Tambah', id: 'tb.add-mhs', iconCls: 'silk-add', handler: function() { fnAddMatkul(); } }], bbar: new Ext.PagingToolbar({ store: ds_matkul, displayInfo: true, pageSize: 18, mode: 'local', displayMsg: 'Data {0} - {1} dari {2}', emptyMsg: "Belum ada data" }), listeners: { cellclick: onCellMatkulClick } }); var fp_matkul = new Ext.form.FormPanel({ xtype: 'form', title: 'Mata Kuliah', iconCls:'silk-book', buttonAlign: 'left', bodyStyle: 'padding: 5px', border: false, //forceFit: true, waitMsg: 'Waiting...', maskDisabled: false, monitorValid: true, frame: true, items: [{ xtype: 'combo', id: 'cb.prodi-matkul', fieldLabel: 'Program Studi', width: 300, editable: false, //allowBlank: false, store: ds_prodireg, triggerAction: 'all', valueField: 'kdprodi', displayField: 'lnmprodi', forceSelection: true, submitValue: true, mode: 'local', emptyText:'Pilih...', listeners:{ scope: this, 'select': function(){ ds_matkul.reload({ params: { kdprodi: RH.getCompValue('cb.prodi-matkul', true) } }); } } }, { xtype: 'panel', layout:'fit', items: [gp_matkul], }], }); SET_PAGE_CONTENT(fp_matkul); /** FUNCTIONS */ function onCellMatkulClick(grid, rowIndex, columnIndex, e) { var t = e.getTarget(); var record = grid.getStore().getAt(rowIndex); // Get the Record //var columnId = grid.getColumnModel().getId(columnIndex); // Get column id var sm = grid.getSelectionModel(); var sel = sm.getSelected(); if (t.className == 'imgEdit') { fnEditMatkul(grid, record); return true; } if (t.className == 'imgDelete') { fnDeleteMatkul(grid, record); return true; } return false; } function reloadMatkul(){ ds_matkul.reload(); } function fnAddMatkul(){ var grid = gp_matkul; wAddEdit_matkul(false, grid, null, wAddEditStoresObj); } function fnEditMatkul(grid, record){ wAddEdit_matkul(true, grid, record, wAddEditStoresObj); } function fnDeleteMatkul(grid, record){ var url = BASE_URL + 'matkul_controller/delete_matkul'; var params = new Object({ kdprodi : record.data['kdprodi'], kdmk : record.data['kdmk'] }); RH.deleteGridRecord(url, params, grid ); } } /** WIN - FORM ENTRY/EDIT MATAKULIAH */ function wAddEdit_matkul(isUpdate, grid, record, wFormStoresObj){ var winTitle = (isUpdate)?'Mata Kuliah (Edit)':'Mata Kuliah (Entry)'; var ds_prodireg = wFormStoresObj.prodi; var ds_kelmk = wFormStoresObj.kelmk; /** FORM ENTRY/EDIT MATA-KULIAH */ var matkul_form = new Ext.form.FormPanel({ xtype:'form', id: 'frm.matkul', buttonAlign: 'left', labelWidth: 150, labelAlign: 'right', bodyStyle: 'padding:10px 3px 3px 5px', // atas, kanan, bawah, kiri monitorValid: true, height: 250, width: 500, layout: 'form', frame: false, defaultType:'textfield', items: [ { xtype: 'combo', id: 'cb.frm.prodi', fieldLabel: 'Program Studi', width: 300, store: ds_prodireg, triggerAction: 'all', valueField: 'kdprodi', displayField: 'lnmprodi', forceSelection: true, submitValue: true, mode: 'local', emptyText:'Pilih...', allowBlank: false, editable: false },{ id: 'tf.frm.kdmk', fieldLabel: 'Kode Mata Kuliah', width: 150, allowBlank: false, },{ id: 'tf.frm.nmmk-ind', fieldLabel: 'Nama Mata Kuliah (Ind)', width: 300, allowBlank: false, },{ id: 'tf.frm.nmmk-eng', fieldLabel: 'Nama Mata Kuliah (Eng)', width: 300, },{ id: 'tf.frm.nmmk-aka', fieldLabel: 'Nama Mata Kuliah (alias)', width: 300, },{ xtype: 'combo', id: 'cb.frm.kelmk', fieldLabel: 'Kelompok Mata Kuliah', store: ds_kelmk, triggerAction: 'all', valueField: 'kode', displayField: 'nama', forceSelection: true, submitValue: true, editable:false, mode: 'local', emptyText:'Pilih...', width: 300, }], buttons: [{ text: 'Simpan', iconCls:'silk-save', handler: function() { fnSaveMatkul(); } }, { text: 'Kembali', iconCls:'', handler: function() { wMatkul.close(); } }] }); var wMatkul = new Ext.Window({ title: winTitle, modal: true, closable:false, items: [matkul_form] }); /** CALL SET FORM AND SHOW THE FORM (WINDOW) */ setMatkulForm(isUpdate, record); wMatkul.show(); /** FORM FUNCTIONS */ function setMatkulForm(isUpdate, record){ var kdprodi = RH.getCompValue('cb.prodi-matkul', true); if(isUpdate){ if(record != null){ Ext.getCmp('cb.frm.prodi').disable(); Ext.getCmp('tf.frm.kdmk').disable(); RH.setCompValue('cb.frm.prodi', record.data['kdprodi']); RH.setCompValue('tf.frm.kdmk', record.data['kdmk']); RH.setCompValue('tf.frm.nmmk-ind', record.data['nmmkind']); RH.setCompValue('tf.frm.nmmk-eng', record.data['nmmkeng']); RH.setCompValue('tf.frm.nmmk-aka', record.data['nmmkalias']); RH.setCompValue('cb.frm.kelmk', record.data['kdkelmk']); return; } } if(kdprodi != ''){ Ext.getCmp('cb.frm.prodi').disable(); RH.setCompValue('cb.frm.prodi', kdprodi); return; } } function fnSaveMatkul(){ var idForm = 'frm.matkul'; var sUrl = 'matkul_controller/insert_matkul'; var sParams = getInsertMatkulParams(); 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 = 'matkul_controller/update_matkul'; msgSuccess = 'Update data berhasil'; msgFail = 'Update data gagal'; } //call form grid submit function (common function by RH) RH.submitGridForm(idForm, sUrl, sParams, grid, wMatkul, msgWait, msgSuccess, msgFail, msgInvalid); //wMatkul.close(); } // GET PARAMETERS FOR INSERT/UPDATE function getInsertMatkulParams(){ return new Object({ kdprodi : RH.getCompValue('cb.frm.prodi'), kdmk : RH.getCompValue('tf.frm.kdmk'), nmmkind : RH.getCompValue('tf.frm.nmmk-ind'), nmmkeng : RH.getCompValue('tf.frm.nmmk-eng'), nmmkalias : RH.getCompValue('tf.frm.nmmk-aka'), kdkelmk : RH.getCompValue('cb.frm.kelmk') }); } }