function pKurikulum(){
/** COMMON STORES */
var ds_prodireg = store_prodireg();
var ds_years = store_tahun();
/** STORE for GRID COLUMN EDITOR type COMBO */
var dcUrl = BASE_URL + 'data_controller/';
var obj2Fields = new Object([
{ name: 'kode' }, { name: 'nama' }
]);
var obj4Fields = new Object([
{ name: 'id' }, { name: 'kode' }, { name: 'nama' }, { name: 'deskripsi' }
]);
var ds_jkurikulum = RH.getCommonJsonStore(obj2Fields, dcUrl + 'get_jkurikulum');
var ds_jmatkul = RH.getCommonJsonStore(obj2Fields, dcUrl + 'get_jmatkul');
var ds_stmatkul = RH.getCommonJsonStore(obj2Fields, dcUrl + 'get_stmatkul');
var ds_semester = RH.getCommonJsonStore(obj4Fields, dcUrl + 'get_semester');
/** MAIN GRID STORE: DS_KURIKULUM */
var fields_kur = RH.storeFields('kdprodi','thnmasuk','kdmk','nmmkind','idsemester',
'jmlsks','skstatapmuka','skspraktikum','sksprakteklap',
'jnskurikulum','jnsmk','stmk');
var pageSize = 15;
var ds_kur = RH.JsonStore({
url : BASE_URL + 'kurikulum_controller/get_kurikulum',
fields : fields_kur,
limit: pageSize,
params: [
{key:'kdprodi', id:'cb.prodi-kur'}
,{key:'thnmasuk', id:'cb.thmasuk-kur'}
],
enableSearch: true,
});
//SEARCH COMPONENT
var sb_kur = RH.searchComp({
id: 'sb_kur',
fields : ['kdmk:Kode Mata Kuliah','nmmkind:Nama Mata Kuliah (Ind)'],
selected : 'nmmkind',
store : ds_kur,
textWidth : 250
});
/**
THE GRID COLUMN =====================================
*/
/** RENDERER for GRID COLUMN */
function render_jkurikulum(value) {
//RH.getRecordFieldValue(store, field, key, value)
var val = RH.getRecordFieldValue(ds_jkurikulum, 'nama', 'kode', value);
return RH.qtipEdit(val,'12px');
}
function render_jmatkul(value) {
var val = RH.getRecordFieldValue(ds_jmatkul, 'nama', 'kode', value);
return RH.qtipEdit(val,'12px');
}
function render_stmatkul(value) {
var val = RH.getRecordFieldValue(ds_stmatkul, 'nama', 'kode', value);
return RH.qtipEdit(val,'12px');
}
function render_semester(value) {
var val = RH.getRecordFieldValue(ds_semester, 'kode', 'id', value);
return RH.qtipEdit(val,'12px');
}
function render_numEdit(value) {
return RH.qtipEdit(value,'12px');
}
/** FUNCTION for GRID COLUMN EDITOR */
var fnSelect = function(combo, record){
//The ID of THE combo must equals the field (key) to be updated
var field = combo.getId();
var value = '';
if(record.data['kode'])
value = record.data['kode'];
if(record.data['id'])
value = record.data['id'];
//Update Kurikulum set the field with the value
updateKurikulum(field, value);
};
var fnChange = function(numfield, newValue, oldValue){
//The ID of THE textField or NumberField must equals the field (key) to be updated
var field = this.getId();
var value = (newValue)? newValue : oldValue;
//Update Kurikulum set the field with the value
updateKurikulum(field, value);
};
/** GRID COLUMN MODEL */
var cm_kur = new Ext.grid.ColumnModel([
new Ext.grid.RowNumberer(), //for rows numbering
{
header: RH.h3('Kode'), width:70,
dataIndex: 'kdmk',
sortable: true
}, {
header: RH.h3('Nama Mata Kuliah (Ind)'), width: 250,
dataIndex: 'nmmkind',
sortable: true,
}, {
header: RH.h3('Semester'), width: 66,
dataIndex: 'idsemester',
renderer: render_semester,
editor: RH.getComboEditor('idsemester', false, ds_semester, 'id', 'kode', fnSelect),
}, {
header: RH.h3('Jumlah
SKS'), width: 70,
dataIndex: 'jmlsks', align:'right',
renderer: render_numEdit,
editor: RH.getNumEditor('jmlsks', 'INTEGER', 0, 10, false, fnChange),
}, {
header: RH.h3('Tatap
Muka'), width: 70,
dataIndex: 'skstatapmuka', align:'right',
renderer: render_numEdit,
editor: RH.getNumEditor('skstatapmuka', 'INTEGER', 0, 10, false, fnChange),
}, {
header: RH.h3('Praktikum'), width: 70,
dataIndex: 'skspraktikum', align:'right',
renderer: render_numEdit,
editor: RH.getNumEditor('skspraktikum', 'INTEGER', 0, 10, false, fnChange),
}, {
header: RH.h3('Praktek
Lapangan'), width: 70,
dataIndex: 'sksprakteklap', align:'right',
renderer: render_numEdit,
editor: RH.getNumEditor('sksprakteklap', 'INTEGER', 0, 10, false, fnChange),
}, {
header: RH.h3('Jenis
Kurikulum'), width: 90,
dataIndex: 'jnskurikulum',
renderer: render_jkurikulum,
editor: RH.getComboEditor('jnskurikulum', false, ds_jkurikulum, 'kode', 'nama', fnSelect),
}, {
header: RH.h3('Jenis
Mata Kuliah'), width: 110,
dataIndex: 'jnsmk',
renderer: render_jmatkul,
editor: RH.getComboEditor('jnsmk', false, ds_jmatkul, 'kode', 'nama', fnSelect),
}, {
header: RH.h3('Status
Mata Kuliah'), width: 100,
dataIndex: 'stmk',
renderer: render_stmatkul,
editor: RH.getComboEditor('stmk', false, ds_stmatkul, 'kode', 'nama', fnSelect),
},
RH.DeleteColumn()
]
);
// Selection Model
var sm_kur = new Ext.grid.RowSelectionModel({
singleSelect: true
});
// Grid View
var gv_kur = new Ext.grid.GridView({emptyText: '< Belum ada Data >'});
/*
var cellEditing = new Ext.grid.plugin.CellEditing({
clicksToEdit: 1
});
*/
var gp_kur = new Ext.grid.EditorGridPanel({ //PAKE EditorGridPanel
ds: ds_kur,
cm: cm_kur,
sm: sm_kur,
view: gv_kur,
clicksToEdit: 1, //for cell editing (single click =1, dblclick=2)
forceFit: true, //autoHeight: true,
layout:'anchor',
//autoSizeColumns: true,
//autoExpandColumn: 'nmmkind',
autoScroll:true,
//enableColumnResize: true,
columnLines: true,
loadMask: true,
tbar:[{
text: 'Tambah', id: 'tb.add-kur', iconCls: 'silk-add',
handler: function() { fnAddKurikulum(); }
}, {
text: 'Salin Mata Kuliah dari Kurikulum Sebelumnya', id: 'tb.copy-kur', iconCls: 'silk-page-copy',
handler: function() { fnCopyKurikulum(); }
},sb_kur],
bbar: new Ext.PagingToolbar({
store: ds_kur,
displayInfo: true,
pageSize: pageSize,
mode: 'local',
displayMsg: 'Data {0} - {1} dari {2}',
emptyMsg: "Belum ada data"
}),
listeners: {
cellclick: onCellKurClick
}
});
//var fp_kur = new Ext.form.FormPanel({
var fp_kur = new Ext.Panel({
//xtype: 'form',
title: 'Kurikulum', iconCls:'silk-book',
buttonAlign: 'left',
bodyStyle: 'padding: 5px',
border: false,
layout: 'border',
waitMsg: 'Waiting...',
maskDisabled: false,
monitorValid: true,
frame: true,
items: [{
xtype: 'fieldset', flex: 1,
labelWidth:140, labelAlign:'right',
items: [{
xtype: 'combo', id: 'cb.prodi-kur', fieldLabel: 'Program Studi',
width: 300, editable: false,
store: ds_prodireg, triggerAction: 'all',
valueField: 'kdprodi', displayField: 'lnmprodi',
forceSelection: true, submitValue: true, mode: 'local',
emptyText:'Pilih...',
listeners:{
scope: this, 'select': function(){
reloadGridKur();
}
}
},{
xtype: 'combo', id: 'cb.thmasuk-kur', fieldLabel: 'Tahun Masuk/Angkatan',
editable: true,
store: ds_years, triggerAction: 'all',
valueField: 'kode', displayField: 'nama',
forceSelection: true, submitValue: true, mode: 'local',
emptyText:'Pilih...',
listeners:{
scope: this, 'select': function(){
reloadGridKur();
}
}
},{
xtype: 'textfield', id: 'hidden.kdmk', hidden:true,
}]
},{
xtype: 'panel', layout:'fit',
title:'Mata Kuliah',
items: [gp_kur],
tbar: [{
text: 'Tambah', id: 'tb.add-kur', iconCls: 'silk-add',
handler: function() { fnAddKurikulum(); }
}, {
text: 'Salin Mata Kuliah dari Kurikulum Sebelumnya', id: 'tb.copy-kur', iconCls: 'silk-page-copy',
handler: function() { fnCopyKurikulum(); }
}]
}],
});
/**
FUNCTIONS
*/
function onCellKurClick(grid, rowIndex, columnIndex, e) {
var t = e.getTarget();
var record = grid.getStore().getAt(rowIndex); // Get the Record
RH.setCompValue('hidden.kdmk', record.data['kdmk']);
if (t.className == 'imgEdit') {
fnEditKurikulum(grid, record);
return true;
}
if (t.className == 'imgDelete') {
fnDeleteKurikulum(grid, record);
return true;
}
return true; //back to ClickToEdit=1
}
function reloadGridKur(){
ds_kur.reload({
params: {
kdprodi: RH.getCompValue('cb.prodi-kur', true),
thnmasuk: RH.getCompValue('cb.thmasuk-kur', true)
}
});
}
function fnAddKurikulum(){
/*for DEBUG: RH.warning(RH.searchObj.params[0].name); return;*/
var grid = gp_kur;
var kdprodi = RH.getCompValue('cb.prodi-kur', true);
var thnmasuk = RH.getCompValue('cb.thmasuk-kur', true);
if(kdprodi == '') { RH.warning('Program Studi harus diisi'); return; };
if(thnmasuk == '') { RH.warning('Tahun Masuk/Angkatan harus diisi'); return; };
wLookupMatkul(kdprodi, thnmasuk, grid);
}
function fnCopyKurikulum(){
var grid = gp_kur;
var kdprodi = RH.getCompValue('cb.prodi-kur', true);
var thnmasuk = RH.getCompValue('cb.thmasuk-kur', true);
if(kdprodi == '') { RH.warning('Program Studi harus diisi'); return; };
if(thnmasuk == '') { RH.warning('Tahun Masuk/Angkatan harus diisi'); return; };
if(ds_kur.getCount() > 0){
RH.warning('Data sudah ada. Hapus terlebih dahulu');
return;
}
var combo_prodi = Ext.getCmp('cb.prodi-kur');
var combo_tahun = Ext.getCmp('cb.thmasuk-kur');
wFormCopyKurikulum(combo_prodi, combo_tahun, grid)
}
function fnEditKurikulum(grid, record){
//DO HERE.........
//EDIT NUMERICS ON THE GRID
}
function fnDeleteKurikulum(grid, record){
var url = BASE_URL + 'kurikulum_controller/delete_kurikulum';
var params = new Object({
kdprodi : record.data['kdprodi'],
thnmasuk : record.data['thnmasuk'],
kdmk : record.data['kdmk'],
});
RH.deleteGridRecord(url, params, grid );
}
function updateKurikulum(field, value){
Ext.Ajax.request({
url: BASE_URL + 'kurikulum_controller/update1field_kurikulum',
params: {
kdprodi : RH.getCompValue('cb.prodi-kur',true),
thnmasuk : RH.getCompValue('cb.thmasuk-kur',true),
kdmk : RH.getCompValue('hidden.kdmk',true),
field : field,
value : value,
},
success: function() {
// Ext.Msg.alert("Informasi", "Ubah Data Berhasil");
ds_kur.reload();
},
failure: function() {
// Ext.Msg.alert("Informasi", "Ubah Data Gagal");
}
});
}
SET_PAGE_CONTENT(fp_kur);
}
/**
LOOKUP MATAKULIAH FOR ADD KURIKULUM
*/
function wLookupMatkul(kdprodi, thnmasuk, masterGrid){
/**
DATA SOURCE
*/
var fieldsLookup = RH.storeFields('kdprodi','kdmk','nmmkind','nmmkeng','nmmkalias','kdkelmk');
var ds_lookup = RH.JsonStore({
url : BASE_URL + 'matkul_controller/get_matkulByProdi',
fields : fieldsLookup,
limit : 18,
params: [{key:'kdprodi', value: kdprodi}],
enableSearch: true,
});
//SEARCH COMPONENT
var sb_lookup = RH.searchComp({
id: 'sb_lookup',
fields : ['kdmk:Kode Mata Kuliah','nmmkind:Nama Mata Kuliah (Ind)','nmmkeng:Nama Mata Kuliah (Eng)'],
selected : 'kdmk',
store : ds_lookup,
textWidth : 200
});
/**
GRID LOOKUP MATA KULIAH
*/
// COLUMN MODEL
var cm_lookup = 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
}]
);
// Selection Model
var sm_lookup = new Ext.grid.RowSelectionModel({
singleSelect: true
});
// Grid View
var gv_lookup = new Ext.grid.GridView({
emptyText: '< Belum ada Data >'
});
var gp_lookup = new Ext.grid.GridPanel({
ds: ds_lookup,
cm: cm_lookup,
sm: sm_lookup,
view: gv_lookup,
forceFit: true,
layout:'anchor',
autoSizeColumns: true, //autoExpandColumn: 'nmmkind',
autoScroll:true,
enableColumnResize: true,
enableColumnHide: false,
enableColumnMove: false,
columnLines: true,
loadMask: true,
tbar:[sb_lookup],
bbar: new Ext.PagingToolbar({
store: ds_lookup,
displayInfo: true, pageSize: 18, mode: 'local',
displayMsg: 'Data {0} - {1} dari {2}',
emptyMsg: "Belum ada data"
}),
listeners: {
rowdblclick: onRowDblClick
}
});
/**
WIN LOOKUP MATA KULIAH
*/
var wLookup = new Ext.Window({
id: 'w.look-matkul',
title: 'Mata Kuliah',
modal: true,
layout: 'fit',
width:720, height:400,
items: [gp_lookup]
}).show();
/**
FUNCTIONS
*/
function onRowDblClick(grid, rowIdx) {
var store = ds_lookup;
var rec = store.getAt(rowIdx);
var kdmk = rec.data['kdmk'];
//INSERT NEW KURIKULUM RECORD (MATA KULIAH)
Ext.Ajax.request({
url: 'kurikulum_controller/insert_kurikulum',
method: 'POST',
params: {
kdprodi : kdprodi,
thnmasuk : thnmasuk,
kdmk : kdmk
},
waitMsg: 'Tunggu, sedang proses menyimpan...',
success: function() {
Ext.Msg.alert("Info", "Simpan Data Berhasil");
masterGrid.getStore().reload();
wLookup.close();
},
failure: function(result){
Ext.Msg.alert("Info", "Simpan Data Gagal");
}
});
}
}
/**
FORM COPY KURIKULUM
*/
function wFormCopyKurikulum(combo_prodi, combo_tahun, masterGrid){
//the store must same (shared store)
var ds_prodireg = combo_prodi.getStore();
var ds_years = combo_tahun.getStore();
var kdprodi = combo_prodi.getValue();
var thmasuk = combo_tahun.getValue();
var copy_form = new Ext.form.FormPanel({
xtype:'form',
id: 'frm.copy',
buttonAlign: 'left',
labelWidth: 180, labelAlign: 'right',
bodyStyle: 'padding:10px 3px 3px 5px', // atas, kanan, bawah, kiri
monitorValid: true,
height: 160, width: 500,
layout: 'form',
frame: false,
defaultType:'combo',
items: [{
id: 'cb.prodi-copy', fieldLabel: 'Program Studi',
store: ds_prodireg, triggerAction: 'all',
valueField: 'kdprodi', displayField: 'lnmprodi',
forceSelection: true, submitValue: true, mode: 'local',
allowBlank: false, editable: false,
width: 300,
},{
id: 'cb.thbaru-copy', fieldLabel: 'Tahun Masuk/Angkatan (Baru)',
store: ds_years, triggerAction: 'all', allowBlank: false,
valueField: 'kode', displayField: 'nama',
forceSelection: true, submitValue: true, mode: 'local',
width: 150,
},{
id: 'cb.thlama-copy', fieldLabel: 'Tahun Masuk/Angkatan (Lama)',
store: ds_years, triggerAction: 'all', editable: true,
valueField: 'kode', displayField: 'nama',
forceSelection: true, submitValue: true, mode: 'local',
emptyText:'Pilih...', width:150,
}],
buttons: [{
text: 'Simpan', iconCls:'silk-save',
handler: function() {
fnSaveCopy();
}
}, {
text: 'Kembali', iconCls:'',
handler: function() {
wCopyKurikulum.close();
}
}]
});
/**SET THE FORM */
setForm();
var wCopyKurikulum = new Ext.Window({
title: 'Salin Mata Kuliah dari Kurikulum Sebelumnya',
modal: true, closable:false,
items: [copy_form]
}).show();
/**
FUNCTIONS
*/
function setForm(){
Ext.getCmp('cb.prodi-copy').disable();
Ext.getCmp('cb.thbaru-copy').disable();
RH.setCompValue('cb.prodi-copy', kdprodi);
RH.setCompValue('cb.thbaru-copy', thmasuk);
}
/**
SAVE COPY FUNCTIONS
*/
function fnSaveCopy(){
var thlama = RH.getCompValue('cb.thlama-copy',true);
if(thlama == '') { RH.warning('Tahun Masuk/Angkatan (Lama) harus diisi'); return; };
var idForm = 'frm.copy';
var sUrl = 'kurikulum_controller/copy_kurikulum';
var sParams = new Object({
kdprodi : RH.getCompValue('cb.prodi-copy'),
thbaru : RH.getCompValue('cb.thbaru-copy'),
thlama : thlama
});
var grid = masterGrid;
var msgWait = 'Tunggu, sedang proses menyimpan...';
var msgSuccess = 'Salin data berhasil';
var msgFail = 'Salin data gagal';
var msgInvalid = 'Data belum valid (data primer belum terisi)!';
//call form grid submit function (common function by RH)
RH.submitGridForm(idForm, sUrl, sParams, grid, wCopyKurikulum,
msgWait, msgSuccess, msgFail, msgInvalid);
}
}