Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Capturing User details for re-using throughout a Sencha app
Ext.Ajax.request({
url: 'userEndpointUrl',
failure: function(data, operation) {
console.log('failure while trying to fetch roles for user..');
console.log(operation);
},
success: function(data, operation) {
console.log('success fetching roles....');
var response = Ext.JSON.decode(data.responseText);
// initialize User in the app
User.initUser(response.userName, response.rights);
}
});
onMenuPanelRenderer : function() {
var hasWebRole = User.hasRole(Config.role.web);
var hasAdminRole = User.hasRole(Config.role.admin);
if (hasWebRole) {
// set mentu item visible true based on role
}
if (hasAdminRole) {
// set mentu item visible true based on role
}
}
Ext.define('AppName.app.User', {
singleton: true,
alternateClassName: ['User'],
constructor: function(config) {
this.initConfig(config);
},
config: {
username: null,
rights: null
// probably some more details
},
initUser : function(username, rights) {
this.username = username;
this.rights = rights;
return this;
},
getRights: function() {
return this.rights;
},
hasRole: function(role) {
var rights = User.getRights();
for (i = 0; i < rights.length; i++) {
if (rights[i] === role) {
return true;
}
}
return false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment