//
var um_user_list_store = new Ext.data.JsonStore({
root: 'users',
totalProperty: 'totalCount',
idProperty: 'id',
remoteSort: true,
fields: [{
name: 'id',
type: 'int'
},{
name: 'status',
type: 'string'
},{
name: 'login',
type: 'string'
},{
name: 'created',
type: 'string'
},{
name: 'last',
type: 'string'
},{
name: 'access',
type: 'int'
},{
name: 'lang',
type: 'int'
},{
name: 'site',
type: 'int'
}],
proxy : new Ext.data.HttpProxy({
method: 'POST',
prettyUrls: false,
url: '/lib/controller/listUsers.php',
headers: {
UID: =$UserID;?>,
SID: '=$Session;?>'
}
})
});
var um_selected_user_id = 0;
var um_user_locked = false;
var um_add_user_window = null;
var um_edit_user_window = null;
function um_user_access_renderer( val ){
if( val == 0 ){
return '=$Labels->GetLabel("_GUEST_");?>';
} else {
if( val < 6 ){
return '=$Labels->GetLabel("_REGULAR_");?>';
} else {
if( val == 10 ){
return '=$Labels->GetLabel("_FOUNDER_");?>';
} else {
return '=$Labels->GetLabel("_ADMIN_");?>';
};
};
};
};
function um_user_status_renderer( val ){
switch( val ){
case 'D': return '
';
case 'A': return '
';
};
return '
';
};
var um_user_list_col_model_opt = {
columns: [
{header: "id", width: 50, sortable: false, menuDisabled: true, align: 'center', fixed: true, css: 'vertical-align: middle;', dataIndex: 'id' },
{header: "=$Labels->GetLabel("_STATUS_");?>", width: 80, sortable: false, renderer: um_user_status_renderer, fixed: true, menuDisabled: true, align: 'center', css: 'vertical-align: middle;', dataIndex: 'status' },
{header: "=$Labels->GetLabel("_LOGIN_");?>", width: 80, sortable: false, fixed: true, menuDisabled: true, /*renderer: camCapRenderer,*/ dataIndex: 'login' },
{header: "=$Labels->GetLabel("_CREATED_");?>", width: 150, sortable: false, renderer: unix_ts_renderer, menuDisabled: true, align: 'left', css: 'vertical-align: middle;', dataIndex: 'created' },
{header: "=$Labels->GetLabel("_LAST_ACCESS_");?>", width: 150, sortable: false, renderer: unix_ts_renderer, fixed: true, menuDisabled: true, align: 'left', css: 'vertical-align: middle;', dataIndex: 'last' },
{header: "=$Labels->GetLabel("_TYPE_");?>", width: 100, sortable: false, renderer: um_user_access_renderer, dataIndex: 'access' },
{header: "=$Labels->GetLabel("_INFO_");?>", width: 200, sortable: false, dataindex: 'data' }
],
defaults: {
sortable: true,
menuDisabled: true,
width: 100
},
listeners: {
hiddenchange: function(cm, colIndex, hidden) {
//saveConfig(colIndex, hidden);
}
}
};
var um_user_list_sel_model_opt = {
singleSelect: true,
listeners: {
rowselect: function( sm, row, rec ) {
um_selected_user_id = rec.data.id;
if ( rec.data.status == 'A' ){
Ext.getCmp('um_lock_user_btn').setText("=$Labels->GetLabel("_LOCK_USER_");?>");
um_user_locked = false;
} else {
Ext.getCmp('um_lock_user_btn').setText("=$Labels->GetLabel("_UNLOCK_USER_");?>");
um_user_locked = true;
};
if( um_selected_user_id == 1 || rec.data.access == 10 ){
Ext.getCmp('um_del_user_btn').disable();
Ext.getCmp('um_lock_user_btn').disable();
} else {
Ext.getCmp('um_del_user_btn').enable();
Ext.getCmp('um_lock_user_btn').enable();
};
if( um_selected_user_id == 1 ){
Ext.getCmp('um_edit_user_btn').disable();
} else {
Ext.getCmp('um_edit_user_btn').enable();
};
}
}
};
function addNewUser(){
if( um_add_user_window == null ){
um_add_user_window = new Ext.Window({
modal: true,
title: "=$Labels->GetLabel("_EDIT_USER_CRACCES_");?>",
width: 400,
height: 250,
layout: 'fit',
closeAction: 'hide',
listeners:{
beforehide : function(){
//Ext.getCmp('connectstarterbutton').toggle( false, false );
}
},
items:[{
layout: 'table',
border: false,
defaults: {
// applied to each contained panel
bodyStyle:'padding-top:10px;padding-left:20px;padding-right:20px;padding-bottom:10px;'
},
layoutConfig: {
// The total column count must be specified here
columns: 2
},
items: [{
border: false,
html: "=$Labels->GetLabel("_USER_LOGIN_");?>:"
},{
xtype: 'textfield',
id: 'um_ua_login',
width: 200
},{
border: false,
html: "=$Labels->GetLabel("_NEW_PASSWORD_");?>:"
},{
xtype: 'textfield',
id: 'um_ua_pwd1',
inputType: 'password',
width: 200
},{
border: false,
html: "=$Labels->GetLabel("_REP_PASSWORD_");?>:"
},{
xtype: 'textfield',
id: 'um_ua_pwd2',
inputType: 'password',
width: 200
},{
border: false,
html: "=$Labels->GetLabel("_ACCESS_LEVEL_");?>:"
},{
xtype: 'combo',
id: 'um_ua_access',
editable: false,
typeAhead: true,
triggerAction: 'all',
width: 200,
lazyRender:true,
mode: 'local',
value: 2,
store: new Ext.data.ArrayStore({
id: 0,
fields: ['acc_lvl', 'displayText' ],
data: [[2,"=$Labels->GetLabel("_ACCESS_MINIMAL_");?>"],[4,"=$Labels->GetLabel("_ACCESS_OPERATOR_");?>"],[6,"=$Labels->GetLabel("_ACCESS_ADMIN_");?>"]]
}),
valueField: 'acc_lvl',
displayField: 'displayText'
}]
}],
bbar: [ '->',{
text: "=$Labels->GetLabel("_CANCEL_");?>",
handler: function(){
um_add_user_window.hide();
}
},{
text: "=$Labels->GetLabel("_SAVE_");?>",
handler: function(){
var lo = Ext.getCmp('um_ua_login').getValue();
var pwd = Ext.getCmp('um_ua_pwd1').getValue();
var rwd = Ext.getCmp('um_ua_pwd2').getValue();
var acc = Ext.getCmp('um_ua_access').getValue();
var sbt = true;
if( acc > my_access ){
sbt = false;
Ext.Msg.show({
title: "=$Labels->GetLabel("_ERROR_MSG_");?>",
msg: "You Can not add more privileged user!",
buttons: Ext.Msg.OK,
icon: Ext.MessageBox.ERROR //QUESTION
});
};
if( sbt && pwd!=''){
if( pwd != rwd ){
sbt = false;
Ext.Msg.show({
title: "=$Labels->GetLabel("_ERROR_MSG_");?>",
msg: "Passwords don\'t match!",
buttons: Ext.Msg.OK,
icon: Ext.MessageBox.ERROR //QUESTION
});
};
} else {
sbt = false;
Ext.Msg.show({
title: "=$Labels->GetLabel("_ERROR_MSG_");?>",
msg: "You Can not Add User Without Password!",
buttons: Ext.Msg.OK,
icon: Ext.MessageBox.ERROR //QUESTION
});
};
if( sbt && lo == '' ){
sbt = false;
Ext.Msg.show({
title: "=$Labels->GetLabel("_ERROR_MSG_");?>",
msg: "You Can not Add User Without Login!",
buttons: Ext.Msg.OK,
icon: Ext.MessageBox.ERROR //QUESTION
});
};
if( sbt ){
Ext.Ajax.request({
url: '/lib/controller/updateUser.php',
params: {
OP: 0,
UID: =$UserID;?>,
SID: '=$Session;?>',
NLO: lo,
PW1: pwd,
PW2: rwd,
ACC: acc
},
success: function( response, opts ){
// If the response is JSON, you have to decode it
var data = Ext.decode(response.responseText);
if( data.success == true ) {
Ext.Msg.show({
title: "=$Labels->GetLabel("_INFO_MSG_");?>",
msg: "=$Labels->GetLabel("_SETTING_SAVE_OK_");?>",
buttons: Ext.Msg.OK,//YESNOCANCEL,
fn: function(){
um_user_list_store.reload();
um_add_user_window.hide();
},
//animEl: 'elId',
icon: Ext.MessageBox.INFO //QUESTION
});
} else {
Ext.Msg.show({
title: "=$Labels->GetLabel("_ERROR_MSG_");?>",
msg: data['error'],
buttons: Ext.Msg.OK,//YESNOCANCEL,
fn: function(){
um_add_user_window.hide();
},
//animEl: 'elId',
icon: Ext.MessageBox.ERROR //QUESTION
});
};
},
failure: failureAJAXFunction
});
};
}
}]
});
};
um_add_user_window.show();
Ext.getCmp('um_ua_login').setValue( '' );
Ext.getCmp('um_ua_pwd1').setValue( '' );
Ext.getCmp('um_ua_pwd2').setValue( '' );
Ext.getCmp('um_ua_access').setValue( 2 );
};
function doUserOperation( op ){
if( um_selected_user_id < 1 ) return;
Ext.Ajax.request({
url: '/lib/controller/updateUser.php',
params: {
OP: op,
UID: =$UserID;?>,
SID: '=$Session;?>',
SUID: um_selected_user_id
},
success: function( response, opts ){
// If the response is JSON, you have to decode it
var data = Ext.decode(response.responseText);
if( data.success == true ) {
Ext.Msg.show({
title: "=$Labels->GetLabel("_INFO_MSG_");?>",
msg: "=$Labels->GetLabel("_SETTING_SAVE_OK_");?>",
buttons: Ext.Msg.OK,//YESNOCANCEL,
fn: function(){
um_user_list_store.reload();
},
//animEl: 'elId',
icon: Ext.MessageBox.INFO //QUESTION
});
} else {
Ext.Msg.show({
title: "=$Labels->GetLabel("_ERROR_MSG_");?>",
msg: data.msg,
buttons: Ext.Msg.OK,//YESNOCANCEL,
//animEl: 'elId',
icon: Ext.MessageBox.ERROR //QUESTION
});
};
},
failure: failureAJAXFunction
});
};
function editSelectedUser(){
if( um_edit_user_window == null ){
um_edit_user_window = new Ext.Window({
modal: true,
title: "=$Labels->GetLabel("_EDIT_USER_CRACCES_");?>",
width: 400,
height: 250,
layout: 'fit',
closeAction: 'hide',
listeners:{
beforehide : function(){
//Ext.getCmp('connectstarterbutton').toggle( false, false );
}
},
items:[{
layout: 'table',
border: false,
defaults: {
// applied to each contained panel
bodyStyle:'padding-top:10px;padding-left:20px;padding-right:20px;padding-bottom:10px;'
},
layoutConfig: {
// The total column count must be specified here
columns: 2
},
items: [{
border: false,
html: "=$Labels->GetLabel("_USER_LOGIN_");?>:"
},{
xtype: 'textfield',
id: 'um_ue_login',
width: 200
},{
border: false,
html: "=$Labels->GetLabel("_NEW_PASSWORD_");?>:"
},{
xtype: 'textfield',
id: 'um_ue_pwd1',
inputType: 'password',
width: 200
},{
border: false,
html: "=$Labels->GetLabel("_REP_PASSWORD_");?>:"
},{
xtype: 'textfield',
id: 'um_ue_pwd2',
inputType: 'password',
width: 200
},{
border: false,
html: "=$Labels->GetLabel("_ACCESS_LEVEL_");?>:"
},{
xtype: 'combo',
id: 'um_ue_access',
editable: false,
typeAhead: true,
triggerAction: 'all',
width: 200,
lazyRender:true,
mode: 'local',
value: 2,
store: new Ext.data.ArrayStore({
id: 0,
fields: ['acc_lvl', 'displayText' ],
data: [[2,"=$Labels->GetLabel("_ACCESS_MINIMAL_");?>"],[4,"=$Labels->GetLabel("_ACCESS_OPERATOR_");?>"],[6,"=$Labels->GetLabel("_ACCESS_ADMIN_");?>"],[10,"=$Labels->GetLabel("_ACCESS_FACTORY_");?>"]]
}),
valueField: 'acc_lvl',
displayField: 'displayText'
}]
}],
bbar: [ '->',{
text: "=$Labels->GetLabel("_CANCEL_");?>",
handler: function(){
um_edit_user_window.hide();
}
},{
text: "=$Labels->GetLabel("_SAVE_");?>",
handler: function(){
var aid = um_user_list_store.find( 'id', um_selected_user_id );
var r = um_user_list_store.getAt( aid );
var lo = Ext.getCmp('um_ue_login').getValue();
var pwd = Ext.getCmp('um_ue_pwd1').getValue();
var rwd = Ext.getCmp('um_ue_pwd2').getValue();
var acc = Ext.getCmp('um_ue_access').getValue();
var olo = r.data.login;
var oacc = r.data.access;
var sbt = true;
if( oacc > my_access ){
sbt = false;
Ext.Msg.show({
title: "=$Labels->GetLabel("_ERROR_MSG_");?>",
msg: "You Can not change settings of more privileged user!",
buttons: Ext.Msg.OK,
icon: Ext.MessageBox.ERROR
});
};
if( sbt && oacc != acc ){
if( acc > my_access ){
sbt = false;
Ext.Msg.show({
title: "=$Labels->GetLabel("_ERROR_MSG_");?>",
msg: "You Can not change access level to more privileged user then you are!",
buttons: Ext.Msg.OK,
icon: Ext.MessageBox.ERROR
});
} else {
if( acc == 10 ){
sbt = false;
Ext.Msg.show({
title: "=$Labels->GetLabel("_ERROR_MSG_");?>",
msg: "You Can not change access level to Factory Defined Master!",
buttons: Ext.Msg.OK,
icon: Ext.MessageBox.ERROR
});
};
};
};
if( sbt && pwd!=''){
if( pwd != rwd ){
sbt = false;
Ext.Msg.show({
title: "=$Labels->GetLabel("_ERROR_MSG_");?>",
msg: "Passwords does not match!",
buttons: Ext.Msg.OK,
icon: Ext.MessageBox.ERROR
});
};
};
if( sbt && olo != lo ){
sbt = false;
Ext.Msg.show({
title: "=$Labels->GetLabel("_QERY_MSG_");?>",
msg: "Are you sure to change Login User Name?",
buttons: Ext.Msg.YESNOCANCEL,
fn: function( a ){
if( a == 'yes' ){
Ext.Ajax.request({
url: '/lib/controller/updateUser.php',
params: {
OP: 1,
SUID: um_selected_user_id,
UID: =$UserID;?>,
SID: '=$Session;?>',
NLO: lo,
OLO: olo,
PW1: pwd,
PW2: rwd,
ACC: acc
},
success: function( response, opts ){
var data = Ext.decode(response.responseText);
if( data.success == true ) {
Ext.Msg.show({
title: "=$Labels->GetLabel("_INFO_MSG_");?>",
msg: "=$Labels->GetLabel("_SETTING_SAVE_OK_");?>",
buttons: Ext.Msg.OK,//YESNOCANCEL,
fn: function(){
um_user_list_store.reload();
um_edit_user_window.hide();
},
//animEl: 'elId',
icon: Ext.MessageBox.INFO //QUESTION
});
} else {
Ext.Msg.show({
title: "=$Labels->GetLabel("_ERROR_MSG_");?>",
msg: data['error'],
buttons: Ext.Msg.OK,//YESNOCANCEL,
fn: function(){
um_edit_user_window.hide();
},
//animEl: 'elId',
icon: Ext.MessageBox.ERROR //QUESTION
});
};
},
failure: failureAJAXFunction
});
};
},
icon: Ext.MessageBox.QUESTION
});
};
if( sbt ){
Ext.Ajax.request({
url: '/lib/controller/updateUser.php',
params: {
OP: 1,
SUID: um_selected_user_id,
UID: =$UserID;?>,
SID: '=$Session;?>',
NLO: lo,
OLO: olo,
PW1: pwd,
PW2: rwd,
ACC: acc
},
success: function( response, opts ){
// If the response is JSON, you have to decode it
var data = Ext.decode(response.responseText);
if( data.success == true ) {
Ext.Msg.show({
title: "=$Labels->GetLabel("_INFO_MSG_");?>",
msg: "=$Labels->GetLabel("_SETTING_SAVE_OK_");?>",
buttons: Ext.Msg.OK,//YESNOCANCEL,
fn: function(){
//SettingsLidar3D.hide();
um_user_list_store.reload();
um_edit_user_window.hide();
},
//animEl: 'elId',
icon: Ext.MessageBox.INFO //QUESTION
});
} else {
Ext.Msg.show({
title: "=$Labels->GetLabel("_ERROR_MSG_");?>",
msg: data['error'],
buttons: Ext.Msg.OK,//YESNOCANCEL,
fn: function(){
um_edit_user_window.hide();
},
//animEl: 'elId',
icon: Ext.MessageBox.ERROR //QUESTION
});
};
},
failure: failureAJAXFunction
});
};
}
}]
});
};
um_edit_user_window.show();
var aid = um_user_list_store.find( 'id', um_selected_user_id );
var r = um_user_list_store.getAt( aid );
Ext.getCmp('um_ue_login').setValue( r.data.login );
Ext.getCmp('um_ue_access').setValue( r.data.access );
if( r.data.access == 10 ){
Ext.getCmp('um_ue_access').disable();
} else {
Ext.getCmp('um_ue_access').enable();
};
};
function loadUserEditor(){
if( tlInterval!= null ){
window.clearInterval( tlInterval );
tlInterval = null;
timelineObj = null;
};
var tPanel = Ext.getCmp('main_content');
tPanel.removeAll( true );
Ext.getCmp('main_content').setTitle( "=$Labels->GetLabel("_USERS_MNGMT_");?>" );
tPanel.add({
columnWidth: 1.0,
frame: false,
border: false,
items: [{
xtype: 'panel',
layout: 'fit',
layoutConfig: {
align : 'stretch',
pack : 'start'
},
height: PanelH-5,
flex: 1,
frame: false,
border: false,
items:{
frame: false,
height: PanelH-5,
xtype: 'grid',
ds: um_user_list_store,
cm: new Ext.grid.ColumnModel( um_user_list_col_model_opt ),
sm: new Ext.grid.RowSelectionModel( um_user_list_sel_model_opt )
},
tbar: [{
xtype: 'button',
id: 'um_add_user_btn',
text: "=$Labels->GetLabel("_ADD_USER_");?>",
handler: addNewUser
},{
xtype: 'button',
id: 'um_edit_user_btn',
text: "=$Labels->GetLabel("_EDIT_USER_");?>",
disabled: true,
handler: editSelectedUser
},{
xtype: 'button',
id: 'um_lock_user_btn',
text: "=$Labels->GetLabel("_LOCK_USER_");?>",
disabled: true,
handler: function(){
if( um_user_locked ){
doUserOperation( 3 );
} else {
doUserOperation( 2 );
};
}
},{
xtype: 'button',
id: 'um_del_user_btn',
text: "=$Labels->GetLabel("_DEL_USER_");?>",
disabled: true,
handler: function(){
doUserOperation( 4 );
}
}]
}]
});
tPanel.doLayout();
um_selected_user_id = 0;
um_user_list_store.reload();
};