Skip to content

Commit 51b10db

Browse files
committed
more comprehensive list widget leftover object handling in client
1 parent 89f46fa commit 51b10db

File tree

1 file changed

+34
-14
lines changed
  • openid-connect-server-webapp/src/main/webapp/resources/js

1 file changed

+34
-14
lines changed

openid-connect-server-webapp/src/main/webapp/resources/js/client.js

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,9 @@ var ClientFormView = Backbone.View.extend({
609609
this.defaultAcrValuesCollection = new Backbone.Collection();
610610
this.requestUrisCollection = new Backbone.Collection();
611611
// TODO: add Spring authorities collection and resource IDs collection?
612+
613+
// collection of sub-views that need to be sync'd on save
614+
this.listWidgetViews = [];
612615
},
613616

614617
events:{
@@ -800,12 +803,15 @@ var ClientFormView = Backbone.View.extend({
800803

801804
$('.control-group').removeClass('error');
802805

806+
807+
// sync any leftover collection items
808+
_.each(this.listWidgetViews, function(v) {
809+
v.addItem($.Event('click'));
810+
});
811+
812+
803813
// build the scope object
804814
var scopes = this.scopeCollection.pluck("item");
805-
var extraScope = $('#scope input').val();
806-
if (extraScope) {
807-
scopes.push(extraScope);
808-
}
809815

810816
// build the grant type object
811817
var grantTypes = [];
@@ -992,55 +998,69 @@ var ClientFormView = Backbone.View.extend({
992998

993999
var _self = this;
9941000

1001+
// clear the sub-view collection
1002+
this.listWidgetViews = [];
1003+
9951004
// build and bind registered redirect URI collection and view
9961005
_.each(this.model.get("redirectUris"), function (redirectUri) {
9971006
_self.redirectUrisCollection.add(new URIModel({item:redirectUri}));
9981007
});
9991008

1000-
$("#redirectUris .controls",this.el).html(new ListWidgetView({
1009+
1010+
var redirUriView = new ListWidgetView({
10011011
type:'uri',
10021012
placeholder: 'https://',
1003-
collection: this.redirectUrisCollection}).render().el);
1013+
collection: this.redirectUrisCollection});
1014+
$("#redirectUris .controls",this.el).html(redirUriView.render().el);
1015+
this.listWidgetViews.push(redirUriView);
10041016

10051017
// build and bind scopes
10061018
_.each(this.model.get("scope"), function (scope) {
10071019
_self.scopeCollection.add(new Backbone.Model({item:scope}));
10081020
});
10091021

1010-
$("#scope .controls",this.el).html(new ListWidgetView({
1022+
var scopeView = new ListWidgetView({
10111023
placeholder: 'new scope',
10121024
autocomplete: _.uniq(_.flatten(this.options.systemScopeList.pluck("value"))),
1013-
collection: this.scopeCollection}).render().el);
1025+
collection: this.scopeCollection});
1026+
$("#scope .controls",this.el).html(scopeView.render().el);
1027+
this.listWidgetViews.push(scopeView);
10141028

10151029
// build and bind contacts
10161030
_.each(this.model.get('contacts'), function (contact) {
10171031
_self.contactsCollection.add(new Backbone.Model({item:contact}));
10181032
});
10191033

1020-
$("#contacts .controls", this.el).html(new ListWidgetView({
1034+
var contactsView = new ListWidgetView({
10211035
placeholder: 'new contact',
1022-
collection: this.contactsCollection}).render().el);
1036+
collection: this.contactsCollection});
1037+
$("#contacts .controls", this.el).html(contactsView.render().el);
1038+
this.listWidgetViews.push(contactsView);
10231039

10241040

10251041
// build and bind request URIs
10261042
_.each(this.model.get('requestUris'), function (requestUri) {
10271043
_self.requestUrisCollection.add(new URIModel({item:requestUri}));
10281044
});
10291045

1030-
$('#requestUris .controls', this.el).html(new ListWidgetView({
1046+
var requestUriView = new ListWidgetView({
10311047
type: 'uri',
10321048
placeholder: 'https://',
1033-
collection: this.requestUrisCollection}).render().el);
1049+
collection: this.requestUrisCollection});
1050+
$('#requestUris .controls', this.el).html(requestUriView.render().el);
1051+
this.listWidgetViews.push(requestUriView);
10341052

10351053
// build and bind default ACR values
10361054
_.each(this.model.get('defaultAcrValues'), function (defaultAcrValue) {
10371055
_self.defaultAcrValuesCollection.add(new Backbone.Model({item:defaultAcrValue}));
10381056
});
10391057

1040-
$('#defaultAcrValues .controls', this.el).html(new ListWidgetView({
1058+
var defaultAcrView = new ListWidgetView({
10411059
placeholder: 'new ACR value',
10421060
// TODO: autocomplete from spec
1043-
collection: this.defaultAcrValuesCollection}).render().el);
1061+
collection: this.defaultAcrValuesCollection});
1062+
$('#defaultAcrValues .controls', this.el).html(defaultAcrView.render().el);
1063+
this.listWidgetViews.push(defaultAcrView);
10441064

10451065
// build and bind
10461066

0 commit comments

Comments
 (0)