From 9f979cb7424706c7a31bb2022733231a897c7e14 Mon Sep 17 00:00:00 2001 From: Michael Jett Date: Thu, 3 May 2012 12:57:09 -0400 Subject: [PATCH] Views now load after fetching templates --- .../src/main/webapp/resources/js/app.js | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/openid-connect-server/src/main/webapp/resources/js/app.js b/openid-connect-server/src/main/webapp/resources/js/app.js index bdce97e28..02e7797fe 100644 --- a/openid-connect-server/src/main/webapp/resources/js/app.js +++ b/openid-connect-server/src/main/webapp/resources/js/app.js @@ -1,4 +1,3 @@ -//$(function () { var ClientModel = Backbone.Model.extend({ @@ -29,16 +28,9 @@ initialize:function () { - var self = this; - - if (!($.isFunction(self.template))) { - $.get('resources/template/client.html', function (templates) { - $('body').append(templates); - self.template = _.template($('#tmpl-client').html()); - }); - } - - this.model.bind("change", this.render, this); + this.template = _.template($('#tmpl-client').html()); + this.model.bind('change', this.render, this); + //this.model.on('change', this.render) }, render:function (eventName) { @@ -67,13 +59,23 @@ } }); - var view = new ClientView({ - el:$('#client-table tbody'), - model: new ClientModel() + + $(function () { + + // load templates and append them to the body + + $.get('resources/template/client.html', function (templates) { + $('body').append(templates); + + var view = new ClientView({ + el:$('#client-table tbody'), + model:new ClientModel() + }); + + view.model.set({name:'hello world'}); + }); + + }); - view.model.set({name:'hello world'}); - -//}); -