Newer
Older
/*
WiSP Users
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 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);
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
} 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();
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// 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:'Topups',
tooltip:'User topups',
iconCls:'logs',
handler: function() {
var selectedItem = WiSPUserWindow.getComponent('gridpanel').getSelectionModel().getSelected();
// Check if we have selected item
if (selectedItem) {
// If so display window
showWiSPUserTopupsWindow(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'}
]);
// Group store
var groupStore;
groupStore = new Ext.data.SimpleStore({
fields: [
'name'
],
});
// Group record that can be added to above store
var groupRecord = Ext.data.Record.create([
{name: 'name'}
]);
// 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:LocationID,'+
};
// We doing an Add
} else {
submitAjaxConfig = {
params: {
SOAPFunction: 'createWiSPUser',
SOAPParams:
'0:Username,'+
'0:Password,'+
'0:Firstname,'+
'0:Lastname,'+
'0:Phone,'+
'0:Email,'+
'0:Attributes,'+
},
hook: function() {
// Get modified attribute records
var attributes = attributeStore.getModifiedRecords();
// Get modified group records
var groups = groupStore.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');
}
// Loop and add to our hash
for(var i = 0, len = groups.length; i < len; i++){
var group = groups[i];
ret['Groups['+i+'][Name]'] = group.get('name');
}
return ret;
}
// Build the attribute editor grid
var attributeEditor = new Ext.grid.EditorGridPanel({
plain: true,
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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
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
});
// Build the group editor grid
var groupEditor = new Ext.grid.EditorGridPanel({
plain: true,
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
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
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
autoScroll: true,
// Set row selection model
selModel: new Ext.grid.RowSelectionModel({
singleSelect: true
}),
// Inline toolbars
tbar: [
{
text:'Add',
tooltip:'Add group',
iconCls:'add',
handler: function() {
var newGroupStoreRecord = new groupRecord({
name: ''
});
groupStore.insert(0,newGroupStoreRecord);
}
},
'-',
{
text:'Remove',
tooltip:'Remove group',
iconCls:'remove',
handler: function() {
var selectedItem = groupEditor.getSelectionModel().getSelected();
// Check if we have selected item
if (selectedItem) {
// If so remove
groupStore.remove(selectedItem);
} else {
wispUserFormWindow.getEl().mask();
// Display error
Ext.Msg.show({
title: "Nothing selected",
msg: "No group 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,
store: new Ext.ux.JsonStore({
sortInfo: { field: "Name", direction: "ASC" },
baseParams: {
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'AdminUserGroups',
SOAPFunction: 'getAdminGroups',
SOAPParams: '__null,__search'
}
}),
displayField: 'Name',
valueField: 'ID',
forceSelection: true,
triggerAction: 'all',
editable: false
})
},
]),
store: groupStore
});
// Create window
var wispUserFormWindow = new Ext.ux.GenericFormWindow(
// Window config
{
title: "User Information",
minWidth: 700,
},
// 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,
{
fieldLabel: 'Password',
name: 'Password',
vtype: 'usernamePart',
maskRe: usernamePartRe,
},
{
xtype: 'tabpanel',
plain: 'true',
deferredRender: false, // Load all panels!
activeTab: 0,
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
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
},
{
xtype: 'combo',
fieldLabel: 'Location',
name: 'Location',
allowBlank: true,
store: new Ext.ux.JsonStore({
sortInfo: { field: "Name", direction: "ASC" },
baseParams: {
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'WiSPUsers',
SOAPFunction: 'getWiSPLocations',
SOAPParams: '__null,__search'
}
}),
displayField: 'Name',
valueField: 'ID',
hiddenName: 'LocationID',
forceSelection: true,
triggerAction: 'all',
editable: false
},
{
title: 'Groups',
layout: 'form',
defaultType: 'textfield',
items: [
groupEditor
]
},
{
title: 'Attributes',
layout: 'form',
defaultType: 'textfield',
items: [
attributeEditor
{
title: 'Add Many',
layout: 'form',
defaultType: 'textfield',
items: [
{
fieldLabel: 'Prefix',
name: 'Prefix',
allowBlank: true,
},
{
fieldLabel: 'Number',
name: 'Number',
allowBlank: true,
},
]
},
],
},
// 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',
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
}
});
}
}
// 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',
}
});
// Unmask if user answered no
} else {
parent.getEl().unmask();
}
}
});
}