enabled scope editing on existing policies
parent
3d760cad8b
commit
f3a777a2c8
|
@ -1114,6 +1114,7 @@ var AppRouter = Backbone.Router.extend({
|
||||||
// need to load it directly
|
// need to load it directly
|
||||||
policies = new PolicyCollection([], {rsid: rsid});
|
policies = new PolicyCollection([], {rsid: rsid});
|
||||||
rs = new ResourceSetModel({id: 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 {
|
} else {
|
||||||
// the resource set is loaded, preload the claims
|
// the resource set is loaded, preload the claims
|
||||||
policies = new PolicyCollection(rs.get('policies'), {rsid: rsid});
|
policies = new PolicyCollection(rs.get('policies'), {rsid: rsid});
|
||||||
|
@ -1148,8 +1149,9 @@ var AppRouter = Backbone.Router.extend({
|
||||||
var policy = null;
|
var policy = null;
|
||||||
if (rs == null) {
|
if (rs == null) {
|
||||||
// need to load it directly
|
// need to load it directly
|
||||||
rs = new ResourceSetModel({id: rsid});
|
|
||||||
policy = new PolicyModel({id: pid}, {rsid: 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 {
|
} else {
|
||||||
// the resource set is loaded, preload the claims
|
// the resource set is loaded, preload the claims
|
||||||
_.each(rs.get('policies'), function(p) {
|
_.each(rs.get('policies'), function(p) {
|
||||||
|
|
|
@ -419,7 +419,7 @@ var PolicyView = Backbone.View.extend({
|
||||||
|
|
||||||
|
|
||||||
var PolicyFormView = Backbone.View.extend({
|
var PolicyFormView = Backbone.View.extend({
|
||||||
tagName: 'span',
|
tagName: 'div',
|
||||||
|
|
||||||
initialize:function(options) {
|
initialize:function(options) {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
|
@ -431,6 +431,10 @@ var PolicyFormView = Backbone.View.extend({
|
||||||
this.scopeCollection = new Backbone.Collection();
|
this.scopeCollection = new Backbone.Collection();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
events:{
|
||||||
|
'click .btn-save': 'savePolicy'
|
||||||
|
},
|
||||||
|
|
||||||
load:function(callback) {
|
load:function(callback) {
|
||||||
if (this.model.isFetched &&
|
if (this.model.isFetched &&
|
||||||
this.options.rs.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) {
|
render:function (eventName) {
|
||||||
var json = this.model.toJSON();
|
var json = this.model.toJSON();
|
||||||
var rs = this.options.rs.toJSON();
|
var rs = this.options.rs.toJSON();
|
||||||
|
|
|
@ -162,14 +162,13 @@
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
|
||||||
<div class="control-group" id="scopes">
|
<div class="control-group" id="scopes">
|
||||||
<label class="control-label" data-i18n="common.scope">Scopes</label>
|
<label class="control-label" data-i18n="common.scope">Scopes:</label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<% console.log(rs); console.log(policy); %>
|
|
||||||
<% _.each(rs.scopes, function(scope) { %>
|
<% _.each(rs.scopes, function(scope) { %>
|
||||||
<div>
|
<div>
|
||||||
<input type="checkbox"
|
<input type="checkbox" id="scope-<%- scope %>"
|
||||||
<%-($.inArray(scope, policy.scopes) > -1 ? 'checked' : '')%>>
|
<%-($.inArray(scope, policy.scopes) > -1 ? 'checked' : '')%> value="<%- scope %>">
|
||||||
<label class="checkbox"><%- scope %></label>
|
<label for="scope-<%- scope %>" class="checkbox"><%- scope %></label>
|
||||||
</div>
|
</div>
|
||||||
<% }); %>
|
<% }); %>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue