Skip to content
Snippets Groups Projects
Commit 48b2aaf9 authored by Robert Anderson's avatar Robert Anderson
Browse files

Implemented grid panel for adding wisp user attributes.

parent 8bfcbc95
No related branches found
No related tags found
No related merge requests found
...@@ -170,22 +170,67 @@ function createWiSPUser($params) { ...@@ -170,22 +170,67 @@ function createWiSPUser($params) {
global $db; global $db;
DBBegin(); DBBegin();
# Insert username
$res = DBDo("INSERT INTO users (Username) VALUES (?)",array($params[0]['Username'])); $res = DBDo("INSERT INTO users (Username) VALUES (?)",array($params[0]['Username']));
# Continue with others if successful
if ($res !== FALSE) { if ($res !== FALSE) {
$userID = DBLastInsertID(); $userID = DBLastInsertID();
$res = DBDo("INSERT INTO wisp_userdata (UserID) VALUES (?)",array($userID)); DBDo("
INSERT INTO
user_attributes (UserID,Name,Operator,Value)
VALUES
(?,?,?,?)",
array($userID,
'User-Password',
'==',
$params[0]['Password'])
);
} }
# Link users ID to make user a wisp user
if ($res !== FALSE) {
DBDo("INSERT INTO wisp_userdata (UserID) VALUES (?)",array($userID));
}
# Personal information is optional when adding
if ($res !== FALSE && isset($params[0]['Firstname'])) {
$res = DBDo("UPDATE wisp_userdata SET FirstName = ? WHERE UserID = ?",array($params[0]['Firstname'],$userID));
}
if ($res !== FALSE && isset($params[0]['Lastname'])) {
$res = DBDo("UPDATE wisp_userdata SET LastName = ? WHERE UserID = ?",array($params[0]['Lastname'],$userID));
}
if ($res !== FALSE && isset($params[0]['Phone'])) {
$res = DBDo("UPDATE wisp_userdata SET Phone = ? WHERE UserID = ?",array($params[0]['Phone'],$userID));
}
if ($res !== FALSE && isset($params[0]['Email'])) {
$res = DBDo("UPDATE wisp_userdata SET Email = ? WHERE UserID = ?",array($params[0]['Email'],$userID));
}
# Grab each attribute and add it's details to the database
if ($res !== FALSE) {
foreach ($params[0]['Attributes'] as $attr) {
$res = DBDo("
INSERT INTO
user_attributes (UserID,Name,Operator,Value)
VALUES
(?,?,?,?)",
array(
$userID,
$attr['Name'],
$attr['Operator'],
$attr['Value'])
);
}
}
# Commit changes if all was successful, else break
if ($res !== FALSE) { if ($res !== FALSE) {
DBCommit(); DBCommit();
return $res; return $res;
} else { } else {
DBRollback(); DBRollback();
} }
# if (!is_numeric($res)) {
# return $res;
# }
return NULL; return NULL;
} }
......
...@@ -77,9 +77,24 @@ Ext.ux.GenericFormWindow = function(windowConfig,formConfig,submitAjaxConfig) { ...@@ -77,9 +77,24 @@ Ext.ux.GenericFormWindow = function(windowConfig,formConfig,submitAjaxConfig) {
var panel = this.ownerCt; var panel = this.ownerCt;
var win = panel.ownerCt; var win = panel.ownerCt;
var ajaxParams;
if (submitAjaxConfig.params) {
ajaxParams = submitAjaxConfig.params;
if (submitAjaxConfig.hook) {
var extraParams = submitAjaxConfig.hook();
}
ajaxParams = Ext.apply(ajaxParams,extraParams);
} else {
ajaxParams = submitAjaxConfig;
}
// Submit panel // Submit panel
panel.submit({ panel.submit({
params: submitAjaxConfig, params: ajaxParams,
// Close window on success // Close window on success
success: function() { success: function() {
win.close(); win.close();
......
...@@ -22,7 +22,7 @@ function showWiSPUserWindow() { ...@@ -22,7 +22,7 @@ function showWiSPUserWindow() {
tooltip:'Add user', tooltip:'Add user',
iconCls:'add', iconCls:'add',
handler: function() { handler: function() {
showWiSPUserEditWindow(); showWiSPUserAddEditWindow();
} }
}, },
'-', '-',
...@@ -35,7 +35,7 @@ function showWiSPUserWindow() { ...@@ -35,7 +35,7 @@ function showWiSPUserWindow() {
// Check if we have selected item // Check if we have selected item
if (selectedItem) { if (selectedItem) {
// If so display window // If so display window
showWiSPUserEditWindow(selectedItem.data.ID); showWiSPUserAddEditWindow(selectedItem.data.ID);
} else { } else {
WiSPUserWindow.getEl().mask(); WiSPUserWindow.getEl().mask();
...@@ -181,12 +181,27 @@ function showWiSPUserWindow() { ...@@ -181,12 +181,27 @@ function showWiSPUserWindow() {
// Display edit/add form // Display edit/add form
function showWiSPUserEditWindow(id) { function showWiSPUserAddEditWindow(id) {
var submitAjaxConfig; var submitAjaxConfig;
var editMode; 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 // We doing an update
if (id) { if (id) {
submitAjaxConfig = { submitAjaxConfig = {
...@@ -209,32 +224,192 @@ function showWiSPUserEditWindow(id) { ...@@ -209,32 +224,192 @@ function showWiSPUserEditWindow(id) {
// We doing an Add // We doing an Add
} else { } else {
submitAjaxConfig = { submitAjaxConfig = {
SOAPFunction: 'createWiSPUser', params: {
SOAPParams: SOAPFunction: 'createWiSPUser',
'0:Username,'+ SOAPParams:
'0:Password,'+ '0:Username,'+
'0:Firstname,'+ '0:Password,'+
'0:Lastname,'+ '0:Firstname,'+
'0:Phone,'+ '0:Lastname,'+
'0:Email,'+ '0:Phone,'+
'0:MACAddress,'+ '0:Email,'+
'0:IPAddress,'+ '0:Attributes'
'0:Datalimit,'+ },
'0:Uptimelimit'
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;
}
}; };
} }
// 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 // Create window
var wispUserFormWindow = new Ext.ux.GenericFormWindow( var wispUserFormWindow = new Ext.ux.GenericFormWindow(
// Window config // Window config
{ {
title: "User Information", title: "User Information",
width: 475, width: 700,
height: 340, height: 392,
minWidth: 475, minWidth: 700,
minHeight: 340 minHeight: 392
}, },
// Form panel config // Form panel config
{ {
...@@ -265,7 +440,7 @@ function showWiSPUserEditWindow(id) { ...@@ -265,7 +440,7 @@ function showWiSPUserEditWindow(id) {
plain: 'true', plain: 'true',
deferredRender: false, // Load all panels! deferredRender: false, // Load all panels!
activeTab: 0, activeTab: 0,
height: 200, height: 250,
defaults: { defaults: {
layout: 'form', layout: 'form',
bodyStyle: 'padding: 10px;' bodyStyle: 'padding: 10px;'
...@@ -307,132 +482,7 @@ function showWiSPUserEditWindow(id) { ...@@ -307,132 +482,7 @@ function showWiSPUserEditWindow(id) {
layout: 'form', layout: 'form',
defaultType: 'textfield', defaultType: 'textfield',
items: [ items: [
{ attributeEditor
xtype: 'combo',
//id: 'combo',
fieldLabel: 'Name',
name: 'Name',
allowBlank: false,
width: 160,
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: 'getWiSPUserAttributeNames',
SOAPParams: '__null,__search'
}
}),
displayField: 'Name',
valueField: 'Name',
hiddenName: 'Name',
forceSelection: true,
triggerAction: 'all',
editable: false
},
{
xtype: 'combo',
//id: 'combo',
fieldLabel: 'Value',
name: 'Value',
allowBlank: false,
width: 160,
store: new Ext.ux.JsonStore({
sortInfo: { field: "Value", direction: "ASC" },
baseParams: {
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'WiSPUsers',
SOAPFunction: 'getWiSPUserAttributeValues',
SOAPParams: '__null,__search'
}
}),
displayField: 'Value',
valueField: 'Value',
hiddenName: 'Value',
forceSelection: true,
triggerAction: 'all',
editable: false
},
/*{
xtype: 'combo',
//id: 'combo',
fieldLabel: 'Group',
name: 'Group',
allowBlank: true,
width: 140,
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',
hiddenName: 'GroupID',
forceSelection: false,
triggerAction: 'all',
editable: false
},*/
/*{
xtype: 'combo',
//id: 'combo',
fieldLabel: 'Location',
name: 'Location',
allowBlank: true,
width: 160,
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: 'getWiSPLocations',
SOAPParams: '__null,__search'
}
}),
displayField: 'Name',
valueField: 'ID',
hiddenName: 'LocationID',
forceSelection: false,
triggerAction: 'all',
editable: false
},*/
/*{
fieldLabel: 'MAC Address',
name: 'MACAddress',
allowBlank: true
},
{
fieldLabel: 'IP Address',
name: 'IPAddress',
allowBlank: true
},
{
fieldLabel: 'Data Limit',
name: 'Datalimit',
vtype: 'number',
allowBlank: true
},
{
fieldLabel: 'Uptime Limit',
name: 'Uptimelimit',
vtype: 'number',
allowBlank: true
}*/
] ]
}, },
] ]
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment