From 53922374dffc46db9e12039858dfa96cad62565c Mon Sep 17 00:00:00 2001 From: Justin Richer Date: Thu, 2 Jul 2015 18:53:08 -0400 Subject: [PATCH] problems loading the resource set --- .../src/main/webapp/resources/js/admin.js | 51 +++++++++++- .../src/main/webapp/resources/js/policy.js | 45 +++++++++-- .../webapp/resources/template/policy.html | 78 ++++++++++++++++--- 3 files changed, 155 insertions(+), 19 deletions(-) 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 13501396f..a23fe3fb9 100644 --- a/uma-server-webapp/src/main/webapp/resources/js/admin.js +++ b/uma-server-webapp/src/main/webapp/resources/js/admin.js @@ -1111,14 +1111,14 @@ var AppRouter = Backbone.Router.extend({ var rs = this.resourceSetList.get(rsid); if (rs == null) { // need to load it directly - var policy = new PolicyCollection([], {rsid: rsid}); + var policies = new PolicyCollection([], {rsid: rsid}); } else { // the resource set is loaded, preload the claims - var policy = new PolicyCollection(rs.get('policies'), {rsid: rsid}); + var policies = new PolicyCollection(rs.get('policies'), {rsid: rsid}); policy.isFetched = true; } - var view = new PolicyListView({model: policy, rs: rs, systemScopeList: this.systemScopeList}); + var view = new PolicyListView({model: policies, rs: rs, systemScopeList: this.systemScopeList}); view.load(function() { $('#content').html(view.render().el); @@ -1127,6 +1127,51 @@ var AppRouter = Backbone.Router.extend({ }, + newPolicy:function(rsid) { + + }, + + editPolicy:function(rsid, pid) { + this.breadCrumbView.collection.reset(); + this.breadCrumbView.collection.add([ + {text:$.t('admin.home'), href:""}, + {text:$.t('policy.resource-sets'), href:"manage/#user/policy"}, + {text:$.t('policy.edit-policies'), href:"manage/#user/policy/" + rsid}, + {text:$.t('policy.edit-policy'), href:"manage/#user/policy/" + rsid + "/" + pid} + ]); + + this.updateSidebar('user/policy'); + + var rs = this.resourceSetList.get(rsid); + var policy = null; + if (rs == null) { + // need to load it directly + rs = new ResourceSetModel({id: rsid}); + policy = new PolicyModel({id: pid}, {rsid: rsid}); + } else { + // the resource set is loaded, preload the claims + _.each(rs.get('policies'), function(p) { + if (p.id == pid) { + policy = new PolicyModel(p, {rsid: rsid}); + policy.isFetched = true; + } + }); + if (policy == null) { + // need to load it directly + policy = new PolicyModel({id: pid}, {rsid: rsid}); + } + } + + var view = new PolicyFormView({model: policy, rs: rs, systemScopeList: this.systemScopeList}); + + view.load(function() { + $('#content').html(view.render().el); + setPageTitle($.t('policy.edit-policy')); + }); + + + }, + updateSidebar:function(item) { $('.sidebar-nav li.active').removeClass('active'); 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 0b737fe76..7d56ef8d8 100644 --- a/uma-server-webapp/src/main/webapp/resources/js/policy.js +++ b/uma-server-webapp/src/main/webapp/resources/js/policy.js @@ -25,7 +25,12 @@ var ResourceSetCollection = Backbone.Collection.extend({ }); var PolicyModel = Backbone.Model.extend({ - + urlRoot: function() { + return 'api/policy/' + this.options.rsid + '/'; + }, + initialize: function(model, options) { + this.options = options; + } }); var PolicyCollection = Backbone.Collection.extend({ @@ -242,6 +247,7 @@ var PolicyListView = Backbone.View.extend({ load:function(callback) { if (this.model.isFetched && + this.options.rs.isFetched && this.options.systemScopeList.isFetched) { callback(); return; @@ -250,10 +256,12 @@ var PolicyListView = Backbone.View.extend({ $('#loadingbox').sheet('show'); $('#loading').html( '' + $.t('policy.loading-policies') + ' ' + + '' + $.t('policy.loading-rs') + ' ' + '' + $.t("common.scopes") + ' ' ); $.when(this.model.fetchIfNeeded({success:function(e) {$('#loading-policies').addClass('label-success');}}), + this.options.rs.fetchIfNeeded({success:function(e) {$('#loading-rs').addClass('label-success');}}), this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}})) .done(function() { $('#loadingbox').sheet('hide'); @@ -344,10 +352,6 @@ var PolicyView = Backbone.View.extend({ this.template = _.template($('#tmpl-policy').html()); } - if (!this.scopeTemplate) { - this.scopeTemplate = _.template($('#tmpl-scope-list').html()); - } - }, events:{ @@ -414,11 +418,38 @@ var PolicyFormView = Backbone.View.extend({ if (!this.template) { this.template = _.template($('#tmpl-policy-form').html()); } + + this.scopeCollection = new Backbone.Collection(); }, - render:function (eventName) { - + load:function(callback) { + if (this.model.isFetched && + this.options.rs.isFetched && + this.options.systemScopeList.isFetched) { + callback(); + return; + } + + $('#loadingbox').sheet('show'); + $('#loading').html( + '' + $.t('policy.loading-policies') + ' ' + + '' + $.t('policy.loading-rs') + ' ' + + '' + $.t("common.scopes") + ' ' + ); + + $.when(this.model.fetchIfNeeded({success:function(e) {$('#loading-policies').addClass('label-success');}}), + this.options.rs.fetchIfNeeded({success:function(e) {$('#loading-rs').addClass('label-success');}}), + this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}})) + .done(function() { + $('#loadingbox').sheet('hide'); + callback(); + }); + }, + + render:function (eventName) { + var json = this.model.toJSON(); + this.$el.html(this.template({policy: json, rs: this.options.rs})); return this; } 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 981f6a2c8..45b83a6aa 100644 --- a/uma-server-webapp/src/main/webapp/resources/template/policy.html +++ b/uma-server-webapp/src/main/webapp/resources/template/policy.html @@ -72,15 +72,6 @@ -
-
-
- - -
-
-
-
Users that you share this resource will with need to be able to present the following claims in order to access the resource.
@@ -144,4 +135,73 @@ + + \ No newline at end of file