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,294 +53,329 @@ 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 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); var regex = new RegExp(expression);
if (attrs.item == null || !attrs.item.match(regex)) { if (attrs.item == null || !attrs.item.match(regex)) {
return "Invalid URI"; return "Invalid URI";
} }
} }
});
});
/* /*
* Backbone JS Reusable ListWidget * Backbone JS Reusable ListWidget Options { collection: Backbone JS Collection
* Options * type: ('uri'|'default') autocomplete: ['item1','item2'] List of auto complete
* { * items }
* collection: Backbone JS Collection *
* type: ('uri'|'default')
* autocomplete: ['item1','item2'] List of auto complete items
* }
*
*/ */
var ListWidgetChildView = Backbone.View.extend({ var ListWidgetChildView = Backbone.View.extend({
tagName: 'tr', tagName: 'tr',
events:{ events: {
"click .btn-delete-list-item":'deleteItem', "click .btn-delete-list-item": 'deleteItem',
"change .checkbox-list-item":'toggleCheckbox' "change .checkbox-list-item": 'toggleCheckbox'
}, },
deleteItem:function (e) { deleteItem: function(e) {
e.preventDefault(); e.preventDefault();
e.stopImmediatePropagation(); e.stopImmediatePropagation();
//this.$el.tooltip('delete'); // this.$el.tooltip('delete');
this.model.destroy({ this.model.destroy({
dataType: false, processData: false, dataType: false,
error:app.errorHandlerView.handleError() processData: false,
}); error: app.errorHandlerView.handleError()
});
}, },
toggleCheckbox:function(e) { toggleCheckbox: function(e) {
e.preventDefault(); e.preventDefault();
e.stopImmediatePropagation(); e.stopImmediatePropagation();
if ($(e.target).is(':checked')) { if ($(e.target).is(':checked')) {
this.options.collection.add(this.model); this.options.collection.add(this.model);
} else { } else {
this.options.collection.remove(this.model); this.options.collection.remove(this.model);
} }
}, },
initialize:function (options) { initialize: function(options) {
this.options = {toggle: false, checked: false}; this.options = {
_.extend(this.options, options); toggle: false,
if (!this.template) { checked: false
this.template = _.template($('#tmpl-list-widget-child').html()); };
} _.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)); this.$el.html(this.template(data));
$('.item-full', this.el).hide(); $('.item-full', this.el).hide();
if (this.model.get('item').length > 30) { 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; var _self = this;
$(this.el).click(function(event) { $(this.el).click(function(event) {
event.preventDefault(); event.preventDefault();
$('.item-short', _self.el).hide(); $('.item-short', _self.el).hide();
$('.item-full', _self.el).show(); $('.item-full', _self.el).show();
_self.$el.tooltip('destroy'); _self.$el.tooltip('destroy');
}); });
} }
$(this.el).i18n();
return this;
$(this.el).i18n(); }
return this;
}
}); });
var ListWidgetView = Backbone.View.extend({ var ListWidgetView = Backbone.View.extend({
tagName: "div", tagName: "div",
events:{ events: {
"click .btn-add-list-item":"addItem", "click .btn-add-list-item": "addItem",
"keypress":function (e) { "keypress": function(e) {
// trap the enter key // trap the enter key
if (e.which == 13) { if (e.which == 13) {
e.preventDefault(); e.preventDefault();
this.addItem(e); this.addItem(e);
$("input", this.$el).focus(); $("input", this.$el).focus();
} }
} }
}, },
initialize:function (options) { initialize: function(options) {
this.options = options; this.options = options;
if (!this.template) { if (!this.template) {
this.template = _.template($('#tmpl-list-widget').html()); this.template = _.template($('#tmpl-list-widget').html());
} }
this.collection.bind('add', this.render, this); this.collection.bind('add', this.render, this);
this.collection.bind('remove', this.render, this); this.collection.bind('remove', this.render, this);
}, },
addItem:function(e) { addItem: function(e) {
e.preventDefault(); e.preventDefault();
var input_value = $("input", this.el).val().trim(); var input_value = $("input", this.el).val().trim();
if (input_value === ""){ if (input_value === "") {
return; return;
} }
var model; var model;
if (this.options.type == 'uri') { if (this.options.type == 'uri') {
model = new URIModel({item:input_value}); model = new URIModel({
} else { item: input_value
model = new Backbone.Model({item:input_value}); });
model.validate = function(attrs) { } else {
if(!attrs.item) { model = new Backbone.Model({
return "value can't be null"; item: input_value
} });
}; model.validate = function(attrs) {
} if (!attrs.item) {
return "value can't be null";
}
};
}
// if it's valid and doesn't already exist // 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({
this.collection.add(model); item: input_value
} else { }).length < 1) {
// else add a visual error indicator this.collection.add(model);
$(".control-group", this.el).addClass('error'); } else {
} // else add a visual error indicator
}, $(".control-group", this.el).addClass('error');
}
},
render:function (eventName) { render: function(eventName) {
this.$el.html(this.template({placeholder:this.options.placeholder, this.$el.html(this.template({
helpBlockText:this.options.helpBlockText})); placeholder: this.options.placeholder,
helpBlockText: this.options.helpBlockText
}));
var _self = this; var _self = this;
if (_.size(this.collection.models) == 0 && _.size(this.options.autocomplete) == 0) { if (_.size(this.collection.models) == 0 && _.size(this.options.autocomplete) == 0) {
$("tbody", _self.el).html($('#tmpl-list-widget-child-empty').html()); $("tbody", _self.el).html($('#tmpl-list-widget-child-empty').html());
} else { } else {
// make a copy of our collection to work from // make a copy of our collection to work from
var values = this.collection.clone(); 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
if (this.options.autocomplete) { // them all as checkboxes
_.each(this.options.autocomplete, function(option) { if (this.options.autocomplete) {
var found = _.find(values.models, function(element) { _.each(this.options.autocomplete, function(option) {
return element.get('item') == option; var found = _.find(values.models, function(element) {
}); return element.get('item') == option;
});
var model = null; var model = null;
var checked = false; var checked = false;
if (found) { if (found) {
// if we found the element, check the box // if we found the element, check the box
model = found; model = found;
checked = true; checked = true;
// and remove it from the list of items to be rendered later // and remove it from the list of items to be rendered
values.remove(found, {silent: true}); // later
} else { values.remove(found, {
model = new Backbone.Model({item:option}); silent: true
checked = false; });
} } else {
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({
$("tbody", _self.el).append(el); model: model,
toggle: true,
checked: checked,
collection: _self.collection
}).render().el;
$("tbody", _self.el).append(el);
}, this); }, 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;
$("tbody", _self.el).append(el);
}, this);
}
// now render everything not in the autocomplete list $(this.el).i18n();
_.each(values.models, function (model) { return this;
var el = new ListWidgetChildView({model:model, collection: _self.collection}).render().el; }
$("tbody", _self.el).append(el);
}, this);
}
$(this.el).i18n();
return this;
}
}); });
var BreadCrumbView = Backbone.View.extend({ var BreadCrumbView = Backbone.View.extend({
tagName: 'ul', tagName: 'ul',
initialize:function (options) { initialize: function(options) {
this.options = options; this.options = options;
if (!this.template) { if (!this.template) {
this.template = _.template($('#tmpl-breadcrumbs').html()); this.template = _.template($('#tmpl-breadcrumbs').html());
} }
this.$el.addClass('breadcrumb'); this.$el.addClass('breadcrumb');
this.collection.bind('add', this.render, this); this.collection.bind('add', this.render, this);
}, },
render:function () { render: function() {
this.$el.empty(); this.$el.empty();
var parent = this; var parent = this;
// go through each of the breadcrumb models // 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
if (index == parent.collection.size() - 1) { // inactive
crumb.set({active:true}, {silent:true}); if (index == parent.collection.size() - 1) {
} else { crumb.set({
crumb.set({active:false}, {silent:true}); active: true
} }, {
silent: true
});
} else {
crumb.set({
active: false
}, {
silent: true
});
}
this.$el.append(this.template(crumb.toJSON())); this.$el.append(this.template(crumb.toJSON()));
}, this); }, this);
$('#breadcrumbs').html(this.el); $('#breadcrumbs').html(this.el);
$(this.el).i18n(); $(this.el).i18n();
} }
}); });
// User Profile // User Profile
var UserProfileView = Backbone.View.extend({ var UserProfileView = Backbone.View.extend({
tagName: 'span', tagName: 'span',
initialize:function(options) { initialize: function(options) {
this.options = options; this.options = options;
if (!this.template) { if (!this.template) {
this.template = _.template($('#tmpl-user-profile-element').html()); this.template = _.template($('#tmpl-user-profile-element').html());
} }
}, },
render:function() { render: function() {
$(this.el).html($('#tmpl-user-profile').html()); $(this.el).html($('#tmpl-user-profile').html());
var t = this.template; var t = this.template;
_.each(this.model, function (value, key) { _.each(this.model, function(value, key) {
if (key && value) { if (key && value) {
if (typeof(value) === 'object') { if (typeof (value) === 'object') {
var el = this.el; var el = this.el;
var k = key; var k = key;
_.each(value, function (value, key) { _.each(value, function(value, key) {
$('dl', el).append( $('dl', el).append(t({
t({key: key, value: value, category: k}) key: key,
); value: value,
}); category: k
} else if (typeof(value) === 'array') { }));
// TODO: handle array types });
} else { } else if (typeof (value) === 'array') {
$('dl', this.el).append( // TODO: handle array types
t({key: key, value: value}) } else {
); $('dl', this.el).append(t({
} key: key,
} value: value
}, this); }));
}
}
}, this);
$(this.el).i18n(); $(this.el).i18n();
return this; return this;
} }
}); });
@ -348,22 +383,22 @@ var UserProfileView = Backbone.View.extend({
// error handler // error handler
var ErrorHandlerView = Backbone.View.extend({ var ErrorHandlerView = Backbone.View.extend({
initialize:function(options) { initialize: function(options) {
this.options = options; this.options = options;
if (!this.template) { if (!this.template) {
this.template = _.template($('#tmpl-error-box').html()); this.template = _.template($('#tmpl-error-box').html());
} }
if (!this.headerTemplate) { if (!this.headerTemplate) {
this.headerTemplate = _.template($('#tmpl-error-header').html()); this.headerTemplate = _.template($('#tmpl-error-header').html());
} }
}, },
reloadPage:function(event) { reloadPage: function(event) {
event.preventDefault(); event.preventDefault();
window.location.reload(true); window.location.reload(true);
}, },
handleError:function(message) { handleError: function(message) {
if (!message) { if (!message) {
message = {}; message = {};
@ -377,17 +412,24 @@ var ErrorHandlerView = Backbone.View.extend({
console.log(message.log); console.log(message.log);
} }
_self.showErrorMessage( _self.showErrorMessage(_self.headerTemplate({
_self.headerTemplate({message: message, model: model, response: response, options: options}), message: message,
_self.template({message: message, model: model, response: response, options: options}) 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); $('#modalAlert .modal-body .page-reload').on('click', _self.reloadPage);
} }
}, },
showErrorMessage:function(header, message) { showErrorMessage: function(header, message) {
// hide the sheet if it's visible // hide the sheet if it's visible
$('#loadingbox').sheet('hide'); $('#loadingbox').sheet('hide');
@ -404,58 +446,62 @@ var ErrorHandlerView = Backbone.View.extend({
} }
}); });
// Router // Router
var AppRouter = Backbone.Router.extend({ var AppRouter = Backbone.Router.extend({
routes:{ routes: {
"": "root" "": "root"
}, },
root:function() { root: function() {
if (isAdmin()) { if (isAdmin()) {
this.navigate('admin/clients', {trigger: true}); this.navigate('admin/clients', {
} else { trigger: true
this.navigate('user/approved', {trigger: true}); });
} } else {
}, this.navigate('user/approved', {
trigger: true
});
}
},
initialize:function () { initialize: function() {
this.breadCrumbView = new BreadCrumbView({ this.breadCrumbView = new BreadCrumbView({
collection:new Backbone.Collection() collection: new Backbone.Collection()
}); });
this.breadCrumbView.render(); this.breadCrumbView.render();
this.errorHandlerView = new ErrorHandlerView(); this.errorHandlerView = new ErrorHandlerView();
// call all the extra initialization functions // call all the extra initialization functions
var app = this; var app = this;
_.each(ui.init, function(fn) { _.each(ui.init, function(fn) {
fn(app); fn(app);
}); });
}, },
notImplemented:function(){ notImplemented: function() {
this.breadCrumbView.collection.reset(); this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([ this.breadCrumbView.collection.add([{
{text:$.t('admin.home'), href:""} text: $.t('admin.home'),
]); href: ""
}]);
this.updateSidebar('none'); this.updateSidebar('none');
$('#content').html("<h2>Not implemented yet.</h2>"); $('#content').html("<h2>Not implemented yet.</h2>");
}, },
updateSidebar:function(item) { updateSidebar: function(item) {
$('.sidebar-nav li.active').removeClass('active'); $('.sidebar-nav li.active').removeClass('active');
$('.sidebar-nav li a[href^="manage/#' + item + '"]').parent().addClass('active'); $('.sidebar-nav li a[href^="manage/#' + item + '"]').parent().addClass('active');
} }
}); });
// holds the global app. // holds the global app.
@ -463,59 +509,67 @@ var AppRouter = Backbone.Router.extend({
var app = null; var app = null;
// main // main
$(function () { $(function() {
var loader = function(source) { var loader = function(source) {
return $.get(source, function (templates) { return $.get(source, function(templates) {
console.log('Loading file: ' + source); console.log('Loading file: ' + source);
$('#templates').append(templates); $('#templates').append(templates);
}); });
}; };
// load templates and append them to the body // load templates and append them to the body
$.when.apply(null, ui.templates.map(loader) $.when.apply(null, ui.templates.map(loader)).done(function() {
).done(function() { console.log('done');
console.log('done'); $.ajaxSetup({
$.ajaxSetup({cache:false}); cache: false
app = new AppRouter(); });
app = new AppRouter();
_.each(ui.routes.reverse(), function(route) { _.each(ui.routes.reverse(), function(route) {
console.log("Adding route: " + route.name); console.log("Adding route: " + route.name);
app.route(route.path, route.name, route.callback); app.route(route.path, route.name, route.callback);
}); });
app.on('route', function(name, args) { app.on('route', function(name, args) {
// scroll to top of page on new route selection // 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 // grab all hashed URLs and send them through the app router instead
$(document).on('click', 'a[href^="manage/#"]', function(event) { $(document).on('click', 'a[href^="manage/#"]', function(event) {
event.preventDefault(); event.preventDefault();
app.navigate(this.hash.slice(1), {trigger: true}); app.navigate(this.hash.slice(1), {
}); trigger: true
});
});
var base = $('base').attr('href'); var base = $('base').attr('href');
$.getJSON(base + '.well-known/openid-configuration', function(data) { $.getJSON(base + '.well-known/openid-configuration', function(data) {
app.serverConfiguration = data; app.serverConfiguration = data;
var baseUrl = $.url(app.serverConfiguration.issuer); 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); 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-header').html($.t('error.title'));
$('#modalAlert div.modal-body').html($.t('error.message') + message + ' <br /> ' + [filename, lineno, colno, error]); $('#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 $("#modalAlert").modal({ // wire up the actual modal functionality
"backdrop" : "static", // and show the dialog
"keyboard" : true, "backdrop": "static",
"show" : true // ensure the modal is shown immediately "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({ var BlackListCollection = Backbone.Collection.extend({
initialize: function() { }, initialize: function() {
},
url: "api/blacklist" url: "api/blacklist"
}); });
@ -29,50 +30,50 @@ var BlackListCollection = Backbone.Collection.extend({
var BlackListListView = Backbone.View.extend({ var BlackListListView = Backbone.View.extend({
tagName: 'span', tagName: 'span',
initialize:function(options) { initialize: function(options) {
this.options = options; this.options = options;
}, },
load:function(callback) { load: function(callback) {
if (this.collection.isFetched) { if (this.collection.isFetched) {
callback(); callback();
return; return;
} }
$('#loadingbox').sheet('show'); $('#loadingbox').sheet('show');
$('#loading').html( $('#loading').html('<span class="label" id="loading-blacklist">' + $.t('admin.blacklist') + '</span> ');
'<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()})) $.when(this.collection.fetchIfNeeded({
.done(function() { success: function(e) {
$('#loadingbox').sheet('hide'); $('#loading-blacklist').addClass('label-success');
callback(); },
}); error: app.errorHandlerView.handleError()
}, })).done(function() {
$('#loadingbox').sheet('hide');
callback();
});
},
events: { events: {
"click .refresh-table":"refreshTable", "click .refresh-table": "refreshTable",
"click .btn-add":"addItem", "click .btn-add": "addItem",
"submit #add-blacklist form":"addItem" "submit #add-blacklist form": "addItem"
}, },
refreshTable:function(e) { refreshTable: function(e) {
e.preventDefault(); e.preventDefault();
var _self = this; var _self = this;
$('#loadingbox').sheet('show'); $('#loadingbox').sheet('show');
$('#loading').html( $('#loading').html('<span class="label" id="loading-blacklist">' + $.t('admin.blacklist') + '</span> ');
'<span class="label" id="loading-blacklist">' + $.t('admin.blacklist') + '</span> '
);
$.when(this.collection.fetch()).done(function() { $.when(this.collection.fetch()).done(function() {
$('#loadingbox').sheet('hide'); $('#loadingbox').sheet('hide');
_self.render(); _self.render();
}); });
}, },
togglePlaceholder:function() { togglePlaceholder: function() {
if (this.collection.length > 0) { if (this.collection.length > 0) {
$('#blacklist-table', this.el).show(); $('#blacklist-table', this.el).show();
$('#blacklist-table-empty', this.el).hide(); $('#blacklist-table-empty', this.el).hide();
@ -82,47 +83,49 @@ var BlackListListView = Backbone.View.extend({
} }
}, },
render:function (eventName) { render: function(eventName) {
$(this.el).html($('#tmpl-blacklist-table').html()); $(this.el).html($('#tmpl-blacklist-table').html());
var _self = this; var _self = this;
_.each(this.collection.models, function(blacklist) { _.each(this.collection.models, function(blacklist) {
var view = new BlackListWidgetView({model: blacklist}); var view = new BlackListWidgetView({
model: blacklist
});
view.parentView = _self; view.parentView = _self;
$("#blacklist-table", _self.el).append(view.render().el); $("#blacklist-table", _self.el).append(view.render().el);
}, this); }, this);
this.togglePlaceholder(); this.togglePlaceholder();
$(this.el).i18n(); $(this.el).i18n();
return this; return this;
}, },
addItem:function(e) { addItem: function(e) {
e.preventDefault(); e.preventDefault();
var input_value = $("#blacklist-uri", this.el).val().trim(); var input_value = $("#blacklist-uri", this.el).val().trim();
if (input_value === "") { if (input_value === "") {
return; return;
} }
// TODO: URI/pattern validation, check against existing clients // TODO: URI/pattern validation, check against existing clients
var item = new BlackListModel({ var item = new BlackListModel({
uri: input_value uri: input_value
}); });
var _self = this; // closures... var _self = this; // closures...
item.save({}, { item.save({}, {
success:function() { success: function() {
_self.collection.add(item); _self.collection.add(item);
_self.render(); _self.render();
}, },
error:app.errorHandlerView.handleError() error: app.errorHandlerView.handleError()
}); });
} }
@ -132,7 +135,7 @@ var BlackListWidgetView = Backbone.View.extend({
tagName: 'tr', tagName: 'tr',
initialize:function(options) { initialize: function(options) {
this.options = options; this.options = options;
if (!this.template) { if (!this.template) {
@ -140,49 +143,51 @@ var BlackListWidgetView = Backbone.View.extend({
} }
}, },
render:function() { render: function() {
this.$el.html(this.template(this.model.toJSON())); this.$el.html(this.template(this.model.toJSON()));
return this; return this;
}, },
events:{ events: {
'click .btn-delete':'deleteBlacklist' 'click .btn-delete': 'deleteBlacklist'
}, },
deleteBlacklist:function (e) { deleteBlacklist: function(e) {
e.preventDefault(); e.preventDefault();
if (confirm($.t("blacklist.confirm"))) { if (confirm($.t("blacklist.confirm"))) {
var _self = this; var _self = this;
this.model.destroy({ this.model.destroy({
dataType: false, processData: false, dataType: false,
success:function () { processData: false,
success: function() {
_self.$el.fadeTo("fast", 0.00, function () { //fade _self.$el.fadeTo("fast", 0.00, function() { // fade
$(this).slideUp("fast", function () { //slide up $(this).slideUp("fast", function() { // slide up
$(this).remove(); //then remove from the DOM $(this).remove(); // then remove from the DOM
_self.parentView.togglePlaceholder(); _self.parentView.togglePlaceholder();
}); });
}); });
}, },
error:app.errorHandlerView.handleError() error: app.errorHandlerView.handleError()
}); });
_self.parentView.delegateEvents(); _self.parentView.delegateEvents();
} }
return false; return false;
} }
}); });
ui.routes.push({
ui.routes.push({path: "admin/blacklist", name: "blackList", callback: path: "admin/blacklist",
function() { name: "blackList",
callback: function() {
if (!isAdmin()) { if (!isAdmin()) {
this.root(); this.root();
@ -190,21 +195,24 @@ ui.routes.push({path: "admin/blacklist", name: "blackList", callback:
} }
this.breadCrumbView.collection.reset(); this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([ this.breadCrumbView.collection.add([{
{text:$.t('admin.home'), href:""}, text: $.t('admin.home'),
{text:$.t('admin.manage-blacklist'), href:"manage/#admin/blacklist"} href: ""
]); }, {
text: $.t('admin.manage-blacklist'),
href: "manage/#admin/blacklist"
}]);
this.updateSidebar('admin/blacklist'); this.updateSidebar('admin/blacklist');
var view = new BlackListListView({collection: this.blackListList}); var view = new BlackListListView({
collection: this.blackListList
});
view.load( view.load(function(collection, response, options) {
function(collection, response, options) { $('#content').html(view.render().el);
$('#content').html(view.render().el); setPageTitle($.t('admin.manage-blacklist'));
setPageTitle($.t('admin.manage-blacklist')); });
}
);
} }
}); });
@ -212,5 +220,5 @@ ui.routes.push({path: "admin/blacklist", name: "blackList", callback:
ui.templates.push('resources/template/blacklist.html'); ui.templates.push('resources/template/blacklist.html');
ui.init.push(function(app) { ui.init.push(function(app) {
app.blackListList = new BlackListCollection(); app.blackListList = new BlackListCollection();
}); });

View File

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

View File

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

View File

@ -15,40 +15,40 @@
* limitations under the License. * limitations under the License.
*******************************************************************************/ *******************************************************************************/
var ResRegClient = Backbone.Model.extend({ var ResRegClient = Backbone.Model.extend({
idAttribute: "client_id", idAttribute: "client_id",
defaults:{ defaults: {
client_id:null, client_id: null,
client_secret:null, client_secret: null,
client_name:null, client_name: null,
client_uri:null, client_uri: null,
logo_uri:null, logo_uri: null,
contacts:[], contacts: [],
tos_uri:null, tos_uri: null,
token_endpoint_auth_method:null, token_endpoint_auth_method: null,
scope:null, scope: null,
policy_uri:null, policy_uri: null,
jwks_uri:null, jwks_uri: null,
jwks:null, jwks: null,
jwksType:'URI', jwksType: 'URI',
application_type:null, application_type: null,
registration_access_token:null, registration_access_token: null,
registration_client_uri:null registration_client_uri: null
}, },
sync: function(method, model, options){ sync: function(method, model, options) {
if (model.get('registration_access_token')) { if (model.get('registration_access_token')) {
var headers = options.headers ? options.headers : {}; var headers = options.headers ? options.headers : {};
headers['Authorization'] = 'Bearer ' + model.get('registration_access_token'); headers['Authorization'] = 'Bearer ' + model.get('registration_access_token');
options.headers = headers; options.headers = headers;
} }
return this.constructor.__super__.sync(method, model, options); return this.constructor.__super__.sync(method, model, options);
}, },
urlRoot:'resource' urlRoot: 'resource'
}); });
@ -56,46 +56,52 @@ var ResRegRootView = Backbone.View.extend({
tagName: 'span', tagName: 'span',
initialize:function(options) { initialize: function(options) {
this.options = options; this.options = options;
}, },
events:{ events: {
"click #newreg":"newReg", "click #newreg": "newReg",
"click #editreg":"editReg" "click #editreg": "editReg"
}, },
load:function(callback) { load: function(callback) {
if (this.options.systemScopeList.isFetched) { if (this.options.systemScopeList.isFetched) {
callback(); callback();
return; return;
} }
$('#loadingbox').sheet('show'); $('#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.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}, error:app.errorHandlerView.handleError()})) $.when(this.options.systemScopeList.fetchIfNeeded({
.done(function() { success: function(e) {
$('#loadingbox').sheet('hide'); $('#loading-scopes').addClass('label-success');
callback(); },
}); error: app.errorHandlerView.handleError()
})).done(function() {
$('#loadingbox').sheet('hide');
callback();
});
}, },
render:function() { render: function() {
$(this.el).html($('#tmpl-rsreg').html()); $(this.el).html($('#tmpl-rsreg').html());
$(this.el).i18n(); $(this.el).i18n();
return this; return this;
}, },
newReg:function(e) { newReg: function(e) {
e.preventDefault(); e.preventDefault();
this.remove(); this.remove();
app.navigate('dev/resource/new', {trigger: true}); app.navigate('dev/resource/new', {
trigger: true
});
}, },
editReg:function(e) { editReg: function(e) {
e.preventDefault(); e.preventDefault();
var clientId = $('#clientId').val(); var clientId = $('#clientId').val();
var token = $('#regtoken').val(); var token = $('#regtoken').val();
@ -109,27 +115,38 @@ var ResRegRootView = Backbone.View.extend({
client.fetch({ client.fetch({
success: function() { success: function() {
if (client.get("jwks")) { if (client.get("jwks")) {
client.set({ client.set({
jwksType: "VAL" jwksType: "VAL"
}, { silent: true }); }, {
} else { silent: true
client.set({ });
jwksType: "URI" } else {
}, { silent: true }); client.set({
} jwksType: "URI"
}, {
silent: true
});
}
var view = new ResRegEditView({model: client, systemScopeList: app.systemScopeList}); var view = new ResRegEditView({
model: client,
systemScopeList: app.systemScopeList
});
view.load(function() { view.load(function() {
$('#content').html(view.render().el); $('#content').html(view.render().el);
view.delegateEvents(); view.delegateEvents();
setPageTitle($.t('rsreg.new')); setPageTitle($.t('rsreg.new'));
app.navigate('dev/resource/edit', {trigger: true}); app.navigate('dev/resource/edit', {
self.remove(); 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,330 +156,376 @@ var ResRegEditView = Backbone.View.extend({
tagName: 'span', tagName: 'span',
initialize:function(options) { initialize: function(options) {
this.options = options; this.options = options;
if (!this.template) { if (!this.template) {
this.template = _.template($('#tmpl-rsreg-resource-form').html()); this.template = _.template($('#tmpl-rsreg-resource-form').html());
} }
this.redirectUrisCollection = new Backbone.Collection(); this.redirectUrisCollection = new Backbone.Collection();
this.scopeCollection = new Backbone.Collection(); this.scopeCollection = new Backbone.Collection();
this.contactsCollection = new Backbone.Collection(); this.contactsCollection = new Backbone.Collection();
this.defaultAcrValuesCollection = new Backbone.Collection(); this.defaultAcrValuesCollection = new Backbone.Collection();
this.requestUrisCollection = new Backbone.Collection(); this.requestUrisCollection = new Backbone.Collection();
this.listWidgetViews = []; this.listWidgetViews = [];
}, },
load:function(callback) { load: function(callback) {
if (this.options.systemScopeList.isFetched) { if (this.options.systemScopeList.isFetched) {
callback(); callback();
return; return;
} }
$('#loadingbox').sheet('show'); $('#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.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}, error:app.errorHandlerView.handleError()})) $.when(this.options.systemScopeList.fetchIfNeeded({
.done(function() { success: function(e) {
$('#loadingbox').sheet('hide'); $('#loading-scopes').addClass('label-success');
callback(); },
}); error: app.errorHandlerView.handleError()
})).done(function() {
$('#loadingbox').sheet('hide');
callback();
});
}, },
events:{ events: {
"click .btn-save":"saveClient", "click .btn-save": "saveClient",
"click .btn-cancel":"cancel", "click .btn-cancel": "cancel",
"click .btn-delete":"deleteClient", "click .btn-delete": "deleteClient",
"change #logoUri input":"previewLogo", "change #logoUri input": "previewLogo",
"change #tokenEndpointAuthMethod input:radio":"toggleClientCredentials", "change #tokenEndpointAuthMethod input:radio": "toggleClientCredentials",
"change #jwkSelector input:radio":"toggleJWKSetType" "change #jwkSelector input:radio": "toggleJWKSetType"
}, },
cancel:function(e) { cancel: function(e) {
e.preventDefault(); e.preventDefault();
app.navigate('dev/resource', {trigger: true}); app.navigate('dev/resource', {
}, trigger: true
});
},
deleteClient:function (e) { deleteClient: function(e) {
e.preventDefault(); e.preventDefault();
if (confirm($.t('client.client-table.confirm'))) { if (confirm($.t('client.client-table.confirm'))) {
var self = this; var self = this;
this.model.destroy({ this.model.destroy({
dataType: false, processData: false, dataType: false,
success:function () { processData: false,
self.remove(); success: function() {
app.navigate('dev/resource', {trigger: true}); self.remove();
}, app.navigate('dev/resource', {
error:app.errorHandlerView.handleError() trigger: true
}); });
},
error: app.errorHandlerView.handleError()
});
} }
return false; return false;
}, },
previewLogo:function() { previewLogo: function() {
if ($('#logoUri input', this.el).val()) { if ($('#logoUri input', this.el).val()) {
$('#logoPreview', this.el).empty(); $('#logoPreview', this.el).empty();
$('#logoPreview', this.el).attr('src', $('#logoUri input', this.el).val()); $('#logoPreview', this.el).attr('src', $('#logoUri input', this.el).val());
} else { } else {
//$('#logoBlock', this.el).hide(); // $('#logoBlock', this.el).hide();
$('#logoPreview', this.el).attr('src', 'resources/images/logo_placeholder.gif'); $('#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
* @param event * parameter
*/ *
toggleClientCredentials:function() { * @param event
*/
toggleClientCredentials: function() {
var tokenEndpointAuthMethod = $('#tokenEndpointAuthMethod input', this.el).filter(':checked').val(); var tokenEndpointAuthMethod = $('#tokenEndpointAuthMethod input', this.el).filter(':checked').val();
// show or hide the signing algorithm method depending on what's selected // show or hide the signing algorithm method depending on what's
if (tokenEndpointAuthMethod == 'private_key_jwt' // selected
|| tokenEndpointAuthMethod == 'client_secret_jwt') { if (tokenEndpointAuthMethod == 'private_key_jwt' || tokenEndpointAuthMethod == 'client_secret_jwt') {
$('#tokenEndpointAuthSigningAlg', this.el).show(); $('#tokenEndpointAuthSigningAlg', this.el).show();
} else { } else {
$('#tokenEndpointAuthSigningAlg', this.el).hide(); $('#tokenEndpointAuthSigningAlg', this.el).hide();
} }
}, },
/** /**
* Set up the form based on the JWK Set selector * Set up the form based on the JWK Set selector
*/ */
toggleJWKSetType:function() { toggleJWKSetType: function() {
var jwkSelector = $('#jwkSelector input:radio', this.el).filter(':checked').val(); var jwkSelector = $('#jwkSelector input:radio', this.el).filter(':checked').val();
if (jwkSelector == 'URI') { if (jwkSelector == 'URI') {
$('#jwksUri', this.el).show(); $('#jwksUri', this.el).show();
$('#jwks', this.el).hide(); $('#jwks', this.el).hide();
} else if (jwkSelector == 'VAL') { } else if (jwkSelector == 'VAL') {
$('#jwksUri', this.el).hide(); $('#jwksUri', this.el).hide();
$('#jwks', this.el).show(); $('#jwks', this.el).show();
} else { } else {
$('#jwksUri', this.el).hide(); $('#jwksUri', this.el).hide();
$('#jwks', this.el).hide(); $('#jwks', this.el).hide();
} }
}, },
disableUnsupportedJOSEItems:function(serverSupported, query) { disableUnsupportedJOSEItems: function(serverSupported, query) {
var supported = ['default']; var supported = ['default'];
if (serverSupported) { if (serverSupported) {
supported = _.union(supported, serverSupported); supported = _.union(supported, serverSupported);
} }
$(query, this.$el).each(function(idx) { $(query, this.$el).each(function(idx) {
if(_.contains(supported, $(this).val())) { if (_.contains(supported, $(this).val())) {
$(this).prop('disabled', false); $(this).prop('disabled', false);
} else { } else {
$(this).prop('disabled', true); $(this).prop('disabled', true);
} }
}); });
}, },
// returns "null" if given the value "default" as a string, otherwise returns input value. useful for parsing the JOSE algorithm dropdowns // returns "null" if given the value "default" as a string,
defaultToNull:function(value) { // otherwise returns input value. useful for parsing the JOSE
if (value == 'default') { // algorithm dropdowns
return null; defaultToNull: function(value) {
} else { if (value == 'default') {
return value; return null;
} } else {
}, return value;
}
},
saveClient:function (e) { saveClient: function(e) {
e.preventDefault(); e.preventDefault();
$('.control-group').removeClass('error'); $('.control-group').removeClass('error');
// sync any leftover collection items // sync any leftover collection items
_.each(this.listWidgetViews, function(v) { _.each(this.listWidgetViews, function(v) {
v.addItem($.Event('click')); v.addItem($.Event('click'));
}); });
// build the scope object // build the scope object
var scopes = this.scopeCollection.pluck("item").join(" "); var scopes = this.scopeCollection.pluck("item").join(" ");
var contacts = this.contactsCollection.pluck('item'); var contacts = this.contactsCollection.pluck('item');
var userInfo = getUserInfo(); var userInfo = getUserInfo();
if (userInfo && userInfo.email) { if (userInfo && userInfo.email) {
if (!_.contains(contacts, userInfo.email)) { if (!_.contains(contacts, userInfo.email)) {
contacts.push(userInfo.email); contacts.push(userInfo.email);
} }
} }
// process the JWKS // process the JWKS
var jwksUri = null; var jwksUri = null;
var jwks = null; var jwks = null;
var jwkSelector = $('#jwkSelector input:radio', this.el).filter(':checked').val(); var jwkSelector = $('#jwkSelector input:radio', this.el).filter(':checked').val();
if (jwkSelector == 'URI') { if (jwkSelector == 'URI') {
jwksUri = $('#jwksUri input').val(); jwksUri = $('#jwksUri input').val();
jwks = null; jwks = null;
} else if (jwkSelector == 'VAL') { } else if (jwkSelector == 'VAL') {
jwksUri = null; jwksUri = null;
try { try {
jwks = JSON.parse($('#jwks textarea').val()); jwks = JSON.parse($('#jwks textarea').val());
} catch (e) { } catch (e) {
console.log("An error occurred when parsing the JWK Set"); 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")); app.errorHandlerView.showErrorMessage($.t("client.client-form.error.jwk-set"), $.t("client.client-form.error.jwk-set-parse"));
return false; return false;
} }
} else { } else {
jwksUri = null; jwksUri = null;
jwks = null; jwks = null;
} }
var attrs = { var attrs = {
client_name:$('#clientName input').val(), client_name: $('#clientName input').val(),
logo_uri:$('#logoUri input').val(), logo_uri: $('#logoUri input').val(),
scope: scopes, scope: scopes,
client_secret: null, // never send a client secret client_secret: null, // never send a client secret
tos_uri: $('#tosUri input').val(), tos_uri: $('#tosUri input').val(),
policy_uri: $('#policyUri input').val(), policy_uri: $('#policyUri input').val(),
client_uri: $('#clientUri input').val(), client_uri: $('#clientUri input').val(),
application_type: $('#applicationType input').filter(':checked').val(), application_type: $('#applicationType input').filter(':checked').val(),
jwks_uri: jwksUri, jwks_uri: jwksUri,
jwks: jwks, jwks: jwks,
token_endpoint_auth_method: $('#tokenEndpointAuthMethod input').filter(':checked').val(), token_endpoint_auth_method: $('#tokenEndpointAuthMethod input').filter(':checked').val(),
contacts: contacts, contacts: contacts,
token_endpoint_auth_signing_alg: this.defaultToNull($('#tokenEndpointAuthSigningAlg select').val()) token_endpoint_auth_signing_alg: this.defaultToNull($('#tokenEndpointAuthSigningAlg select').val())
}; };
// set all empty strings to nulls // set all empty strings to nulls
for (var key in attrs) { for ( var key in attrs) {
if (attrs[key] === "") { if (attrs[key] === "") {
attrs[key] = null; attrs[key] = null;
} }
} }
var _self = this; var _self = this;
this.model.save(attrs, { this.model.save(attrs, {
success:function () { success: function() {
// switch to an "edit" view // switch to an "edit" view
app.navigate('dev/resource/edit', {trigger: true}); app.navigate('dev/resource/edit', {
_self.remove(); trigger: true
});
_self.remove();
if (_self.model.get("jwks")) { if (_self.model.get("jwks")) {
_self.model.set({ _self.model.set({
jwksType: "VAL" jwksType: "VAL"
}, { silent: true }); }, {
} else { silent: true
_self.model.set({ });
jwksType: "URI" } else {
}, { silent: true }); _self.model.set({
} jwksType: "URI"
}, {
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() { view.load(function() {
// reload // reload
$('#content').html(view.render().el); $('#content').html(view.render().el);
view.delegateEvents(); view.delegateEvents();
}); });
}, },
error:app.errorHandlerView.handleError() error: app.errorHandlerView.handleError()
}); });
return false; return false;
}, },
render:function() { render: function() {
$(this.el).html(this.template({client: this.model.toJSON(), userInfo: getUserInfo()})); $(this.el).html(this.template({
client: this.model.toJSON(),
userInfo: getUserInfo()
}));
this.listWidgetViews = []; this.listWidgetViews = [];
var _self = this; var _self = this;
// build and bind scopes // build and bind scopes
var scopes = this.model.get("scope"); var scopes = this.model.get("scope");
var scopeSet = scopes ? scopes.split(" ") : []; var scopeSet = scopes ? scopes.split(" ") : [];
_.each(scopeSet, function (scope) { _.each(scopeSet, function(scope) {
_self.scopeCollection.add(new Backbone.Model({item:scope})); _self.scopeCollection.add(new Backbone.Model({
}); item: scope
}));
});
var scopeView = new ListWidgetView({ var scopeView = new ListWidgetView({
placeholder: $.t('client.client-form.scope-placeholder'), placeholder: $.t('client.client-form.scope-placeholder'),
autocomplete: _.uniq(_.flatten(this.options.systemScopeList.unrestrictedScopes().pluck("value"))), autocomplete: _.uniq(_.flatten(this.options.systemScopeList.unrestrictedScopes().pluck("value"))),
helpBlockText: $.t('rsreg.client-form.scope-help'), helpBlockText: $.t('rsreg.client-form.scope-help'),
collection: this.scopeCollection}); collection: this.scopeCollection
$("#scope .controls",this.el).html(scopeView.render().el); });
this.listWidgetViews.push(scopeView); $("#scope .controls", this.el).html(scopeView.render().el);
this.listWidgetViews.push(scopeView);
// build and bind contacts // build and bind contacts
_.each(this.model.get('contacts'), function (contact) { _.each(this.model.get('contacts'), function(contact) {
_self.contactsCollection.add(new Backbone.Model({item:contact})); _self.contactsCollection.add(new Backbone.Model({
}); item: contact
}));
});
var contactView = new ListWidgetView({ var contactView = new ListWidgetView({
placeholder: $.t('client.client-form.contacts-placeholder'), placeholder: $.t('client.client-form.contacts-placeholder'),
helpBlockText: $.t('client.client-form.contacts-help'), 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); $("#contacts .controls", this.el).html(contactView.render().el);
this.listWidgetViews.push(contactView);
this.toggleClientCredentials();
this.previewLogo();
this.toggleJWKSetType();
this.toggleClientCredentials(); // disable unsupported JOSE algorithms
this.previewLogo(); this.disableUnsupportedJOSEItems(app.serverConfiguration.token_endpoint_auth_signing_alg_values_supported, '#tokenEndpointAuthSigningAlg option');
this.toggleJWKSetType();
// disable unsupported JOSE algorithms this.$('.nyi').clickover({
this.disableUnsupportedJOSEItems(app.serverConfiguration.token_endpoint_auth_signing_alg_values_supported, '#tokenEndpointAuthSigningAlg option'); placement: 'right',
title: $.t('common.not-yet-implemented'),
content: $.t('common.not-yet-implemented-content')
});
this.$('.nyi').clickover({ $(this.el).i18n();
placement: 'right', return this;
title: $.t('common.not-yet-implemented'),
content: $.t('common.not-yet-implemented-content')
});
$(this.el).i18n();
return this;
} }
}); });
ui.routes.push({path: "dev/resource", name: "resReg", callback: ui.routes.push({
function() { path: "dev/resource",
name: "resReg",
callback: function() {
this.breadCrumbView.collection.reset(); this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([ this.breadCrumbView.collection.add([{
{text:$.t('admin.home'), href:""}, text: $.t('admin.home'),
{text:$.t('admin.self-service-resource'), href:"manage/#dev/resource"} href: ""
]); }, {
text: $.t('admin.self-service-resource'),
href: "manage/#dev/resource"
}]);
this.updateSidebar('dev/resource'); this.updateSidebar('dev/resource');
var view = new ResRegRootView({systemScopeList: this.systemScopeList}); var view = new ResRegRootView({
systemScopeList: this.systemScopeList
});
view.load(function() { view.load(function() {
$('#content').html(view.render().el); $('#content').html(view.render().el);
setPageTitle($.t('admin.self-service-resource')); setPageTitle($.t('admin.self-service-resource'));
}); });
} }
}); });
ui.routes.push({path: "dev/resource/new", name: "newResReg", callback: ui.routes.push({
function() { path: "dev/resource/new",
name: "newResReg",
callback: function() {
this.breadCrumbView.collection.reset(); this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([ this.breadCrumbView.collection.add([{
{text:$.t('admin.home'), href:""}, text: $.t('admin.home'),
{text:$.t('admin.self-service-resource'), href:"manage/#dev/resource"}, href: ""
{text:$.t('rsreg.new'), href:"manage/#dev/resource/new"} }, {
]); text: $.t('admin.self-service-resource'),
href: "manage/#dev/resource"
}, {
text: $.t('rsreg.new'),
href: "manage/#dev/resource/new"
}]);
this.updateSidebar('dev/resource'); this.updateSidebar('dev/resource');
var client = new ResRegClient(); 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() { view.load(function() {
@ -473,10 +536,12 @@ ui.routes.push({path: "dev/resource/new", name: "newResReg", callback:
} }
client.set({ client.set({
scope: _.uniq(_.flatten(app.systemScopeList.defaultUnrestrictedScopes().pluck("value"))).join(" "), scope: _.uniq(_.flatten(app.systemScopeList.defaultUnrestrictedScopes().pluck("value"))).join(" "),
token_endpoint_auth_method: 'client_secret_basic', token_endpoint_auth_method: 'client_secret_basic',
contacts: contacts contacts: contacts
}, { silent: true }); }, {
silent: true
});
$('#content').html(view.render().el); $('#content').html(view.render().el);
view.delegateEvents(); 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: ui.routes.push({
function() { path: "dev/resource/edit",
name: "editResReg",
callback: function() {
this.breadCrumbView.collection.reset(); this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([ this.breadCrumbView.collection.add([{
{text:$.t('admin.home'), href:""}, text: $.t('admin.home'),
{text:$.t('admin.self-service-resource'), href:"manage/#dev/resource"}, href: ""
{text:$.t('rsreg.edit'), href:"manage/#dev/resource/edit"} }, {
]); text: $.t('admin.self-service-resource'),
href: "manage/#dev/resource"
}, {
text: $.t('rsreg.edit'),
href: "manage/#dev/resource/edit"
}]);
this.updateSidebar('dev/resource'); this.updateSidebar('dev/resource');
setPageTitle($.t('rsreg.edit')); 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({ var SystemScopeModel = Backbone.Model.extend({
idAttribute: 'id', idAttribute: 'id',
defaults:{ defaults: {
id:null, id: null,
description:null, description: null,
icon:null, icon: null,
value:null, value: null,
defaultScope:false, defaultScope: false,
restricted:false restricted: false
}, },
urlRoot: 'api/scopes' urlRoot: 'api/scopes'
@ -58,7 +58,9 @@ var SystemScopeCollection = Backbone.Collection.extend({
}, },
getByValue: function(value) { getByValue: function(value) {
var scopes = this.where({value: value}); var scopes = this.where({
value: value
});
if (scopes.length == 1) { if (scopes.length == 1) {
return scopes[0]; return scopes[0];
} else { } else {
@ -72,119 +74,132 @@ var SystemScopeView = Backbone.View.extend({
tagName: 'tr', tagName: 'tr',
initialize:function (options) { initialize: function(options) {
this.options = options; this.options = options;
if (!this.template) { if (!this.template) {
this.template = _.template($('#tmpl-system-scope').html()); this.template = _.template($('#tmpl-system-scope').html());
} }
this.model.bind('change', this.render, this); this.model.bind('change', this.render, this);
},
events: {
'click .btn-edit':'editScope',
'click .btn-delete':'deleteScope'
}, },
editScope:function(e) { events: {
e.preventDefault(); 'click .btn-edit': 'editScope',
app.navigate('admin/scope/' + this.model.id, {trigger: true}); 'click .btn-delete': 'deleteScope'
}, },
render:function (eventName) { editScope: function(e) {
this.$el.html(this.template(this.model.toJSON())); e.preventDefault();
app.navigate('admin/scope/' + this.model.id, {
trigger: true
});
},
$('.restricted', this.el).tooltip({title: $.t('scope.system-scope-table.tooltip-restricted')}); render: function(eventName) {
$('.default', this.el).tooltip({title: $.t('scope.system-scope-table.tooltip-default')}); this.$el.html(this.template(this.model.toJSON()));
$(this.el).i18n(); $('.restricted', this.el).tooltip({
return this; title: $.t('scope.system-scope-table.tooltip-restricted')
}, });
$('.default', this.el).tooltip({
title: $.t('scope.system-scope-table.tooltip-default')
});
deleteScope:function (e) { $(this.el).i18n();
e.preventDefault(); return this;
},
if (confirm($.t("scope.system-scope-table.confirm"))) { deleteScope: function(e) {
var _self = this; e.preventDefault();
this.model.destroy({ if (confirm($.t("scope.system-scope-table.confirm"))) {
dataType: false, processData: false, var _self = this;
success:function () {
_self.$el.fadeTo("fast", 0.00, function () { //fade this.model.destroy({
$(this).slideUp("fast", function () { //slide up dataType: false,
$(this).remove(); //then remove from the DOM processData: false,
_self.parentView.togglePlaceholder(); success: function() {
});
});
},
error:app.errorHandlerView.handleError()
});
_self.parentView.delegateEvents(); _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()
});
return false; _self.parentView.delegateEvents();
}, }
close:function () { return false;
$(this.el).unbind(); },
$(this.el).empty();
} close: function() {
$(this.el).unbind();
$(this.el).empty();
}
}); });
var SystemScopeListView = Backbone.View.extend({ var SystemScopeListView = Backbone.View.extend({
tagName: 'span', tagName: 'span',
initialize:function(options) { initialize: function(options) {
this.options = options; this.options = options;
}, },
load:function(callback) { load: function(callback) {
if (this.model.isFetched) { if (this.model.isFetched) {
callback(); callback();
return; return;
} }
$('#loadingbox').sheet('show'); $('#loadingbox').sheet('show');
$('#loading').html( $('#loading').html('<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ');
'<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()})) $.when(this.model.fetchIfNeeded({
.done(function() { success: function(e) {
$('#loadingbox').sheet('hide'); $('#loading-scopes').addClass('label-success');
callback(); },
}); error: app.errorHandlerView.handleError()
}, })).done(function() {
$('#loadingbox').sheet('hide');
events:{ callback();
"click .new-scope":"newScope", });
"click .refresh-table":"refreshTable"
}, },
newScope:function(e) { events: {
"click .new-scope": "newScope",
"click .refresh-table": "refreshTable"
},
newScope: function(e) {
this.remove(); 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; var _self = this;
$('#loadingbox').sheet('show'); $('#loadingbox').sheet('show');
$('#loading').html( $('#loading').html('<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ');
'<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()})) $.when(this.model.fetch({
.done(function() { success: function(e) {
$('#loadingbox').sheet('hide'); $('#loading-scopes').addClass('label-success');
_self.render(); },
}); error: app.errorHandlerView.handleError()
})).done(function() {
$('#loadingbox').sheet('hide');
_self.render();
});
}, },
togglePlaceholder:function() { togglePlaceholder: function() {
if (this.model.length > 0) { if (this.model.length > 0) {
$('#scope-table', this.el).show(); $('#scope-table', this.el).show();
$('#scope-table-empty', this.el).hide(); $('#scope-table-empty', this.el).hide();
@ -194,161 +209,159 @@ var SystemScopeListView = Backbone.View.extend({
} }
}, },
render: function (eventName) { render: function(eventName) {
// append and render the table structure // append and render the table structure
$(this.el).html($('#tmpl-system-scope-table').html()); $(this.el).html($('#tmpl-system-scope-table').html());
var _self = this; var _self = this;
_.each(this.model.models, function (scope) { _.each(this.model.models, function(scope) {
var view = new SystemScopeView({model: scope}); var view = new SystemScopeView({
model: scope
});
view.parentView = _self; view.parentView = _self;
$("#scope-table", _self.el).append(view.render().el); $("#scope-table", _self.el).append(view.render().el);
}, this); }, this);
this.togglePlaceholder(); this.togglePlaceholder();
$(this.el).i18n(); $(this.el).i18n();
return this; return this;
} }
}); });
var SystemScopeFormView = Backbone.View.extend({ var SystemScopeFormView = Backbone.View
tagName: 'span', .extend({
tagName: 'span',
initialize:function(options) { initialize: function(options) {
this.options = options; this.options = options;
if (!this.template) { if (!this.template) {
this.template = _.template($('#tmpl-system-scope-form').html()); this.template = _.template($('#tmpl-system-scope-form').html());
} }
if (!this.iconTemplate) { if (!this.iconTemplate) {
this.iconTemplate = _.template($('#tmpl-system-scope-icon').html()); this.iconTemplate = _.template($('#tmpl-system-scope-icon').html());
} }
// initialize our icon set into slices for the selector // initialize our icon set into slices for the selector
if (!this.bootstrapIcons) { if (!this.bootstrapIcons) {
this.bootstrapIcons = []; this.bootstrapIcons = [];
var iconList = ['glass', 'music', 'search', 'envelope', 'heart', 'star', 'star-empty', 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',
'user', 'film', 'th-large', 'th', 'th-list', 'ok', 'remove', 'zoom-in', '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',
'zoom-out', 'off', 'signal', 'cog', 'trash', 'home', 'file', 'time', 'road', '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',
'download-alt', 'download', 'upload', 'inbox', 'play-circle', 'repeat', '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',
'refresh', 'list-alt', 'lock', 'flag', 'headphones', 'volume-off', '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',
'volume-down', 'volume-up', 'qrcode', 'barcode', 'tag', 'tags', 'book', 'wrench', 'tasks', 'filter', 'briefcase', 'fullscreen'];
'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; var size = 3;
while (iconList.length > 0) { while (iconList.length > 0) {
this.bootstrapIcons.push(iconList.splice(0, size)); this.bootstrapIcons.push(iconList.splice(0, size));
} }
} }
}, },
events:{ events: {
'click .btn-save':'saveScope', 'click .btn-save': 'saveScope',
'click .btn-cancel': function() {app.navigate('admin/scope', {trigger: true}); }, 'click .btn-cancel': function() {
'click .btn-icon':'selectIcon' app.navigate('admin/scope', {
}, trigger: true
});
},
'click .btn-icon': 'selectIcon'
},
load:function(callback) { load: function(callback) {
if (this.model.isFetched) { if (this.model.isFetched) {
callback(); callback();
return; return;
} }
$('#loadingbox').sheet('show'); $('#loadingbox').sheet('show');
$('#loading').html( $('#loading').html('<span class="label" id="loading-scopes">' + $.t("common.scopes") + '</span> ');
'<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()})) $.when(this.model.fetchIfNeeded({
.done(function() { success: function(e) {
$('#loadingbox').sheet('hide'); $('#loading-scopes').addClass('label-success');
callback(); },
}); error: app.errorHandlerView.handleError()
})).done(function() {
$('#loadingbox').sheet('hide');
callback();
});
}, },
saveScope:function(e) { saveScope: function(e) {
e.preventDefault(); e.preventDefault();
var value = $('#value input').val(); var value = $('#value input').val();
if (value == null || value.trim() == "") { if (value == null || value.trim() == "") {
// error: can't have a blank scope // error: can't have a blank scope
return false; return false;
} }
var valid = this.model.set({ var valid = this.model.set({
value:value, value: value,
description:$('#description textarea').val(), description: $('#description textarea').val(),
icon:$('#iconDisplay input').val(), icon: $('#iconDisplay input').val(),
defaultScope:$('#defaultScope input').is(':checked'), defaultScope: $('#defaultScope input').is(':checked'),
restricted:$('#restricted input').is(':checked') restricted: $('#restricted input').is(':checked')
});
if (valid) {
var _self = this;
this.model.save({}, {
success: function() {
app.systemScopeList.add(_self.model);
app.navigate('admin/scope', {
trigger: true
});
},
error: app.errorHandlerView.handleError()
});
}
return false;
},
selectIcon: function(e) {
e.preventDefault();
var icon = e.target.value;
$('#iconDisplay input').val(icon);
$('#iconDisplay #iconName').html(icon);
$('#iconDisplay i').removeClass();
$('#iconDisplay i').addClass('icon-' + icon);
$('#iconDisplay i').addClass('icon-white');
$('#iconSelector').modal('hide');
return false;
},
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
}));
}, this);
$(this.el).i18n();
return this;
}
}); });
if (valid) { ui.routes.push({
path: "admin/scope",
var _self = this; name: "siteScope",
this.model.save({}, { callback: function() {
success:function() {
app.systemScopeList.add(_self.model);
app.navigate('admin/scope', {trigger: true});
},
error:app.errorHandlerView.handleError()
});
}
return false;
},
selectIcon:function(e) {
e.preventDefault();
var icon = e.target.value;
$('#iconDisplay input').val(icon);
$('#iconDisplay #iconName').html(icon);
$('#iconDisplay i').removeClass();
$('#iconDisplay i').addClass('icon-' + icon);
$('#iconDisplay i').addClass('icon-white');
$('#iconSelector').modal('hide');
return false;
},
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}));
}, this);
$(this.el).i18n();
return this;
}
});
ui.routes.push({path: "admin/scope", name: "siteScope", callback:
function() {
if (!isAdmin()) { if (!isAdmin()) {
this.root(); this.root();
@ -356,14 +369,19 @@ ui.routes.push({path: "admin/scope", name: "siteScope", callback:
} }
this.breadCrumbView.collection.reset(); this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([ this.breadCrumbView.collection.add([{
{text:$.t('admin.home'), href:""}, text: $.t('admin.home'),
{text:$.t('scope.manage'), href:"manage/#admin/scope"} href: ""
]); }, {
text: $.t('scope.manage'),
href: "manage/#admin/scope"
}]);
this.updateSidebar('admin/scope'); this.updateSidebar('admin/scope');
var view = new SystemScopeListView({model:this.systemScopeList}); var view = new SystemScopeListView({
model: this.systemScopeList
});
view.load(function() { view.load(function() {
$('#content').html(view.render().el); $('#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: ui.routes.push({
function() { path: "admin/scope/new",
name: "newScope",
callback: function() {
if (!isAdmin()) { if (!isAdmin()) {
this.root(); this.root();
@ -384,17 +403,24 @@ ui.routes.push({path: "admin/scope/new", name:"newScope", callback:
} }
this.breadCrumbView.collection.reset(); this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([ this.breadCrumbView.collection.add([{
{text:$.t('admin.home'), href:""}, text: $.t('admin.home'),
{text:$.t('scope.manage'), href:"manage/#admin/scope"}, href: ""
{text:$.t('scope.system-scope-form.new'), href:"manage/#admin/scope/new"} }, {
]); text: $.t('scope.manage'),
href: "manage/#admin/scope"
}, {
text: $.t('scope.system-scope-form.new'),
href: "manage/#admin/scope/new"
}]);
this.updateSidebar('admin/scope'); this.updateSidebar('admin/scope');
var scope = new SystemScopeModel(); var scope = new SystemScopeModel();
var view = new SystemScopeFormView({model:scope}); var view = new SystemScopeFormView({
model: scope
});
view.load(function() { view.load(function() {
$('#content').html(view.render().el); $('#content').html(view.render().el);
setPageTitle($.t('scope.system-scope-form.new')); 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: ui.routes.push({
function(sid) { path: "admin/scope/:id",
name: "editScope",
callback: function(sid) {
if (!isAdmin()) { if (!isAdmin()) {
this.root(); this.root();
@ -412,20 +440,29 @@ ui.routes.push({path: "admin/scope/:id", name: "editScope", callback:
} }
this.breadCrumbView.collection.reset(); this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([ this.breadCrumbView.collection.add([{
{text:$.t('admin.home'), href:""}, text: $.t('admin.home'),
{text:$.t('scope.manage'), href:"manage/#admin/scope"}, href: ""
{text:$.t('scope.system-scope-form.edit'), href:"manage/#admin/scope/" + sid} }, {
]); text: $.t('scope.manage'),
href: "manage/#admin/scope"
}, {
text: $.t('scope.system-scope-form.edit'),
href: "manage/#admin/scope/" + sid
}]);
this.updateSidebar('admin/scope'); this.updateSidebar('admin/scope');
var scope = this.systemScopeList.get(sid); var scope = this.systemScopeList.get(sid);
if (!scope) { 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() { view.load(function() {
$('#content').html(view.render().el); $('#content').html(view.render().el);
setPageTitle($.t('scope.system-scope-form.new')); setPageTitle($.t('scope.system-scope-form.new'));
@ -437,5 +474,5 @@ ui.routes.push({path: "admin/scope/:id", name: "editScope", callback:
ui.templates.push('resources/template/scope.html'); ui.templates.push('resources/template/scope.html');
ui.init.push(function(app) { ui.init.push(function(app) {
app.systemScopeList = new SystemScopeCollection(); app.systemScopeList = new SystemScopeCollection();
}); });

View File

@ -18,14 +18,14 @@
var AccessTokenModel = Backbone.Model.extend({ var AccessTokenModel = Backbone.Model.extend({
idAttribute: 'id', idAttribute: 'id',
defaults:{ defaults: {
id:null, id: null,
value:null, value: null,
refreshTokenId:null, refreshTokenId: null,
scopes:[], scopes: [],
clientId:null, clientId: null,
userId:null, userId: null,
expiration:null expiration: null
}, },
urlRoot: 'api/tokens/access' urlRoot: 'api/tokens/access'
@ -44,32 +44,32 @@ var AccessTokenView = Backbone.View.extend({
tagName: 'tr', tagName: 'tr',
initialize:function (options) { initialize: function(options) {
this.options = options; this.options = options;
if (!this.template) { if (!this.template) {
this.template = _.template($('#tmpl-access-token').html()); this.template = _.template($('#tmpl-access-token').html());
} }
if (!this.scopeTemplate) { if (!this.scopeTemplate) {
this.scopeTemplate = _.template($('#tmpl-scope-list').html()); this.scopeTemplate = _.template($('#tmpl-scope-list').html());
} }
if (!this.moreInfoTemplate) { if (!this.moreInfoTemplate) {
this.moreInfoTemplate = _.template($('#tmpl-client-more-info-block').html()); this.moreInfoTemplate = _.template($('#tmpl-client-more-info-block').html());
} }
this.model.bind('change', this.render, this); this.model.bind('change', this.render, this);
}, },
events: { events: {
'click .btn-delete':'deleteToken', 'click .btn-delete': 'deleteToken',
'click .token-substring':'showTokenValue', 'click .token-substring': 'showTokenValue',
'click .toggleMoreInformation': 'toggleMoreInformation' 'click .toggleMoreInformation': 'toggleMoreInformation'
}, },
render:function (eventName) { render: function(eventName) {
var expirationDate = this.model.get("expiration"); var expirationDate = this.model.get("expiration");
@ -81,51 +81,62 @@ var AccessTokenView = Backbone.View.extend({
expirationDate = moment(expirationDate).calendar(); 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)); this.$el.html(this.template(json));
// hide full value // hide full value
$('.token-full', this.el).hide(); $('.token-full', this.el).hide();
// show scopes // 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(); $(this.el).i18n();
return this; return this;
}, },
deleteToken:function (e) { deleteToken: function(e) {
e.preventDefault(); e.preventDefault();
if (confirm($.t("token.token-table.confirm"))) { if (confirm($.t("token.token-table.confirm"))) {
var _self = this; var _self = this;
this.model.destroy({ this.model.destroy({
dataType: false, processData: false, dataType: false,
success:function () { processData: false,
success: function() {
_self.$el.fadeTo("fast", 0.00, function () { //fade _self.$el.fadeTo("fast", 0.00, function() { // fade
$(this).slideUp("fast", function () { //slide up $(this).slideUp("fast", function() { // slide up
$(this).remove(); //then remove from the DOM $(this).remove(); // then remove from the DOM
// refresh the table in case we removed an id token, too // refresh the table in case we removed an id token,
_self.parentView.refreshTable(); // too
}); _self.parentView.refreshTable();
}); });
}, });
error:app.errorHandlerView.handleError() },
}); error: app.errorHandlerView.handleError()
});
this.parentView.delegateEvents(); this.parentView.delegateEvents();
} }
return false; return false;
}, },
toggleMoreInformation:function(e) { toggleMoreInformation: function(e) {
e.preventDefault(); e.preventDefault();
if ($('.moreInformation', this.el).is(':visible')) { if ($('.moreInformation', this.el).is(':visible')) {
// hide it // hide it
@ -141,28 +152,28 @@ var AccessTokenView = Backbone.View.extend({
} }
}, },
close:function () { close: function() {
$(this.el).unbind(); $(this.el).unbind();
$(this.el).empty(); $(this.el).empty();
}, },
showTokenValue:function (e) { showTokenValue: function(e) {
e.preventDefault(); e.preventDefault();
$('.token-substring', this.el).hide(); $('.token-substring', this.el).hide();
$('.token-full', this.el).show(); $('.token-full', this.el).show();
} }
}); });
var RefreshTokenModel = Backbone.Model.extend({ var RefreshTokenModel = Backbone.Model.extend({
idAttribute: 'id', idAttribute: 'id',
defaults:{ defaults: {
id:null, id: null,
value:null, value: null,
scopes:[], scopes: [],
clientId:null, clientId: null,
userId:null, userId: null,
expiration:null expiration: null
}, },
urlRoot: 'api/tokens/refresh' urlRoot: 'api/tokens/refresh'
@ -181,32 +192,32 @@ var RefreshTokenView = Backbone.View.extend({
tagName: 'tr', tagName: 'tr',
initialize:function (options) { initialize: function(options) {
this.options = options; this.options = options;
if (!this.template) { if (!this.template) {
this.template = _.template($('#tmpl-refresh-token').html()); this.template = _.template($('#tmpl-refresh-token').html());
} }
if (!this.scopeTemplate) { if (!this.scopeTemplate) {
this.scopeTemplate = _.template($('#tmpl-scope-list').html()); this.scopeTemplate = _.template($('#tmpl-scope-list').html());
} }
if (!this.moreInfoTemplate) { if (!this.moreInfoTemplate) {
this.moreInfoTemplate = _.template($('#tmpl-client-more-info-block').html()); this.moreInfoTemplate = _.template($('#tmpl-client-more-info-block').html());
} }
this.model.bind('change', this.render, this); this.model.bind('change', this.render, this);
}, },
events: { events: {
'click .btn-delete':'deleteToken', 'click .btn-delete': 'deleteToken',
'click .token-substring':'showTokenValue', 'click .token-substring': 'showTokenValue',
'click .toggleMoreInformation': 'toggleMoreInformation' 'click .toggleMoreInformation': 'toggleMoreInformation'
}, },
render:function (eventName) { render: function(eventName) {
var expirationDate = this.model.get("expiration"); var expirationDate = this.model.get("expiration");
@ -218,52 +229,64 @@ var RefreshTokenView = Backbone.View.extend({
expirationDate = moment(expirationDate).calendar(); 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)); this.$el.html(this.template(json));
// hide full value // hide full value
$('.token-full', this.el).hide(); $('.token-full', this.el).hide();
// show scopes // 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(); $(this.el).i18n();
return this; return this;
}, },
deleteToken:function (e) { deleteToken: function(e) {
e.preventDefault(); e.preventDefault();
if (confirm($.t('token.token-table.confirm-refresh'))) { if (confirm($.t('token.token-table.confirm-refresh'))) {
var _self = this; var _self = this;
this.model.destroy({ this.model.destroy({
dataType: false, processData: false, dataType: false,
success:function () { processData: false,
success: function() {
_self.$el.fadeTo("fast", 0.00, function () { //fade _self.$el.fadeTo("fast", 0.00, function() { // fade
$(this).slideUp("fast", function () { //slide up $(this).slideUp("fast", function() { // slide up
$(this).remove(); //then remove from the DOM $(this).remove(); // then remove from the DOM
// refresh the table in case the access tokens have changed, too // refresh the table in case the access tokens have
_self.parentView.refreshTable(); // changed, too
}); _self.parentView.refreshTable();
}); });
}, });
error:app.errorHandlerView.handleError() },
}); error: app.errorHandlerView.handleError()
});
_self.parentView.delegateEvents(); _self.parentView.delegateEvents();
} }
return false; return false;
}, },
toggleMoreInformation:function(e) { toggleMoreInformation: function(e) {
e.preventDefault(); e.preventDefault();
if ($('.moreInformation', this.el).is(':visible')) { if ($('.moreInformation', this.el).is(':visible')) {
// hide it // hide it
@ -279,101 +302,128 @@ var RefreshTokenView = Backbone.View.extend({
}, },
close:function () { close: function() {
$(this.el).unbind(); $(this.el).unbind();
$(this.el).empty(); $(this.el).empty();
}, },
showTokenValue:function (e) { showTokenValue: function(e) {
e.preventDefault(); e.preventDefault();
$('.token-substring', this.el).hide(); $('.token-substring', this.el).hide();
$('.token-full', this.el).show(); $('.token-full', this.el).show();
} }
}); });
var TokenListView = Backbone.View.extend({ var TokenListView = Backbone.View.extend({
tagName: 'span', tagName: 'span',
initialize:function(options) { initialize: function(options) {
this.options = options; this.options = options;
}, },
events:{ events: {
"click .refresh-table":"refreshTable", "click .refresh-table": "refreshTable",
'page .paginator-access':'changePageAccess', 'page .paginator-access': 'changePageAccess',
'page .paginator-refresh':'changePageRefresh' 'page .paginator-refresh': 'changePageRefresh'
}, },
load:function(callback) { load: function(callback) {
if (this.model.access.isFetched && if (this.model.access.isFetched && this.model.refresh.isFetched && this.options.clientList.isFetched && this.options.systemScopeList.isFetched) {
this.model.refresh.isFetched && callback();
this.options.clientList.isFetched && return;
this.options.systemScopeList.isFetched) { }
callback();
return;
}
$('#loadingbox').sheet('show'); $('#loadingbox').sheet('show');
$('#loading').html( $('#loading').html(
'<span class="label" id="loading-access">' + $.t('token.token-table.access-tokens') + '</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">'
'<span class="label" id="loading-refresh">' + $.t('token.token-table.refresh-tokens') + '</span> ' + + $.t('common.scopes') + '</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()}), $.when(this.model.access.fetchIfNeeded({
this.model.refresh.fetchIfNeeded({success:function(e) {$('#loading-refresh').addClass('label-success');}, error: app.errorHandlerView.handleError()}), success: function(e) {
this.options.clientList.fetchIfNeeded({success:function(e) {$('#loading-clients').addClass('label-success');}, error: app.errorHandlerView.handleError()}), $('#loading-access').addClass('label-success');
this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}, error: app.errorHandlerView.handleError()})) },
.done(function() { error: app.errorHandlerView.handleError()
$('#loadingbox').sheet('hide'); }), this.model.refresh.fetchIfNeeded({
callback(); 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) { changePageAccess: function(event, num) {
$('.paginator-access', this.el).bootpag({page: num}); $('.paginator-access', this.el).bootpag({
page: num
});
$('#access-token-table tbody tr', this.el).each(function(index, element) { $('#access-token-table tbody tr', this.el).each(function(index, element) {
if (Math.ceil((index + 1) / 10) != num) { if (Math.ceil((index + 1) / 10) != num) {
$(element).hide(); $(element).hide();
} else { } else {
$(element).show(); $(element).show();
} }
}); });
}, },
changePageRefresh:function(event, num) { changePageRefresh: function(event, num) {
$('.paginator-refresh', this.el).bootpag({page: num}); $('.paginator-refresh', this.el).bootpag({
page: num
});
$('#refresh-token-table tbody tr', this.el).each(function(index, element) { $('#refresh-token-table tbody tr', this.el).each(function(index, element) {
if (Math.ceil((index + 1) / 10) != num) { if (Math.ceil((index + 1) / 10) != num) {
$(element).hide(); $(element).hide();
} else { } else {
$(element).show(); $(element).show();
} }
}); });
}, },
refreshTable:function(e) { refreshTable: function(e) {
$('#loadingbox').sheet('show'); $('#loadingbox').sheet('show');
$('#loading').html( $('#loading').html(
'<span class="label" id="loading-access">' + $.t('token.token-table.access-tokens') + '</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">'
'<span class="label" id="loading-refresh">' + $.t('token.token-table.refresh-tokens') + '</span> ' + + $.t('common.scopes') + '</span> ');
'<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' + var _self = this;
'<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ' $.when(this.model.access.fetch({
); success: function(e) {
var _self = this; $('#loading-access').addClass('label-success');
$.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()}), error: app.errorHandlerView.handleError()
this.options.clientList.fetch({success:function(e) {$('#loading-clients').addClass('label-success');}, error: app.errorHandlerView.handleError()}), }), this.model.refresh.fetch({
this.options.systemScopeList.fetch({success:function(e) {$('#loading-scopes').addClass('label-success');}, error: app.errorHandlerView.handleError()})) success: function(e) {
.done(function(){ $('#loading-refresh').addClass('label-success');
_self.render(); },
$('#loadingbox').sheet('hide'); 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) { if (this.model.access.length > 0) {
$('#access-token-table', this.el).show(); $('#access-token-table', this.el).show();
$('#access-token-table-empty', this.el).hide(); $('#access-token-table-empty', this.el).hide();
@ -393,110 +443,128 @@ var TokenListView = Backbone.View.extend({
$('#refresh-token-count', this.el).html(this.model.refresh.length); $('#refresh-token-count', this.el).html(this.model.refresh.length);
}, },
render: function (eventName) { render: function(eventName) {
// append and render the table structure // append and render the table structure
$(this.el).html($('#tmpl-token-table').html()); $(this.el).html($('#tmpl-token-table').html());
var _self = this; var _self = this;
// set up pagination // set up pagination
var numPagesAccess = Math.ceil(this.model.access.length / 10); var numPagesAccess = Math.ceil(this.model.access.length / 10);
if (numPagesAccess > 1) { if (numPagesAccess > 1) {
$('.paginator-access', this.el).show(); $('.paginator-access', this.el).show();
$('.paginator-access', this.el).bootpag({ $('.paginator-access', this.el).bootpag({
total: numPagesAccess, total: numPagesAccess,
page: 1 page: 1
}); });
} else { } else {
$('.paginator-access', this.el).hide(); $('.paginator-access', this.el).hide();
} }
// count up refresh tokens // count up refresh tokens
var refreshCount = {}; var refreshCount = {};
_.each(this.model.access.models, function (token, index) { _.each(this.model.access.models, function(token, index) {
// look up client // look up client
var client = _self.options.clientList.getByClientId(token.get('clientId')); 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; view.parentView = _self;
var element = view.render().el; var element = view.render().el;
$('#access-token-table', _self.el).append(element); $('#access-token-table', _self.el).append(element);
if (Math.ceil((index + 1) / 10) != 1) { if (Math.ceil((index + 1) / 10) != 1) {
$(element).hide(); $(element).hide();
} }
//console.log(token.get('refreshTokenId')); // console.log(token.get('refreshTokenId'));
var refId = token.get('refreshTokenId'); var refId = token.get('refreshTokenId');
if (refId != null) { if (refId != null) {
if (refreshCount[refId]) { if (refreshCount[refId]) {
refreshCount[refId] += 1; refreshCount[refId] += 1;
} else { } else {
refreshCount[refId] = 1; refreshCount[refId] = 1;
} }
} }
}); });
//console.log(refreshCount); // console.log(refreshCount);
// set up pagination // set up pagination
var numPagesRefresh = Math.ceil(this.model.refresh.length / 10); var numPagesRefresh = Math.ceil(this.model.refresh.length / 10);
if (numPagesRefresh > 1) { if (numPagesRefresh > 1) {
$('.paginator-refresh', this.el).show(); $('.paginator-refresh', this.el).show();
$('.paginator-refresh', this.el).bootpag({ $('.paginator-refresh', this.el).bootpag({
total: numPagesRefresh, total: numPagesRefresh,
page: 1 page: 1
}); });
} else { } else {
$('.paginator-refresh', this.el).hide(); $('.paginator-refresh', this.el).hide();
} }
_.each(this.model.refresh.models, function (token, index) { _.each(this.model.refresh.models, function(token, index) {
// look up client // look up client
var client = _self.options.clientList.getByClientId(token.get('clientId')); 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; view.parentView = _self;
var element = view.render().el; var element = view.render().el;
$('#refresh-token-table', _self.el).append(element); $('#refresh-token-table', _self.el).append(element);
if (Math.ceil((index + 1) / 10) != 1) { if (Math.ceil((index + 1) / 10) != 1) {
$(element).hide(); $(element).hide();
} }
}); });
/* /*
_.each(this.model.models, function (scope) { * _.each(this.model.models, function (scope) { $("#scope-table",
$("#scope-table", this.el).append(new SystemScopeView({model: scope}).render().el); * this.el).append(new SystemScopeView({model: scope}).render().el); },
}, this); * this);
*/ */
this.togglePlaceholder(); this.togglePlaceholder();
$(this.el).i18n(); $(this.el).i18n();
return this; return this;
} }
}); });
ui.routes.push({
ui.routes.push({path: "user/tokens", name: "tokens", callback: path: "user/tokens",
function() { name: "tokens",
callback: function() {
this.breadCrumbView.collection.reset(); this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([ this.breadCrumbView.collection.add([{
{text:$.t('admin.home'), href:""}, text: $.t('admin.home'),
{text:$.t('token.manage'), href:"manage/#user/tokens"} href: ""
]); }, {
text: $.t('token.manage'),
href: "manage/#user/tokens"
}]);
this.updateSidebar('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( view.load(function(collection, response, options) {
function(collection, response, options) { $('#content').html(view.render().el);
$('#content').html(view.render().el); setPageTitle($.t('token.manage'));
setPageTitle($.t('token.manage')); });
}
);
} }
}); });
@ -504,6 +572,6 @@ ui.routes.push({path: "user/tokens", name: "tokens", callback:
ui.templates.push('resources/template/token.html'); ui.templates.push('resources/template/token.html');
ui.init.push(function(app) { ui.init.push(function(app) {
app.accessTokensList = new AccessTokenCollection(); app.accessTokensList = new AccessTokenCollection();
app.refreshTokensList = new RefreshTokenCollection(); app.refreshTokensList = new RefreshTokenCollection();
}); });

View File

@ -18,7 +18,8 @@ var WhiteListModel = Backbone.Model.extend({
idAttribute: "id", idAttribute: "id",
initialize: function () { }, initialize: function() {
},
urlRoot: "api/whitelist" urlRoot: "api/whitelist"
@ -26,17 +27,19 @@ var WhiteListModel = Backbone.Model.extend({
var WhiteListCollection = Backbone.Collection.extend({ var WhiteListCollection = Backbone.Collection.extend({
initialize: function() { initialize: function() {
//this.fetch(); // this.fetch();
}, },
getByClientId: function(clientId) { getByClientId: function(clientId) {
var clients = this.where({clientId: clientId}); var clients = this.where({
clientId: clientId
});
if (clients.length == 1) { if (clients.length == 1) {
return clients[0]; return clients[0];
} else { } else {
return null; return null;
} }
}, },
model: WhiteListModel, model: WhiteListModel,
url: "api/whitelist" url: "api/whitelist"
@ -46,51 +49,61 @@ var WhiteListCollection = Backbone.Collection.extend({
var WhiteListListView = Backbone.View.extend({ var WhiteListListView = Backbone.View.extend({
tagName: 'span', tagName: 'span',
initialize:function (options) { initialize: function(options) {
this.options = options; this.options = options;
}, },
load:function(callback) { load: function(callback) {
if (this.model.isFetched && if (this.model.isFetched && this.options.clientList.isFetched && this.options.systemScopeList.isFetched) {
this.options.clientList.isFetched && callback();
this.options.systemScopeList.isFetched) { return;
callback(); }
return;
}
$('#loadingbox').sheet('show'); $('#loadingbox').sheet('show');
$('#loading').html( $('#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> ');
'<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()}), $.when(this.model.fetchIfNeeded({
this.options.clientList.fetchIfNeeded({success:function(e) {$('#loading-clients').addClass('label-success');}, error: app.errorHandlerView.handleError()}), success: function(e) {
this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}, error: app.errorHandlerView.handleError()})) $('#loading-whitelist').addClass('label-success');
.done(function() { },
$('#loadingbox').sheet('hide'); error: app.errorHandlerView.handleError()
callback(); }), this.options.clientList.fetchIfNeeded({
}); success: function(e) {
}, $('#loading-clients').addClass('label-success');
},
events:{ error: app.errorHandlerView.handleError()
"click .refresh-table":"refreshTable" }), this.options.systemScopeList.fetchIfNeeded({
success: function(e) {
$('#loading-scopes').addClass('label-success');
},
error: app.errorHandlerView.handleError()
})).done(function() {
$('#loadingbox').sheet('hide');
callback();
});
}, },
render:function (eventName) { events: {
"click .refresh-table": "refreshTable"
},
render: function(eventName) {
$(this.el).html($('#tmpl-whitelist-table').html()); $(this.el).html($('#tmpl-whitelist-table').html());
var _self = this; var _self = this;
_.each(this.model.models, function (whiteList) { _.each(this.model.models, function(whiteList) {
// look up client // look up client
var client = _self.options.clientList.getByClientId(whiteList.get('clientId')); var client = _self.options.clientList.getByClientId(whiteList.get('clientId'));
// if there's no client ID, this is an error! // if there's no client ID, this is an error!
if (client != null) { 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; view.parentView = _self;
$('#whitelist-table', _self.el).append(view.render().el); $('#whitelist-table', _self.el).append(view.render().el);
} }
@ -98,11 +111,11 @@ var WhiteListListView = Backbone.View.extend({
}, this); }, this);
this.togglePlaceholder(); this.togglePlaceholder();
$(this.el).i18n(); $(this.el).i18n();
return this; return this;
}, },
togglePlaceholder:function() { togglePlaceholder: function() {
if (this.model.length > 0) { if (this.model.length > 0) {
$('#whitelist-table', this.el).show(); $('#whitelist-table', this.el).show();
$('#whitelist-table-empty', this.el).hide(); $('#whitelist-table-empty', this.el).hide();
@ -112,100 +125,121 @@ var WhiteListListView = Backbone.View.extend({
} }
}, },
refreshTable:function(e) { refreshTable: function(e) {
e.preventDefault(); e.preventDefault();
var _self = this; var _self = this;
$('#loadingbox').sheet('show'); $('#loadingbox').sheet('show');
$('#loading').html( $('#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> ');
'<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()}), $.when(this.model.fetch({
this.options.clientList.fetch({success:function(e) {$('#loading-clients').addClass('label-success');}, error: app.errorHandlerView.handleError()}), success: function(e) {
this.options.systemScopeList.fetch({success:function(e) {$('#loading-scopes').addClass('label-success');}, error: app.errorHandlerView.handleError()})) $('#loading-whitelist').addClass('label-success');
.done(function() { },
$('#loadingbox').sheet('hide'); error: app.errorHandlerView.handleError()
_self.render(); }), 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();
});
}
}); });
var WhiteListView = Backbone.View.extend({ var WhiteListView = Backbone.View.extend({
tagName: 'tr', tagName: 'tr',
initialize:function(options) { initialize: function(options) {
this.options = options; this.options = options;
if (!this.template) { if (!this.template) {
this.template = _.template($('#tmpl-whitelist').html()); this.template = _.template($('#tmpl-whitelist').html());
} }
if (!this.scopeTemplate) { if (!this.scopeTemplate) {
this.scopeTemplate = _.template($('#tmpl-scope-list').html()); this.scopeTemplate = _.template($('#tmpl-scope-list').html());
} }
if (!this.moreInfoTemplate) { if (!this.moreInfoTemplate) {
this.moreInfoTemplate = _.template($('#tmpl-client-more-info-block').html()); this.moreInfoTemplate = _.template($('#tmpl-client-more-info-block').html());
} }
this.model.bind('change', this.render, this); 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)); 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(); $(this.el).i18n();
return this; return this;
}, },
events:{ events: {
'click .btn-edit': 'editWhitelist', 'click .btn-edit': 'editWhitelist',
'click .btn-delete': 'deleteWhitelist', 'click .btn-delete': 'deleteWhitelist',
'click .toggleMoreInformation': 'toggleMoreInformation' 'click .toggleMoreInformation': 'toggleMoreInformation'
}, },
editWhitelist:function(e) { editWhitelist: function(e) {
e.preventDefault(); 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(); e.preventDefault();
if (confirm($.t('whitelist.confirm'))) { if (confirm($.t('whitelist.confirm'))) {
var _self = this; var _self = this;
this.model.destroy({ this.model.destroy({
dataType: false, processData: false, dataType: false,
success:function () { processData: false,
_self.$el.fadeTo("fast", 0.00, function () { //fade success: function() {
$(this).slideUp("fast", function () { //slide up _self.$el.fadeTo("fast", 0.00, function() { // fade
$(this).remove(); //then remove from the DOM $(this).slideUp("fast", function() { // slide up
// check the placeholder in case it's empty now $(this).remove(); // then remove from the DOM
_self.parentView.togglePlaceholder(); // check the placeholder in case it's empty now
}); _self.parentView.togglePlaceholder();
}); });
}, });
error:app.errorHandlerView.handleError() },
}); error: app.errorHandlerView.handleError()
});
_self.parentView.delegateEvents(); _self.parentView.delegateEvents();
} }
return false; return false;
}, },
toggleMoreInformation:function(e) { toggleMoreInformation: function(e) {
e.preventDefault(); e.preventDefault();
if ($('.moreInformation', this.el).is(':visible')) { if ($('.moreInformation', this.el).is(':visible')) {
// hide it // hide it
@ -221,7 +255,7 @@ var WhiteListView = Backbone.View.extend({
} }
}, },
close:function() { close: function() {
$(this.el).unbind(); $(this.el).unbind();
$(this.el).empty(); $(this.el).empty();
} }
@ -230,8 +264,8 @@ var WhiteListView = Backbone.View.extend({
var WhiteListFormView = Backbone.View.extend({ var WhiteListFormView = Backbone.View.extend({
tagName: 'span', tagName: 'span',
initialize:function (options) { initialize: function(options) {
this.options = options; this.options = options;
if (!this.template) { if (!this.template) {
this.template = _.template($('#tmpl-whitelist-form').html()); this.template = _.template($('#tmpl-whitelist-form').html());
} }
@ -242,187 +276,219 @@ var WhiteListFormView = Backbone.View.extend({
}, },
load:function(callback) { load: function(callback) {
if (this.options.client) { if (this.options.client) {
// we know what client we're dealing with already // we know what client we're dealing with already
if (this.model.isFetched && if (this.model.isFetched && this.options.client.isFetched) {
this.options.client.isFetched) { callback();
callback(); return;
return; }
}
$('#loadingbox').sheet('show'); $('#loadingbox').sheet('show');
$('#loading').html( $('#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> ');
'<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()}), $.when(this.model.fetchIfNeeded({
this.options.client.fetchIfNeeded({success:function(e) {$('#loading-clients').addClass('label-success');}, error: app.errorHandlerView.handleError()}), success: function(e) {
this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}, error: app.errorHandlerView.handleError()})) $('#loading-whitelist').addClass('label-success');
.done(function() { },
$('#loadingbox').sheet('hide'); error: app.errorHandlerView.handleError()
callback(); }), 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();
});
} else { } else {
// we need to get the client information from the list // we need to get the client information from the list
if (this.model.isFetched && if (this.model.isFetched && this.options.clientList.isFetched && this.options.systemScopeList.isFetched) {
this.options.clientList.isFetched &&
this.options.systemScopeList.isFetched) {
var client = this.options.clientList.getByClientId(this.model.get('clientId')); var client = this.options.clientList.getByClientId(this.model.get('clientId'));
this.options.client = client; this.options.client = client;
callback(); callback();
return; return;
} }
$('#loadingbox').sheet('show'); $('#loadingbox').sheet('show');
$('#loading').html( $('#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> ');
'<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; var _self = this;
$.when(this.model.fetchIfNeeded({success:function(e) {$('#loading-whitelist').addClass('label-success');}, error: app.errorHandlerView.handleError()}), $.when(this.model.fetchIfNeeded({
this.options.clientList.fetchIfNeeded({success:function(e) {$('#loading-clients').addClass('label-success');}, error: app.errorHandlerView.handleError()}), success: function(e) {
this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}, error: app.errorHandlerView.handleError()})) $('#loading-whitelist').addClass('label-success');
.done(function() { },
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')); var client = _self.options.clientList.getByClientId(_self.model.get('clientId'));
_self.options.client = client; _self.options.client = client;
$('#loadingbox').sheet('hide'); $('#loadingbox').sheet('hide');
callback(); callback();
}); });
} }
},
events: {
'click .btn-save': 'saveWhiteList',
'click .btn-cancel': 'cancelWhiteList',
}, },
events:{ saveWhiteList: function(e) {
'click .btn-save':'saveWhiteList', e.preventDefault();
'click .btn-cancel':'cancelWhiteList',
},
saveWhiteList:function (e) {
e.preventDefault();
$('.control-group').removeClass('error'); $('.control-group').removeClass('error');
// sync any leftover collection items // sync any leftover collection items
_.each(this.listWidgetViews, function(v) { _.each(this.listWidgetViews, function(v) {
v.addItem($.Event('click')); v.addItem($.Event('click'));
}); });
// process allowed scopes // process allowed scopes
var allowedScopes = this.scopeCollection.pluck("item"); 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({ var valid = this.model.set({
allowedScopes: allowedScopes allowedScopes: allowedScopes
}); });
if (valid) { if (valid) {
var _self = this; var _self = this;
this.model.save({}, { this.model.save({}, {
success:function () { success: function() {
app.whiteListList.add(_self.model); 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()
});
}
return false; return false;
}, },
cancelWhiteList:function(e) { cancelWhiteList: function(e) {
e.preventDefault(); e.preventDefault();
// TODO: figure out where we came from and go back there instead // TODO: figure out where we came from and go back there instead
if (this.model.get('id') == null) { if (this.model.get('id') == null) {
// if it's a new whitelist entry, go back to the client listing page // if it's a new whitelist entry, go back to the client listing page
app.navigate('admin/clients', {trigger:true}); app.navigate('admin/clients', {
} else { trigger: true
// if we're editing a whitelist, go back to the whitelists page });
app.navigate('admin/whitelists', {trigger:true}); } else {
} // if we're editing a whitelist, go back to the whitelists page
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)); this.$el.html(this.template(json));
this.listWidgetViews = []; this.listWidgetViews = [];
var _self = this; var _self = this;
// build and bind scopes // build and bind scopes
_.each(this.model.get("allowedScopes"), function (scope) { _.each(this.model.get("allowedScopes"), function(scope) {
_self.scopeCollection.add(new Backbone.Model({item:scope})); _self.scopeCollection.add(new Backbone.Model({
}); item: scope
}));
});
var scopeView = new ListWidgetView({ var scopeView = new ListWidgetView({
placeholder: $.t('whitelist.whitelist-form.scope-placeholder'), placeholder: $.t('whitelist.whitelist-form.scope-placeholder'),
autocomplete: this.options.client.get("scope"), autocomplete: this.options.client.get("scope"),
helpBlockText: $.t('whitelist.whitelist-form.scope-help'), helpBlockText: $.t('whitelist.whitelist-form.scope-help'),
collection: this.scopeCollection}); collection: this.scopeCollection
$("#scope .controls",this.el).html(scopeView.render().el); });
this.listWidgetViews.push(scopeView); $("#scope .controls", this.el).html(scopeView.render().el);
this.listWidgetViews.push(scopeView);
$(this.el).i18n(); $(this.el).i18n();
return this; return this;
} }
}); });
ui.routes.push({
ui.routes.push({path: "admin/whitelists", name: "whiteList", callback: path: "admin/whitelists",
function () { name: "whiteList",
callback: function() {
if (!isAdmin()) { if (!isAdmin()) {
this.root(); this.root();
return; return;
} }
this.updateSidebar('admin/whitelists'); this.updateSidebar('admin/whitelists');
this.breadCrumbView.collection.reset(); this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([ this.breadCrumbView.collection.add([{
{text:$.t('admin.home'), href:""}, text: $.t('admin.home'),
{text:$.t('whitelist.manage'), href:"manage/#admin/whitelists"} 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,
view.load( clientList: this.clientList,
function() { systemScopeList: this.systemScopeList
$('#content').html(view.render().el); });
view.delegateEvents();
setPageTitle($.t('whitelist.manage'));
}
);
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: ui.routes.push({
function(cid) { path: "admin/whitelist/new/:cid",
name: "newWhitelist",
callback: function(cid) {
if (!isAdmin()) { if (!isAdmin()) {
this.root(); this.root();
@ -430,41 +496,55 @@ ui.routes.push({path: "admin/whitelist/new/:cid", name: "newWhitelist", callback
} }
this.breadCrumbView.collection.reset(); this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([ this.breadCrumbView.collection.add([{
{text:$.t('admin.home'), href:""}, text: $.t('admin.home'),
{text:$.t('whitelist.manage'), href:"manage/#admin/whitelists"}, href: ""
{text:$.t('whitelist.new'), href:"manage/#admin/whitelist/new/" + cid} }, {
]); text: $.t('whitelist.manage'),
href: "manage/#admin/whitelists"
}, {
text: $.t('whitelist.new'),
href: "manage/#admin/whitelist/new/" + cid
}]);
this.updateSidebar('admin/whitelists'); this.updateSidebar('admin/whitelists');
var whiteList = new WhiteListModel(); var whiteList = new WhiteListModel();
var client = this.clientList.get(cid); var client = this.clientList.get(cid);
if (!client) { 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( view.load(function() {
function() {
// set the scopes on the model now that everything's loaded // 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); $('#content').html(view.render().el);
view.delegateEvents(); view.delegateEvents();
setPageTitle($.t('whitelist.manage')); setPageTitle($.t('whitelist.manage'));
} });
);
} }
}); });
ui.routes.push({
ui.routes.push({path: "admin/whitelist/:id", name: "editWhitelist", callback: path: "admin/whitelist/:id",
function(id) { name: "editWhitelist",
callback: function(id) {
if (!isAdmin()) { if (!isAdmin()) {
this.root(); this.root();
@ -472,28 +552,37 @@ ui.routes.push({path: "admin/whitelist/:id", name: "editWhitelist", callback:
} }
this.breadCrumbView.collection.reset(); this.breadCrumbView.collection.reset();
this.breadCrumbView.collection.add([ this.breadCrumbView.collection.add([{
{text:$.t('admin.home'), href:""}, text: $.t('admin.home'),
{text:$.t('whitelist.manage'), href:"manage/#admin/whitelists"}, href: ""
{text:$.t('whitelist.edit'), href:"manage/#admin/whitelist/" + id} }, {
]); text: $.t('whitelist.manage'),
href: "manage/#admin/whitelists"
}, {
text: $.t('whitelist.edit'),
href: "manage/#admin/whitelist/" + id
}]);
this.updateSidebar('admin/whitelists'); this.updateSidebar('admin/whitelists');
var whiteList = this.whiteListList.get(id); var whiteList = this.whiteListList.get(id);
if (!whiteList) { 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( view.load(function() {
function() { $('#content').html(view.render().el);
$('#content').html(view.render().el); view.delegateEvents();
view.delegateEvents(); setPageTitle($.t('whitelist.manage'));
setPageTitle($.t('whitelist.manage')); });
}
);
} }
@ -502,5 +591,5 @@ ui.routes.push({path: "admin/whitelist/:id", name: "editWhitelist", callback:
ui.templates.push('resources/template/whitelist.html'); ui.templates.push('resources/template/whitelist.html');
ui.init.push(function(app) { ui.init.push(function(app) {
app.whiteListList = new WhiteListCollection(); app.whiteListList = new WhiteListCollection();
}); });