From b4f3039c5a6aad6c47f86e61b7b32bd1520f42aa Mon Sep 17 00:00:00 2001 From: Justin Richer Date: Thu, 13 Nov 2014 14:16:00 -1000 Subject: [PATCH] applied list widget catch to all objects --- .../src/main/webapp/resources/js/client.js | 2 - .../src/main/webapp/resources/js/dynreg.js | 42 +++++++++++++------ .../src/main/webapp/resources/js/rsreg.js | 41 +++++++++++++----- .../src/main/webapp/resources/js/whitelist.js | 15 ++++++- 4 files changed, 73 insertions(+), 27 deletions(-) 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 716e512a2..033c16b09 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 @@ -803,13 +803,11 @@ var ClientFormView = Backbone.View.extend({ $('.control-group').removeClass('error'); - // sync any leftover collection items _.each(this.listWidgetViews, function(v) { v.addItem($.Event('click')); }); - // build the scope object var scopes = this.scopeCollection.pluck("item"); diff --git a/openid-connect-server-webapp/src/main/webapp/resources/js/dynreg.js b/openid-connect-server-webapp/src/main/webapp/resources/js/dynreg.js index ef0cf477a..d7e077506 100644 --- a/openid-connect-server-webapp/src/main/webapp/resources/js/dynreg.js +++ b/openid-connect-server-webapp/src/main/webapp/resources/js/dynreg.js @@ -176,6 +176,8 @@ var DynRegEditView = Backbone.View.extend({ this.contactsCollection = new Backbone.Collection(); this.defaultAcrValuesCollection = new Backbone.Collection(); this.requestUrisCollection = new Backbone.Collection(); + + this.listWidgetViews = []; }, load:function(callback) { @@ -318,6 +320,11 @@ var DynRegEditView = Backbone.View.extend({ $('.control-group').removeClass('error'); + // sync any leftover collection items + _.each(this.listWidgetViews, function(v) { + v.addItem($.Event('click')); + }); + // build the scope object var scopes = this.scopeCollection.pluck("item").join(" "); @@ -434,17 +441,21 @@ var DynRegEditView = Backbone.View.extend({ render:function() { $(this.el).html(this.template({client: this.model.toJSON(), userInfo: getUserInfo()})); - var _self = this; + this.listWidgetViews = []; + + var _self = this; // build and bind registered redirect URI collection and view _.each(this.model.get("redirect_uris"), function (redirectUri) { _self.redirectUrisCollection.add(new URIModel({item:redirectUri})); }); - $("#redirectUris .controls",this.el).html(new ListWidgetView({ + var redirectUriView = new ListWidgetView({ type:'uri', placeholder: 'https://', - collection: this.redirectUrisCollection}).render().el); + collection: this.redirectUrisCollection}); + $("#redirectUris .controls",this.el).html(redirectUriView.render().el); + this.listWidgetViews.push(redirectUriView); // build and bind scopes var scopes = this.model.get("scope"); @@ -453,40 +464,47 @@ var DynRegEditView = Backbone.View.extend({ _self.scopeCollection.add(new Backbone.Model({item:scope})); }); - $("#scope .controls",this.el).html(new ListWidgetView({ + var scopeView = new ListWidgetView({ placeholder: 'new scope', autocomplete: _.uniq(_.flatten(this.options.systemScopeList.pluck("value"))), - collection: this.scopeCollection}).render().el); + collection: this.scopeCollection}); + $("#scope .controls",this.el).html(scopeView.render().el); + this.listWidgetViews.push(scopeView); // build and bind contacts _.each(this.model.get('contacts'), function (contact) { _self.contactsCollection.add(new Backbone.Model({item:contact})); }); - $("#contacts .controls div", this.el).html(new ListWidgetView({ + var contactView = new ListWidgetView({ placeholder: 'new contact', - collection: this.contactsCollection}).render().el); - + collection: this.contactsCollection}); + $("#contacts .controls div", this.el).html(contactView.render().el); + this.listWidgetViews.push(contactView); // build and bind request URIs _.each(this.model.get('request_uris'), function (requestUri) { _self.requestUrisCollection.add(new URIModel({item:requestUri})); }); - $('#requestUris .controls', this.el).html(new ListWidgetView({ + var requestUriView = new ListWidgetView({ type: 'uri', placeholder: 'https://', - collection: this.requestUrisCollection}).render().el); + collection: this.requestUrisCollection}); + $('#requestUris .controls', this.el).html(requestUriView.render().el); + this.listWidgetViews.push(requestUriView); // build and bind default ACR values _.each(this.model.get('default_acr_values'), function (defaultAcrValue) { _self.defaultAcrValuesCollection.add(new Backbone.Model({item:defaultAcrValue})); }); - $('#defaultAcrValues .controls', this.el).html(new ListWidgetView({ + var defaultAcrView = new ListWidgetView({ placeholder: 'new ACR value', // TODO: autocomplete from spec - collection: this.defaultAcrValuesCollection}).render().el); + collection: this.defaultAcrValuesCollection}); + $('#defaultAcrValues .controls', this.el).html(defaultAcrView.render().el); + this.listWidgetViews.push(defaultAcrView); this.toggleClientCredentials(); this.previewLogo(); diff --git a/openid-connect-server-webapp/src/main/webapp/resources/js/rsreg.js b/openid-connect-server-webapp/src/main/webapp/resources/js/rsreg.js index 3b99609e8..5a8f85f87 100644 --- a/openid-connect-server-webapp/src/main/webapp/resources/js/rsreg.js +++ b/openid-connect-server-webapp/src/main/webapp/resources/js/rsreg.js @@ -142,6 +142,8 @@ var ResRegEditView = Backbone.View.extend({ this.contactsCollection = new Backbone.Collection(); this.defaultAcrValuesCollection = new Backbone.Collection(); this.requestUrisCollection = new Backbone.Collection(); + + this.listWidgetViews = []; }, load:function(callback) { @@ -263,6 +265,11 @@ var ResRegEditView = Backbone.View.extend({ $('.control-group').removeClass('error'); + // sync any leftover collection items + _.each(this.listWidgetViews, function(v) { + v.addItem($.Event('click')); + }); + // build the scope object var scopes = this.scopeCollection.pluck("item").join(" "); @@ -334,17 +341,21 @@ var ResRegEditView = Backbone.View.extend({ render:function() { $(this.el).html(this.template({client: this.model.toJSON(), userInfo: getUserInfo()})); - var _self = this; + this.listWidgetViews = []; + + var _self = this; // build and bind registered redirect URI collection and view _.each(this.model.get("redirectUris"), function (redirectUri) { _self.redirectUrisCollection.add(new URIModel({item:redirectUri})); }); - $("#redirectUris .controls",this.el).html(new ListWidgetView({ + var redirectUriView = new ListWidgetView({ type:'uri', placeholder: 'https://', - collection: this.redirectUrisCollection}).render().el); + collection: this.redirectUrisCollection}); + $("#redirectUris .controls",this.el).html(redirectUriView.render().el); + this.listWidgetViews.push(redirectUriView); // build and bind scopes var scopes = this.model.get("scope"); @@ -353,19 +364,23 @@ var ResRegEditView = Backbone.View.extend({ _self.scopeCollection.add(new Backbone.Model({item:scope})); }); - $("#scope .controls",this.el).html(new ListWidgetView({ + var scopeView = new ListWidgetView({ placeholder: 'new scope', autocomplete: _.uniq(_.flatten(this.options.systemScopeList.pluck("value"))), - collection: this.scopeCollection}).render().el); + collection: this.scopeCollection}); + $("#scope .controls",this.el).html(scopeView.render().el); + this.listWidgetViews.push(scopeView); // build and bind contacts _.each(this.model.get('contacts'), function (contact) { _self.contactsCollection.add(new Backbone.Model({item:contact})); }); - $("#contacts .controls div", this.el).html(new ListWidgetView({ + var contactView = new ListWidgetView({ placeholder: 'new contact', - collection: this.contactsCollection}).render().el); + collection: this.contactsCollection}); + $("#contacts .controls div", this.el).html(contactView.render().el); + this.listWidgetViews.push(contactView); // build and bind request URIs @@ -373,20 +388,24 @@ var ResRegEditView = Backbone.View.extend({ _self.requestUrisCollection.add(new URIModel({item:requestUri})); }); - $('#requestUris .controls', this.el).html(new ListWidgetView({ + var requestUriView = new ListWidgetView({ type: 'uri', placeholder: 'https://', - collection: this.requestUrisCollection}).render().el); + collection: this.requestUrisCollection}); + $('#requestUris .controls', this.el).html(requestUriView.render().el); + this.listWidgetViews.push(requestUriView); // build and bind default ACR values _.each(this.model.get('defaultAcrValues'), function (defaultAcrValue) { _self.defaultAcrValuesCollection.add(new Backbone.Model({item:defaultAcrValue})); }); - $('#defaultAcrValues .controls', this.el).html(new ListWidgetView({ + var defaultAcrView = new ListWidgetView({ placeholder: 'new ACR value', // TODO: autocomplete from spec - collection: this.defaultAcrValuesCollection}).render().el); + collection: this.defaultAcrValuesCollection}); + $('#defaultAcrValues .controls', this.el).html(defaultAcrView.render().el); + this.listWidgetViews.push(defaultAcrView); this.toggleClientCredentials(); this.previewLogo(); diff --git a/openid-connect-server-webapp/src/main/webapp/resources/js/whitelist.js b/openid-connect-server-webapp/src/main/webapp/resources/js/whitelist.js index e69d83542..07e9f4f3a 100644 --- a/openid-connect-server-webapp/src/main/webapp/resources/js/whitelist.js +++ b/openid-connect-server-webapp/src/main/webapp/resources/js/whitelist.js @@ -248,6 +248,9 @@ var WhiteListFormView = Backbone.View.extend({ } this.scopeCollection = new Backbone.Collection(); + + this.listWidgetViews = []; + }, events:{ @@ -260,6 +263,11 @@ var WhiteListFormView = Backbone.View.extend({ e.preventDefault(); $('.control-group').removeClass('error'); + // sync any leftover collection items + _.each(this.listWidgetViews, function(v) { + v.addItem($.Event('click')); + }); + // process allowed scopes var allowedScopes = this.scopeCollection.pluck("item"); @@ -319,6 +327,7 @@ var WhiteListFormView = Backbone.View.extend({ this.$el.html(this.template(json)); + this.listWidgetViews = []; var _self = this; // build and bind scopes @@ -326,10 +335,12 @@ var WhiteListFormView = Backbone.View.extend({ _self.scopeCollection.add(new Backbone.Model({item:scope})); }); - $("#scope .controls",this.el).html(new ListWidgetView({ + var scopeView = new ListWidgetView({ placeholder: 'new scope here', autocomplete: this.options.client.scope, - collection: this.scopeCollection}).render().el); + collection: this.scopeCollection}); + $("#scope .controls",this.el).html(scopeView.render().el); + this.listWidgetViews.push(scopeView); return this;