From 5c10eef8b79d44dcca3b38b9089d9bc6ad7794c8 Mon Sep 17 00:00:00 2001 From: Justin Richer Date: Thu, 29 Aug 2013 14:18:54 -0400 Subject: [PATCH] added delete function --- .../src/main/webapp/resources/js/dynreg.js | 49 ++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/openid-connect-server/src/main/webapp/resources/js/dynreg.js b/openid-connect-server/src/main/webapp/resources/js/dynreg.js index e725a76f7..810d0db47 100644 --- a/openid-connect-server/src/main/webapp/resources/js/dynreg.js +++ b/openid-connect-server/src/main/webapp/resources/js/dynreg.js @@ -99,15 +99,26 @@ var DynRegRootView = Backbone.View.extend({ console.log(client.get('registration_access_token')); + var self = this; + client.fetch({success: function() { console.log(client); var dynRegEditView = new DynRegEditView({model: client}); $('#content').html(dynRegEditView.render().el); + app.navigate('dev/dynreg/edit', {trigger: true}); + self.remove(); + }, error: function() { + $('#modalAlert div.modal-body').html("Invalid client or registration access token."); + + $("#modalAlert").modal({ // wire up the actual modal functionality and show the dialog + "backdrop" : "static", + "keyboard" : true, + "show" : true // ensure the modal is shown immediately + }); + }}); - app.navigate('dev/dynreg/edit', {trigger: true}); - this.remove(); } }); @@ -131,9 +142,43 @@ var DynRegEditView = Backbone.View.extend({ events:{ "click .btn-save":"saveClient", "click .btn-cancel": function() { window.history.back(); return false; }, + "click .btn-delete":"deleteClient", "change #logoUri input":"previewLogo" }, + deleteClient:function () { + + if (confirm("Are you sure sure you would like to delete this client?")) { + var self = this; + + this.model.destroy({ + success:function () { + self.remove(); + app.navigate('dev/dynreg', {trigger: true}); + }, + error:function (error, response) { + console.log("An error occurred when deleting a client"); + + //Pull out the response text. + var responseJson = JSON.parse(response.responseText); + + //Display an alert with an error message + $('#modalAlert div.modal-body').html(responseJson.errorMessage); + + $("#modalAlert").modal({ // wire up the actual modal functionality and show the dialog + "backdrop" : "static", + "keyboard" : true, + "show" : true // ensure the modal is shown immediately + }); + } + }); + + app.clientListView.delegateEvents(); + } + + return false; + }, + previewLogo:function(event) { if ($('#logoUri input', this.el).val()) { $('#logoPreview', this.el).empty();