enabled scope editing on existing policies

pull/820/merge
Justin Richer 10 years ago
parent 3d760cad8b
commit f3a777a2c8

@ -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) {

@ -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();

@ -162,14 +162,13 @@
<fieldset>
<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">
<% console.log(rs); console.log(policy); %>
<% _.each(rs.scopes, function(scope) { %>
<div>
<input type="checkbox"
<%-($.inArray(scope, policy.scopes) > -1 ? 'checked' : '')%>>
<label class="checkbox"><%- scope %></label>
<input type="checkbox" id="scope-<%- scope %>"
<%-($.inArray(scope, policy.scopes) > -1 ? 'checked' : '')%> value="<%- scope %>">
<label for="scope-<%- scope %>" class="checkbox"><%- scope %></label>
</div>
<% }); %>
</div>

Loading…
Cancel
Save