Newer
Older
/*
WiSP User Topups
Copyright (C) 2007-2009, AllWorldIT
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
function showWiSPUserTopupsWindow(userID) {
var wispUserTopupsWindow = new Ext.ux.GenericGridWindow(
// Window config
{
title: "User Topups",
width: 500,
height: 335,
minWidth: 500,
minHeight: 335,
},
// Grid config
{
// Inline toolbars
tbar: [
{
text:'Add',
tooltip:'Add topup',
iconCls:'add',
handler: function() {
{
text:'Edit',
tooltip:'Edit topup',
iconCls:'option',
handler: function() {
var selectedItem = wispUserTopupsWindow.getComponent('gridpanel').getSelectionModel().getSelected();
// Check if we have selected item
if (selectedItem) {
// If so display window
showWiSPUserTopupAddEditWindow(userID,selectedItem.data.ID);
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
} else {
wispUserTopupsWindow.getEl().mask();
// Display error
Ext.Msg.show({
title: "Nothing selected",
msg: "No topup selected",
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.CANCEL,
modal: false,
fn: function() {
wispUserTopupsWindow.getEl().unmask();
}
});
}
}
},
'-',
{
text:'Remove',
tooltip:'Remove topup',
iconCls:'remove',
handler: function() {
var selectedItem = wispUserTopupsWindow.getComponent('gridpanel').getSelectionModel().getSelected();
// Check if we have selected item
if (selectedItem) {
// If so display window
showWiSPUserTopupRemoveWindow(wispUserTopupsWindow,selectedItem.data.ID);
} else {
wispUserTopupsWindow.getEl().mask();
// Display error
Ext.Msg.show({
title: "Nothing selected",
msg: "No topup selected",
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.CANCEL,
modal: false,
fn: function() {
wispUserTopupsWindow.getEl().unmask();
}
});
}
}
}
],
// Column model
colModel: new Ext.grid.ColumnModel([
{
id: 'ID',
header: "ID",
sortable: true,
hidden: true,
dataIndex: 'ID'
},
{
dataIndex: 'Type'
},
{
header: "Value",
sortable: true,
dataIndex: 'Value'
},
{
header: "Timestamp",
sortable: true,
hidden: true,
dataIndex: 'Timestamp'
},
{
header: "ValidFrom",
sortable: true,
dataIndex: 'ValidFrom'
},
{
header: "ValidTo",
sortable: true,
dataIndex: 'ValidTo'
]),
},
// Store config
{
baseParams: {
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'WiSPUsers',
SOAPFunction: 'getWiSPUserTopups',
SOAPParams: '0:UserID,__search',
UserID: userID
}
},
// Filter config
{
filters: [
{type: 'numeric', dataIndex: 'ID'},
{type: 'date', dataIndex: 'Timestamp'},
]
}
);
wispUserTopupsWindow.show();
}
// Display edit/add form
function showWiSPUserTopupAddEditWindow(userID,topupID) {
var today = new Date();
var firstOfMonth = today.getFirstDateOfMonth();
var firstOfNext = today.getLastDateOfMonth().add(Date.DAY, 1);
var submitAjaxConfig;
// We doing an update
if (topupID) {
submitAjaxConfig = {
ID: topupID,
SOAPFunction: 'updateWiSPUserTopup',
SOAPParams:
'0:ID,0:Value,0:Type,'+
'0:ValidFrom,0:ValidTo'
};
// We doing an Add
} else {
submitAjaxConfig = {
UserID: userID,
SOAPFunction: 'createWiSPUserTopup',
SOAPParams:
'0:UserID,0:Value,0:Type,'+
'0:ValidFrom,0:ValidTo'
};
}
// Create window
var wispUserTopupFormWindow = new Ext.ux.GenericFormWindow(
// Window config
{
title: "Topup Information",
width: 400,
height: 200,
minWidth: 400,
minHeight: 200
},
// Form panel config
{
labelWidth: 85,
baseParams: {
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'WiSPUsers'
},
items: [
{
width: 157,
[ '2', 'Uptime' ]
],
displayField: 'Type',
valueField: 'Type',
hiddenName: 'Type',
forceSelection: true,
triggerAction: 'all',
editable: false
},
{
xtype: 'numberfield',
fieldLabel: 'Value',
name: 'Value',
minValue: 1,
allowBlank: false
},
{
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
fieldLabel: 'ValidFrom',
name: 'ValidFrom',
id: 'ValidFrom',
vtype: 'daterange',
value: firstOfMonth,
format: 'Y-m-d',
endDateField: 'ValidTo'
},
{
xtype: 'datefield',
fieldLabel: 'ValidTo',
name: 'ValidTo',
id: 'ValidTo',
vtype: 'daterange',
value: firstOfNext,
format: 'Y-m-d',
startDateField: 'ValidFrom'
}
],
},
// Submit button config
submitAjaxConfig
);
wispUserTopupFormWindow.show();
if (topupID) {
wispUserTopupFormWindow.getComponent('formpanel').load({
params: {
id: topupID,
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'WiSPUsers',
SOAPFunction: 'getWiSPUserTopup',
SOAPParams: 'id'
}
});
}
}
// Display edit/add form
function showWiSPUserTopupRemoveWindow(parent,id) {
// Mask parent window
parent.getEl().mask();
// Display remove confirm window
Ext.Msg.show({
title: "Confirm removal",
msg: "Are you very sure you wish to remove this topup?",
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.YESNO,
modal: false,
fn: function(buttonId,text) {
// Check if user clicked on 'yes' button
if (buttonId == 'yes') {
// Do ajax request
uxAjaxRequest(parent,{
params: {
id: id,
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'WiSPUsers',
SOAPFunction: 'removeWiSPUserTopup',
SOAPParams: 'id'
}
});
// Unmask if user answered no
} else {
parent.getEl().unmask();
}
}
});
}