diff --git a/uma-server-webapp/src/main/webapp/resources/js/admin.js b/uma-server-webapp/src/main/webapp/resources/js/admin.js index 3637b1091..fd2696e80 100644 --- a/uma-server-webapp/src/main/webapp/resources/js/admin.js +++ b/uma-server-webapp/src/main/webapp/resources/js/admin.js @@ -1114,6 +1114,7 @@ var AppRouter = Backbone.Router.extend({ // need to load it directly policies = new PolicyCollection([], {rsid: rsid}); rs = new ResourceSetModel({id: rsid}); + this.resourceSetList.add(rs); // it will be loaded below, don't need to load it again in the future } else { // the resource set is loaded, preload the claims policies = new PolicyCollection(rs.get('policies'), {rsid: rsid}); @@ -1148,8 +1149,9 @@ var AppRouter = Backbone.Router.extend({ var policy = null; if (rs == null) { // need to load it directly - rs = new ResourceSetModel({id: rsid}); policy = new PolicyModel({id: pid}, {rsid: rsid}); + rs = new ResourceSetModel({id: rsid}); + this.resourceSetList.add(rs); // it will be loaded below, don't need to load it again in the future } else { // the resource set is loaded, preload the claims _.each(rs.get('policies'), function(p) { diff --git a/uma-server-webapp/src/main/webapp/resources/js/policy.js b/uma-server-webapp/src/main/webapp/resources/js/policy.js index 56bd6df0b..c7d3af155 100644 --- a/uma-server-webapp/src/main/webapp/resources/js/policy.js +++ b/uma-server-webapp/src/main/webapp/resources/js/policy.js @@ -419,7 +419,7 @@ var PolicyView = Backbone.View.extend({ var PolicyFormView = Backbone.View.extend({ - tagName: 'span', + tagName: 'div', initialize:function(options) { this.options = options; @@ -431,6 +431,10 @@ var PolicyFormView = Backbone.View.extend({ this.scopeCollection = new Backbone.Collection(); }, + events:{ + 'click .btn-save': 'savePolicy' + }, + load:function(callback) { if (this.model.isFetched && this.options.rs.isFetched && @@ -455,6 +459,46 @@ var PolicyFormView = Backbone.View.extend({ }); }, + savePolicy:function(e) { + e.preventDefault(); + + // get all the scopes that are checked + var scopes = $('#scopes input[type="checkbox"]:checked').map(function(idx, elem) { return $(elem).val(); }).get(); + + var valid = this.model.set({ + scopes: scopes + }); + + if (valid) { + + var _self = this; + this.model.save({}, { + success:function() { + app.systemScopeList.add(_self.model); + app.navigate('user/policy/' + _self.options.rs.get('id'), {trigger: true}); + }, + error:function(error, response) { + + //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 + }); + } + }); + } + + return false; + + }, + render:function (eventName) { var json = this.model.toJSON(); var rs = this.options.rs.toJSON(); diff --git a/uma-server-webapp/src/main/webapp/resources/template/policy.html b/uma-server-webapp/src/main/webapp/resources/template/policy.html index dbc409583..262d90bda 100644 --- a/uma-server-webapp/src/main/webapp/resources/template/policy.html +++ b/uma-server-webapp/src/main/webapp/resources/template/policy.html @@ -162,14 +162,13 @@