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

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

View File

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

View File

@ -707,4 +707,4 @@ ui.routes.push({path: "dev/dynreg/edit", name: "editDynReg", callback:
}
});
ui.templates.push('resources/template/dynreg.html');
ui.templates.push('resources/template/dynreg.html');

View File

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

View File

@ -504,4 +504,4 @@ ui.routes.push({path: "dev/resource/edit", name: "editResReg", callback:
}
});
ui.templates.push('resources/template/rsreg.html');
ui.templates.push('resources/template/rsreg.html');

View File

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

View File

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

View File

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