function f_pesan(nidu, nim) {
var userpesan1 = "";
var cekjumlah=0, cekjumlahdb=0;
var out = new Ext.form.DisplayField({
cls: 'x-form-text',
autoScroll: true,
height:100,
id: 'out'
});
var out2 = new Ext.form.DisplayField({
cls: 'x-form-text',
autoScroll: true,
height:100,id: 'out2'
});
var text = new Ext.form.TextField({
width: 500,
id: 'text',
emptyText: 'Text...'
});
var call = new Ext.Button({
text: 'Kirim',
handler: function() {
if (Ext.getCmp('text').getValue()) {
Ext.Ajax.request({
url: BASE_URL + 'e_akademic/c_pesan/insert',
method: 'POST',
params: {
kdstsemester: KDSTSEMESTER,
pesan: Ext.getCmp('text').getValue(),
nidu: nidu,
nim: nim,
idpengirim: USERID,
nmpengirim: USERNAME,
waktu: SYS_DATE
},
success: function(response) {
var r = Ext.decode(response.responseText);
if(r.status == false){
Ext.Ajax.request({
url: BASE_URL + 'user/ext_logout',
method: 'POST',
success: function(xhr) {
localStorage.removeItem('access_token');
window.location = BASE_URL + 'user/login';
}
});
}
var success, nimz, niduz, pesanz, tglchatpoz;
tglchatpoz = r.tglchatpo;
success = r.success;
if (success == true) {
Ext.getCmp('text').setValue('');
// out.append(String.format('
{0} :
{1}terkirim pada {2}', 'Saya', r.pesan, tglchatpoz));
// out.el.scroll('b', 50000, true);
ds_nya.load({
scope: this,
callback: function(records, operation, success) {
Ext.getCmp('out').setValue('');
ds_nya.each(function(rec) {
if (USERID === rec.get('idpengirim')) {
userpesan1 = "Saya";
} else {
userpesan1 = rec.get('nama');
}
if (rec.get('success') == true) {
// Ext.getCmp('out').setValue('');
out.append(String.format('{0} :
{1}terkirim pada {2}', userpesan1, rec.get('pesan'), rec.get('tglchatpo')));
out.el.scroll('b', 50000, true);
}
});
}
});
}
}
});
}
}
});
text.on('specialkey', function(t, e) {
if (e.getKey() == e.ENTER) {
call.handler();
}
});
var ds_nya = new Ext.data.JsonStore({
proxy: new Ext.data.HttpProxy({
url: BASE_URL + 'e_akademic/c_pesan/grid',
method: 'POST',
success: function(response){
var r = Ext.decode(response.responseText);
if(r.status == false){
Ext.Ajax.request({
url: BASE_URL + 'user/ext_logout',
method: 'POST',
success: function(xhr) {
localStorage.removeItem('access_token');
window.location = BASE_URL + 'user/login';
}
});
}
}
}),
baseParams: {
kdstsemester: KDSTSEMESTER,
nidu: nidu,
nim: nim
},
root: 'data',
totalProperty: 'results',
fields: [{
name: "idchatpo",
mapping: "idchatpo"
},{
name: "nidu",
mapping: "nidu"
},
{
name: "nim",
mapping: "nim"
},
{
name: "tglchatpo",
mapping: "tglchatpo"
},
{
name: "pesan",
mapping: "pesan"
},
{
name: "success",
mapping: "success"
},
{
name: "idpengirim",
mapping: "idpengirim"
},
{
name: "jumlah",
mapping: "jumlah"
},
{
name: "nama",
mapping: "nama"
}]
});
//======================================================================
var cm = new Ext.grid.ColumnModel({
// specify any defaults for each column
defaults: {
sortable: true // columns are not sortable by default
},
columns: [{
header: 'idchatpo',
width: 50,
dataIndex: 'idchatpo',
sortable: true,
hidden:true
},
{
header: 'Pesan',
width: 560,
dataIndex: 'pesan',
sortable: true
}]
});
var vw = new Ext.grid.GridView({
emptyText: '< Pesan Masih Kosong >'
});
var sm_nya = new Ext.grid.CheckboxSelectionModel({
listeners: {
// rowselect: select_action,
// rowdeselect: deselect_action
}
});
var cari_data = [new Ext.ux.grid.Search({
iconCls: 'btn_search',
minChars: 1,
autoFocus: true,
autoHeight: true,
position: 'top',
mode: 'remote',
width: 200
})];
var grid_nya = new Ext.grid.EditorGridPanel({
store: ds_nya,
frame: true,
//width: 1140,
height: 595,
plugins: cari_data,
id: 'gridnya',
buttonAlign: 'left',
defaults: {
anchor: '-10'
},
forceFit: true,
tbar: [
// {
// text: 'Edit',
// id: 'btn_edit',
// iconCls: 'silk-edit',
// handler: function() {
// if (sm_nya.getCount() > 0) {
// var module_id = sm_nya.getSelected().data['kdjadwalpmb'];
// //form_gallery(gallery_id);
// //alert(module_id);
// //f_jadwalpmb_form(module_id, ds_nya);
// }
// }
// }, '-',
{
text: 'Delete',
id: 'btn_delete',
iconCls: 'silk-delete',
handler: function() {
if (sm_nya.getCount() > 0) {
var delete_id = sm_nya.getSelected().data['idchatpo'];
Ext.MessageBox.show({
title: "Konfirmasi",
msg: "Anda Yakin Untuk menghapus Data ini?",
buttons: Ext.MessageBox.YESNO,
fn: function(btn) {
if (btn == 'yes') {
Ext.Ajax.request({
url: BASE_URL + 'e_akademic/c_pesan/delete',
method: 'POST',
success: function(response) {
var r = Ext.decode(response.responseText);
if(r.status == false){
Ext.Ajax.request({
url: BASE_URL + 'user/ext_logout',
method: 'POST',
success: function(xhr) {
localStorage.removeItem('access_token');
window.location = BASE_URL + 'user/login';
}
});
}
//Ext.MessageBox.alert("Informasi", "Hapus Data Berhasil");
ds_nya.load();
},
failure: function(result) {
//Ext.MessageBox.alert("Informasi", "Hapus Data Gagal");
},
params: {
hapus_id: delete_id
}
});
}
}
});
}
}
}, '-', '->'],
sm: sm_nya,
vw: vw,
autoScroll: true,
cm: cm,
//bbar: paging,
//autoExpandColumn: 'common',
clicksToEdit: 1,
listeners: {
rowdblclick: function rowdblClick(grid, rowIdx) {
var rec = ds_nya.getAt(rowIdx);
//alert(rec.data["kdmenu"] + ', ' + Ext.getCmp('combox').getValue());
}
}
});
// =================================================================================
var r = new Ext.Window({
title: 'Option',
width: 600,
height: 300,
layout: 'fit',
items: [grid_nya],
bbar: [
'->',
{
text: 'Kembali',
handler: function() {
f_pesan(nidu, nim);
r.close();
}
}]
});
var q = new Ext.Window({
title: 'Pesan',
width: 600,
height: 300,
layout: 'fit',
items: [out,out2],
bbar: [
text,
call,
{
text: 'Option',
handler: function() {
q.hide();
ds_nya.load();
r.show();
}
}]
});
q.show();
Ext.getCmp('out').setValue('Silahkan Tulis Pesan Anda...
');
ds_nya.load({
scope: this,
callback: function(records, operation, success) {
Ext.getCmp('out').setValue('');
ds_nya.each(function(rec) {
if (USERID === rec.get('idpengirim')) {
userpesan1 = "Saya";
} else {
userpesan1 = rec.get('nama');
}
if (rec.get('success') == true) {
out.append(String.format('{0} :
{1}terkirim pada {2}', userpesan1, rec.get('pesan'), rec.get('tglchatpo')));
out.el.scroll('b', 50000, true);
}
});
}
});
var interval = setInterval(function() {
cekjumlah=0;
Ext.getCmp('out2').setValue('');
ds_nya.load({
scope: this,
callback: function(records, operation, success) {
ds_nya.each(function(rec) {
if (USERID === rec.get('idpengirim')) {
userpesan1 = "Saya";
} else {
userpesan1 = rec.get('nama');
}
if (rec.get('success') == true) {
out2.append(String.format('{0} :
{1}terkirim pada {2}', userpesan1, rec.get('pesan'), rec.get('tglchatpo')));
out2.el.scroll('b', 50000, true);
}
cekjumlah += 1;
// alert(rec.get('jumlah')+', '+cekjumlah);
if(rec.get('jumlah') == cekjumlah){
Ext.getCmp('out').setValue('');
Ext.getCmp('out').setValue(Ext.getCmp('out2').getValue());
out.el.scroll('b', 50000, true);
}
});
}
});
}, 4000);
}