From 6d5a967d8a2aaa2183d344734e82473b722d9ae6 Mon Sep 17 00:00:00 2001 From: Justin Richer Date: Sun, 25 May 2014 07:58:25 -0400 Subject: [PATCH] fixed client editor lazy loading --- .../src/main/webapp/resources/js/admin.js | 87 ++++++++++++++----- .../src/main/webapp/resources/js/client.js | 20 +++++ 2 files changed, 83 insertions(+), 24 deletions(-) diff --git a/openid-connect-server-webapp/src/main/webapp/resources/js/admin.js b/openid-connect-server-webapp/src/main/webapp/resources/js/admin.js index 2246eea6a..ae819d617 100644 --- a/openid-connect-server-webapp/src/main/webapp/resources/js/admin.js +++ b/openid-connect-server-webapp/src/main/webapp/resources/js/admin.js @@ -523,16 +523,16 @@ var AppRouter = Backbone.Router.extend({ displayClientSecret:false, requireAuthTime:true, defaultMaxAge:60000, - scope: _.uniq(_.flatten(this.systemScopeList.defaultScopes().pluck("value"))), + scope: _.uniq(_.flatten(app.systemScopeList.defaultScopes().pluck("value"))), accessTokenValiditySeconds:3600, idTokenValiditySeconds:600, grantTypes: ["authorization_code"], responseTypes: ["code"], - subjectType: "public" + subjectType: "PUBLIC" }, { silent: true }); - $('#content').html(this.clientFormView.render().el); + $('#content').html(app.clientFormView.render().el); setPageTitle("New Client"); }); }, @@ -551,29 +551,68 @@ var AppRouter = Backbone.Router.extend({ {text:"Edit", href:"manage/#admin/client/" + id} ]); + // TODO: this won't load on its own anymore, need to dynamically load the client in question first (don't need to load the rest) + var client = this.clientList.get(id); + + if (client == null) { + // it wasn't in the list, try loading the client directly + client = new ClientModel({id: id}); + } + + $('#loadingbox').sheet('show'); + $('#loading').html('Scopes ' + + 'Client '); + + // re-sync the client every time + client.fetch({ + success: function(client, response, options) { + $('#loading-client').addClass('label-success'); + + if (client.get("clientSecret") == null) { + client.set({ + requireClientSecret:false + }, { silent: true }); + } + + if ($.inArray("refresh_token", client.get("grantTypes")) != -1) { + client.set({ + allowRefresh: true + }, { silent: true }); + } + + client.set({ + generateClientSecret:false, + displayClientSecret:false + }, { silent: true }); + + app.clientFormView = new ClientFormView({model:client, systemScopeList: app.systemScopeList}); + app.clientFormView.load(function() { + console.log("yup!"); + $('#content').html(app.clientFormView.render().el); + setPageTitle("Edit Client"); + }); + + + }, + error: function(model, response, options) { + + //Pull out the response text. + var responseJson = JSON.parse(response.responseText); + + //Display an alert with an error message + $('#modalAlert div.modal-header').html(responseJson.error); + $('#modalAlert div.modal-body').html(responseJson.error_description); + + $("#modalAlert").modal({ // wire up the actual modal functionality and show the dialog + "backdrop" : "static", + "keyboard" : true, + "show" : true // ensure the modal is shown immediately + }); + + } + }); - if (client.get("clientSecret") == null) { - client.set({ - requireClientSecret:false - }, { silent: true }); - } - - if ($.inArray("refresh_token", client.get("grantTypes")) != -1) { - client.set({ - allowRefresh: true - }, { silent: true }); - } - - client.set({ - generateClientSecret:false, - displayClientSecret:false - }, { silent: true }); - - this.clientFormView = new ClientFormView({model:client, systemScopeList: this.systemScopeList}); - $('#content').html(this.clientFormView.render().el); - - setPageTitle("Edit Client"); }, whiteList:function () { diff --git a/openid-connect-server-webapp/src/main/webapp/resources/js/client.js b/openid-connect-server-webapp/src/main/webapp/resources/js/client.js index 10e58adda..829ecf4b4 100644 --- a/openid-connect-server-webapp/src/main/webapp/resources/js/client.js +++ b/openid-connect-server-webapp/src/main/webapp/resources/js/client.js @@ -496,6 +496,26 @@ var ClientFormView = Backbone.View.extend({ "change #logoUri input":"previewLogo" }, + load:function(callback) { + if (this.options.systemScopeList.isFetched) { + $('#loadingbox').sheet('hide'); + callback(); + return; + } + + if (this.model.get('id') == null) { + // only show the box if this is a new client, otherwise the box is already showing + $('#loadingbox').sheet('show'); + $('#loading').html('Scopes '); + } + + $.when(this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}})) + .done(function() { + $('#loadingbox').sheet('hide'); + callback(); + }); + }, + toggleRefreshTokenTimeout:function () { $("#refreshTokenValidityTime", this.$el).toggle(); },