Newer
Older
/*
Admin 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 showAdminUserTopupsWindow(userID) {
var adminUserTopupsWindow = 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() {
showAdminUserTopupAddEditWindow(userID,0);
}
46
47
48
49
50
51
52
53
54
55
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
{
text:'Edit',
tooltip:'Edit topup',
iconCls:'option',
handler: function() {
var selectedItem = adminUserTopupsWindow.getComponent('gridpanel').getSelectionModel().getSelected();
// Check if we have selected item
if (selectedItem) {
// If so display window
showAdminUserTopupAddEditWindow(userID,selectedItem.data.ID);
} else {
adminUserTopupsWindow.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() {
adminUserTopupsWindow.getEl().unmask();
}
});
}
}
},
'-',
{
text:'Remove',
tooltip:'Remove topup',
iconCls:'remove',
handler: function() {
var selectedItem = adminUserTopupsWindow.getComponent('gridpanel').getSelectionModel().getSelected();
// Check if we have selected item
if (selectedItem) {
// If so display window
showAdminUserTopupRemoveWindow(adminUserTopupsWindow,selectedItem.data.ID);
} else {
adminUserTopupsWindow.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() {
adminUserTopupsWindow.getEl().unmask();
}
});
}
}
}
],
// Column model
colModel: new Ext.grid.ColumnModel([
{
id: 'ID',
header: "ID",
sortable: true,
hidden: true,
dataIndex: 'ID'
},
{
header: "Type",
sortable: true,
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'
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
]),
},
// Store config
{
baseParams: {
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'AdminUsers',
SOAPFunction: 'getAdminUserTopups',
SOAPParams: '0:UserID,__search',
UserID: userID
}
},
// Filter config
{
filters: [
{type: 'numeric', dataIndex: 'ID'},
{type: 'date', dataIndex: 'Timestamp'},
{type: 'numeric', dataIndex: 'Value'},
{type: 'date', dataIndex: 'ValidFrom'},
{type: 'date', dataIndex: 'ValidTo'}
]
}
);
adminUserTopupsWindow.show();
}
// Display edit/add form
function showAdminUserTopupAddEditWindow(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: 'updateAdminUserTopup',
SOAPParams:
'0:ID,0:Value,0:Type,'+
'0:ValidFrom,0:ValidTo'
};
// We doing an Add
} else {
submitAjaxConfig = {
UserID: userID,
SOAPFunction: 'createAdminUserTopup',
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
'0:UserID,0:Value,0:Type,'+
'0:ValidFrom,0:ValidTo'
};
}
// Create window
var adminUserTopupFormWindow = 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: 'AdminUsers'
},
items: [
{
xtype: 'combo',
fieldLabel: 'Type',
name: 'Type',
allowBlank: false,
width: 157,
store: [
[ '1', 'Traffic' ],
[ '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
324
325
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
);
adminUserTopupFormWindow.show();
if (topupID) {
adminUserTopupFormWindow.getComponent('formpanel').load({
params: {
id: topupID,
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'AdminUsers',
SOAPFunction: 'getAdminUserTopup',
SOAPParams: 'id'
}
});
}
}
// Display edit/add form
function showAdminUserTopupRemoveWindow(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: 'AdminUsers',
SOAPFunction: 'removeAdminUserTopup',
SOAPParams: 'id'
}
});
// Unmask if user answered no
} else {
parent.getEl().unmask();
}
}
});
}
// vim: ts=4