Last active
November 16, 2016 06:26
-
-
Save rattanchauhan/fe89ad64f6e9f76adba825af897b4c6f to your computer and use it in GitHub Desktop.
Capturing User details for re-using throughout a Sencha app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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