EditResource.js revision 862a31119ccc38b9e7836a2366c6040ec8b02591
/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2015 ForgeRock AS.
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*/
/*global $, _, Backbone, define*/
'backgrid',
'bootstrap-dialog'
], function(Messages, AbstractView, Backgrid, BackgridUtils, Constants, EventManager, Router, UIUtils, UMAResourceSetWithPolicy, BootstrapModalShare, BootstrapDialog) {
initialize: function(options) {
this.model = null;
},
events: {
'click button#revokeAll': 'onRevokeAll',
'click button#share': 'onShare'
},
},
this.render();
},
onRevokeAll: function() {
var self = this;
message: $.t("uma.resources.show.revokeAllMessage"),
closable: false,
buttons: [{
id: "btn-ok",
label: $.t("common.form.ok"),
cssClass: "btn-primary btn-danger",
dialog.enableButtons(false);
}).always(function() {
});
}
}, {
label: $.t("common.form.cancel"),
}
}]
});
},
onShare: function() {
},
// Get the current id
/**
* Reason: We do not know the id of the data we need until the render function is called with args,
* thus we can only check at this point if we have the correct model to render this view (the model
* might already contain the correct data).
* Behaviour: If the model does require sync'ing then we abort this render via the return and render
* will it invoked again when the model is updated
*/
/**
* FIXME: Ideally the data needs to the be whole model, but I'm told it's also global so we're
* copying in just the attributes I need ATM
*/
// FIXME: Re-enable filtering and pagination
// UserPoliciesCollection = Backbone.PageableCollection.extend({
// url: URLHelper.substitute("__api__/users/__username__/oauth2/resourcesets/" + args[0]),
// parseRecords: function (data, options) {
// return data.policy.permissions;
// },
// sync: backgridUtils.sync
// });
events: {
"click #revoke": "revoke"
},
}
});
className: "selectize-cell",
render: function() {
create: false,
delimiter: ",",
dropdownParent: '#uma',
hideSelected: true,
persist: false,
labelField: 'name',
valueField: 'id',
})[0];
/* This an extention of the original positionDropdown method within Selectize. The override is
* required because using the dropdownParent 'body' places the dropdown out of scope of the
* containing backbone view. However adding the dropdownParent as any other element, has problems
* due the offsets and/positioning being incorrecly calucaluted in orignal positionDropdown method.
*/
if (this.settings.dropdownParent) {
offset.left -= $(this.settings.dropdownParent).offset().left + $(this.settings.dropdownParent).outerWidth() - $(this.settings.dropdownParent).outerWidth(true);
} else {
}
});
};
this.delegateEvents();
return this;
}
});
/**
* There *might* be no policy object present (if all the permissions were removed) so we're
* checking for this and creating an empty collection if there is no policy
*/
columns: [
{
name: "subject",
label: $.t("uma.resources.show.grid.0"),
cell: 'string',
// headerCell: BackgridUtils.FilterHeaderCell,
editable: false
},
{
name: "permissions",
label: $.t("uma.resources.show.grid.2"),
editable: false,
sortable: false
},
{
name: "edit",
label: "",
editable: false,
sortable: false
}],
emptyText: $.t("uma.all.grid.empty")
});
// FIXME: Re-enable filtering and pagination
// paginator = new Backgrid.Extension.Paginator({
// collection: this.model.get('policy').get('permissions'),
// windowSize: 3
// });
this.parentRender(function() {
}
// FIXME: Re-enable filtering and pagination
// self.$el.find("#paginationContainer").append(paginator.render().el);
});
},
if(syncRequired) {
this.stopListening(this.model);
}
return syncRequired;
}
});
return new EditResource();
});