function pMatkul(){ /** 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 */ //MAIN GRID STORE var fields_matkul = RH.storeFields('idmk', 'kdprodi', 'nmprodi', 'kdmk', 'nmmkind', 'nmmkeng', 'nmmkalias', 'kdkelmk','nmkelmk'); var pageSize = 15; var ds_matkul = RH.JsonStore({ url : BASE_URL + 'matkul_controller/get_matkulByProdi', fields : fields_matkul, //root : 'data', //totalProperty : 'results', limit: pageSize, params: [{key:'kdprodi', id:'cb.prodi-matkul'}], enableSearch: true, }); //SEARCH COMPONENT var sb_matkul = RH.searchComp({ id : 'sb_matkul', fields : ['kdmk:Kode Mata Kuliah','nmmkind:Nama Mata Kuliah (Ind)','nmmkeng:Nama Mata Kuliah (Eng)'], selected : 'kdmk', store : ds_matkul, textWidth : 250, }); // COLUMN MODEL var cm_matkul = new Ext.grid.ColumnModel([ new Ext.grid.RowNumberer(), { header: 'kdprodi', dataIndex: 'kdprodi', hidden: true }, { header: 'Kode',width: 80, dataIndex: 'kdmk', sortable: true }, { header: 'Nama Mata Kuliah (Indonesia)', width: 250, dataIndex: 'nmmkind', sortable: true }, { header: 'Nama Mata Kuliah (English)', width: 250, dataIndex: 'nmmkeng', sortable: true }, { header: 'Kelompok Mata Kuliah', width: 200, dataIndex: 'nmkelmk', sortable: true }, { header: 'Program Studi', width: 200, dataIndex: 'nmprodi', sortable: true }, RH.EditColumn(), RH.DeleteColumn() ] ); /**GRID PANEL */ var gp_matkul = RH.GridPanel_T1({ ds: ds_matkul, cm: cm_matkul, singleSelect: true, searchComp: sb_matkul, allowAdd: true, //modeEdit: true,//modeDelete: true, fnAdd: fnAddMatkul, customButton: { text:'Cetak', iconCls: 'silk-printer', handler: function() { if(!RH.getCompValue('cb.prodi-matkul')){ RH.warning('Program Studi Belum Dipilih!'); return; } RH.ShowReport(BASE_URL + 'rpt/rpt_matakuliah/get_matakuliah/'+RH.getCompValue('cb.prodi-matkul')); } }, pageSize: pageSize, cellclick: onCellMatkulClick }); var fp_matkul = RH.GPContainer1_wHeaders({ title: 'Mata Kuliah', iconCls:'silk-book', gridPanel: gp_matkul, headers: [ RH.ActionCombo({ id: 'cb.prodi-matkul', label: 'Program Studi', width: 300, data: ds_prodireg, key: 'kdprodi', display: 'lnmprodi', fnSelect: function(combo){ ds_matkul.reload({ params: { kdprodi: combo.getValue() } }); } }) ], }); 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 RH.EditClick(e, function(){fnEditMatkul(grid, record)}); RH.DeleteClick(e, function(){fnDeleteMatkul(grid, record)}); } function reloadMatkul(){ ds_matkul.reload(); } function fnAddMatkul(){ if(RH.getCompValue('cb.prodi-matkul')==''){ RH.warning('Program Studi Belum Dipilih!'); return; } var grid = gp_matkul; wAddEdit_matkul(false, grid, null, wAddEditStoresObj); } function fnEditMatkul(grid, record){ wAddEdit_matkul(true, grid, record, wAddEditStoresObj); } function fnDeleteMatkul(grid, record){ Ext.Ajax.request({ url:BASE_URL + 'c_tools/get_user', method:'POST', success: function(response){ var r = Ext.decode(response.responseText); USERID = r.userid; USERNAME = r.username; L_MEMBER = r.level_member; NM_KLP = r.nm_klp; //Kondisi Untuk Login// if(NM_KLP == "Administrator"){ var url = BASE_URL + 'matkul_controller/delete_matkul'; var params = new Object({ kdprodi : record.data['kdprodi'], kdmk : record.data['kdmk'], idmk : record.data['idmk'] }); RH.deleteGridRecord(url, params, grid ); }else{ Ext.MessageBox.alert("Info", "Anda bukan Administrator"); } } }); } /* 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: [{ id: 'tf.frm.idmk', fieldLabel: 'ID Mata Kuliah', allowBlank: true, hidden: true }, { xtype: 'combo', id: 'cb.frm.prodi', readOnly:true, disabled:true, 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', maskRe: /[^ ]/, 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); RH.setCompValue('cb.frm.prodi', kdprodi); if(isUpdate){ if(record != null){ Ext.getCmp('tf.frm.kdmk').disable(); RH.setCompValue('tf.frm.idmk', record.data['idmk']); 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; } } } function fnSaveMatkul(){ var idForm = 'frm.matkul'; var sUrl = BASE_URL +'matkul_controller/insert_matkul'; var sParams = getInsertMatkulParams(isUpdate); 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 +'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(isUpdate){ var kdmk = RH.getCompValue('tf.frm.kdmk'); return new Object({ idmk : RH.getCompValue('tf.frm.idmk'), kdprodi : RH.getCompValue('cb.frm.prodi'), kdmk : (isUpdate) ? kdmk:kdmk.split(' ').join(''), 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') }); } }