javascript - How to avoid nested asynchronous callbacks due to Ext Direct and dynamic locale loading? -
javascript - How to avoid nested asynchronous callbacks due to Ext Direct and dynamic locale loading? -
i'm using ext js 4.1 create crm-type application. connect server side, i'm using ext direct via remotingprovider
.
before application launches , renders, want retrieve global variables server via ext direct, configured language of logged in user , configured permissions. then, depending on language of user (from result), need load both ext js locale file , own custom locale file. (note must loaded before component created, because won't applied afterwards.)
so, procedure is:
get globals viaext.php.globals.getglobals
get ext locale via ext.loader.loadscript
, get app locale via ext.loader.loadscript
setup viewport since 1.-3. asynchronous, saw no other way nest callbacks:
ext.application({ name: 'myapp', launch: function() { var app = this; // welcome callback hell... ext.php.globals.getglobals(function(data) { // insert globals app namespace ext.apply(myapp, data); // load ext locale ext.loader.loadscript({ url: 'ext/locale/ext-lang-'+myapp.currentuser.culture.tolowercase()+'.js', onload: function() { // load app locale ext.namespace('myapp.locale'); ext.loader.loadscript({ url: 'app/locale/'+myapp.currentuser.culture.touppercase()+'.js', onload: function() { // finally, set viewport var viewport = ext.create('myapp.view.viewport', { controller: app }); if (myapp.util.haspermission('usermgmt')) app.getcontroller('locations'); // , on ... } }); } }); }); } }); // end application
is there other, more elegant way write code? know there libraries async flow, can of these work ext js api here? or can somehow forcefulness ext.syncrequire
load locales me (so have 1 layer of nesting getglobals
call)? own locales have class defined, ext locales don't. also, somehow mess compiling source files sencha cmd?
your concept bit weird hence have recommendations you. utilize direct in many projects , them had need localization , rather complex ac-managements.
your app should not have need resolve or load before starts. language & localization should provided time main application view loaded your frontend should never resolve access control. can (for situations) accomplish direct api reduce api these actions user have access (this happens when application main view prepared)that create app faster , life easier.
update
the time user login or request mainview should have plenty info supported browser language or @ to the lowest degree when user selects language. knowledge need prepare view.
a acl within frontend not secure , need rechecked @ serverside should hence avoided or simple. simplest way direct provide api matching user access , check within frontend. sort of implicit access control. how implement depends on on ui, there many ways
update 2
why don't provide 1 build per language? don't see reason against it. or split framework application & classes allows update while clients can still utilize cached framework lib.
the api can checked controller (backend) access , method (backend) access. controller may tab , actions menu elements. cause api global available need check if objects or properties exists. let's pretend have backend-controller named car
, method called drive
can check like
if (car) { // has controller access if (car.dirve) { // has access 'drive' action } }
javascript extjs asynchronous extjs4 ext-direct
Comments
Post a Comment