Newer
Older
function showWiSPUserWindow() {
var WiSPUserWindow = new Ext.ux.GenericGridWindow(
// Window config
{
title: "Users",
width: 600,
height: 335,
minWidth: 600,
minHeight: 335,
},
// Grid config
{
// Inline toolbars
tbar: [
{
text:'Add',
tooltip:'Add user',
iconCls:'add',
handler: function() {
showWiSPUserAddEditWindow();
}
},
'-',
{
text:'Edit',
tooltip:'Edit user',
iconCls:'option',
handler: function() {
var selectedItem = WiSPUserWindow.getComponent('gridpanel').getSelectionModel().getSelected();
// Check if we have selected item
if (selectedItem) {
// If so display window
showWiSPUserAddEditWindow(selectedItem.data.ID);
39
40
41
42
43
44
45
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
} else {
WiSPUserWindow.getEl().mask();
// Display error
Ext.Msg.show({
title: "Nothing selected",
msg: "No user selected",
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.CANCEL,
modal: false,
fn: function() {
WiSPUserWindow.getEl().unmask();
}
});
}
}
},
'-',
{
text:'Remove',
tooltip:'Remove user',
iconCls:'remove',
handler: function() {
var selectedItem = WiSPUserWindow.getComponent('gridpanel').getSelectionModel().getSelected();
// Check if we have selected item
if (selectedItem) {
// If so display window
showWiSPUserRemoveWindow(WiSPUserWindow,selectedItem.data.ID);
} else {
WiSPUserWindow.getEl().mask();
// Display error
Ext.Msg.show({
title: "Nothing selected",
msg: "No user selected",
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.CANCEL,
modal: false,
fn: function() {
WiSPUserWindow.getEl().unmask();
}
});
}
}
},
'-',
{
text:'Logs',
tooltip:'User logs',
iconCls:'logs',
handler: function() {
var selectedItem = WiSPUserWindow.getComponent('gridpanel').getSelectionModel().getSelected();
// Check if we have selected item
if (selectedItem) {
// If so display window
showWiSPUserLogsWindow(selectedItem.data.ID);
} else {
WiSPUserWindow.getEl().mask();
// Display error
Ext.Msg.show({
title: "Nothing selected",
msg: "No user selected",
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.CANCEL,
modal: false,
fn: function() {
WiSPUserWindow.getEl().unmask();
}
});
}
}
}
],
// Column model
colModel: new Ext.grid.ColumnModel([
{
id: 'ID',
sortable: true,
dataIndex: 'ID'
},
{
header: "Phone",
sortable: true,
dataIndex: 'Phone'
},
// Store config
{
baseParams: {
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'WiSPUsers',
SOAPFunction: 'getWiSPUsers',
SOAPParams: '__null,__search'
}
},
// Filter config
{
filters: [
{type: 'numeric', dataIndex: 'ID'},
{type: 'string', dataIndex: 'Username'},
{type: 'boolean', dataIndex: 'Disabled'},
{type: 'string', dataIndex: 'Firstname'},
{type: 'string', dataIndex: 'Lastname'},
{type: 'string', dataIndex: 'Email'},
{type: 'string', dataIndex: 'Phone'}
]
}
);
WiSPUserWindow.show();
}
// Display edit/add form
function showWiSPUserAddEditWindow(id) {
var submitAjaxConfig;
var editMode;
// Attribute store
var attributeStore;
attributeStore = new Ext.data.SimpleStore({
fields: [
'name', 'operator', 'value', 'modifier'
],
});
// Attribute record that can be added to above store
var attributeRecord = Ext.data.Record.create([
{name: 'name'},
{name: 'operator'},
{name: 'value'},
{name: 'modifier'}
]);
// We doing an update
if (id) {
submitAjaxConfig = {
ID: id,
SOAPFunction: 'updateWiSPUser',
SOAPParams:
'0:ID,'+
'0:Username,'+
'0:Password,'+
'0:Firstname,'+
'0:Lastname,'+
'0:Phone,'+
'0:Email,'+
'0:MACAddress,'+
'0:IPAddress,'+
'0:Datalimit,'+
'0:Uptimelimit'
};
// We doing an Add
} else {
submitAjaxConfig = {
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
params: {
SOAPFunction: 'createWiSPUser',
SOAPParams:
'0:Username,'+
'0:Password,'+
'0:Firstname,'+
'0:Lastname,'+
'0:Phone,'+
'0:Email,'+
'0:Attributes'
},
hook: function() {
// Get modified records
var attributes = attributeStore.getModifiedRecords();
var ret = { };
// Loop and add to our hash
for(var i = 0, len = attributes.length; i < len; i++){
var attribute = attributes[i];
ret['Attributes['+i+'][Name]'] = attribute.get('name');
ret['Attributes['+i+'][Operator]'] = attribute.get('operator');
ret['Attributes['+i+'][Value]'] = attribute.get('value');
ret['Attributes['+i+'][Modifier]'] = attribute.get('modifier');
}
return ret;
}
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
// Build the attribute editor grid
var attributeEditor = new Ext.grid.EditorGridPanel({
plain: true,
height: 150,
autoScroll: true,
// Set row selection model
selModel: new Ext.grid.RowSelectionModel({
singleSelect: true
}),
// Inline toolbars
tbar: [
{
text:'Add',
tooltip:'Add attribute',
iconCls:'add',
handler: function() {
var newAttrStoreRecord = new attributeRecord({
name: '',
operator: '',
value: '',
modifier: ''
});
attributeStore.insert(0,newAttrStoreRecord);
}
},
'-',
{
text:'Remove',
tooltip:'Remove attribute',
iconCls:'remove',
handler: function() {
var selectedItem = attributeEditor.getSelectionModel().getSelected();
// Check if we have selected item
if (selectedItem) {
// If so remove
attributeStore.remove(selectedItem);
} else {
wispUserFormWindow.getEl().mask();
// Display error
Ext.Msg.show({
title: "Nothing selected",
msg: "No attribute selected",
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.CANCEL,
modal: false,
fn: function() {
wispUserFormWindow.getEl().unmask();
}
});
}
}
},
],
cm: new Ext.grid.ColumnModel([
{
id: 'name',
header: 'Name',
dataIndex: 'name',
width: 150,
editor: new Ext.form.ComboBox({
allowBlank: false,
mode: 'local',
store: [
[ 'SMRadius-Capping-Traffic-Limit', 'Traffic Limit' ],
[ 'SMRadius-Capping-Uptime-Limit', 'Uptime Limit' ],
[ 'Framed-IP-Address', 'IP Address' ],
[ 'Calling-Station-Id', 'MAC Address' ]
],
triggerAction: 'all',
editable: false,
})
},
{
id: 'operator',
header: 'Operator',
dataIndex: 'operator',
width: 300,
editor: new Ext.form.ComboBox({
allowBlank: false,
mode: 'local',
store: [
[ '=', 'Add as reply if unique' ],
[ ':=', 'Set configuration value' ],
[ '==', 'Match value in request' ],
[ '+=', 'Add reply and set configuration' ],
[ '!=', 'Inverse match value in request' ],
[ '<', 'Match less-than value in request' ],
[ '>', 'Match greater-than value in request' ],
[ '<=', 'Match less-than or equal value in request' ],
[ '>=', 'Match greater-than or equal value in request' ],
[ '=~', 'Match string containing regex in request' ],
[ '!~', 'Match string not containing regex in request' ],
[ '=*', 'Match if attribute is defined in request' ],
[ '!*', 'Match if attribute is not defined in request' ],
[ '||==', 'Match any of these values in request' ]
],
triggerAction: 'all',
editable: true,
})
},
{
id: 'value',
header: 'Value',
dataIndex: 'value',
width: 100,
editor: new Ext.form.TextField({
allowBlank: false,
})
},
{
id: 'modifier',
header: 'Modifier',
dataIndex: 'modifier',
width: 80,
editor: new Ext.form.ComboBox({
allowBlank: false,
mode: 'local',
store: [
[ 'Seconds', 'Seconds' ],
[ 'Minutes', 'Minutes' ],
[ 'Hours', 'Hours' ],
[ 'Days', 'Days' ],
[ 'Weeks', 'Weeks' ],
[ 'Months', 'Months' ],
[ 'MBytes', 'MBytes' ],
[ 'GBytes', 'GBytes' ],
[ 'TBytes', 'TBytes' ],
],
triggerAction: 'all',
editable: true,
})
},
]),
store: attributeStore
});
// Create window
var wispUserFormWindow = new Ext.ux.GenericFormWindow(
// Window config
{
title: "User Information",
width: 700,
height: 392,
minWidth: 700,
minHeight: 392
},
// Form panel config
{
labelWidth: 85,
baseParams: {
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'WiSPUsers'
},
items: [
{
fieldLabel: 'Username',
name: 'Username',
vtype: 'usernamePart',
maskRe: usernamePartRe,
allowBlank: false,
},
{
fieldLabel: 'Password',
name: 'Password',
vtype: 'usernamePart',
maskRe: usernamePartRe,
allowBlank: false,
},
{
xtype: 'tabpanel',
plain: 'true',
deferredRender: false, // Load all panels!
activeTab: 0,
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
defaults: {
layout: 'form',
bodyStyle: 'padding: 10px;'
},
items: [
{
title: 'Personal',
layout: 'form',
defaultType: 'textfield',
items: [
{
fieldLabel: 'First Name',
name: 'Firstname',
vtype: 'usernamePart',
allowBlank: true
},
{
fieldLabel: 'Last Name',
name: 'Lastname',
vtype: 'usernamePart',
allowBlank: true
},
{
fieldLabel: 'Phone',
name: 'Phone',
vtype: 'number',
allowBlank: true
},
{
fieldLabel: 'Email',
name: 'Email',
allowBlank: true
}
]
},
{
title: 'Attributes',
layout: 'form',
defaultType: 'textfield',
items: [
attributeEditor
],
},
// Submit button config
submitAjaxConfig
);
wispUserFormWindow.show();
if (id) {
wispUserFormWindow.getComponent('formpanel').load({
params: {
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'WiSPUsers',
SOAPFunction: 'getWiSPUser',
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
}
});
}
}
// Display edit/add form
function showWiSPUserRemoveWindow(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 user?",
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: {
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'WiSPUsers',
SOAPFunction: 'removeWiSPUser',