auto format and cleanup javascript

pull/1169/merge
Justin Richer 2017-03-21 15:04:18 -04:00
parent bd72b4138d
commit 78b9b6ced4
10 changed files with 4427 additions and 3813 deletions

View File

@ -53,9 +53,10 @@ Backbone.Collection.prototype.fetchIfNeeded = function(options) {
}
};
var URIModel = Backbone.Model.extend({
var URIModel = Backbone.Model
.extend({
validate: function(attrs){
validate: function(attrs) {
var expression = /^(?:([a-z0-9+.-]+:\/\/)((?:(?:[a-z0-9-._~!$&'()*+,;=:]|%[0-9A-F]{2})*)@)?((?:[a-z0-9-._~!$&'()*+,;=]|%[0-9A-F]{2})*)(:(?:\d*))?(\/(?:[a-z0-9-._~!$&'()*+,;=:@\/]|%[0-9A-F]{2})*)?|([a-z0-9+.-]+:)(\/?(?:[a-z0-9-._~!$&'()*+,;=:@]|%[0-9A-F]{2})+(?:[a-z0-9-._~!$&'()*+,;=:@\/]|%[0-9A-F]{2})*)?)(\?(?:[a-z0-9-._~!$&'()*+,;=:\/?@]|%[0-9A-F]{2})*)?(#(?:[a-z0-9-._~!$&'()*+,;=:\/?@]|%[0-9A-F]{2})*)?$/i;
var regex = new RegExp(expression);
@ -65,41 +66,37 @@ var URIModel = Backbone.Model.extend({
}
}
});
});
/*
* Backbone JS Reusable ListWidget
* Options
* {
* collection: Backbone JS Collection
* type: ('uri'|'default')
* autocomplete: ['item1','item2'] List of auto complete items
* }
*
* Backbone JS Reusable ListWidget Options { collection: Backbone JS Collection
* type: ('uri'|'default') autocomplete: ['item1','item2'] List of auto complete
* items }
*
*/
var ListWidgetChildView = Backbone.View.extend({
tagName: 'tr',
events:{
"click .btn-delete-list-item":'deleteItem',
"change .checkbox-list-item":'toggleCheckbox'
events: {
"click .btn-delete-list-item": 'deleteItem',
"change .checkbox-list-item": 'toggleCheckbox'
},
deleteItem:function (e) {
deleteItem: function(e) {
e.preventDefault();
e.stopImmediatePropagation();
//this.$el.tooltip('delete');
// this.$el.tooltip('delete');
this.model.destroy({
dataType: false, processData: false,
error:app.errorHandlerView.handleError()
dataType: false,
processData: false,
error: app.errorHandlerView.handleError()
});
},
toggleCheckbox:function(e) {
toggleCheckbox: function(e) {
e.preventDefault();
e.stopImmediatePropagation();
if ($(e.target).is(':checked')) {
@ -110,24 +107,32 @@ var ListWidgetChildView = Backbone.View.extend({
},
initialize:function (options) {
this.options = {toggle: false, checked: false};
initialize: function(options) {
this.options = {
toggle: false,
checked: false
};
_.extend(this.options, options);
if (!this.template) {
this.template = _.template($('#tmpl-list-widget-child').html());
}
},
render:function () {
render: function() {
var data = {model: this.model.toJSON(), opt: this.options};
var data = {
model: this.model.toJSON(),
opt: this.options
};
this.$el.html(this.template(data));
$('.item-full', this.el).hide();
if (this.model.get('item').length > 30) {
this.$el.tooltip({title:$.t('admin.list-widget.tooltip')});
this.$el.tooltip({
title: $.t('admin.list-widget.tooltip')
});
var _self = this;
@ -139,8 +144,6 @@ var ListWidgetChildView = Backbone.View.extend({
});
}
$(this.el).i18n();
return this;
}
@ -150,9 +153,9 @@ var ListWidgetView = Backbone.View.extend({
tagName: "div",
events:{
"click .btn-add-list-item":"addItem",
"keypress":function (e) {
events: {
"click .btn-add-list-item": "addItem",
"keypress": function(e) {
// trap the enter key
if (e.which == 13) {
e.preventDefault();
@ -162,7 +165,7 @@ var ListWidgetView = Backbone.View.extend({
}
},
initialize:function (options) {
initialize: function(options) {
this.options = options;
if (!this.template) {
@ -173,30 +176,36 @@ var ListWidgetView = Backbone.View.extend({
this.collection.bind('remove', this.render, this);
},
addItem:function(e) {
addItem: function(e) {
e.preventDefault();
var input_value = $("input", this.el).val().trim();
if (input_value === ""){
if (input_value === "") {
return;
}
var model;
if (this.options.type == 'uri') {
model = new URIModel({item:input_value});
model = new URIModel({
item: input_value
});
} else {
model = new Backbone.Model({item:input_value});
model = new Backbone.Model({
item: input_value
});
model.validate = function(attrs) {
if(!attrs.item) {
if (!attrs.item) {
return "value can't be null";
}
};
}
// if it's valid and doesn't already exist
if (model.get("item") != null && this.collection.where({item: input_value}).length < 1) {
if (model.get("item") != null && this.collection.where({
item: input_value
}).length < 1) {
this.collection.add(model);
} else {
// else add a visual error indicator
@ -204,10 +213,12 @@ var ListWidgetView = Backbone.View.extend({
}
},
render:function (eventName) {
render: function(eventName) {
this.$el.html(this.template({placeholder:this.options.placeholder,
helpBlockText:this.options.helpBlockText}));
this.$el.html(this.template({
placeholder: this.options.placeholder,
helpBlockText: this.options.helpBlockText
}));
var _self = this;
@ -218,7 +229,8 @@ var ListWidgetView = Backbone.View.extend({
// make a copy of our collection to work from
var values = this.collection.clone();
// look through our autocomplete values (if we have them) and render them all as checkboxes
// look through our autocomplete values (if we have them) and render
// them all as checkboxes
if (this.options.autocomplete) {
_.each(this.options.autocomplete, function(option) {
var found = _.find(values.models, function(element) {
@ -232,23 +244,35 @@ var ListWidgetView = Backbone.View.extend({
// if we found the element, check the box
model = found;
checked = true;
// and remove it from the list of items to be rendered later
values.remove(found, {silent: true});
// and remove it from the list of items to be rendered
// later
values.remove(found, {
silent: true
});
} else {
model = new Backbone.Model({item:option});
model = new Backbone.Model({
item: option
});
checked = false;
}
var el = new ListWidgetChildView({model:model, toggle: true, checked: checked, collection: _self.collection}).render().el;
var el = new ListWidgetChildView({
model: model,
toggle: true,
checked: checked,
collection: _self.collection
}).render().el;
$("tbody", _self.el).append(el);
}, this);
}
// now render everything not in the autocomplete list
_.each(values.models, function (model) {
var el = new ListWidgetChildView({model:model, collection: _self.collection}).render().el;
_.each(values.models, function(model) {
var el = new ListWidgetChildView({
model: model,
collection: _self.collection
}).render().el;
$("tbody", _self.el).append(el);
}, this);
}
@ -263,7 +287,7 @@ var BreadCrumbView = Backbone.View.extend({
tagName: 'ul',
initialize:function (options) {
initialize: function(options) {
this.options = options;
if (!this.template) {
@ -275,19 +299,28 @@ var BreadCrumbView = Backbone.View.extend({
this.collection.bind('add', this.render, this);
},
render:function () {
render: function() {
this.$el.empty();
var parent = this;
// go through each of the breadcrumb models
_.each(this.collection.models, function (crumb, index) {
_.each(this.collection.models, function(crumb, index) {
// if it's the last index in the crumbs then render the link inactive
// if it's the last index in the crumbs then render the link
// inactive
if (index == parent.collection.size() - 1) {
crumb.set({active:true}, {silent:true});
crumb.set({
active: true
}, {
silent: true
});
} else {
crumb.set({active:false}, {silent:true});
crumb.set({
active: false
}, {
silent: true
});
}
this.$el.append(this.template(crumb.toJSON()));
@ -298,44 +331,46 @@ var BreadCrumbView = Backbone.View.extend({
}
});
// User Profile
var UserProfileView = Backbone.View.extend({
tagName: 'span',
initialize:function(options) {
initialize: function(options) {
this.options = options;
if (!this.template) {
this.template = _.template($('#tmpl-user-profile-element').html());
}
},
render:function() {
render: function() {
$(this.el).html($('#tmpl-user-profile').html());
var t = this.template;
_.each(this.model, function (value, key) {
_.each(this.model, function(value, key) {
if (key && value) {
if (typeof(value) === 'object') {
if (typeof (value) === 'object') {
var el = this.el;
var k = key;
_.each(value, function (value, key) {
$('dl', el).append(
t({key: key, value: value, category: k})
);
_.each(value, function(value, key) {
$('dl', el).append(t({
key: key,
value: value,
category: k
}));
});
} else if (typeof(value) === 'array') {
} else if (typeof (value) === 'array') {
// TODO: handle array types
} else {
$('dl', this.el).append(
t({key: key, value: value})
);
$('dl', this.el).append(t({
key: key,
value: value
}));
}
}
}, this);
@ -348,7 +383,7 @@ var UserProfileView = Backbone.View.extend({
// error handler
var ErrorHandlerView = Backbone.View.extend({
initialize:function(options) {
initialize: function(options) {
this.options = options;
if (!this.template) {
this.template = _.template($('#tmpl-error-box').html());
@ -358,12 +393,12 @@ var ErrorHandlerView = Backbone.View.extend({
}
},
reloadPage:function(event) {
reloadPage: function(event) {
event.preventDefault();
window.location.reload(true);
},
handleError:function(message) {
handleError: function(message) {
if (!message) {
message = {};
@ -377,17 +412,24 @@ var ErrorHandlerView = Backbone.View.extend({
console.log(message.log);
}
_self.showErrorMessage(
_self.headerTemplate({message: message, model: model, response: response, options: options}),
_self.template({message: message, model: model, response: response, options: options})
);
_self.showErrorMessage(_self.headerTemplate({
message: message,
model: model,
response: response,
options: options
}), _self.template({
message: message,
model: model,
response: response,
options: options
}));
$('#modalAlert .modal-body .page-reload').on('click', _self.reloadPage);
}
},
showErrorMessage:function(header, message) {
showErrorMessage: function(header, message) {
// hide the sheet if it's visible
$('#loadingbox').sheet('hide');
@ -404,28 +446,31 @@ var ErrorHandlerView = Backbone.View.extend({
}
});
// Router
var AppRouter = Backbone.Router.extend({
routes:{
routes: {
"": "root"
},
root:function() {
root: function() {
if (isAdmin()) {
this.navigate('admin/clients', {trigger: true});
this.navigate('admin/clients', {
trigger: true
});
} else {
this.navigate('user/approved', {trigger: true});
this.navigate('user/approved', {
trigger: true
});
}
},
initialize:function () {
initialize: function() {
this.breadCrumbView = new BreadCrumbView({
collection:new Backbone.Collection()
collection: new Backbone.Collection()
});
this.breadCrumbView.render();
@ -440,18 +485,19 @@ var AppRouter = Backbone.Router.extend({
},
notImplemented:function(){
notImplemented: function() {
this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([
{text:$.t('admin.home'), href:""}
]);
this.breadCrumbView.collection.add([{
text: $.t('admin.home'),
href: ""
}]);
this.updateSidebar('none');
$('#content').html("<h2>Not implemented yet.</h2>");
},
updateSidebar:function(item) {
updateSidebar: function(item) {
$('.sidebar-nav li.active').removeClass('active');
$('.sidebar-nav li a[href^="manage/#' + item + '"]').parent().addClass('active');
@ -463,20 +509,21 @@ var AppRouter = Backbone.Router.extend({
var app = null;
// main
$(function () {
$(function() {
var loader = function(source) {
return $.get(source, function (templates) {
return $.get(source, function(templates) {
console.log('Loading file: ' + source);
$('#templates').append(templates);
});
};
// load templates and append them to the body
$.when.apply(null, ui.templates.map(loader)
).done(function() {
$.when.apply(null, ui.templates.map(loader)).done(function() {
console.log('done');
$.ajaxSetup({cache:false});
$.ajaxSetup({
cache: false
});
app = new AppRouter();
_.each(ui.routes.reverse(), function(route) {
@ -486,36 +533,43 @@ $(function () {
app.on('route', function(name, args) {
// scroll to top of page on new route selection
$("html, body").animate({ scrollTop: 0 }, "slow");
$("html, body").animate({
scrollTop: 0
}, "slow");
});
// grab all hashed URLs and send them through the app router instead
$(document).on('click', 'a[href^="manage/#"]', function(event) {
event.preventDefault();
app.navigate(this.hash.slice(1), {trigger: true});
app.navigate(this.hash.slice(1), {
trigger: true
});
});
var base = $('base').attr('href');
$.getJSON(base + '.well-known/openid-configuration', function(data) {
app.serverConfiguration = data;
var baseUrl = $.url(app.serverConfiguration.issuer);
Backbone.history.start({pushState: true, root: baseUrl.attr('relative') + 'manage/'});
Backbone.history.start({
pushState: true,
root: baseUrl.attr('relative') + 'manage/'
});
});
});
window.onerror = function ( message, filename, lineno, colno, error ){
window.onerror = function(message, filename, lineno, colno, error) {
console.log(message);
//Display an alert with an error message
// Display an alert with an error message
$('#modalAlert div.modal-header').html($.t('error.title'));
$('#modalAlert div.modal-body').html($.t('error.message') + message + ' <br /> ' + [filename, lineno, colno, error]);
$("#modalAlert").modal({ // wire up the actual modal functionality and show the dialog
"backdrop" : "static",
"keyboard" : true,
"show" : true // ensure the modal is shown immediately
$("#modalAlert").modal({ // wire up the actual modal functionality
// and show the dialog
"backdrop": "static",
"keyboard": true,
"show": true
// ensure the modal is shown immediately
});
}
});

View File

@ -21,7 +21,8 @@ var BlackListModel = Backbone.Model.extend({
});
var BlackListCollection = Backbone.Collection.extend({
initialize: function() { },
initialize: function() {
},
url: "api/blacklist"
});
@ -29,42 +30,42 @@ var BlackListCollection = Backbone.Collection.extend({
var BlackListListView = Backbone.View.extend({
tagName: 'span',
initialize:function(options) {
initialize: function(options) {
this.options = options;
},
load:function(callback) {
load: function(callback) {
if (this.collection.isFetched) {
callback();
return;
}
$('#loadingbox').sheet('show');
$('#loading').html(
'<span class="label" id="loading-blacklist">' + $.t('admin.blacklist') + '</span> '
);
$('#loading').html('<span class="label" id="loading-blacklist">' + $.t('admin.blacklist') + '</span> ');
$.when(this.collection.fetchIfNeeded({success:function(e) {$('#loading-blacklist').addClass('label-success');}, error:app.errorHandlerView.handleError()}))
.done(function() {
$.when(this.collection.fetchIfNeeded({
success: function(e) {
$('#loading-blacklist').addClass('label-success');
},
error: app.errorHandlerView.handleError()
})).done(function() {
$('#loadingbox').sheet('hide');
callback();
});
},
events: {
"click .refresh-table":"refreshTable",
"click .btn-add":"addItem",
"submit #add-blacklist form":"addItem"
"click .refresh-table": "refreshTable",
"click .btn-add": "addItem",
"submit #add-blacklist form": "addItem"
},
refreshTable:function(e) {
refreshTable: function(e) {
e.preventDefault();
var _self = this;
$('#loadingbox').sheet('show');
$('#loading').html(
'<span class="label" id="loading-blacklist">' + $.t('admin.blacklist') + '</span> '
);
$('#loading').html('<span class="label" id="loading-blacklist">' + $.t('admin.blacklist') + '</span> ');
$.when(this.collection.fetch()).done(function() {
$('#loadingbox').sheet('hide');
@ -72,7 +73,7 @@ var BlackListListView = Backbone.View.extend({
});
},
togglePlaceholder:function() {
togglePlaceholder: function() {
if (this.collection.length > 0) {
$('#blacklist-table', this.el).show();
$('#blacklist-table-empty', this.el).hide();
@ -82,13 +83,15 @@ var BlackListListView = Backbone.View.extend({
}
},
render:function (eventName) {
render: function(eventName) {
$(this.el).html($('#tmpl-blacklist-table').html());
var _self = this;
_.each(this.collection.models, function(blacklist) {
var view = new BlackListWidgetView({model: blacklist});
var view = new BlackListWidgetView({
model: blacklist
});
view.parentView = _self;
$("#blacklist-table", _self.el).append(view.render().el);
}, this);
@ -99,7 +102,7 @@ var BlackListListView = Backbone.View.extend({
return this;
},
addItem:function(e) {
addItem: function(e) {
e.preventDefault();
var input_value = $("#blacklist-uri", this.el).val().trim();
@ -117,11 +120,11 @@ var BlackListListView = Backbone.View.extend({
var _self = this; // closures...
item.save({}, {
success:function() {
success: function() {
_self.collection.add(item);
_self.render();
},
error:app.errorHandlerView.handleError()
error: app.errorHandlerView.handleError()
});
}
@ -132,7 +135,7 @@ var BlackListWidgetView = Backbone.View.extend({
tagName: 'tr',
initialize:function(options) {
initialize: function(options) {
this.options = options;
if (!this.template) {
@ -140,7 +143,7 @@ var BlackListWidgetView = Backbone.View.extend({
}
},
render:function() {
render: function() {
this.$el.html(this.template(this.model.toJSON()));
@ -148,28 +151,29 @@ var BlackListWidgetView = Backbone.View.extend({
},
events:{
'click .btn-delete':'deleteBlacklist'
events: {
'click .btn-delete': 'deleteBlacklist'
},
deleteBlacklist:function (e) {
deleteBlacklist: function(e) {
e.preventDefault();
if (confirm($.t("blacklist.confirm"))) {
var _self = this;
this.model.destroy({
dataType: false, processData: false,
success:function () {
dataType: false,
processData: false,
success: function() {
_self.$el.fadeTo("fast", 0.00, function () { //fade
$(this).slideUp("fast", function () { //slide up
$(this).remove(); //then remove from the DOM
_self.$el.fadeTo("fast", 0.00, function() { // fade
$(this).slideUp("fast", function() { // slide up
$(this).remove(); // then remove from the DOM
_self.parentView.togglePlaceholder();
});
});
},
error:app.errorHandlerView.handleError()
error: app.errorHandlerView.handleError()
});
_self.parentView.delegateEvents();
@ -180,9 +184,10 @@ var BlackListWidgetView = Backbone.View.extend({
});
ui.routes.push({path: "admin/blacklist", name: "blackList", callback:
function() {
ui.routes.push({
path: "admin/blacklist",
name: "blackList",
callback: function() {
if (!isAdmin()) {
this.root();
@ -190,21 +195,24 @@ ui.routes.push({path: "admin/blacklist", name: "blackList", callback:
}
this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([
{text:$.t('admin.home'), href:""},
{text:$.t('admin.manage-blacklist'), href:"manage/#admin/blacklist"}
]);
this.breadCrumbView.collection.add([{
text: $.t('admin.home'),
href: ""
}, {
text: $.t('admin.manage-blacklist'),
href: "manage/#admin/blacklist"
}]);
this.updateSidebar('admin/blacklist');
var view = new BlackListListView({collection: this.blackListList});
var view = new BlackListListView({
collection: this.blackListList
});
view.load(
function(collection, response, options) {
view.load(function(collection, response, options) {
$('#content').html(view.render().el);
setPageTitle($.t('admin.manage-blacklist'));
}
);
});
}
});

View File

@ -17,61 +17,61 @@
var DynRegClient = Backbone.Model.extend({
idAttribute: "client_id",
defaults:{
client_id:null,
client_secret:null,
redirect_uris:[],
client_name:null,
client_uri:null,
logo_uri:null,
contacts:[],
tos_uri:null,
token_endpoint_auth_method:null,
scope:null,
grant_types:[],
response_types:[],
policy_uri:null,
defaults: {
client_id: null,
client_secret: null,
redirect_uris: [],
client_name: null,
client_uri: null,
logo_uri: null,
contacts: [],
tos_uri: null,
token_endpoint_auth_method: null,
scope: null,
grant_types: [],
response_types: [],
policy_uri: null,
jwks_uri:null,
jwks:null,
jwksType:'URI',
jwks_uri: null,
jwks: null,
jwksType: 'URI',
application_type:null,
sector_identifier_uri:null,
subject_type:null,
application_type: null,
sector_identifier_uri: null,
subject_type: null,
request_object_signing_alg:null,
request_object_signing_alg: null,
userinfo_signed_response_alg:null,
userinfo_encrypted_response_alg:null,
userinfo_encrypted_response_enc:null,
userinfo_signed_response_alg: null,
userinfo_encrypted_response_alg: null,
userinfo_encrypted_response_enc: null,
id_token_signed_response_alg:null,
id_token_encrypted_response_alg:null,
id_token_encrypted_response_enc:null,
id_token_signed_response_alg: null,
id_token_encrypted_response_alg: null,
id_token_encrypted_response_enc: null,
default_max_age:null,
require_auth_time:false,
default_acr_values:null,
default_max_age: null,
require_auth_time: false,
default_acr_values: null,
initiate_login_uri:null,
post_logout_redirect_uris:null,
initiate_login_uri: null,
post_logout_redirect_uris: null,
claims_redirect_uris:[],
claims_redirect_uris: [],
request_uris:[],
request_uris: [],
software_statement:null,
software_id:null,
software_version:null,
software_statement: null,
software_id: null,
software_version: null,
code_challenge_method:null,
code_challenge_method: null,
registration_access_token:null,
registration_client_uri:null
registration_access_token: null,
registration_client_uri: null
},
sync: function(method, model, options){
sync: function(method, model, options) {
if (model.get('registration_access_token')) {
var headers = options.headers ? options.headers : {};
headers['Authorization'] = 'Bearer ' + model.get('registration_access_token');
@ -81,7 +81,7 @@ var DynRegClient = Backbone.Model.extend({
return this.constructor.__super__.sync(method, model, options);
},
urlRoot:'register'
urlRoot: 'register'
});
@ -89,17 +89,17 @@ var DynRegRootView = Backbone.View.extend({
tagName: 'span',
initialize:function(options) {
initialize: function(options) {
this.options = options;
},
events:{
"click #newreg":"newReg",
"click #editreg":"editReg"
events: {
"click #newreg": "newReg",
"click #editreg": "editReg"
},
load:function(callback) {
load: function(callback) {
if (this.options.systemScopeList.isFetched) {
callback();
return;
@ -108,26 +108,32 @@ var DynRegRootView = Backbone.View.extend({
$('#loadingbox').sheet('show');
$('#loading').html('<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ');
$.when(this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}, error:app.errorHandlerView.handleError()}))
.done(function() {
$.when(this.options.systemScopeList.fetchIfNeeded({
success: function(e) {
$('#loading-scopes').addClass('label-success');
},
error: app.errorHandlerView.handleError()
})).done(function() {
$('#loadingbox').sheet('hide');
callback();
});
},
render:function() {
render: function() {
$(this.el).html($('#tmpl-dynreg').html());
$(this.el).i18n();
return this;
},
newReg:function(e) {
newReg: function(e) {
e.preventDefault();
this.remove();
app.navigate('dev/dynreg/new', {trigger: true});
app.navigate('dev/dynreg/new', {
trigger: true
});
},
editReg:function(e) {
editReg: function(e) {
e.preventDefault();
var clientId = $('#clientId').val();
var token = $('#regtoken').val();
@ -144,33 +150,47 @@ var DynRegRootView = Backbone.View.extend({
var userInfo = getUserInfo();
var contacts = client.get("contacts");
if (userInfo != null && userInfo.email != null && ! _.contains(contacts, userInfo.email)) {
if (userInfo != null && userInfo.email != null && !_.contains(contacts, userInfo.email)) {
contacts.push(userInfo.email);
}
client.set({
contacts: contacts
}, { silent: true });
}, {
silent: true
});
if (client.get("jwks")) {
client.set({
jwksType: "VAL"
}, { silent: true });
}, {
silent: true
});
} else {
client.set({
jwksType: "URI"
}, { silent: true });
}, {
silent: true
});
}
var view = new DynRegEditView({model: client, systemScopeList: app.systemScopeList});
var view = new DynRegEditView({
model: client,
systemScopeList: app.systemScopeList
});
view.load(function() {
$('#content').html(view.render().el);
view.delegateEvents();
setPageTitle($.t('dynreg.edit-dynamically-registered'));
app.navigate('dev/dynreg/edit', {trigger: true});
app.navigate('dev/dynreg/edit', {
trigger: true
});
self.remove();
});
}, error:app.errorHandlerView.handleError({message: $.t('dynreg.invalid-access-token')})
},
error: app.errorHandlerView.handleError({
message: $.t('dynreg.invalid-access-token')
})
});
}
@ -180,7 +200,7 @@ var DynRegEditView = Backbone.View.extend({
tagName: 'span',
initialize:function(options) {
initialize: function(options) {
this.options = options;
if (!this.template) {
this.template = _.template($('#tmpl-dynreg-client-form').html());
@ -197,7 +217,7 @@ var DynRegEditView = Backbone.View.extend({
this.listWidgetViews = [];
},
load:function(callback) {
load: function(callback) {
if (this.options.systemScopeList.isFetched) {
callback();
return;
@ -206,40 +226,51 @@ var DynRegEditView = Backbone.View.extend({
$('#loadingbox').sheet('show');
$('#loading').html('<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ');
$.when(this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}, error:app.errorHandlerView.handleError()}))
.done(function() {
$.when(this.options.systemScopeList.fetchIfNeeded({
success: function(e) {
$('#loading-scopes').addClass('label-success');
},
error: app.errorHandlerView.handleError()
})).done(function() {
$('#loadingbox').sheet('hide');
callback();
});
},
events:{
"click .btn-save":"saveClient",
"click .btn-cancel":"cancel",
"click .btn-delete":"deleteClient",
"change #logoUri input":"previewLogo",
"change #tokenEndpointAuthMethod input:radio":"toggleClientCredentials",
"change #jwkSelector input:radio":"toggleJWKSetType"
events: {
"click .btn-save": "saveClient",
"click .btn-cancel": "cancel",
"click .btn-delete": "deleteClient",
"change #logoUri input": "previewLogo",
"change #tokenEndpointAuthMethod input:radio": "toggleClientCredentials",
"change #jwkSelector input:radio": "toggleJWKSetType"
},
cancel:function(e) {
cancel: function(e) {
e.preventDefault();
app.navigate('dev/dynreg', {trigger: true});
app.navigate('dev/dynreg', {
trigger: true
});
},
deleteClient:function (e) {
deleteClient: function(e) {
e.preventDefault();
if (confirm($.t('client.client-table.confirm'))) {
var self = this;
this.model.destroy({
dataType: false, processData: false,
success:function () {
dataType: false,
processData: false,
success: function() {
self.remove();
app.navigate('dev/dynreg', {trigger: true});
app.navigate('dev/dynreg', {
trigger: true
});
},
error:app.errorHandlerView.handleError({"log": "An error occurred when deleting a client"})
error: app.errorHandlerView.handleError({
"log": "An error occurred when deleting a client"
})
});
}
@ -247,27 +278,29 @@ var DynRegEditView = Backbone.View.extend({
return false;
},
previewLogo:function() {
previewLogo: function() {
if ($('#logoUri input', this.el).val()) {
$('#logoPreview', this.el).empty();
$('#logoPreview', this.el).attr('src', $('#logoUri input', this.el).val());
} else {
//$('#logoBlock', this.el).hide();
// $('#logoBlock', this.el).hide();
$('#logoPreview', this.el).attr('src', 'resources/images/logo_placeholder.gif');
}
},
/**
* Set up the form based on the current state of the tokenEndpointAuthMethod parameter
* Set up the form based on the current state of the tokenEndpointAuthMethod
* parameter
*
* @param event
*/
toggleClientCredentials:function() {
toggleClientCredentials: function() {
var tokenEndpointAuthMethod = $('#tokenEndpointAuthMethod input', this.el).filter(':checked').val();
// show or hide the signing algorithm method depending on what's selected
if (tokenEndpointAuthMethod == 'private_key_jwt'
|| tokenEndpointAuthMethod == 'client_secret_jwt') {
// show or hide the signing algorithm method depending on what's
// selected
if (tokenEndpointAuthMethod == 'private_key_jwt' || tokenEndpointAuthMethod == 'client_secret_jwt') {
$('#tokenEndpointAuthSigningAlg', this.el).show();
} else {
$('#tokenEndpointAuthSigningAlg', this.el).hide();
@ -277,7 +310,7 @@ var DynRegEditView = Backbone.View.extend({
/**
* Set up the form based on the JWK Set selector
*/
toggleJWKSetType:function() {
toggleJWKSetType: function() {
var jwkSelector = $('#jwkSelector input:radio', this.el).filter(':checked').val();
if (jwkSelector == 'URI') {
@ -293,13 +326,13 @@ var DynRegEditView = Backbone.View.extend({
},
disableUnsupportedJOSEItems:function(serverSupported, query) {
disableUnsupportedJOSEItems: function(serverSupported, query) {
var supported = ['default'];
if (serverSupported) {
supported = _.union(supported, serverSupported);
}
$(query, this.$el).each(function(idx) {
if(_.contains(supported, $(this).val())) {
if (_.contains(supported, $(this).val())) {
$(this).prop('disabled', false);
} else {
$(this).prop('disabled', true);
@ -308,8 +341,10 @@ var DynRegEditView = Backbone.View.extend({
},
// returns "null" if given the value "default" as a string, otherwise returns input value. useful for parsing the JOSE algorithm dropdowns
defaultToNull:function(value) {
// returns "null" if given the value "default" as a string,
// otherwise returns input value. useful for parsing the JOSE
// algorithm dropdowns
defaultToNull: function(value) {
if (value == 'default') {
return null;
} else {
@ -318,7 +353,7 @@ var DynRegEditView = Backbone.View.extend({
},
// returns "null" if the given value is falsy
emptyToNull:function(value) {
emptyToNull: function(value) {
if (value) {
return value;
} else {
@ -327,7 +362,7 @@ var DynRegEditView = Backbone.View.extend({
},
// maps from a form-friendly name to the real grant parameter name
grantMap:{
grantMap: {
'authorization_code': 'authorization_code',
'password': 'password',
'implicit': 'implicit',
@ -336,8 +371,9 @@ var DynRegEditView = Backbone.View.extend({
'refresh_token': 'refresh_token'
},
// maps from a form-friendly name to the real response type parameter name
responseMap:{
// maps from a form-friendly name to the real response type
// parameter name
responseMap: {
'code': 'code',
'token': 'token',
'idtoken': 'id_token',
@ -347,7 +383,7 @@ var DynRegEditView = Backbone.View.extend({
'code-token-idtoken': 'code token id_token'
},
saveClient:function (e) {
saveClient: function(e) {
e.preventDefault();
$('.control-group').removeClass('error');
@ -362,7 +398,7 @@ var DynRegEditView = Backbone.View.extend({
// build the grant type object
var grantTypes = [];
$.each(this.grantMap, function(index,type) {
$.each(this.grantMap, function(index, type) {
if ($('#grantTypes-' + index).is(':checked')) {
grantTypes.push(type);
}
@ -370,7 +406,7 @@ var DynRegEditView = Backbone.View.extend({
// build the response type object
var responseTypes = [];
$.each(this.responseMap, function(index,type) {
$.each(this.responseMap, function(index, type) {
if ($('#responseTypes-' + index).is(':checked')) {
responseTypes.push(type);
}
@ -384,12 +420,13 @@ var DynRegEditView = Backbone.View.extend({
}
}
// make sure that the subject identifier is consistent with the redirect URIs
// make sure that the subject identifier is consistent with the
// redirect URIs
var subjectType = $('#subjectType input').filter(':checked').val();
var redirectUris = this.redirectUrisCollection.pluck("item");
var sectorIdentifierUri = $('#sectorIdentifierUri input').val();
if (subjectType == 'PAIRWISE' && redirectUris.length > 1 && sectorIdentifierUri == '') {
//Display an alert with an error message
// Display an alert with an error message
app.errorHandlerView.showErrorMessage($.t("client.client-form.error.consistency"), $.t("client.client-form.error.pairwise-sector"));
return false;
@ -418,9 +455,9 @@ var DynRegEditView = Backbone.View.extend({
}
var attrs = {
client_name:this.emptyToNull($('#clientName input').val()),
client_name: this.emptyToNull($('#clientName input').val()),
redirect_uris: redirectUris,
logo_uri:this.emptyToNull($('#logoUri input').val()),
logo_uri: this.emptyToNull($('#logoUri input').val()),
grant_types: grantTypes,
scope: scopes,
client_secret: null, // never send a client secret
@ -457,7 +494,7 @@ var DynRegEditView = Backbone.View.extend({
};
// set all empty strings to nulls
for (var key in attrs) {
for ( var key in attrs) {
if (attrs[key] === "") {
attrs[key] = null;
}
@ -465,31 +502,42 @@ var DynRegEditView = Backbone.View.extend({
var _self = this;
this.model.save(attrs, {
success:function () {
success: function() {
// switch to an "edit" view
app.navigate('dev/dynreg/edit', {trigger: true});
app.navigate('dev/dynreg/edit', {
trigger: true
});
_self.remove();
var userInfo = getUserInfo();
var contacts = _self.model.get("contacts");
if (userInfo != null && userInfo.email != null && ! _.contains(contacts, userInfo.email)) {
if (userInfo != null && userInfo.email != null && !_.contains(contacts, userInfo.email)) {
contacts.push(userInfo.email);
}
_self.model.set({
contacts: contacts
}, { silent: true });
}, {
silent: true
});
if (_self.model.get("jwks")) {
_self.model.set({
jwksType: "VAL"
}, { silent: true });
}, {
silent: true
});
} else {
_self.model.set({
jwksType: "URI"
}, { silent: true });
}, {
silent: true
});
}
var view = new DynRegEditView({model: _self.model, systemScopeList: _self.options.systemScopeList});
var view = new DynRegEditView({
model: _self.model,
systemScopeList: _self.options.systemScopeList
});
view.load(function() {
// reload
@ -497,14 +545,20 @@ var DynRegEditView = Backbone.View.extend({
view.delegateEvents();
});
},
error:app.errorHandlerView.handleError({log: "An error occurred when saving a client"})
error: app.errorHandlerView.handleError({
log: "An error occurred when saving a client"
})
});
return false;
},
render:function() {
var data = {client: this.model.toJSON(), userInfo: getUserInfo(), heartMode: heartMode};
render: function() {
var data = {
client: this.model.toJSON(),
userInfo: getUserInfo(),
heartMode: heartMode
};
$(this.el).html(this.template(data));
this.listWidgetViews = [];
@ -512,94 +566,115 @@ var DynRegEditView = Backbone.View.extend({
var _self = this;
// build and bind registered redirect URI collection and view
_.each(this.model.get("redirect_uris"), function (redirectUri) {
_self.redirectUrisCollection.add(new URIModel({item:redirectUri}));
_.each(this.model.get("redirect_uris"), function(redirectUri) {
_self.redirectUrisCollection.add(new URIModel({
item: redirectUri
}));
});
var redirectUriView = new ListWidgetView({
type:'uri',
type: 'uri',
placeholder: 'https://',
helpBlockText: $.t('client.client-form.redirect-uris-help'),
collection: this.redirectUrisCollection});
$("#redirectUris .controls",this.el).html(redirectUriView.render().el);
collection: this.redirectUrisCollection
});
$("#redirectUris .controls", this.el).html(redirectUriView.render().el);
this.listWidgetViews.push(redirectUriView);
// build and bind scopes
var scopes = this.model.get("scope");
var scopeSet = scopes ? scopes.split(" ") : [];
_.each(scopeSet, function (scope) {
_self.scopeCollection.add(new Backbone.Model({item:scope}));
_.each(scopeSet, function(scope) {
_self.scopeCollection.add(new Backbone.Model({
item: scope
}));
});
var scopeView = new ListWidgetView({
placeholder: $.t('client.client-form.scope-placeholder'),
autocomplete: _.uniq(_.flatten(this.options.systemScopeList.unrestrictedScopes().pluck("value"))),
helpBlockText: $.t('client.client-form.scope-help'),
collection: this.scopeCollection});
$("#scope .controls",this.el).html(scopeView.render().el);
collection: this.scopeCollection
});
$("#scope .controls", this.el).html(scopeView.render().el);
this.listWidgetViews.push(scopeView);
// build and bind contacts
_.each(this.model.get('contacts'), function (contact) {
_self.contactsCollection.add(new Backbone.Model({item:contact}));
_.each(this.model.get('contacts'), function(contact) {
_self.contactsCollection.add(new Backbone.Model({
item: contact
}));
});
var contactView = new ListWidgetView({
placeholder: $.t('client.client-form.contacts-placeholder'),
helpBlockText: $.t('client.client-form.contacts-help'),
collection: this.contactsCollection});
collection: this.contactsCollection
});
$("#contacts .controls div", this.el).html(contactView.render().el);
this.listWidgetViews.push(contactView);
// build and bind post-logout redirect URIs
_.each(this.model.get('post_logout_redirect_uris'), function(postLogoutRedirectUri) {
_self.postLogoutRedirectUrisCollection.add(new URIModel({item:postLogoutRedirectUri}));
_self.postLogoutRedirectUrisCollection.add(new URIModel({
item: postLogoutRedirectUri
}));
});
var postLogoutRedirectUrisView = new ListWidgetView({
type: 'uri',
placeholder: 'https://',
helpBlockText: $.t('client.client-form.post-logout-help'),
collection: this.postLogoutRedirectUrisCollection});
collection: this.postLogoutRedirectUrisCollection
});
$('#postLogoutRedirectUris .controls', this.el).html(postLogoutRedirectUrisView.render().el);
this.listWidgetViews.push(postLogoutRedirectUrisView);
// build and bind claims redirect URIs
_.each(this.model.get('claimsRedirectUris'), function(claimsRedirectUri) {
_self.claimsRedirectUrisCollection.add(new URIModel({item:claimsRedirectUri}));
_self.claimsRedirectUrisCollection.add(new URIModel({
item: claimsRedirectUri
}));
});
var claimsRedirectUrisView = new ListWidgetView({
type: 'uri',
placeholder: 'https://',
helpBlockText: $.t('client.client-form.claims-redirect-uris-help'),
collection: this.claimsRedirectUrisCollection});
collection: this.claimsRedirectUrisCollection
});
$('#claimsRedirectUris .controls', this.el).html(claimsRedirectUrisView.render().el);
this.listWidgetViews.push(claimsRedirectUrisView);
// build and bind request URIs
_.each(this.model.get('request_uris'), function (requestUri) {
_self.requestUrisCollection.add(new URIModel({item:requestUri}));
_.each(this.model.get('request_uris'), function(requestUri) {
_self.requestUrisCollection.add(new URIModel({
item: requestUri
}));
});
var requestUriView = new ListWidgetView({
type: 'uri',
placeholder: 'https://',
helpBlockText: $.t('client.client-form.request-uri-help'),
collection: this.requestUrisCollection});
collection: this.requestUrisCollection
});
$('#requestUris .controls', this.el).html(requestUriView.render().el);
this.listWidgetViews.push(requestUriView);
// build and bind default ACR values
_.each(this.model.get('default_acr_values'), function (defaultAcrValue) {
_self.defaultAcrValuesCollection.add(new Backbone.Model({item:defaultAcrValue}));
_.each(this.model.get('default_acr_values'), function(defaultAcrValue) {
_self.defaultAcrValuesCollection.add(new Backbone.Model({
item: defaultAcrValue
}));
});
var defaultAcrView = new ListWidgetView({
placeholder: $.t('client.client-form.acr-values-placeholder'),
// TODO: autocomplete from spec
helpBlockText: $.t('client.client-form.acr-values-help'),
collection: this.defaultAcrValuesCollection});
collection: this.defaultAcrValuesCollection
});
$('#defaultAcrValues .controls', this.el).html(defaultAcrView.render().el);
this.listWidgetViews.push(defaultAcrView);
@ -623,23 +698,29 @@ var DynRegEditView = Backbone.View.extend({
content: $.t('common.not-yet-implemented-content')
});
$(this.el).i18n();
return this;
}
});
ui.routes.push({path: "dev/dynreg", name: "dynReg", callback:
function() {
ui.routes.push({
path: "dev/dynreg",
name: "dynReg",
callback: function() {
this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([
{text:$.t('admin.home'), href:""},
{text:$.t('admin.self-service-client'), href:"manage/#dev/dynreg"}
]);
this.breadCrumbView.collection.add([{
text: $.t('admin.home'),
href: ""
}, {
text: $.t('admin.self-service-client'),
href: "manage/#dev/dynreg"
}]);
var view = new DynRegRootView({systemScopeList: this.systemScopeList});
var view = new DynRegRootView({
systemScopeList: this.systemScopeList
});
this.updateSidebar('dev/dynreg');
@ -652,20 +733,30 @@ ui.routes.push({path: "dev/dynreg", name: "dynReg", callback:
}
});
ui.routes.push({path: "dev/dynreg/new", name: "newDynReg", callback:
function() {
ui.routes.push({
path: "dev/dynreg/new",
name: "newDynReg",
callback: function() {
this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([
{text:$.t('admin.home'), href:""},
{text:$.t('admin.self-service-client'), href:"manage/#dev/dynreg"},
{text:$.t('dynreg.new-client'), href:"manage/#dev/dynreg/new"}
]);
this.breadCrumbView.collection.add([{
text: $.t('admin.home'),
href: ""
}, {
text: $.t('admin.self-service-client'),
href: "manage/#dev/dynreg"
}, {
text: $.t('dynreg.new-client'),
href: "manage/#dev/dynreg/new"
}]);
this.updateSidebar('dev/dynreg');
var client = new DynRegClient();
var view = new DynRegEditView({model: client, systemScopeList:this.systemScopeList});
var view = new DynRegEditView({
model: client,
systemScopeList: this.systemScopeList
});
view.load(function() {
@ -677,26 +768,30 @@ ui.routes.push({path: "dev/dynreg/new", name: "newDynReg", callback:
if (heartMode) {
client.set({
require_auth_time:true,
default_max_age:60000,
require_auth_time: true,
default_max_age: 60000,
scope: _.uniq(_.flatten(app.systemScopeList.defaultUnrestrictedScopes().pluck("value"))).join(" "),
token_endpoint_auth_method: 'private_key_jwt',
grant_types: ["authorization_code"],
response_types: ["code"],
subject_type: "public",
contacts: contacts
}, { silent: true });
}, {
silent: true
});
} else {
client.set({
require_auth_time:true,
default_max_age:60000,
require_auth_time: true,
default_max_age: 60000,
scope: _.uniq(_.flatten(app.systemScopeList.defaultUnrestrictedScopes().pluck("value"))).join(" "),
token_endpoint_auth_method: 'client_secret_basic',
grant_types: ["authorization_code"],
response_types: ["code"],
subject_type: "public",
contacts: contacts
}, { silent: true });
}, {
silent: true
});
}
$('#content').html(view.render().el);
@ -708,20 +803,28 @@ ui.routes.push({path: "dev/dynreg/new", name: "newDynReg", callback:
}
});
ui.routes.push({path: "dev/dynreg/edit", name: "editDynReg", callback:
function() {
ui.routes.push({
path: "dev/dynreg/edit",
name: "editDynReg",
callback: function() {
this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([
{text:$.t('admin.home'), href:""},
{text:$.t('admin.self-service-client'), href:"manage/#dev/dynreg"},
{text:$.t('dynreg.edit-existing'), href:"manage/#dev/dynreg/edit"}
]);
this.breadCrumbView.collection.add([{
text: $.t('admin.home'),
href: ""
}, {
text: $.t('admin.self-service-client'),
href: "manage/#dev/dynreg"
}, {
text: $.t('dynreg.edit-existing'),
href: "manage/#dev/dynreg/edit"
}]);
this.updateSidebar('dev/dynreg');
setPageTitle($.t('dynreg.edit-existing'));
// note that this doesn't actually load the client, that's supposed to happen elsewhere...
// note that this doesn't actually load the client, that's supposed to
// happen elsewhere...
}
});

View File

@ -17,56 +17,63 @@
var ApprovedSiteModel = Backbone.Model.extend({
idAttribute: 'id',
initialize: function() { },
initialize: function() {
},
urlRoot: 'api/approved'
});
var ApprovedSiteCollection = Backbone.Collection.extend({
initialize: function() { },
initialize: function() {
},
model: ApprovedSiteModel,
url: 'api/approved'
});
var ApprovedSiteListView = Backbone.View.extend({
tagName: 'span',
initialize:function(options) {
initialize: function(options) {
this.options = options;
},
load:function(callback) {
if (this.model.isFetched &&
this.options.clientList.isFetched &&
this.options.systemScopeList.isFetched) {
load: function(callback) {
if (this.model.isFetched && this.options.clientList.isFetched && this.options.systemScopeList.isFetched) {
callback();
return;
}
$('#loadingbox').sheet('show');
$('#loading').html(
'<span class="label" id="loading-grants">' + $.t('grant.grant-table.approved-sites') + '</span> ' +
'<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' +
'<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> '
);
$('#loading').html('<span class="label" id="loading-grants">' + $.t('grant.grant-table.approved-sites') + '</span> ' + '<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' + '<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ');
$.when(this.model.fetchIfNeeded({success:function(e) {$('#loading-grants').addClass('label-success');}, error:app.errorHandlerView.handleError()}),
this.options.clientList.fetchIfNeeded({success:function(e) {$('#loading-clients').addClass('label-success');}, error:app.errorHandlerView.handleError()}),
this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}, error:app.errorHandlerView.handleError()}))
.done(function() {
$.when(this.model.fetchIfNeeded({
success: function(e) {
$('#loading-grants').addClass('label-success');
},
error: app.errorHandlerView.handleError()
}), this.options.clientList.fetchIfNeeded({
success: function(e) {
$('#loading-clients').addClass('label-success');
},
error: app.errorHandlerView.handleError()
}), this.options.systemScopeList.fetchIfNeeded({
success: function(e) {
$('#loading-scopes').addClass('label-success');
},
error: app.errorHandlerView.handleError()
})).done(function() {
$('#loadingbox').sheet('hide');
callback();
});
},
events: {
"click .refresh-table":"refreshTable"
"click .refresh-table": "refreshTable"
},
render:function (eventName) {
render: function(eventName) {
$(this.el).html($('#tmpl-grant-table').html());
var approvedSiteCount = 0;
@ -79,7 +86,11 @@ var ApprovedSiteListView = Backbone.View.extend({
if (client != null) {
var view = new ApprovedSiteView({model: approvedSite, client: client, systemScopeList: this.options.systemScopeList});
var view = new ApprovedSiteView({
model: approvedSite,
client: client,
systemScopeList: this.options.systemScopeList
});
view.parentView = _self;
$('#grant-table', this.el).append(view.render().el);
approvedSiteCount = approvedSiteCount + 1;
@ -93,7 +104,7 @@ var ApprovedSiteListView = Backbone.View.extend({
return this;
},
togglePlaceholder:function() {
togglePlaceholder: function() {
// count entries
if (this.model.length > 0) {
$('#grant-table', this.el).show();
@ -105,20 +116,28 @@ var ApprovedSiteListView = Backbone.View.extend({
},
refreshTable:function(e) {
refreshTable: function(e) {
e.preventDefault();
var _self = this;
$('#loadingbox').sheet('show');
$('#loading').html(
'<span class="label" id="loading-grants">' + $.t('grant.grant-table.approved-sites') + '</span> ' +
'<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' +
'<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> '
);
$('#loading').html('<span class="label" id="loading-grants">' + $.t('grant.grant-table.approved-sites') + '</span> ' + '<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' + '<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ');
$.when(this.model.fetch({success:function(e) {$('#loading-grants').addClass('label-success');}, error:app.errorHandlerView.handleError()}),
this.options.clientList.fetch({success:function(e) {$('#loading-clients').addClass('label-success');}, error:app.errorHandlerView.handleError()}),
this.options.systemScopeList.fetch({success:function(e) {$('#loading-scopes').addClass('label-success');}, error:app.errorHandlerView.handleError()}))
.done(function() {
$.when(this.model.fetch({
success: function(e) {
$('#loading-grants').addClass('label-success');
},
error: app.errorHandlerView.handleError()
}), this.options.clientList.fetch({
success: function(e) {
$('#loading-clients').addClass('label-success');
},
error: app.errorHandlerView.handleError()
}), this.options.systemScopeList.fetch({
success: function(e) {
$('#loading-scopes').addClass('label-success');
},
error: app.errorHandlerView.handleError()
})).done(function() {
$('#loadingbox').sheet('hide');
_self.render();
});
@ -178,7 +197,7 @@ var ApprovedSiteView = Backbone.View.extend({
var hoverTimeoutDate = "";
if (timeoutDate == null) {
displayTimeoutDate = $.t('grant.grant-table.never');
} else if(moment(timeoutDate).isValid()) {
} else if (moment(timeoutDate).isValid()) {
timeoutDate = moment(timeoutDate);
if (moment().diff(timeoutDate, 'months') < 6) {
displayTimeoutDate = timeoutDate.fromNow();
@ -188,21 +207,38 @@ var ApprovedSiteView = Backbone.View.extend({
hoverTimeoutDate = timeoutDate.format("LLL");
}
var formattedDate = {
displayCreationDate: displayCreationDate,
hoverCreationDate: hoverCreationDate,
displayAccessDate: displayAccessDate,
hoverAccessDate: hoverAccessDate,
displayTimeoutDate: displayTimeoutDate,
hoverTimeoutDate: hoverTimeoutDate
};
var formattedDate = {displayCreationDate: displayCreationDate, hoverCreationDate: hoverCreationDate,
displayAccessDate: displayAccessDate, hoverAccessDate: hoverAccessDate,
displayTimeoutDate: displayTimeoutDate, hoverTimeoutDate: hoverTimeoutDate};
var json = {grant: this.model.toJSON(), client: this.options.client.toJSON(), formattedDate: formattedDate};
var json = {
grant: this.model.toJSON(),
client: this.options.client.toJSON(),
formattedDate: formattedDate
};
this.$el.html(this.template(json));
$('.scope-list', this.el).html(this.scopeTemplate({scopes: this.model.get('allowedScopes'), systemScopes: this.options.systemScopeList}));
$('.scope-list', this.el).html(this.scopeTemplate({
scopes: this.model.get('allowedScopes'),
systemScopes: this.options.systemScopeList
}));
$('.client-more-info-block', this.el).html(this.moreInfoTemplate({client: this.options.client.toJSON()}));
$('.client-more-info-block', this.el).html(this.moreInfoTemplate({
client: this.options.client.toJSON()
}));
this.$('.dynamically-registered').tooltip({title: $.t('grant.grant-table.dynamically-registered')});
this.$('.tokens').tooltip({title: $.t('grant.grant-table.active-tokens')});
this.$('.dynamically-registered').tooltip({
title: $.t('grant.grant-table.dynamically-registered')
});
this.$('.tokens').tooltip({
title: $.t('grant.grant-table.active-tokens')
});
$(this.el).i18n();
return this;
},
@ -212,22 +248,23 @@ var ApprovedSiteView = Backbone.View.extend({
'click .toggleMoreInformation': 'toggleMoreInformation'
},
deleteApprovedSite:function(e) {
deleteApprovedSite: function(e) {
e.preventDefault();
if (confirm("Are you sure you want to revoke access to this site?")) {
var self = this;
this.model.destroy({
dataType: false, processData: false,
success:function () {
self.$el.fadeTo("fast", 0.00, function () { //fade
$(this).slideUp("fast", function () { //slide up
$(this).remove(); //then remove from the DOM
dataType: false,
processData: false,
success: function() {
self.$el.fadeTo("fast", 0.00, function() { // fade
$(this).slideUp("fast", function() { // slide up
$(this).remove(); // then remove from the DOM
self.parentView.togglePlaceholder();
});
});
},
error:app.errorHandlerView.handleError()
error: app.errorHandlerView.handleError()
});
this.parentView.delegateEvents();
@ -236,7 +273,7 @@ var ApprovedSiteView = Backbone.View.extend({
return false;
},
toggleMoreInformation:function(e) {
toggleMoreInformation: function(e) {
e.preventDefault();
if ($('.moreInformation', this.el).is(':visible')) {
// hide it
@ -252,30 +289,38 @@ var ApprovedSiteView = Backbone.View.extend({
}
},
close:function() {
close: function() {
$(this.el).unbind();
$(this.el).empty();
}
});
ui.routes.push({path: "user/approved", name: "approvedSites", callback:
ui.routes.push({
path: "user/approved",
name: "approvedSites",
callback:
function() {
this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([
{text:$.t('admin.home'), href:""},
{text:$.t('grant.manage-approved-sites'), href:"manage/#user/approve"}
]);
this.breadCrumbView.collection.add([{
text: $.t('admin.home'),
href: ""
}, {
text: $.t('grant.manage-approved-sites'),
href: "manage/#user/approve"
}]);
this.updateSidebar('user/approved');
var view = new ApprovedSiteListView({model:this.approvedSiteList, clientList: this.clientList, systemScopeList: this.systemScopeList});
view.load(
function(collection, response, options) {
var view = new ApprovedSiteListView({
model: this.approvedSiteList,
clientList: this.clientList,
systemScopeList: this.systemScopeList
});
view.load(function(collection, response, options) {
$('#content').html(view.render().el);
setPageTitle($.t('grant.manage-approved-sites'));
}
);
});
}
});

View File

@ -14,18 +14,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
ui.routes.push({path: "user/profile", name: "profile", callback:
function() {
ui.routes.push({
path: "user/profile",
name: "profile",
callback: function() {
this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([
{text:$.t('admin.home'), href:""},
{text:$.t('admin.user-profile.show'), href:"manage/#user/profile"}
]);
this.breadCrumbView.collection.add([{
text: $.t('admin.home'),
href: ""
}, {
text: $.t('admin.user-profile.show'),
href: "manage/#user/profile"
}]);
this.updateSidebar('user/profile');
var view = new UserProfileView({model: getUserInfo()});
var view = new UserProfileView({
model: getUserInfo()
});
$('#content').html(view.render().el);
setPageTitle($.t('admin.user-profile.show'));

View File

@ -17,28 +17,28 @@
var ResRegClient = Backbone.Model.extend({
idAttribute: "client_id",
defaults:{
client_id:null,
client_secret:null,
client_name:null,
client_uri:null,
logo_uri:null,
contacts:[],
tos_uri:null,
token_endpoint_auth_method:null,
scope:null,
policy_uri:null,
defaults: {
client_id: null,
client_secret: null,
client_name: null,
client_uri: null,
logo_uri: null,
contacts: [],
tos_uri: null,
token_endpoint_auth_method: null,
scope: null,
policy_uri: null,
jwks_uri:null,
jwks:null,
jwksType:'URI',
jwks_uri: null,
jwks: null,
jwksType: 'URI',
application_type:null,
registration_access_token:null,
registration_client_uri:null
application_type: null,
registration_access_token: null,
registration_client_uri: null
},
sync: function(method, model, options){
sync: function(method, model, options) {
if (model.get('registration_access_token')) {
var headers = options.headers ? options.headers : {};
headers['Authorization'] = 'Bearer ' + model.get('registration_access_token');
@ -48,7 +48,7 @@ var ResRegClient = Backbone.Model.extend({
return this.constructor.__super__.sync(method, model, options);
},
urlRoot:'resource'
urlRoot: 'resource'
});
@ -56,17 +56,17 @@ var ResRegRootView = Backbone.View.extend({
tagName: 'span',
initialize:function(options) {
initialize: function(options) {
this.options = options;
},
events:{
"click #newreg":"newReg",
"click #editreg":"editReg"
events: {
"click #newreg": "newReg",
"click #editreg": "editReg"
},
load:function(callback) {
load: function(callback) {
if (this.options.systemScopeList.isFetched) {
callback();
return;
@ -75,26 +75,32 @@ var ResRegRootView = Backbone.View.extend({
$('#loadingbox').sheet('show');
$('#loading').html('<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ');
$.when(this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}, error:app.errorHandlerView.handleError()}))
.done(function() {
$.when(this.options.systemScopeList.fetchIfNeeded({
success: function(e) {
$('#loading-scopes').addClass('label-success');
},
error: app.errorHandlerView.handleError()
})).done(function() {
$('#loadingbox').sheet('hide');
callback();
});
},
render:function() {
render: function() {
$(this.el).html($('#tmpl-rsreg').html());
$(this.el).i18n();
return this;
},
newReg:function(e) {
newReg: function(e) {
e.preventDefault();
this.remove();
app.navigate('dev/resource/new', {trigger: true});
app.navigate('dev/resource/new', {
trigger: true
});
},
editReg:function(e) {
editReg: function(e) {
e.preventDefault();
var clientId = $('#clientId').val();
var token = $('#regtoken').val();
@ -112,24 +118,35 @@ var ResRegRootView = Backbone.View.extend({
if (client.get("jwks")) {
client.set({
jwksType: "VAL"
}, { silent: true });
}, {
silent: true
});
} else {
client.set({
jwksType: "URI"
}, { silent: true });
}, {
silent: true
});
}
var view = new ResRegEditView({model: client, systemScopeList: app.systemScopeList});
var view = new ResRegEditView({
model: client,
systemScopeList: app.systemScopeList
});
view.load(function() {
$('#content').html(view.render().el);
view.delegateEvents();
setPageTitle($.t('rsreg.new'));
app.navigate('dev/resource/edit', {trigger: true});
app.navigate('dev/resource/edit', {
trigger: true
});
self.remove();
});
},
error:app.errorHandlerView.handleError({message: $.t('dynreg.invalid-access-token')})
error: app.errorHandlerView.handleError({
message: $.t('dynreg.invalid-access-token')
})
});
}
@ -139,7 +156,7 @@ var ResRegEditView = Backbone.View.extend({
tagName: 'span',
initialize:function(options) {
initialize: function(options) {
this.options = options;
if (!this.template) {
this.template = _.template($('#tmpl-rsreg-resource-form').html());
@ -154,7 +171,7 @@ var ResRegEditView = Backbone.View.extend({
this.listWidgetViews = [];
},
load:function(callback) {
load: function(callback) {
if (this.options.systemScopeList.isFetched) {
callback();
return;
@ -163,40 +180,49 @@ var ResRegEditView = Backbone.View.extend({
$('#loadingbox').sheet('show');
$('#loading').html('<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ');
$.when(this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}, error:app.errorHandlerView.handleError()}))
.done(function() {
$.when(this.options.systemScopeList.fetchIfNeeded({
success: function(e) {
$('#loading-scopes').addClass('label-success');
},
error: app.errorHandlerView.handleError()
})).done(function() {
$('#loadingbox').sheet('hide');
callback();
});
},
events:{
"click .btn-save":"saveClient",
"click .btn-cancel":"cancel",
"click .btn-delete":"deleteClient",
"change #logoUri input":"previewLogo",
"change #tokenEndpointAuthMethod input:radio":"toggleClientCredentials",
"change #jwkSelector input:radio":"toggleJWKSetType"
events: {
"click .btn-save": "saveClient",
"click .btn-cancel": "cancel",
"click .btn-delete": "deleteClient",
"change #logoUri input": "previewLogo",
"change #tokenEndpointAuthMethod input:radio": "toggleClientCredentials",
"change #jwkSelector input:radio": "toggleJWKSetType"
},
cancel:function(e) {
cancel: function(e) {
e.preventDefault();
app.navigate('dev/resource', {trigger: true});
app.navigate('dev/resource', {
trigger: true
});
},
deleteClient:function (e) {
deleteClient: function(e) {
e.preventDefault();
if (confirm($.t('client.client-table.confirm'))) {
var self = this;
this.model.destroy({
dataType: false, processData: false,
success:function () {
dataType: false,
processData: false,
success: function() {
self.remove();
app.navigate('dev/resource', {trigger: true});
app.navigate('dev/resource', {
trigger: true
});
},
error:app.errorHandlerView.handleError()
error: app.errorHandlerView.handleError()
});
}
@ -204,27 +230,29 @@ var ResRegEditView = Backbone.View.extend({
return false;
},
previewLogo:function() {
previewLogo: function() {
if ($('#logoUri input', this.el).val()) {
$('#logoPreview', this.el).empty();
$('#logoPreview', this.el).attr('src', $('#logoUri input', this.el).val());
} else {
//$('#logoBlock', this.el).hide();
// $('#logoBlock', this.el).hide();
$('#logoPreview', this.el).attr('src', 'resources/images/logo_placeholder.gif');
}
},
/**
* Set up the form based on the current state of the tokenEndpointAuthMethod parameter
* Set up the form based on the current state of the tokenEndpointAuthMethod
* parameter
*
* @param event
*/
toggleClientCredentials:function() {
toggleClientCredentials: function() {
var tokenEndpointAuthMethod = $('#tokenEndpointAuthMethod input', this.el).filter(':checked').val();
// show or hide the signing algorithm method depending on what's selected
if (tokenEndpointAuthMethod == 'private_key_jwt'
|| tokenEndpointAuthMethod == 'client_secret_jwt') {
// show or hide the signing algorithm method depending on what's
// selected
if (tokenEndpointAuthMethod == 'private_key_jwt' || tokenEndpointAuthMethod == 'client_secret_jwt') {
$('#tokenEndpointAuthSigningAlg', this.el).show();
} else {
$('#tokenEndpointAuthSigningAlg', this.el).hide();
@ -234,7 +262,7 @@ var ResRegEditView = Backbone.View.extend({
/**
* Set up the form based on the JWK Set selector
*/
toggleJWKSetType:function() {
toggleJWKSetType: function() {
var jwkSelector = $('#jwkSelector input:radio', this.el).filter(':checked').val();
if (jwkSelector == 'URI') {
@ -250,13 +278,13 @@ var ResRegEditView = Backbone.View.extend({
},
disableUnsupportedJOSEItems:function(serverSupported, query) {
disableUnsupportedJOSEItems: function(serverSupported, query) {
var supported = ['default'];
if (serverSupported) {
supported = _.union(supported, serverSupported);
}
$(query, this.$el).each(function(idx) {
if(_.contains(supported, $(this).val())) {
if (_.contains(supported, $(this).val())) {
$(this).prop('disabled', false);
} else {
$(this).prop('disabled', true);
@ -265,8 +293,10 @@ var ResRegEditView = Backbone.View.extend({
},
// returns "null" if given the value "default" as a string, otherwise returns input value. useful for parsing the JOSE algorithm dropdowns
defaultToNull:function(value) {
// returns "null" if given the value "default" as a string,
// otherwise returns input value. useful for parsing the JOSE
// algorithm dropdowns
defaultToNull: function(value) {
if (value == 'default') {
return null;
} else {
@ -274,7 +304,7 @@ var ResRegEditView = Backbone.View.extend({
}
},
saveClient:function (e) {
saveClient: function(e) {
e.preventDefault();
$('.control-group').removeClass('error');
@ -310,7 +340,7 @@ var ResRegEditView = Backbone.View.extend({
} catch (e) {
console.log("An error occurred when parsing the JWK Set");
//Display an alert with an error message
// Display an alert with an error message
app.errorHandlerView.showErrorMessage($.t("client.client-form.error.jwk-set"), $.t("client.client-form.error.jwk-set-parse"));
return false;
}
@ -320,8 +350,8 @@ var ResRegEditView = Backbone.View.extend({
}
var attrs = {
client_name:$('#clientName input').val(),
logo_uri:$('#logoUri input').val(),
client_name: $('#clientName input').val(),
logo_uri: $('#logoUri input').val(),
scope: scopes,
client_secret: null, // never send a client secret
tos_uri: $('#tosUri input').val(),
@ -336,7 +366,7 @@ var ResRegEditView = Backbone.View.extend({
};
// set all empty strings to nulls
for (var key in attrs) {
for ( var key in attrs) {
if (attrs[key] === "") {
attrs[key] = null;
}
@ -344,22 +374,31 @@ var ResRegEditView = Backbone.View.extend({
var _self = this;
this.model.save(attrs, {
success:function () {
success: function() {
// switch to an "edit" view
app.navigate('dev/resource/edit', {trigger: true});
app.navigate('dev/resource/edit', {
trigger: true
});
_self.remove();
if (_self.model.get("jwks")) {
_self.model.set({
jwksType: "VAL"
}, { silent: true });
}, {
silent: true
});
} else {
_self.model.set({
jwksType: "URI"
}, { silent: true });
}, {
silent: true
});
}
var view = new ResRegEditView({model: _self.model, systemScopeList: _self.options.systemScopeList});
var view = new ResRegEditView({
model: _self.model,
systemScopeList: _self.options.systemScopeList
});
view.load(function() {
// reload
@ -367,14 +406,17 @@ var ResRegEditView = Backbone.View.extend({
view.delegateEvents();
});
},
error:app.errorHandlerView.handleError()
error: app.errorHandlerView.handleError()
});
return false;
},
render:function() {
$(this.el).html(this.template({client: this.model.toJSON(), userInfo: getUserInfo()}));
render: function() {
$(this.el).html(this.template({
client: this.model.toJSON(),
userInfo: getUserInfo()
}));
this.listWidgetViews = [];
@ -383,31 +425,36 @@ var ResRegEditView = Backbone.View.extend({
// build and bind scopes
var scopes = this.model.get("scope");
var scopeSet = scopes ? scopes.split(" ") : [];
_.each(scopeSet, function (scope) {
_self.scopeCollection.add(new Backbone.Model({item:scope}));
_.each(scopeSet, function(scope) {
_self.scopeCollection.add(new Backbone.Model({
item: scope
}));
});
var scopeView = new ListWidgetView({
placeholder: $.t('client.client-form.scope-placeholder'),
autocomplete: _.uniq(_.flatten(this.options.systemScopeList.unrestrictedScopes().pluck("value"))),
helpBlockText: $.t('rsreg.client-form.scope-help'),
collection: this.scopeCollection});
$("#scope .controls",this.el).html(scopeView.render().el);
collection: this.scopeCollection
});
$("#scope .controls", this.el).html(scopeView.render().el);
this.listWidgetViews.push(scopeView);
// build and bind contacts
_.each(this.model.get('contacts'), function (contact) {
_self.contactsCollection.add(new Backbone.Model({item:contact}));
_.each(this.model.get('contacts'), function(contact) {
_self.contactsCollection.add(new Backbone.Model({
item: contact
}));
});
var contactView = new ListWidgetView({
placeholder: $.t('client.client-form.contacts-placeholder'),
helpBlockText: $.t('client.client-form.contacts-help'),
collection: this.contactsCollection});
collection: this.contactsCollection
});
$("#contacts .controls", this.el).html(contactView.render().el);
this.listWidgetViews.push(contactView);
this.toggleClientCredentials();
this.previewLogo();
this.toggleJWKSetType();
@ -421,25 +468,31 @@ var ResRegEditView = Backbone.View.extend({
content: $.t('common.not-yet-implemented-content')
});
$(this.el).i18n();
return this;
}
});
ui.routes.push({path: "dev/resource", name: "resReg", callback:
function() {
ui.routes.push({
path: "dev/resource",
name: "resReg",
callback: function() {
this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([
{text:$.t('admin.home'), href:""},
{text:$.t('admin.self-service-resource'), href:"manage/#dev/resource"}
]);
this.breadCrumbView.collection.add([{
text: $.t('admin.home'),
href: ""
}, {
text: $.t('admin.self-service-resource'),
href: "manage/#dev/resource"
}]);
this.updateSidebar('dev/resource');
var view = new ResRegRootView({systemScopeList: this.systemScopeList});
var view = new ResRegRootView({
systemScopeList: this.systemScopeList
});
view.load(function() {
$('#content').html(view.render().el);
@ -449,20 +502,30 @@ ui.routes.push({path: "dev/resource", name: "resReg", callback:
}
});
ui.routes.push({path: "dev/resource/new", name: "newResReg", callback:
function() {
ui.routes.push({
path: "dev/resource/new",
name: "newResReg",
callback: function() {
this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([
{text:$.t('admin.home'), href:""},
{text:$.t('admin.self-service-resource'), href:"manage/#dev/resource"},
{text:$.t('rsreg.new'), href:"manage/#dev/resource/new"}
]);
this.breadCrumbView.collection.add([{
text: $.t('admin.home'),
href: ""
}, {
text: $.t('admin.self-service-resource'),
href: "manage/#dev/resource"
}, {
text: $.t('rsreg.new'),
href: "manage/#dev/resource/new"
}]);
this.updateSidebar('dev/resource');
var client = new ResRegClient();
var view = new ResRegEditView({model: client, systemScopeList:this.systemScopeList});
var view = new ResRegEditView({
model: client,
systemScopeList: this.systemScopeList
});
view.load(function() {
@ -476,7 +539,9 @@ ui.routes.push({path: "dev/resource/new", name: "newResReg", callback:
scope: _.uniq(_.flatten(app.systemScopeList.defaultUnrestrictedScopes().pluck("value"))).join(" "),
token_endpoint_auth_method: 'client_secret_basic',
contacts: contacts
}, { silent: true });
}, {
silent: true
});
$('#content').html(view.render().el);
view.delegateEvents();
@ -487,20 +552,28 @@ ui.routes.push({path: "dev/resource/new", name: "newResReg", callback:
}
});
ui.routes.push({path: "dev/resource/edit", name: "editResReg", callback:
function() {
ui.routes.push({
path: "dev/resource/edit",
name: "editResReg",
callback: function() {
this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([
{text:$.t('admin.home'), href:""},
{text:$.t('admin.self-service-resource'), href:"manage/#dev/resource"},
{text:$.t('rsreg.edit'), href:"manage/#dev/resource/edit"}
]);
this.breadCrumbView.collection.add([{
text: $.t('admin.home'),
href: ""
}, {
text: $.t('admin.self-service-resource'),
href: "manage/#dev/resource"
}, {
text: $.t('rsreg.edit'),
href: "manage/#dev/resource/edit"
}]);
this.updateSidebar('dev/resource');
setPageTitle($.t('rsreg.edit'));
// note that this doesn't actually load the client, that's supposed to happen elsewhere...
// note that this doesn't actually load the client, that's supposed to
// happen elsewhere...
}
});

View File

@ -17,13 +17,13 @@
var SystemScopeModel = Backbone.Model.extend({
idAttribute: 'id',
defaults:{
id:null,
description:null,
icon:null,
value:null,
defaultScope:false,
restricted:false
defaults: {
id: null,
description: null,
icon: null,
value: null,
defaultScope: false,
restricted: false
},
urlRoot: 'api/scopes'
@ -58,7 +58,9 @@ var SystemScopeCollection = Backbone.Collection.extend({
},
getByValue: function(value) {
var scopes = this.where({value: value});
var scopes = this.where({
value: value
});
if (scopes.length == 1) {
return scopes[0];
} else {
@ -72,7 +74,7 @@ var SystemScopeView = Backbone.View.extend({
tagName: 'tr',
initialize:function (options) {
initialize: function(options) {
this.options = options;
if (!this.template) {
@ -84,43 +86,50 @@ var SystemScopeView = Backbone.View.extend({
},
events: {
'click .btn-edit':'editScope',
'click .btn-delete':'deleteScope'
'click .btn-edit': 'editScope',
'click .btn-delete': 'deleteScope'
},
editScope:function(e) {
editScope: function(e) {
e.preventDefault();
app.navigate('admin/scope/' + this.model.id, {trigger: true});
app.navigate('admin/scope/' + this.model.id, {
trigger: true
});
},
render:function (eventName) {
render: function(eventName) {
this.$el.html(this.template(this.model.toJSON()));
$('.restricted', this.el).tooltip({title: $.t('scope.system-scope-table.tooltip-restricted')});
$('.default', this.el).tooltip({title: $.t('scope.system-scope-table.tooltip-default')});
$('.restricted', this.el).tooltip({
title: $.t('scope.system-scope-table.tooltip-restricted')
});
$('.default', this.el).tooltip({
title: $.t('scope.system-scope-table.tooltip-default')
});
$(this.el).i18n();
return this;
},
deleteScope:function (e) {
deleteScope: function(e) {
e.preventDefault();
if (confirm($.t("scope.system-scope-table.confirm"))) {
var _self = this;
this.model.destroy({
dataType: false, processData: false,
success:function () {
dataType: false,
processData: false,
success: function() {
_self.$el.fadeTo("fast", 0.00, function () { //fade
$(this).slideUp("fast", function () { //slide up
$(this).remove(); //then remove from the DOM
_self.$el.fadeTo("fast", 0.00, function() { // fade
$(this).slideUp("fast", function() { // slide up
$(this).remove(); // then remove from the DOM
_self.parentView.togglePlaceholder();
});
});
},
error:app.errorHandlerView.handleError()
error: app.errorHandlerView.handleError()
});
_self.parentView.delegateEvents();
@ -129,7 +138,7 @@ var SystemScopeView = Backbone.View.extend({
return false;
},
close:function () {
close: function() {
$(this.el).unbind();
$(this.el).empty();
}
@ -138,53 +147,59 @@ var SystemScopeView = Backbone.View.extend({
var SystemScopeListView = Backbone.View.extend({
tagName: 'span',
initialize:function(options) {
initialize: function(options) {
this.options = options;
},
load:function(callback) {
load: function(callback) {
if (this.model.isFetched) {
callback();
return;
}
$('#loadingbox').sheet('show');
$('#loading').html(
'<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> '
);
$('#loading').html('<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ');
$.when(this.model.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}, error:app.errorHandlerView.handleError()}))
.done(function() {
$.when(this.model.fetchIfNeeded({
success: function(e) {
$('#loading-scopes').addClass('label-success');
},
error: app.errorHandlerView.handleError()
})).done(function() {
$('#loadingbox').sheet('hide');
callback();
});
},
events:{
"click .new-scope":"newScope",
"click .refresh-table":"refreshTable"
events: {
"click .new-scope": "newScope",
"click .refresh-table": "refreshTable"
},
newScope:function(e) {
newScope: function(e) {
this.remove();
app.navigate('admin/scope/new', {trigger: true});
app.navigate('admin/scope/new', {
trigger: true
});
},
refreshTable:function(e) {
refreshTable: function(e) {
var _self = this;
$('#loadingbox').sheet('show');
$('#loading').html(
'<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> '
);
$('#loading').html('<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ');
$.when(this.model.fetch({success:function(e) {$('#loading-scopes').addClass('label-success');}, error:app.errorHandlerView.handleError()}))
.done(function() {
$.when(this.model.fetch({
success: function(e) {
$('#loading-scopes').addClass('label-success');
},
error: app.errorHandlerView.handleError()
})).done(function() {
$('#loadingbox').sheet('hide');
_self.render();
});
},
togglePlaceholder:function() {
togglePlaceholder: function() {
if (this.model.length > 0) {
$('#scope-table', this.el).show();
$('#scope-table-empty', this.el).hide();
@ -194,15 +209,17 @@ var SystemScopeListView = Backbone.View.extend({
}
},
render: function (eventName) {
render: function(eventName) {
// append and render the table structure
$(this.el).html($('#tmpl-system-scope-table').html());
var _self = this;
_.each(this.model.models, function (scope) {
var view = new SystemScopeView({model: scope});
_.each(this.model.models, function(scope) {
var view = new SystemScopeView({
model: scope
});
view.parentView = _self;
$("#scope-table", _self.el).append(view.render().el);
}, this);
@ -213,10 +230,11 @@ var SystemScopeListView = Backbone.View.extend({
}
});
var SystemScopeFormView = Backbone.View.extend({
var SystemScopeFormView = Backbone.View
.extend({
tagName: 'span',
initialize:function(options) {
initialize: function(options) {
this.options = options;
if (!this.template) {
this.template = _.template($('#tmpl-system-scope-form').html());
@ -229,28 +247,11 @@ var SystemScopeFormView = Backbone.View.extend({
if (!this.bootstrapIcons) {
this.bootstrapIcons = [];
var iconList = ['glass', 'music', 'search', 'envelope', 'heart', 'star', 'star-empty',
'user', 'film', 'th-large', 'th', 'th-list', 'ok', 'remove', 'zoom-in',
'zoom-out', 'off', 'signal', 'cog', 'trash', 'home', 'file', 'time', 'road',
'download-alt', 'download', 'upload', 'inbox', 'play-circle', 'repeat',
'refresh', 'list-alt', 'lock', 'flag', 'headphones', 'volume-off',
'volume-down', 'volume-up', 'qrcode', 'barcode', 'tag', 'tags', 'book',
'bookmark', 'print', 'camera', 'font', 'bold', 'italic', 'text-height',
'text-width', 'align-left', 'align-center', 'align-right', 'align-justify',
'list', 'indent-left', 'indent-right', 'facetime-video', 'picture', 'pencil',
'map-marker', 'adjust', 'tint', 'edit', 'share', 'check', 'move', 'step-backward',
'fast-backward', 'backward', 'play', 'pause', 'stop', 'forward', 'fast-forward',
'step-forward', 'eject', 'chevron-left', 'chevron-right', 'plus-sign',
'minus-sign', 'remove-sign', 'ok-sign', 'question-sign', 'info-sign',
'screenshot', 'remove-circle', 'ok-circle', 'ban-circle', 'arrow-left',
'arrow-right', 'arrow-up', 'arrow-down', 'share-alt', 'resize-full', 'resize-small',
'plus', 'minus', 'asterisk', 'exclamation-sign', 'gift', 'leaf', 'fire',
'eye-open', 'eye-close', 'warning-sign', 'plane', 'calendar', 'random',
'comment', 'magnet', 'chevron-up', 'chevron-down', 'retweet', 'shopping-cart',
'folder-close', 'folder-open', 'resize-vertical', 'resize-horizontal',
'hdd', 'bullhorn', 'bell', 'certificate', 'thumbs-up', 'thumbs-down',
'hand-right', 'hand-left', 'hand-up', 'hand-down', 'circle-arrow-right',
'circle-arrow-left', 'circle-arrow-up', 'circle-arrow-down', 'globe',
var iconList = ['glass', 'music', 'search', 'envelope', 'heart', 'star', 'star-empty', 'user', 'film', 'th-large', 'th', 'th-list', 'ok', 'remove', 'zoom-in', 'zoom-out', 'off', 'signal', 'cog', 'trash', 'home', 'file', 'time', 'road', 'download-alt', 'download', 'upload', 'inbox', 'play-circle', 'repeat', 'refresh', 'list-alt', 'lock',
'flag', 'headphones', 'volume-off', 'volume-down', 'volume-up', 'qrcode', 'barcode', 'tag', 'tags', 'book', 'bookmark', 'print', 'camera', 'font', 'bold', 'italic', 'text-height', 'text-width', 'align-left', 'align-center', 'align-right', 'align-justify', 'list', 'indent-left', 'indent-right', 'facetime-video', 'picture',
'pencil', 'map-marker', 'adjust', 'tint', 'edit', 'share', 'check', 'move', 'step-backward', 'fast-backward', 'backward', 'play', 'pause', 'stop', 'forward', 'fast-forward', 'step-forward', 'eject', 'chevron-left', 'chevron-right', 'plus-sign', 'minus-sign', 'remove-sign', 'ok-sign', 'question-sign', 'info-sign', 'screenshot',
'remove-circle', 'ok-circle', 'ban-circle', 'arrow-left', 'arrow-right', 'arrow-up', 'arrow-down', 'share-alt', 'resize-full', 'resize-small', 'plus', 'minus', 'asterisk', 'exclamation-sign', 'gift', 'leaf', 'fire', 'eye-open', 'eye-close', 'warning-sign', 'plane', 'calendar', 'random', 'comment', 'magnet', 'chevron-up',
'chevron-down', 'retweet', 'shopping-cart', 'folder-close', 'folder-open', 'resize-vertical', 'resize-horizontal', 'hdd', 'bullhorn', 'bell', 'certificate', 'thumbs-up', 'thumbs-down', 'hand-right', 'hand-left', 'hand-up', 'hand-down', 'circle-arrow-right', 'circle-arrow-left', 'circle-arrow-up', 'circle-arrow-down', 'globe',
'wrench', 'tasks', 'filter', 'briefcase', 'fullscreen'];
var size = 3;
@ -261,32 +262,38 @@ var SystemScopeFormView = Backbone.View.extend({
}
},
events:{
'click .btn-save':'saveScope',
'click .btn-cancel': function() {app.navigate('admin/scope', {trigger: true}); },
'click .btn-icon':'selectIcon'
events: {
'click .btn-save': 'saveScope',
'click .btn-cancel': function() {
app.navigate('admin/scope', {
trigger: true
});
},
'click .btn-icon': 'selectIcon'
},
load:function(callback) {
load: function(callback) {
if (this.model.isFetched) {
callback();
return;
}
$('#loadingbox').sheet('show');
$('#loading').html(
'<span class="label" id="loading-scopes">' + $.t("common.scopes") + '</span> '
);
$('#loading').html('<span class="label" id="loading-scopes">' + $.t("common.scopes") + '</span> ');
$.when(this.model.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}, error:app.errorHandlerView.handleError()}))
.done(function() {
$.when(this.model.fetchIfNeeded({
success: function(e) {
$('#loading-scopes').addClass('label-success');
},
error: app.errorHandlerView.handleError()
})).done(function() {
$('#loadingbox').sheet('hide');
callback();
});
},
saveScope:function(e) {
saveScope: function(e) {
e.preventDefault();
var value = $('#value input').val();
@ -297,29 +304,31 @@ var SystemScopeFormView = Backbone.View.extend({
}
var valid = this.model.set({
value:value,
description:$('#description textarea').val(),
icon:$('#iconDisplay input').val(),
defaultScope:$('#defaultScope input').is(':checked'),
restricted:$('#restricted input').is(':checked')
value: value,
description: $('#description textarea').val(),
icon: $('#iconDisplay input').val(),
defaultScope: $('#defaultScope input').is(':checked'),
restricted: $('#restricted input').is(':checked')
});
if (valid) {
var _self = this;
this.model.save({}, {
success:function() {
success: function() {
app.systemScopeList.add(_self.model);
app.navigate('admin/scope', {trigger: true});
app.navigate('admin/scope', {
trigger: true
});
},
error:app.errorHandlerView.handleError()
error: app.errorHandlerView.handleError()
});
}
return false;
},
selectIcon:function(e) {
selectIcon: function(e) {
e.preventDefault();
var icon = e.target.value;
@ -338,17 +347,21 @@ var SystemScopeFormView = Backbone.View.extend({
render: function(eventName) {
this.$el.html(this.template(this.model.toJSON()));
_.each(this.bootstrapIcons, function (items) {
$("#iconSelector .modal-body", this.el).append(this.iconTemplate({items:items}));
_.each(this.bootstrapIcons, function(items) {
$("#iconSelector .modal-body", this.el).append(this.iconTemplate({
items: items
}));
}, this);
$(this.el).i18n();
return this;
}
});
});
ui.routes.push({path: "admin/scope", name: "siteScope", callback:
function() {
ui.routes.push({
path: "admin/scope",
name: "siteScope",
callback: function() {
if (!isAdmin()) {
this.root();
@ -356,14 +369,19 @@ ui.routes.push({path: "admin/scope", name: "siteScope", callback:
}
this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([
{text:$.t('admin.home'), href:""},
{text:$.t('scope.manage'), href:"manage/#admin/scope"}
]);
this.breadCrumbView.collection.add([{
text: $.t('admin.home'),
href: ""
}, {
text: $.t('scope.manage'),
href: "manage/#admin/scope"
}]);
this.updateSidebar('admin/scope');
var view = new SystemScopeListView({model:this.systemScopeList});
var view = new SystemScopeListView({
model: this.systemScopeList
});
view.load(function() {
$('#content').html(view.render().el);
@ -374,9 +392,10 @@ ui.routes.push({path: "admin/scope", name: "siteScope", callback:
}
});
ui.routes.push({path: "admin/scope/new", name:"newScope", callback:
function() {
ui.routes.push({
path: "admin/scope/new",
name: "newScope",
callback: function() {
if (!isAdmin()) {
this.root();
@ -384,17 +403,24 @@ ui.routes.push({path: "admin/scope/new", name:"newScope", callback:
}
this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([
{text:$.t('admin.home'), href:""},
{text:$.t('scope.manage'), href:"manage/#admin/scope"},
{text:$.t('scope.system-scope-form.new'), href:"manage/#admin/scope/new"}
]);
this.breadCrumbView.collection.add([{
text: $.t('admin.home'),
href: ""
}, {
text: $.t('scope.manage'),
href: "manage/#admin/scope"
}, {
text: $.t('scope.system-scope-form.new'),
href: "manage/#admin/scope/new"
}]);
this.updateSidebar('admin/scope');
var scope = new SystemScopeModel();
var view = new SystemScopeFormView({model:scope});
var view = new SystemScopeFormView({
model: scope
});
view.load(function() {
$('#content').html(view.render().el);
setPageTitle($.t('scope.system-scope-form.new'));
@ -403,8 +429,10 @@ ui.routes.push({path: "admin/scope/new", name:"newScope", callback:
}
});
ui.routes.push({path: "admin/scope/:id", name: "editScope", callback:
function(sid) {
ui.routes.push({
path: "admin/scope/:id",
name: "editScope",
callback: function(sid) {
if (!isAdmin()) {
this.root();
@ -412,20 +440,29 @@ ui.routes.push({path: "admin/scope/:id", name: "editScope", callback:
}
this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([
{text:$.t('admin.home'), href:""},
{text:$.t('scope.manage'), href:"manage/#admin/scope"},
{text:$.t('scope.system-scope-form.edit'), href:"manage/#admin/scope/" + sid}
]);
this.breadCrumbView.collection.add([{
text: $.t('admin.home'),
href: ""
}, {
text: $.t('scope.manage'),
href: "manage/#admin/scope"
}, {
text: $.t('scope.system-scope-form.edit'),
href: "manage/#admin/scope/" + sid
}]);
this.updateSidebar('admin/scope');
var scope = this.systemScopeList.get(sid);
if (!scope) {
scope = new SystemScopeModel({id: sid});
scope = new SystemScopeModel({
id: sid
});
}
var view = new SystemScopeFormView({model:scope});
var view = new SystemScopeFormView({
model: scope
});
view.load(function() {
$('#content').html(view.render().el);
setPageTitle($.t('scope.system-scope-form.new'));

View File

@ -18,14 +18,14 @@
var AccessTokenModel = Backbone.Model.extend({
idAttribute: 'id',
defaults:{
id:null,
value:null,
refreshTokenId:null,
scopes:[],
clientId:null,
userId:null,
expiration:null
defaults: {
id: null,
value: null,
refreshTokenId: null,
scopes: [],
clientId: null,
userId: null,
expiration: null
},
urlRoot: 'api/tokens/access'
@ -44,7 +44,7 @@ var AccessTokenView = Backbone.View.extend({
tagName: 'tr',
initialize:function (options) {
initialize: function(options) {
this.options = options;
if (!this.template) {
@ -64,12 +64,12 @@ var AccessTokenView = Backbone.View.extend({
},
events: {
'click .btn-delete':'deleteToken',
'click .token-substring':'showTokenValue',
'click .btn-delete': 'deleteToken',
'click .token-substring': 'showTokenValue',
'click .toggleMoreInformation': 'toggleMoreInformation'
},
render:function (eventName) {
render: function(eventName) {
var expirationDate = this.model.get("expiration");
@ -81,7 +81,11 @@ var AccessTokenView = Backbone.View.extend({
expirationDate = moment(expirationDate).calendar();
}
var json = {token: this.model.toJSON(), client: this.options.client.toJSON(), formattedExpiration: expirationDate};
var json = {
token: this.model.toJSON(),
client: this.options.client.toJSON(),
formattedExpiration: expirationDate
};
this.$el.html(this.template(json));
@ -89,15 +93,20 @@ var AccessTokenView = Backbone.View.extend({
$('.token-full', this.el).hide();
// show scopes
$('.scope-list', this.el).html(this.scopeTemplate({scopes: this.model.get('scopes'), systemScopes: this.options.systemScopeList}));
$('.scope-list', this.el).html(this.scopeTemplate({
scopes: this.model.get('scopes'),
systemScopes: this.options.systemScopeList
}));
$('.client-more-info-block', this.el).html(this.moreInfoTemplate({client: this.options.client.toJSON()}));
$('.client-more-info-block', this.el).html(this.moreInfoTemplate({
client: this.options.client.toJSON()
}));
$(this.el).i18n();
return this;
},
deleteToken:function (e) {
deleteToken: function(e) {
e.preventDefault();
if (confirm($.t("token.token-table.confirm"))) {
@ -105,18 +114,20 @@ var AccessTokenView = Backbone.View.extend({
var _self = this;
this.model.destroy({
dataType: false, processData: false,
success:function () {
dataType: false,
processData: false,
success: function() {
_self.$el.fadeTo("fast", 0.00, function () { //fade
$(this).slideUp("fast", function () { //slide up
$(this).remove(); //then remove from the DOM
// refresh the table in case we removed an id token, too
_self.$el.fadeTo("fast", 0.00, function() { // fade
$(this).slideUp("fast", function() { // slide up
$(this).remove(); // then remove from the DOM
// refresh the table in case we removed an id token,
// too
_self.parentView.refreshTable();
});
});
},
error:app.errorHandlerView.handleError()
error: app.errorHandlerView.handleError()
});
this.parentView.delegateEvents();
@ -125,7 +136,7 @@ var AccessTokenView = Backbone.View.extend({
return false;
},
toggleMoreInformation:function(e) {
toggleMoreInformation: function(e) {
e.preventDefault();
if ($('.moreInformation', this.el).is(':visible')) {
// hide it
@ -141,12 +152,12 @@ var AccessTokenView = Backbone.View.extend({
}
},
close:function () {
close: function() {
$(this.el).unbind();
$(this.el).empty();
},
showTokenValue:function (e) {
showTokenValue: function(e) {
e.preventDefault();
$('.token-substring', this.el).hide();
$('.token-full', this.el).show();
@ -156,13 +167,13 @@ var AccessTokenView = Backbone.View.extend({
var RefreshTokenModel = Backbone.Model.extend({
idAttribute: 'id',
defaults:{
id:null,
value:null,
scopes:[],
clientId:null,
userId:null,
expiration:null
defaults: {
id: null,
value: null,
scopes: [],
clientId: null,
userId: null,
expiration: null
},
urlRoot: 'api/tokens/refresh'
@ -181,7 +192,7 @@ var RefreshTokenView = Backbone.View.extend({
tagName: 'tr',
initialize:function (options) {
initialize: function(options) {
this.options = options;
if (!this.template) {
@ -201,12 +212,12 @@ var RefreshTokenView = Backbone.View.extend({
},
events: {
'click .btn-delete':'deleteToken',
'click .token-substring':'showTokenValue',
'click .btn-delete': 'deleteToken',
'click .token-substring': 'showTokenValue',
'click .toggleMoreInformation': 'toggleMoreInformation'
},
render:function (eventName) {
render: function(eventName) {
var expirationDate = this.model.get("expiration");
@ -218,7 +229,12 @@ var RefreshTokenView = Backbone.View.extend({
expirationDate = moment(expirationDate).calendar();
}
var json = {token: this.model.toJSON(), client: this.options.client.toJSON(), formattedExpiration: expirationDate, accessTokenCount: this.options.accessTokenCount};
var json = {
token: this.model.toJSON(),
client: this.options.client.toJSON(),
formattedExpiration: expirationDate,
accessTokenCount: this.options.accessTokenCount
};
this.$el.html(this.template(json));
@ -226,16 +242,21 @@ var RefreshTokenView = Backbone.View.extend({
$('.token-full', this.el).hide();
// show scopes
$('.scope-list', this.el).html(this.scopeTemplate({scopes: this.model.get('scopes'), systemScopes: this.options.systemScopeList}));
$('.scope-list', this.el).html(this.scopeTemplate({
scopes: this.model.get('scopes'),
systemScopes: this.options.systemScopeList
}));
$('.client-more-info-block', this.el).html(this.moreInfoTemplate({client: this.options.client.toJSON()}));
$('.client-more-info-block', this.el).html(this.moreInfoTemplate({
client: this.options.client.toJSON()
}));
$(this.el).i18n();
return this;
},
deleteToken:function (e) {
deleteToken: function(e) {
e.preventDefault();
if (confirm($.t('token.token-table.confirm-refresh'))) {
@ -243,18 +264,20 @@ var RefreshTokenView = Backbone.View.extend({
var _self = this;
this.model.destroy({
dataType: false, processData: false,
success:function () {
dataType: false,
processData: false,
success: function() {
_self.$el.fadeTo("fast", 0.00, function () { //fade
$(this).slideUp("fast", function () { //slide up
$(this).remove(); //then remove from the DOM
// refresh the table in case the access tokens have changed, too
_self.$el.fadeTo("fast", 0.00, function() { // fade
$(this).slideUp("fast", function() { // slide up
$(this).remove(); // then remove from the DOM
// refresh the table in case the access tokens have
// changed, too
_self.parentView.refreshTable();
});
});
},
error:app.errorHandlerView.handleError()
error: app.errorHandlerView.handleError()
});
_self.parentView.delegateEvents();
@ -263,7 +286,7 @@ var RefreshTokenView = Backbone.View.extend({
return false;
},
toggleMoreInformation:function(e) {
toggleMoreInformation: function(e) {
e.preventDefault();
if ($('.moreInformation', this.el).is(':visible')) {
// hide it
@ -279,12 +302,12 @@ var RefreshTokenView = Backbone.View.extend({
},
close:function () {
close: function() {
$(this.el).unbind();
$(this.el).empty();
},
showTokenValue:function (e) {
showTokenValue: function(e) {
e.preventDefault();
$('.token-substring', this.el).hide();
$('.token-full', this.el).show();
@ -294,46 +317,58 @@ var RefreshTokenView = Backbone.View.extend({
var TokenListView = Backbone.View.extend({
tagName: 'span',
initialize:function(options) {
initialize: function(options) {
this.options = options;
},
events:{
"click .refresh-table":"refreshTable",
'page .paginator-access':'changePageAccess',
'page .paginator-refresh':'changePageRefresh'
events: {
"click .refresh-table": "refreshTable",
'page .paginator-access': 'changePageAccess',
'page .paginator-refresh': 'changePageRefresh'
},
load:function(callback) {
if (this.model.access.isFetched &&
this.model.refresh.isFetched &&
this.options.clientList.isFetched &&
this.options.systemScopeList.isFetched) {
load: function(callback) {
if (this.model.access.isFetched && this.model.refresh.isFetched && this.options.clientList.isFetched && this.options.systemScopeList.isFetched) {
callback();
return;
}
$('#loadingbox').sheet('show');
$('#loading').html(
'<span class="label" id="loading-access">' + $.t('token.token-table.access-tokens') + '</span> ' +
'<span class="label" id="loading-refresh">' + $.t('token.token-table.refresh-tokens') + '</span> ' +
'<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' +
'<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> '
);
'<span class="label" id="loading-access">' + $.t('token.token-table.access-tokens') + '</span> ' + '<span class="label" id="loading-refresh">' + $.t('token.token-table.refresh-tokens') + '</span> ' + '<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' + '<span class="label" id="loading-scopes">'
+ $.t('common.scopes') + '</span> ');
$.when(this.model.access.fetchIfNeeded({success:function(e) {$('#loading-access').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
this.model.refresh.fetchIfNeeded({success:function(e) {$('#loading-refresh').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
this.options.clientList.fetchIfNeeded({success:function(e) {$('#loading-clients').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}, error: app.errorHandlerView.handleError()}))
.done(function() {
$.when(this.model.access.fetchIfNeeded({
success: function(e) {
$('#loading-access').addClass('label-success');
},
error: app.errorHandlerView.handleError()
}), this.model.refresh.fetchIfNeeded({
success: function(e) {
$('#loading-refresh').addClass('label-success');
},
error: app.errorHandlerView.handleError()
}), this.options.clientList.fetchIfNeeded({
success: function(e) {
$('#loading-clients').addClass('label-success');
},
error: app.errorHandlerView.handleError()
}), this.options.systemScopeList.fetchIfNeeded({
success: function(e) {
$('#loading-scopes').addClass('label-success');
},
error: app.errorHandlerView.handleError()
})).done(function() {
$('#loadingbox').sheet('hide');
callback();
});
},
changePageAccess:function(event, num) {
$('.paginator-access', this.el).bootpag({page: num});
changePageAccess: function(event, num) {
$('.paginator-access', this.el).bootpag({
page: num
});
$('#access-token-table tbody tr', this.el).each(function(index, element) {
if (Math.ceil((index + 1) / 10) != num) {
$(element).hide();
@ -343,8 +378,10 @@ var TokenListView = Backbone.View.extend({
});
},
changePageRefresh:function(event, num) {
$('.paginator-refresh', this.el).bootpag({page: num});
changePageRefresh: function(event, num) {
$('.paginator-refresh', this.el).bootpag({
page: num
});
$('#refresh-token-table tbody tr', this.el).each(function(index, element) {
if (Math.ceil((index + 1) / 10) != num) {
$(element).hide();
@ -354,26 +391,39 @@ var TokenListView = Backbone.View.extend({
});
},
refreshTable:function(e) {
refreshTable: function(e) {
$('#loadingbox').sheet('show');
$('#loading').html(
'<span class="label" id="loading-access">' + $.t('token.token-table.access-tokens') + '</span> ' +
'<span class="label" id="loading-refresh">' + $.t('token.token-table.refresh-tokens') + '</span> ' +
'<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' +
'<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> '
);
'<span class="label" id="loading-access">' + $.t('token.token-table.access-tokens') + '</span> ' + '<span class="label" id="loading-refresh">' + $.t('token.token-table.refresh-tokens') + '</span> ' + '<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' + '<span class="label" id="loading-scopes">'
+ $.t('common.scopes') + '</span> ');
var _self = this;
$.when(this.model.access.fetch({success:function(e) {$('#loading-access').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
this.model.refresh.fetch({success:function(e) {$('#loading-refresh').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
this.options.clientList.fetch({success:function(e) {$('#loading-clients').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
this.options.systemScopeList.fetch({success:function(e) {$('#loading-scopes').addClass('label-success');}, error: app.errorHandlerView.handleError()}))
.done(function(){
$.when(this.model.access.fetch({
success: function(e) {
$('#loading-access').addClass('label-success');
},
error: app.errorHandlerView.handleError()
}), this.model.refresh.fetch({
success: function(e) {
$('#loading-refresh').addClass('label-success');
},
error: app.errorHandlerView.handleError()
}), this.options.clientList.fetch({
success: function(e) {
$('#loading-clients').addClass('label-success');
},
error: app.errorHandlerView.handleError()
}), this.options.systemScopeList.fetch({
success: function(e) {
$('#loading-scopes').addClass('label-success');
},
error: app.errorHandlerView.handleError()
})).done(function() {
_self.render();
$('#loadingbox').sheet('hide');
});
},
togglePlaceholder:function() {
togglePlaceholder: function() {
if (this.model.access.length > 0) {
$('#access-token-table', this.el).show();
$('#access-token-table-empty', this.el).hide();
@ -393,7 +443,7 @@ var TokenListView = Backbone.View.extend({
$('#refresh-token-count', this.el).html(this.model.refresh.length);
},
render: function (eventName) {
render: function(eventName) {
// append and render the table structure
$(this.el).html($('#tmpl-token-table').html());
@ -415,10 +465,14 @@ var TokenListView = Backbone.View.extend({
// count up refresh tokens
var refreshCount = {};
_.each(this.model.access.models, function (token, index) {
_.each(this.model.access.models, function(token, index) {
// look up client
var client = _self.options.clientList.getByClientId(token.get('clientId'));
var view = new AccessTokenView({model: token, client: client, systemScopeList: _self.options.systemScopeList});
var view = new AccessTokenView({
model: token,
client: client,
systemScopeList: _self.options.systemScopeList
});
view.parentView = _self;
var element = view.render().el;
$('#access-token-table', _self.el).append(element);
@ -426,7 +480,7 @@ var TokenListView = Backbone.View.extend({
$(element).hide();
}
//console.log(token.get('refreshTokenId'));
// console.log(token.get('refreshTokenId'));
var refId = token.get('refreshTokenId');
if (refId != null) {
if (refreshCount[refId]) {
@ -439,7 +493,7 @@ var TokenListView = Backbone.View.extend({
});
//console.log(refreshCount);
// console.log(refreshCount);
// set up pagination
var numPagesRefresh = Math.ceil(this.model.refresh.length / 10);
@ -453,10 +507,15 @@ var TokenListView = Backbone.View.extend({
$('.paginator-refresh', this.el).hide();
}
_.each(this.model.refresh.models, function (token, index) {
_.each(this.model.refresh.models, function(token, index) {
// look up client
var client = _self.options.clientList.getByClientId(token.get('clientId'));
var view = new RefreshTokenView({model: token, client: client, systemScopeList: _self.options.systemScopeList, accessTokenCount: refreshCount[token.get('id')]});
var view = new RefreshTokenView({
model: token,
client: client,
systemScopeList: _self.options.systemScopeList,
accessTokenCount: refreshCount[token.get('id')]
});
view.parentView = _self;
var element = view.render().el;
$('#refresh-token-table', _self.el).append(element);
@ -466,11 +525,11 @@ var TokenListView = Backbone.View.extend({
});
/*
_.each(this.model.models, function (scope) {
$("#scope-table", this.el).append(new SystemScopeView({model: scope}).render().el);
}, this);
*/
/*
* _.each(this.model.models, function (scope) { $("#scope-table",
* this.el).append(new SystemScopeView({model: scope}).render().el); },
* this);
*/
this.togglePlaceholder();
$(this.el).i18n();
@ -478,25 +537,34 @@ var TokenListView = Backbone.View.extend({
}
});
ui.routes.push({path: "user/tokens", name: "tokens", callback:
function() {
ui.routes.push({
path: "user/tokens",
name: "tokens",
callback: function() {
this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([
{text:$.t('admin.home'), href:""},
{text:$.t('token.manage'), href:"manage/#user/tokens"}
]);
this.breadCrumbView.collection.add([{
text: $.t('admin.home'),
href: ""
}, {
text: $.t('token.manage'),
href: "manage/#user/tokens"
}]);
this.updateSidebar('user/tokens');
var view = new TokenListView({model: {access: this.accessTokensList, refresh: this.refreshTokensList}, clientList: this.clientList, systemScopeList: this.systemScopeList});
var view = new TokenListView({
model: {
access: this.accessTokensList,
refresh: this.refreshTokensList
},
clientList: this.clientList,
systemScopeList: this.systemScopeList
});
view.load(
function(collection, response, options) {
view.load(function(collection, response, options) {
$('#content').html(view.render().el);
setPageTitle($.t('token.manage'));
}
);
});
}
});

View File

@ -18,7 +18,8 @@ var WhiteListModel = Backbone.Model.extend({
idAttribute: "id",
initialize: function () { },
initialize: function() {
},
urlRoot: "api/whitelist"
@ -26,11 +27,13 @@ var WhiteListModel = Backbone.Model.extend({
var WhiteListCollection = Backbone.Collection.extend({
initialize: function() {
//this.fetch();
// this.fetch();
},
getByClientId: function(clientId) {
var clients = this.where({clientId: clientId});
var clients = this.where({
clientId: clientId
});
if (clients.length == 1) {
return clients[0];
} else {
@ -46,51 +49,61 @@ var WhiteListCollection = Backbone.Collection.extend({
var WhiteListListView = Backbone.View.extend({
tagName: 'span',
initialize:function (options) {
initialize: function(options) {
this.options = options;
},
load:function(callback) {
if (this.model.isFetched &&
this.options.clientList.isFetched &&
this.options.systemScopeList.isFetched) {
load: function(callback) {
if (this.model.isFetched && this.options.clientList.isFetched && this.options.systemScopeList.isFetched) {
callback();
return;
}
$('#loadingbox').sheet('show');
$('#loading').html(
'<span class="label" id="loading-whitelist">' + $.t('whitelist.whitelist') + '</span> ' +
'<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' +
'<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> '
);
$('#loading').html('<span class="label" id="loading-whitelist">' + $.t('whitelist.whitelist') + '</span> ' + '<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' + '<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ');
$.when(this.model.fetchIfNeeded({success:function(e) {$('#loading-whitelist').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
this.options.clientList.fetchIfNeeded({success:function(e) {$('#loading-clients').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}, error: app.errorHandlerView.handleError()}))
.done(function() {
$.when(this.model.fetchIfNeeded({
success: function(e) {
$('#loading-whitelist').addClass('label-success');
},
error: app.errorHandlerView.handleError()
}), this.options.clientList.fetchIfNeeded({
success: function(e) {
$('#loading-clients').addClass('label-success');
},
error: app.errorHandlerView.handleError()
}), this.options.systemScopeList.fetchIfNeeded({
success: function(e) {
$('#loading-scopes').addClass('label-success');
},
error: app.errorHandlerView.handleError()
})).done(function() {
$('#loadingbox').sheet('hide');
callback();
});
},
events:{
"click .refresh-table":"refreshTable"
events: {
"click .refresh-table": "refreshTable"
},
render:function (eventName) {
render: function(eventName) {
$(this.el).html($('#tmpl-whitelist-table').html());
var _self = this;
_.each(this.model.models, function (whiteList) {
_.each(this.model.models, function(whiteList) {
// look up client
var client = _self.options.clientList.getByClientId(whiteList.get('clientId'));
// if there's no client ID, this is an error!
if (client != null) {
var view = new WhiteListView({model: whiteList, client: client, systemScopeList: _self.options.systemScopeList});
var view = new WhiteListView({
model: whiteList,
client: client,
systemScopeList: _self.options.systemScopeList
});
view.parentView = _self;
$('#whitelist-table', _self.el).append(view.render().el);
}
@ -102,7 +115,7 @@ var WhiteListListView = Backbone.View.extend({
return this;
},
togglePlaceholder:function() {
togglePlaceholder: function() {
if (this.model.length > 0) {
$('#whitelist-table', this.el).show();
$('#whitelist-table-empty', this.el).hide();
@ -112,20 +125,28 @@ var WhiteListListView = Backbone.View.extend({
}
},
refreshTable:function(e) {
refreshTable: function(e) {
e.preventDefault();
var _self = this;
$('#loadingbox').sheet('show');
$('#loading').html(
'<span class="label" id="loading-whitelist">' + $.t('whitelist.whitelist') + '</span> ' +
'<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' +
'<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> '
);
$('#loading').html('<span class="label" id="loading-whitelist">' + $.t('whitelist.whitelist') + '</span> ' + '<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' + '<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ');
$.when(this.model.fetch({success:function(e) {$('#loading-whitelist').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
this.options.clientList.fetch({success:function(e) {$('#loading-clients').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
this.options.systemScopeList.fetch({success:function(e) {$('#loading-scopes').addClass('label-success');}, error: app.errorHandlerView.handleError()}))
.done(function() {
$.when(this.model.fetch({
success: function(e) {
$('#loading-whitelist').addClass('label-success');
},
error: app.errorHandlerView.handleError()
}), this.options.clientList.fetch({
success: function(e) {
$('#loading-clients').addClass('label-success');
},
error: app.errorHandlerView.handleError()
}), this.options.systemScopeList.fetch({
success: function(e) {
$('#loading-scopes').addClass('label-success');
},
error: app.errorHandlerView.handleError()
})).done(function() {
$('#loadingbox').sheet('hide');
_self.render();
});
@ -135,7 +156,7 @@ var WhiteListListView = Backbone.View.extend({
var WhiteListView = Backbone.View.extend({
tagName: 'tr',
initialize:function(options) {
initialize: function(options) {
this.options = options;
if (!this.template) {
this.template = _.template($('#tmpl-whitelist').html());
@ -152,51 +173,64 @@ var WhiteListView = Backbone.View.extend({
this.model.bind('change', this.render, this);
},
render:function(eventName) {
render: function(eventName) {
var json = {whiteList: this.model.toJSON(), client: this.options.client.toJSON()};
var json = {
whiteList: this.model.toJSON(),
client: this.options.client.toJSON()
};
this.$el.html(this.template(json));
$('.scope-list', this.el).html(this.scopeTemplate({scopes: this.model.get('allowedScopes'), systemScopes: this.options.systemScopeList}));
$('.scope-list', this.el).html(this.scopeTemplate({
scopes: this.model.get('allowedScopes'),
systemScopes: this.options.systemScopeList
}));
$('.client-more-info-block', this.el).html(this.moreInfoTemplate({client: this.options.client.toJSON()}));
$('.client-more-info-block', this.el).html(this.moreInfoTemplate({
client: this.options.client.toJSON()
}));
this.$('.dynamically-registered').tooltip({title: $.t('common.dynamically-registered')});
this.$('.dynamically-registered').tooltip({
title: $.t('common.dynamically-registered')
});
$(this.el).i18n();
return this;
},
events:{
events: {
'click .btn-edit': 'editWhitelist',
'click .btn-delete': 'deleteWhitelist',
'click .toggleMoreInformation': 'toggleMoreInformation'
},
editWhitelist:function(e) {
editWhitelist: function(e) {
e.preventDefault();
app.navigate('admin/whitelist/' + this.model.get('id'), {trigger: true});
app.navigate('admin/whitelist/' + this.model.get('id'), {
trigger: true
});
},
deleteWhitelist:function(e) {
deleteWhitelist: function(e) {
e.preventDefault();
if (confirm($.t('whitelist.confirm'))) {
var _self = this;
this.model.destroy({
dataType: false, processData: false,
success:function () {
_self.$el.fadeTo("fast", 0.00, function () { //fade
$(this).slideUp("fast", function () { //slide up
$(this).remove(); //then remove from the DOM
dataType: false,
processData: false,
success: function() {
_self.$el.fadeTo("fast", 0.00, function() { // fade
$(this).slideUp("fast", function() { // slide up
$(this).remove(); // then remove from the DOM
// check the placeholder in case it's empty now
_self.parentView.togglePlaceholder();
});
});
},
error:app.errorHandlerView.handleError()
error: app.errorHandlerView.handleError()
});
_self.parentView.delegateEvents();
@ -205,7 +239,7 @@ var WhiteListView = Backbone.View.extend({
return false;
},
toggleMoreInformation:function(e) {
toggleMoreInformation: function(e) {
e.preventDefault();
if ($('.moreInformation', this.el).is(':visible')) {
// hide it
@ -221,7 +255,7 @@ var WhiteListView = Backbone.View.extend({
}
},
close:function() {
close: function() {
$(this.el).unbind();
$(this.el).empty();
}
@ -230,7 +264,7 @@ var WhiteListView = Backbone.View.extend({
var WhiteListFormView = Backbone.View.extend({
tagName: 'span',
initialize:function (options) {
initialize: function(options) {
this.options = options;
if (!this.template) {
this.template = _.template($('#tmpl-whitelist-form').html());
@ -242,27 +276,34 @@ var WhiteListFormView = Backbone.View.extend({
},
load:function(callback) {
load: function(callback) {
if (this.options.client) {
// we know what client we're dealing with already
if (this.model.isFetched &&
this.options.client.isFetched) {
if (this.model.isFetched && this.options.client.isFetched) {
callback();
return;
}
$('#loadingbox').sheet('show');
$('#loading').html(
'<span class="label" id="loading-whitelist">' + $.t('whitelist.whitelist') + '</span> ' +
'<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' +
'<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> '
);
$('#loading').html('<span class="label" id="loading-whitelist">' + $.t('whitelist.whitelist') + '</span> ' + '<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' + '<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ');
$.when(this.model.fetchIfNeeded({success:function(e) {$('#loading-whitelist').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
this.options.client.fetchIfNeeded({success:function(e) {$('#loading-clients').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}, error: app.errorHandlerView.handleError()}))
.done(function() {
$.when(this.model.fetchIfNeeded({
success: function(e) {
$('#loading-whitelist').addClass('label-success');
},
error: app.errorHandlerView.handleError()
}), this.options.client.fetchIfNeeded({
success: function(e) {
$('#loading-clients').addClass('label-success');
},
error: app.errorHandlerView.handleError()
}), this.options.systemScopeList.fetchIfNeeded({
success: function(e) {
$('#loading-scopes').addClass('label-success');
},
error: app.errorHandlerView.handleError()
})).done(function() {
$('#loadingbox').sheet('hide');
callback();
});
@ -270,9 +311,7 @@ var WhiteListFormView = Backbone.View.extend({
} else {
// we need to get the client information from the list
if (this.model.isFetched &&
this.options.clientList.isFetched &&
this.options.systemScopeList.isFetched) {
if (this.model.isFetched && this.options.clientList.isFetched && this.options.systemScopeList.isFetched) {
var client = this.options.clientList.getByClientId(this.model.get('clientId'));
this.options.client = client;
@ -282,18 +321,26 @@ var WhiteListFormView = Backbone.View.extend({
}
$('#loadingbox').sheet('show');
$('#loading').html(
'<span class="label" id="loading-whitelist">' + $.t('whitelist.whitelist') + '</span> ' +
'<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' +
'<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> '
);
$('#loading').html('<span class="label" id="loading-whitelist">' + $.t('whitelist.whitelist') + '</span> ' + '<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' + '<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ');
var _self = this;
$.when(this.model.fetchIfNeeded({success:function(e) {$('#loading-whitelist').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
this.options.clientList.fetchIfNeeded({success:function(e) {$('#loading-clients').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}, error: app.errorHandlerView.handleError()}))
.done(function() {
$.when(this.model.fetchIfNeeded({
success: function(e) {
$('#loading-whitelist').addClass('label-success');
},
error: app.errorHandlerView.handleError()
}), this.options.clientList.fetchIfNeeded({
success: function(e) {
$('#loading-clients').addClass('label-success');
},
error: app.errorHandlerView.handleError()
}), this.options.systemScopeList.fetchIfNeeded({
success: function(e) {
$('#loading-scopes').addClass('label-success');
},
error: app.errorHandlerView.handleError()
})).done(function() {
var client = _self.options.clientList.getByClientId(_self.model.get('clientId'));
_self.options.client = client;
@ -304,18 +351,15 @@ var WhiteListFormView = Backbone.View.extend({
}
},
events: {
'click .btn-save': 'saveWhiteList',
'click .btn-cancel': 'cancelWhiteList',
},
events:{
'click .btn-save':'saveWhiteList',
'click .btn-cancel':'cancelWhiteList',
},
saveWhiteList:function (e) {
saveWhiteList: function(e) {
e.preventDefault();
$('.control-group').removeClass('error');
@ -327,7 +371,11 @@ var WhiteListFormView = Backbone.View.extend({
// process allowed scopes
var allowedScopes = this.scopeCollection.pluck("item");
this.model.set({clientId: this.options.client.get('clientId')}, {silent: true});
this.model.set({
clientId: this.options.client.get('clientId')
}, {
silent: true
});
var valid = this.model.set({
allowedScopes: allowedScopes
@ -336,11 +384,13 @@ var WhiteListFormView = Backbone.View.extend({
if (valid) {
var _self = this;
this.model.save({}, {
success:function () {
success: function() {
app.whiteListList.add(_self.model);
app.navigate('admin/whitelists', {trigger:true});
app.navigate('admin/whitelists', {
trigger: true
});
},
error:app.errorHandlerView.handleError()
error: app.errorHandlerView.handleError()
});
}
@ -348,21 +398,28 @@ var WhiteListFormView = Backbone.View.extend({
},
cancelWhiteList:function(e) {
cancelWhiteList: function(e) {
e.preventDefault();
// TODO: figure out where we came from and go back there instead
if (this.model.get('id') == null) {
// if it's a new whitelist entry, go back to the client listing page
app.navigate('admin/clients', {trigger:true});
app.navigate('admin/clients', {
trigger: true
});
} else {
// if we're editing a whitelist, go back to the whitelists page
app.navigate('admin/whitelists', {trigger:true});
app.navigate('admin/whitelists', {
trigger: true
});
}
},
render:function (eventName) {
render: function(eventName) {
var json = {whiteList: this.model.toJSON(), client: this.options.client.toJSON()};
var json = {
whiteList: this.model.toJSON(),
client: this.options.client.toJSON()
};
this.$el.html(this.template(json));
@ -370,16 +427,19 @@ var WhiteListFormView = Backbone.View.extend({
var _self = this;
// build and bind scopes
_.each(this.model.get("allowedScopes"), function (scope) {
_self.scopeCollection.add(new Backbone.Model({item:scope}));
_.each(this.model.get("allowedScopes"), function(scope) {
_self.scopeCollection.add(new Backbone.Model({
item: scope
}));
});
var scopeView = new ListWidgetView({
placeholder: $.t('whitelist.whitelist-form.scope-placeholder'),
autocomplete: this.options.client.get("scope"),
helpBlockText: $.t('whitelist.whitelist-form.scope-help'),
collection: this.scopeCollection});
$("#scope .controls",this.el).html(scopeView.render().el);
collection: this.scopeCollection
});
$("#scope .controls", this.el).html(scopeView.render().el);
this.listWidgetViews.push(scopeView);
$(this.el).i18n();
@ -389,9 +449,10 @@ var WhiteListFormView = Backbone.View.extend({
});
ui.routes.push({path: "admin/whitelists", name: "whiteList", callback:
function () {
ui.routes.push({
path: "admin/whitelists",
name: "whiteList",
callback: function() {
if (!isAdmin()) {
this.root();
@ -401,28 +462,33 @@ ui.routes.push({path: "admin/whitelists", name: "whiteList", callback:
this.updateSidebar('admin/whitelists');
this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([
{text:$.t('admin.home'), href:""},
{text:$.t('whitelist.manage'), href:"manage/#admin/whitelists"}
]);
this.breadCrumbView.collection.add([{
text: $.t('admin.home'),
href: ""
}, {
text: $.t('whitelist.manage'),
href: "manage/#admin/whitelists"
}]);
var view = new WhiteListListView({model:this.whiteListList, clientList: this.clientList, systemScopeList: this.systemScopeList});
var view = new WhiteListListView({
model: this.whiteListList,
clientList: this.clientList,
systemScopeList: this.systemScopeList
});
view.load(
function() {
view.load(function() {
$('#content').html(view.render().el);
view.delegateEvents();
setPageTitle($.t('whitelist.manage'));
}
);
});
}
});
ui.routes.push({path: "admin/whitelist/new/:cid", name: "newWhitelist", callback:
function(cid) {
ui.routes.push({
path: "admin/whitelist/new/:cid",
name: "newWhitelist",
callback: function(cid) {
if (!isAdmin()) {
this.root();
@ -430,11 +496,16 @@ ui.routes.push({path: "admin/whitelist/new/:cid", name: "newWhitelist", callback
}
this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([
{text:$.t('admin.home'), href:""},
{text:$.t('whitelist.manage'), href:"manage/#admin/whitelists"},
{text:$.t('whitelist.new'), href:"manage/#admin/whitelist/new/" + cid}
]);
this.breadCrumbView.collection.add([{
text: $.t('admin.home'),
href: ""
}, {
text: $.t('whitelist.manage'),
href: "manage/#admin/whitelists"
}, {
text: $.t('whitelist.new'),
href: "manage/#admin/whitelist/new/" + cid
}]);
this.updateSidebar('admin/whitelists');
@ -442,29 +513,38 @@ ui.routes.push({path: "admin/whitelist/new/:cid", name: "newWhitelist", callback
var client = this.clientList.get(cid);
if (!client) {
client = new ClientModel({id: cid});
client = new ClientModel({
id: cid
});
}
var view = new WhiteListFormView({model: whiteList, client: client, systemScopeList: this.systemScopeList});
var view = new WhiteListFormView({
model: whiteList,
client: client,
systemScopeList: this.systemScopeList
});
view.load(
function() {
view.load(function() {
// set the scopes on the model now that everything's loaded
whiteList.set({allowedScopes: client.get('scope')}, {silent: true});
whiteList.set({
allowedScopes: client.get('scope')
}, {
silent: true
});
$('#content').html(view.render().el);
view.delegateEvents();
setPageTitle($.t('whitelist.manage'));
}
);
});
}
});
ui.routes.push({path: "admin/whitelist/:id", name: "editWhitelist", callback:
function(id) {
ui.routes.push({
path: "admin/whitelist/:id",
name: "editWhitelist",
callback: function(id) {
if (!isAdmin()) {
this.root();
@ -472,28 +552,37 @@ ui.routes.push({path: "admin/whitelist/:id", name: "editWhitelist", callback:
}
this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([
{text:$.t('admin.home'), href:""},
{text:$.t('whitelist.manage'), href:"manage/#admin/whitelists"},
{text:$.t('whitelist.edit'), href:"manage/#admin/whitelist/" + id}
]);
this.breadCrumbView.collection.add([{
text: $.t('admin.home'),
href: ""
}, {
text: $.t('whitelist.manage'),
href: "manage/#admin/whitelists"
}, {
text: $.t('whitelist.edit'),
href: "manage/#admin/whitelist/" + id
}]);
this.updateSidebar('admin/whitelists');
var whiteList = this.whiteListList.get(id);
if (!whiteList) {
whiteList = new WhiteListModel({id: id});
whiteList = new WhiteListModel({
id: id
});
}
var view = new WhiteListFormView({model: whiteList, clientList: this.clientList, systemScopeList: this.systemScopeList});
var view = new WhiteListFormView({
model: whiteList,
clientList: this.clientList,
systemScopeList: this.systemScopeList
});
view.load(
function() {
view.load(function() {
$('#content').html(view.render().el);
view.delegateEvents();
setPageTitle($.t('whitelist.manage'));
}
);
});
}