modularized app router initialization functions

pull/1192/merge
Justin Richer 2017-02-20 14:06:41 -05:00
parent 503d6f5725
commit f2173907ac
10 changed files with 43 additions and 19 deletions

View File

@ -20,8 +20,9 @@
// set up a global variable for UI components to hang extensions off of
var ui = {
templates: ["resources/template/admin.html"],
routes: []
templates: ["resources/template/admin.html"], // template files to load for UI
routes: [], // routes to add to the UI {path: URI to map to, name: unique name for internal use, callback: function to call when route is activated}
init: [] // functions to call after initialization is complete
};
</script>

View File

@ -430,14 +430,7 @@ var AppRouter = Backbone.Router.extend({
initialize:function () {
this.clientList = new ClientCollection();
this.whiteListList = new WhiteListCollection();
this.blackListList = new BlackListCollection();
this.approvedSiteList = new ApprovedSiteCollection();
this.systemScopeList = new SystemScopeCollection();
this.clientStats = new StatsModel();
this.accessTokensList = new AccessTokenCollection();
this.refreshTokensList = new RefreshTokenCollection();
this.breadCrumbView = new BreadCrumbView({
collection:new Backbone.Collection()
@ -447,6 +440,12 @@ var AppRouter = Backbone.Router.extend({
this.errorHandlerView = new ErrorHandlerView();
// call all the extra initialization functions
var app = this;
_.each(ui.init, function(fn) {
fn(app);
});
},
notImplemented:function(){
@ -482,8 +481,7 @@ $(function () {
};
// load templates and append them to the body
$.when.apply(null,
ui.templates.map(loader)
$.when.apply(null, ui.templates.map(loader)
).done(function() {
console.log('done');
$.ajaxSetup({cache:false});

View File

@ -210,3 +210,7 @@ ui.routes.push({path: "admin/blacklist", name: "blackList", callback:
});
ui.templates.push('resources/template/blacklist.html');
ui.init.push(function(app) {
app.blackListList = new BlackListCollection();
});

View File

@ -1324,3 +1324,7 @@ ui.routes.push({path: "admin/client/:id", name: "editClient", callback:
});
ui.templates.push('resources/template/client.html');
ui.init.push(function(app) {
app.clientList = new ClientCollection();
});

View File

@ -280,3 +280,7 @@ ui.routes.push({path: "user/approved", name: "approvedSites", callback:
});
ui.templates.push('resources/template/grant.html');
ui.init.push(function(app) {
app.approvedSiteList = new ApprovedSiteCollection();
});

View File

@ -435,3 +435,7 @@ ui.routes.push({path: "admin/scope/:id", name: "editScope", callback:
});
ui.templates.push('resources/template/scope.html');
ui.init.push(function(app) {
app.systemScopeList = new SystemScopeCollection();
});

View File

@ -502,3 +502,8 @@ ui.routes.push({path: "user/tokens", name: "tokens", callback:
});
ui.templates.push('resources/template/token.html');
ui.init.push(function(app) {
app.accessTokensList = new AccessTokenCollection();
app.refreshTokensList = new RefreshTokenCollection();
});

View File

@ -500,3 +500,7 @@ ui.routes.push({path: "admin/whitelist/:id", name: "editWhitelist", callback:
});
ui.templates.push('resources/template/whitelist.html');
ui.init.push(function(app) {
app.whiteListList = new WhiteListCollection();
});