auto format and cleanup javascript
parent
bd72b4138d
commit
78b9b6ced4
|
@ -53,344 +53,386 @@ Backbone.Collection.prototype.fetchIfNeeded = function(options) {
|
|||
}
|
||||
};
|
||||
|
||||
var URIModel = Backbone.Model.extend({
|
||||
var URIModel = Backbone.Model
|
||||
.extend({
|
||||
|
||||
validate: function(attrs){
|
||||
validate: function(attrs) {
|
||||
|
||||
var expression = /^(?:([a-z0-9+.-]+:\/\/)((?:(?:[a-z0-9-._~!$&'()*+,;=:]|%[0-9A-F]{2})*)@)?((?:[a-z0-9-._~!$&'()*+,;=]|%[0-9A-F]{2})*)(:(?:\d*))?(\/(?:[a-z0-9-._~!$&'()*+,;=:@\/]|%[0-9A-F]{2})*)?|([a-z0-9+.-]+:)(\/?(?:[a-z0-9-._~!$&'()*+,;=:@]|%[0-9A-F]{2})+(?:[a-z0-9-._~!$&'()*+,;=:@\/]|%[0-9A-F]{2})*)?)(\?(?:[a-z0-9-._~!$&'()*+,;=:\/?@]|%[0-9A-F]{2})*)?(#(?:[a-z0-9-._~!$&'()*+,;=:\/?@]|%[0-9A-F]{2})*)?$/i;
|
||||
var regex = new RegExp(expression);
|
||||
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);
|
||||
|
||||
if (attrs.item == null || !attrs.item.match(regex)) {
|
||||
return "Invalid URI";
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
if (attrs.item == null || !attrs.item.match(regex)) {
|
||||
return "Invalid URI";
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/*
|
||||
* Backbone JS Reusable ListWidget
|
||||
* Options
|
||||
* {
|
||||
* collection: Backbone JS Collection
|
||||
* type: ('uri'|'default')
|
||||
* autocomplete: ['item1','item2'] List of auto complete items
|
||||
* }
|
||||
*
|
||||
* Backbone JS Reusable ListWidget Options { collection: Backbone JS Collection
|
||||
* type: ('uri'|'default') autocomplete: ['item1','item2'] List of auto complete
|
||||
* items }
|
||||
*
|
||||
*/
|
||||
var ListWidgetChildView = Backbone.View.extend({
|
||||
|
||||
tagName: 'tr',
|
||||
tagName: 'tr',
|
||||
|
||||
events:{
|
||||
"click .btn-delete-list-item":'deleteItem',
|
||||
"change .checkbox-list-item":'toggleCheckbox'
|
||||
},
|
||||
|
||||
deleteItem:function (e) {
|
||||
e.preventDefault();
|
||||
e.stopImmediatePropagation();
|
||||
//this.$el.tooltip('delete');
|
||||
|
||||
this.model.destroy({
|
||||
dataType: false, processData: false,
|
||||
error:app.errorHandlerView.handleError()
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
toggleCheckbox:function(e) {
|
||||
e.preventDefault();
|
||||
e.stopImmediatePropagation();
|
||||
if ($(e.target).is(':checked')) {
|
||||
this.options.collection.add(this.model);
|
||||
} else {
|
||||
this.options.collection.remove(this.model);
|
||||
}
|
||||
|
||||
},
|
||||
events: {
|
||||
"click .btn-delete-list-item": 'deleteItem',
|
||||
"change .checkbox-list-item": 'toggleCheckbox'
|
||||
},
|
||||
|
||||
initialize:function (options) {
|
||||
this.options = {toggle: false, checked: false};
|
||||
_.extend(this.options, options);
|
||||
if (!this.template) {
|
||||
this.template = _.template($('#tmpl-list-widget-child').html());
|
||||
}
|
||||
},
|
||||
deleteItem: function(e) {
|
||||
e.preventDefault();
|
||||
e.stopImmediatePropagation();
|
||||
// this.$el.tooltip('delete');
|
||||
|
||||
render:function () {
|
||||
|
||||
var data = {model: this.model.toJSON(), opt: this.options};
|
||||
|
||||
this.$el.html(this.template(data));
|
||||
this.model.destroy({
|
||||
dataType: false,
|
||||
processData: false,
|
||||
error: app.errorHandlerView.handleError()
|
||||
});
|
||||
|
||||
$('.item-full', this.el).hide();
|
||||
|
||||
if (this.model.get('item').length > 30) {
|
||||
this.$el.tooltip({title:$.t('admin.list-widget.tooltip')});
|
||||
|
||||
var _self = this;
|
||||
|
||||
$(this.el).click(function(event) {
|
||||
event.preventDefault();
|
||||
$('.item-short', _self.el).hide();
|
||||
$('.item-full', _self.el).show();
|
||||
_self.$el.tooltip('destroy');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
$(this.el).i18n();
|
||||
return this;
|
||||
}
|
||||
},
|
||||
|
||||
toggleCheckbox: function(e) {
|
||||
e.preventDefault();
|
||||
e.stopImmediatePropagation();
|
||||
if ($(e.target).is(':checked')) {
|
||||
this.options.collection.add(this.model);
|
||||
} else {
|
||||
this.options.collection.remove(this.model);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
initialize: function(options) {
|
||||
this.options = {
|
||||
toggle: false,
|
||||
checked: false
|
||||
};
|
||||
_.extend(this.options, options);
|
||||
if (!this.template) {
|
||||
this.template = _.template($('#tmpl-list-widget-child').html());
|
||||
}
|
||||
},
|
||||
|
||||
render: function() {
|
||||
|
||||
var data = {
|
||||
model: this.model.toJSON(),
|
||||
opt: this.options
|
||||
};
|
||||
|
||||
this.$el.html(this.template(data));
|
||||
|
||||
$('.item-full', this.el).hide();
|
||||
|
||||
if (this.model.get('item').length > 30) {
|
||||
this.$el.tooltip({
|
||||
title: $.t('admin.list-widget.tooltip')
|
||||
});
|
||||
|
||||
var _self = this;
|
||||
|
||||
$(this.el).click(function(event) {
|
||||
event.preventDefault();
|
||||
$('.item-short', _self.el).hide();
|
||||
$('.item-full', _self.el).show();
|
||||
_self.$el.tooltip('destroy');
|
||||
});
|
||||
}
|
||||
|
||||
$(this.el).i18n();
|
||||
return this;
|
||||
}
|
||||
});
|
||||
|
||||
var ListWidgetView = Backbone.View.extend({
|
||||
|
||||
tagName: "div",
|
||||
tagName: "div",
|
||||
|
||||
events:{
|
||||
"click .btn-add-list-item":"addItem",
|
||||
"keypress":function (e) {
|
||||
// trap the enter key
|
||||
if (e.which == 13) {
|
||||
e.preventDefault();
|
||||
this.addItem(e);
|
||||
$("input", this.$el).focus();
|
||||
}
|
||||
}
|
||||
},
|
||||
events: {
|
||||
"click .btn-add-list-item": "addItem",
|
||||
"keypress": function(e) {
|
||||
// trap the enter key
|
||||
if (e.which == 13) {
|
||||
e.preventDefault();
|
||||
this.addItem(e);
|
||||
$("input", this.$el).focus();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
initialize:function (options) {
|
||||
this.options = options;
|
||||
initialize: function(options) {
|
||||
this.options = options;
|
||||
|
||||
if (!this.template) {
|
||||
this.template = _.template($('#tmpl-list-widget').html());
|
||||
}
|
||||
if (!this.template) {
|
||||
this.template = _.template($('#tmpl-list-widget').html());
|
||||
}
|
||||
|
||||
this.collection.bind('add', this.render, this);
|
||||
this.collection.bind('remove', this.render, this);
|
||||
},
|
||||
this.collection.bind('add', this.render, this);
|
||||
this.collection.bind('remove', this.render, this);
|
||||
},
|
||||
|
||||
addItem:function(e) {
|
||||
e.preventDefault();
|
||||
addItem: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var input_value = $("input", this.el).val().trim();
|
||||
var input_value = $("input", this.el).val().trim();
|
||||
|
||||
if (input_value === ""){
|
||||
return;
|
||||
}
|
||||
if (input_value === "") {
|
||||
return;
|
||||
}
|
||||
|
||||
var model;
|
||||
var model;
|
||||
|
||||
if (this.options.type == 'uri') {
|
||||
model = new URIModel({item:input_value});
|
||||
} else {
|
||||
model = new Backbone.Model({item:input_value});
|
||||
model.validate = function(attrs) {
|
||||
if(!attrs.item) {
|
||||
return "value can't be null";
|
||||
}
|
||||
};
|
||||
}
|
||||
if (this.options.type == 'uri') {
|
||||
model = new URIModel({
|
||||
item: input_value
|
||||
});
|
||||
} else {
|
||||
model = new Backbone.Model({
|
||||
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 (model.get("item") != null && this.collection.where({item: input_value}).length < 1) {
|
||||
this.collection.add(model);
|
||||
} else {
|
||||
// else add a visual error indicator
|
||||
$(".control-group", this.el).addClass('error');
|
||||
}
|
||||
},
|
||||
// if it's valid and doesn't already exist
|
||||
if (model.get("item") != null && this.collection.where({
|
||||
item: input_value
|
||||
}).length < 1) {
|
||||
this.collection.add(model);
|
||||
} 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,
|
||||
helpBlockText:this.options.helpBlockText}));
|
||||
this.$el.html(this.template({
|
||||
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) {
|
||||
$("tbody", _self.el).html($('#tmpl-list-widget-child-empty').html());
|
||||
} else {
|
||||
|
||||
// make a copy of our collection to work from
|
||||
var values = this.collection.clone();
|
||||
if (_.size(this.collection.models) == 0 && _.size(this.options.autocomplete) == 0) {
|
||||
$("tbody", _self.el).html($('#tmpl-list-widget-child-empty').html());
|
||||
} else {
|
||||
|
||||
// look through our autocomplete values (if we have them) and render them all as checkboxes
|
||||
if (this.options.autocomplete) {
|
||||
_.each(this.options.autocomplete, function(option) {
|
||||
var found = _.find(values.models, function(element) {
|
||||
return element.get('item') == option;
|
||||
});
|
||||
|
||||
var model = null;
|
||||
var checked = false;
|
||||
|
||||
if (found) {
|
||||
// if we found the element, check the box
|
||||
model = found;
|
||||
checked = true;
|
||||
// and remove it from the list of items to be rendered later
|
||||
values.remove(found, {silent: true});
|
||||
} else {
|
||||
model = new Backbone.Model({item:option});
|
||||
checked = false;
|
||||
}
|
||||
|
||||
var el = new ListWidgetChildView({model:model, toggle: true, checked: checked, collection: _self.collection}).render().el;
|
||||
$("tbody", _self.el).append(el);
|
||||
|
||||
}, this);
|
||||
}
|
||||
|
||||
|
||||
// now render everything not in the autocomplete list
|
||||
_.each(values.models, function (model) {
|
||||
var el = new ListWidgetChildView({model:model, collection: _self.collection}).render().el;
|
||||
$("tbody", _self.el).append(el);
|
||||
}, this);
|
||||
}
|
||||
// make a copy of our collection to work from
|
||||
var values = this.collection.clone();
|
||||
|
||||
// look through our autocomplete values (if we have them) and render
|
||||
// them all as checkboxes
|
||||
if (this.options.autocomplete) {
|
||||
_.each(this.options.autocomplete, function(option) {
|
||||
var found = _.find(values.models, function(element) {
|
||||
return element.get('item') == option;
|
||||
});
|
||||
|
||||
var model = null;
|
||||
var checked = false;
|
||||
|
||||
if (found) {
|
||||
// if we found the element, check the box
|
||||
model = found;
|
||||
checked = true;
|
||||
// and remove it from the list of items to be rendered
|
||||
// later
|
||||
values.remove(found, {
|
||||
silent: true
|
||||
});
|
||||
} else {
|
||||
model = new Backbone.Model({
|
||||
item: option
|
||||
});
|
||||
checked = false;
|
||||
}
|
||||
|
||||
var el = new ListWidgetChildView({
|
||||
model: model,
|
||||
toggle: true,
|
||||
checked: checked,
|
||||
collection: _self.collection
|
||||
}).render().el;
|
||||
$("tbody", _self.el).append(el);
|
||||
|
||||
}, this);
|
||||
}
|
||||
|
||||
// now render everything not in the autocomplete list
|
||||
_.each(values.models, function(model) {
|
||||
var el = new ListWidgetChildView({
|
||||
model: model,
|
||||
collection: _self.collection
|
||||
}).render().el;
|
||||
$("tbody", _self.el).append(el);
|
||||
}, this);
|
||||
}
|
||||
|
||||
$(this.el).i18n();
|
||||
return this;
|
||||
}
|
||||
|
||||
$(this.el).i18n();
|
||||
return this;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
var BreadCrumbView = Backbone.View.extend({
|
||||
|
||||
tagName: 'ul',
|
||||
tagName: 'ul',
|
||||
|
||||
initialize:function (options) {
|
||||
this.options = options;
|
||||
initialize: function(options) {
|
||||
this.options = options;
|
||||
|
||||
if (!this.template) {
|
||||
this.template = _.template($('#tmpl-breadcrumbs').html());
|
||||
}
|
||||
if (!this.template) {
|
||||
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();
|
||||
var parent = this;
|
||||
this.$el.empty();
|
||||
var parent = this;
|
||||
|
||||
// go through each of the breadcrumb models
|
||||
_.each(this.collection.models, function (crumb, index) {
|
||||
// go through each of the breadcrumb models
|
||||
_.each(this.collection.models, function(crumb, index) {
|
||||
|
||||
// if it's the last index in the crumbs then render the link inactive
|
||||
if (index == parent.collection.size() - 1) {
|
||||
crumb.set({active:true}, {silent:true});
|
||||
} else {
|
||||
crumb.set({active:false}, {silent:true});
|
||||
}
|
||||
// if it's the last index in the crumbs then render the link
|
||||
// inactive
|
||||
if (index == parent.collection.size() - 1) {
|
||||
crumb.set({
|
||||
active: true
|
||||
}, {
|
||||
silent: true
|
||||
});
|
||||
} else {
|
||||
crumb.set({
|
||||
active: false
|
||||
}, {
|
||||
silent: true
|
||||
});
|
||||
}
|
||||
|
||||
this.$el.append(this.template(crumb.toJSON()));
|
||||
}, this);
|
||||
this.$el.append(this.template(crumb.toJSON()));
|
||||
}, this);
|
||||
|
||||
$('#breadcrumbs').html(this.el);
|
||||
$(this.el).i18n();
|
||||
}
|
||||
$('#breadcrumbs').html(this.el);
|
||||
$(this.el).i18n();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// User Profile
|
||||
|
||||
var UserProfileView = Backbone.View.extend({
|
||||
tagName: 'span',
|
||||
|
||||
initialize:function(options) {
|
||||
this.options = options;
|
||||
if (!this.template) {
|
||||
this.template = _.template($('#tmpl-user-profile-element').html());
|
||||
}
|
||||
},
|
||||
|
||||
render:function() {
|
||||
|
||||
$(this.el).html($('#tmpl-user-profile').html());
|
||||
|
||||
var t = this.template;
|
||||
|
||||
_.each(this.model, function (value, key) {
|
||||
if (key && value) {
|
||||
|
||||
if (typeof(value) === 'object') {
|
||||
|
||||
var el = this.el;
|
||||
var k = key;
|
||||
|
||||
_.each(value, function (value, key) {
|
||||
$('dl', el).append(
|
||||
t({key: key, value: value, category: k})
|
||||
);
|
||||
});
|
||||
} else if (typeof(value) === 'array') {
|
||||
// TODO: handle array types
|
||||
} else {
|
||||
$('dl', this.el).append(
|
||||
t({key: key, value: value})
|
||||
);
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
|
||||
$(this.el).i18n();
|
||||
initialize: function(options) {
|
||||
this.options = options;
|
||||
if (!this.template) {
|
||||
this.template = _.template($('#tmpl-user-profile-element').html());
|
||||
}
|
||||
},
|
||||
|
||||
render: function() {
|
||||
|
||||
$(this.el).html($('#tmpl-user-profile').html());
|
||||
|
||||
var t = this.template;
|
||||
|
||||
_.each(this.model, function(value, key) {
|
||||
if (key && value) {
|
||||
|
||||
if (typeof (value) === 'object') {
|
||||
|
||||
var el = this.el;
|
||||
var k = key;
|
||||
|
||||
_.each(value, function(value, key) {
|
||||
$('dl', el).append(t({
|
||||
key: key,
|
||||
value: value,
|
||||
category: k
|
||||
}));
|
||||
});
|
||||
} else if (typeof (value) === 'array') {
|
||||
// TODO: handle array types
|
||||
} else {
|
||||
$('dl', this.el).append(t({
|
||||
key: key,
|
||||
value: value
|
||||
}));
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
|
||||
$(this.el).i18n();
|
||||
return this;
|
||||
}
|
||||
});
|
||||
|
||||
// error handler
|
||||
var ErrorHandlerView = Backbone.View.extend({
|
||||
|
||||
initialize:function(options) {
|
||||
this.options = options;
|
||||
if (!this.template) {
|
||||
this.template = _.template($('#tmpl-error-box').html());
|
||||
}
|
||||
if (!this.headerTemplate) {
|
||||
this.headerTemplate = _.template($('#tmpl-error-header').html());
|
||||
}
|
||||
|
||||
initialize: function(options) {
|
||||
this.options = options;
|
||||
if (!this.template) {
|
||||
this.template = _.template($('#tmpl-error-box').html());
|
||||
}
|
||||
if (!this.headerTemplate) {
|
||||
this.headerTemplate = _.template($('#tmpl-error-header').html());
|
||||
}
|
||||
},
|
||||
|
||||
reloadPage:function(event) {
|
||||
|
||||
reloadPage: function(event) {
|
||||
event.preventDefault();
|
||||
window.location.reload(true);
|
||||
},
|
||||
|
||||
handleError:function(message) {
|
||||
|
||||
handleError: function(message) {
|
||||
|
||||
if (!message) {
|
||||
message = {};
|
||||
}
|
||||
|
||||
var _self = this;
|
||||
|
||||
|
||||
return function(model, response, options) {
|
||||
|
||||
|
||||
if (message.log) {
|
||||
console.log(message.log);
|
||||
}
|
||||
|
||||
_self.showErrorMessage(
|
||||
_self.headerTemplate({message: message, model: model, response: response, options: options}),
|
||||
_self.template({message: message, model: model, response: response, options: options})
|
||||
);
|
||||
|
||||
|
||||
_self.showErrorMessage(_self.headerTemplate({
|
||||
message: message,
|
||||
model: model,
|
||||
response: response,
|
||||
options: options
|
||||
}), _self.template({
|
||||
message: message,
|
||||
model: model,
|
||||
response: response,
|
||||
options: options
|
||||
}));
|
||||
|
||||
$('#modalAlert .modal-body .page-reload').on('click', _self.reloadPage);
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
showErrorMessage:function(header, message) {
|
||||
},
|
||||
|
||||
showErrorMessage: function(header, message) {
|
||||
// hide the sheet if it's visible
|
||||
$('#loadingbox').sheet('hide');
|
||||
|
||||
|
||||
$('#modalAlert').i18n();
|
||||
$('#modalAlert div.modal-header').html(header);
|
||||
$('#modalAlert .modal-body').html(message);
|
||||
|
@ -400,62 +442,66 @@ var ErrorHandlerView = Backbone.View.extend({
|
|||
'keyboard': true,
|
||||
'show': true
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Router
|
||||
var AppRouter = Backbone.Router.extend({
|
||||
|
||||
routes:{
|
||||
|
||||
"": "root"
|
||||
|
||||
},
|
||||
|
||||
root:function() {
|
||||
if (isAdmin()) {
|
||||
this.navigate('admin/clients', {trigger: true});
|
||||
} else {
|
||||
this.navigate('user/approved', {trigger: true});
|
||||
}
|
||||
},
|
||||
|
||||
initialize:function () {
|
||||
routes: {
|
||||
|
||||
this.breadCrumbView = new BreadCrumbView({
|
||||
collection:new Backbone.Collection()
|
||||
});
|
||||
"": "root"
|
||||
|
||||
this.breadCrumbView.render();
|
||||
|
||||
this.errorHandlerView = new ErrorHandlerView();
|
||||
},
|
||||
|
||||
// call all the extra initialization functions
|
||||
var app = this;
|
||||
_.each(ui.init, function(fn) {
|
||||
fn(app);
|
||||
});
|
||||
root: function() {
|
||||
if (isAdmin()) {
|
||||
this.navigate('admin/clients', {
|
||||
trigger: true
|
||||
});
|
||||
} else {
|
||||
this.navigate('user/approved', {
|
||||
trigger: true
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
},
|
||||
initialize: function() {
|
||||
|
||||
notImplemented:function(){
|
||||
this.breadCrumbView.collection.reset();
|
||||
this.breadCrumbView.collection.add([
|
||||
{text:$.t('admin.home'), href:""}
|
||||
]);
|
||||
|
||||
this.updateSidebar('none');
|
||||
|
||||
$('#content').html("<h2>Not implemented yet.</h2>");
|
||||
},
|
||||
|
||||
updateSidebar:function(item) {
|
||||
$('.sidebar-nav li.active').removeClass('active');
|
||||
|
||||
$('.sidebar-nav li a[href^="manage/#' + item + '"]').parent().addClass('active');
|
||||
}
|
||||
this.breadCrumbView = new BreadCrumbView({
|
||||
collection: new Backbone.Collection()
|
||||
});
|
||||
|
||||
this.breadCrumbView.render();
|
||||
|
||||
this.errorHandlerView = new ErrorHandlerView();
|
||||
|
||||
// call all the extra initialization functions
|
||||
var app = this;
|
||||
_.each(ui.init, function(fn) {
|
||||
fn(app);
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
notImplemented: function() {
|
||||
this.breadCrumbView.collection.reset();
|
||||
this.breadCrumbView.collection.add([{
|
||||
text: $.t('admin.home'),
|
||||
href: ""
|
||||
}]);
|
||||
|
||||
this.updateSidebar('none');
|
||||
|
||||
$('#content').html("<h2>Not implemented yet.</h2>");
|
||||
},
|
||||
|
||||
updateSidebar: function(item) {
|
||||
$('.sidebar-nav li.active').removeClass('active');
|
||||
|
||||
$('.sidebar-nav li a[href^="manage/#' + item + '"]').parent().addClass('active');
|
||||
}
|
||||
});
|
||||
|
||||
// holds the global app.
|
||||
|
@ -463,59 +509,67 @@ var AppRouter = Backbone.Router.extend({
|
|||
var app = null;
|
||||
|
||||
// main
|
||||
$(function () {
|
||||
$(function() {
|
||||
|
||||
var loader = function(source) {
|
||||
return $.get(source, function (templates) {
|
||||
console.log('Loading file: ' + source);
|
||||
$('#templates').append(templates);
|
||||
});
|
||||
};
|
||||
|
||||
// load templates and append them to the body
|
||||
$.when.apply(null, ui.templates.map(loader)
|
||||
).done(function() {
|
||||
console.log('done');
|
||||
$.ajaxSetup({cache:false});
|
||||
app = new AppRouter();
|
||||
var loader = function(source) {
|
||||
return $.get(source, function(templates) {
|
||||
console.log('Loading file: ' + source);
|
||||
$('#templates').append(templates);
|
||||
});
|
||||
};
|
||||
|
||||
_.each(ui.routes.reverse(), function(route) {
|
||||
console.log("Adding route: " + route.name);
|
||||
app.route(route.path, route.name, route.callback);
|
||||
});
|
||||
|
||||
app.on('route', function(name, args) {
|
||||
// scroll to top of page on new route selection
|
||||
$("html, body").animate({ scrollTop: 0 }, "slow");
|
||||
});
|
||||
|
||||
// grab all hashed URLs and send them through the app router instead
|
||||
$(document).on('click', 'a[href^="manage/#"]', function(event) {
|
||||
event.preventDefault();
|
||||
app.navigate(this.hash.slice(1), {trigger: true});
|
||||
});
|
||||
|
||||
var base = $('base').attr('href');
|
||||
$.getJSON(base + '.well-known/openid-configuration', function(data) {
|
||||
app.serverConfiguration = data;
|
||||
var baseUrl = $.url(app.serverConfiguration.issuer);
|
||||
Backbone.history.start({pushState: true, root: baseUrl.attr('relative') + 'manage/'});
|
||||
});
|
||||
});
|
||||
|
||||
window.onerror = function ( message, filename, lineno, colno, error ){
|
||||
console.log(message);
|
||||
//Display an alert with an error message
|
||||
// load templates and append them to the body
|
||||
$.when.apply(null, ui.templates.map(loader)).done(function() {
|
||||
console.log('done');
|
||||
$.ajaxSetup({
|
||||
cache: false
|
||||
});
|
||||
app = new AppRouter();
|
||||
|
||||
_.each(ui.routes.reverse(), function(route) {
|
||||
console.log("Adding route: " + route.name);
|
||||
app.route(route.path, route.name, route.callback);
|
||||
});
|
||||
|
||||
app.on('route', function(name, args) {
|
||||
// scroll to top of page on new route selection
|
||||
$("html, body").animate({
|
||||
scrollTop: 0
|
||||
}, "slow");
|
||||
});
|
||||
|
||||
// grab all hashed URLs and send them through the app router instead
|
||||
$(document).on('click', 'a[href^="manage/#"]', function(event) {
|
||||
event.preventDefault();
|
||||
app.navigate(this.hash.slice(1), {
|
||||
trigger: true
|
||||
});
|
||||
});
|
||||
|
||||
var base = $('base').attr('href');
|
||||
$.getJSON(base + '.well-known/openid-configuration', function(data) {
|
||||
app.serverConfiguration = data;
|
||||
var baseUrl = $.url(app.serverConfiguration.issuer);
|
||||
Backbone.history.start({
|
||||
pushState: true,
|
||||
root: baseUrl.attr('relative') + 'manage/'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
window.onerror = function(message, filename, lineno, colno, error) {
|
||||
console.log(message);
|
||||
// Display an alert with an error message
|
||||
$('#modalAlert div.modal-header').html($.t('error.title'));
|
||||
$('#modalAlert div.modal-body').html($.t('error.message') + message + ' <br /> ' + [filename, lineno, colno, error]);
|
||||
|
||||
$("#modalAlert").modal({ // wire up the actual modal functionality and show the dialog
|
||||
"backdrop" : "static",
|
||||
"keyboard" : true,
|
||||
"show" : true // ensure the modal is shown immediately
|
||||
});
|
||||
|
||||
}
|
||||
$("#modalAlert").modal({ // wire up the actual modal functionality
|
||||
// and show the dialog
|
||||
"backdrop": "static",
|
||||
"keyboard": true,
|
||||
"show": true
|
||||
// ensure the modal is shown immediately
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -16,63 +16,64 @@
|
|||
*******************************************************************************/
|
||||
var BlackListModel = Backbone.Model.extend({
|
||||
idAttribute: 'id',
|
||||
|
||||
|
||||
urlRoot: 'api/blacklist'
|
||||
});
|
||||
|
||||
var BlackListCollection = Backbone.Collection.extend({
|
||||
initialize: function() { },
|
||||
initialize: function() {
|
||||
},
|
||||
|
||||
url: "api/blacklist"
|
||||
});
|
||||
|
||||
var BlackListListView = Backbone.View.extend({
|
||||
tagName: 'span',
|
||||
|
||||
initialize:function(options) {
|
||||
this.options = options;
|
||||
|
||||
initialize: function(options) {
|
||||
this.options = options;
|
||||
},
|
||||
|
||||
load:function(callback) {
|
||||
if (this.collection.isFetched) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
load: function(callback) {
|
||||
if (this.collection.isFetched) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html(
|
||||
'<span class="label" id="loading-blacklist">' + $.t('admin.blacklist') + '</span> '
|
||||
);
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html('<span class="label" id="loading-blacklist">' + $.t('admin.blacklist') + '</span> ');
|
||||
|
||||
$.when(this.collection.fetchIfNeeded({
|
||||
success: function(e) {
|
||||
$('#loading-blacklist').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
})).done(function() {
|
||||
$('#loadingbox').sheet('hide');
|
||||
callback();
|
||||
});
|
||||
},
|
||||
|
||||
$.when(this.collection.fetchIfNeeded({success:function(e) {$('#loading-blacklist').addClass('label-success');}, error:app.errorHandlerView.handleError()}))
|
||||
.done(function() {
|
||||
$('#loadingbox').sheet('hide');
|
||||
callback();
|
||||
});
|
||||
},
|
||||
|
||||
events: {
|
||||
"click .refresh-table":"refreshTable",
|
||||
"click .btn-add":"addItem",
|
||||
"submit #add-blacklist form":"addItem"
|
||||
"click .refresh-table": "refreshTable",
|
||||
"click .btn-add": "addItem",
|
||||
"submit #add-blacklist form": "addItem"
|
||||
},
|
||||
|
||||
refreshTable:function(e) {
|
||||
e.preventDefault();
|
||||
refreshTable: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var _self = this;
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html(
|
||||
'<span class="label" id="loading-blacklist">' + $.t('admin.blacklist') + '</span> '
|
||||
);
|
||||
var _self = this;
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html('<span class="label" id="loading-blacklist">' + $.t('admin.blacklist') + '</span> ');
|
||||
|
||||
$.when(this.collection.fetch()).done(function() {
|
||||
$('#loadingbox').sheet('hide');
|
||||
_self.render();
|
||||
});
|
||||
},
|
||||
|
||||
togglePlaceholder:function() {
|
||||
$.when(this.collection.fetch()).done(function() {
|
||||
$('#loadingbox').sheet('hide');
|
||||
_self.render();
|
||||
});
|
||||
},
|
||||
|
||||
togglePlaceholder: function() {
|
||||
if (this.collection.length > 0) {
|
||||
$('#blacklist-table', this.el).show();
|
||||
$('#blacklist-table-empty', this.el).hide();
|
||||
|
@ -81,136 +82,143 @@ var BlackListListView = Backbone.View.extend({
|
|||
$('#blacklist-table-empty', this.el).show();
|
||||
}
|
||||
},
|
||||
|
||||
render:function (eventName) {
|
||||
|
||||
|
||||
render: function(eventName) {
|
||||
|
||||
$(this.el).html($('#tmpl-blacklist-table').html());
|
||||
|
||||
|
||||
var _self = this;
|
||||
_.each(this.collection.models, function(blacklist) {
|
||||
var view = new BlackListWidgetView({model: blacklist});
|
||||
var view = new BlackListWidgetView({
|
||||
model: blacklist
|
||||
});
|
||||
view.parentView = _self;
|
||||
$("#blacklist-table", _self.el).append(view.render().el);
|
||||
}, this);
|
||||
|
||||
|
||||
this.togglePlaceholder();
|
||||
|
||||
$(this.el).i18n();
|
||||
|
||||
$(this.el).i18n();
|
||||
return this;
|
||||
},
|
||||
|
||||
addItem:function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var input_value = $("#blacklist-uri", this.el).val().trim();
|
||||
|
||||
if (input_value === "") {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: URI/pattern validation, check against existing clients
|
||||
|
||||
var item = new BlackListModel({
|
||||
uri: input_value
|
||||
});
|
||||
|
||||
var _self = this; // closures...
|
||||
|
||||
item.save({}, {
|
||||
success:function() {
|
||||
_self.collection.add(item);
|
||||
_self.render();
|
||||
},
|
||||
error:app.errorHandlerView.handleError()
|
||||
});
|
||||
addItem: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var input_value = $("#blacklist-uri", this.el).val().trim();
|
||||
|
||||
if (input_value === "") {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: URI/pattern validation, check against existing clients
|
||||
|
||||
var item = new BlackListModel({
|
||||
uri: input_value
|
||||
});
|
||||
|
||||
var _self = this; // closures...
|
||||
|
||||
item.save({}, {
|
||||
success: function() {
|
||||
_self.collection.add(item);
|
||||
_self.render();
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
var BlackListWidgetView = Backbone.View.extend({
|
||||
|
||||
|
||||
tagName: 'tr',
|
||||
|
||||
initialize:function(options) {
|
||||
|
||||
initialize: function(options) {
|
||||
this.options = options;
|
||||
|
||||
|
||||
if (!this.template) {
|
||||
this.template = _.template($('#tmpl-blacklist-item').html());
|
||||
}
|
||||
},
|
||||
|
||||
render:function() {
|
||||
|
||||
render: function() {
|
||||
|
||||
this.$el.html(this.template(this.model.toJSON()));
|
||||
|
||||
return this;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
events:{
|
||||
'click .btn-delete':'deleteBlacklist'
|
||||
|
||||
events: {
|
||||
'click .btn-delete': 'deleteBlacklist'
|
||||
},
|
||||
|
||||
deleteBlacklist:function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
if (confirm($.t("blacklist.confirm"))) {
|
||||
var _self = this;
|
||||
deleteBlacklist: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
this.model.destroy({
|
||||
dataType: false, processData: false,
|
||||
success:function () {
|
||||
|
||||
_self.$el.fadeTo("fast", 0.00, function () { //fade
|
||||
$(this).slideUp("fast", function () { //slide up
|
||||
$(this).remove(); //then remove from the DOM
|
||||
_self.parentView.togglePlaceholder();
|
||||
});
|
||||
});
|
||||
},
|
||||
error:app.errorHandlerView.handleError()
|
||||
});
|
||||
if (confirm($.t("blacklist.confirm"))) {
|
||||
var _self = this;
|
||||
|
||||
_self.parentView.delegateEvents();
|
||||
}
|
||||
this.model.destroy({
|
||||
dataType: false,
|
||||
processData: false,
|
||||
success: function() {
|
||||
|
||||
return false;
|
||||
}
|
||||
_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()
|
||||
});
|
||||
|
||||
_self.parentView.delegateEvents();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
ui.routes.push({
|
||||
path: "admin/blacklist",
|
||||
name: "blackList",
|
||||
callback: function() {
|
||||
|
||||
ui.routes.push({path: "admin/blacklist", name: "blackList", callback:
|
||||
function() {
|
||||
|
||||
if (!isAdmin()) {
|
||||
this.root();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.breadCrumbView.collection.reset();
|
||||
this.breadCrumbView.collection.add([
|
||||
{text:$.t('admin.home'), href:""},
|
||||
{text:$.t('admin.manage-blacklist'), href:"manage/#admin/blacklist"}
|
||||
]);
|
||||
|
||||
this.updateSidebar('admin/blacklist');
|
||||
|
||||
var view = new BlackListListView({collection: this.blackListList});
|
||||
|
||||
view.load(
|
||||
function(collection, response, options) {
|
||||
$('#content').html(view.render().el);
|
||||
setPageTitle($.t('admin.manage-blacklist'));
|
||||
}
|
||||
);
|
||||
this.breadCrumbView.collection.add([{
|
||||
text: $.t('admin.home'),
|
||||
href: ""
|
||||
}, {
|
||||
text: $.t('admin.manage-blacklist'),
|
||||
href: "manage/#admin/blacklist"
|
||||
}]);
|
||||
|
||||
this.updateSidebar('admin/blacklist');
|
||||
|
||||
var view = new BlackListListView({
|
||||
collection: this.blackListList
|
||||
});
|
||||
|
||||
view.load(function(collection, response, options) {
|
||||
$('#content').html(view.render().el);
|
||||
setPageTitle($.t('admin.manage-blacklist'));
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
ui.templates.push('resources/template/blacklist.html');
|
||||
|
||||
ui.init.push(function(app) {
|
||||
app.blackListList = new BlackListCollection();
|
||||
app.blackListList = new BlackListCollection();
|
||||
});
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -16,84 +16,95 @@
|
|||
*******************************************************************************/
|
||||
var ApprovedSiteModel = Backbone.Model.extend({
|
||||
idAttribute: 'id',
|
||||
|
||||
initialize: function() { },
|
||||
|
||||
|
||||
initialize: function() {
|
||||
},
|
||||
|
||||
urlRoot: 'api/approved'
|
||||
|
||||
|
||||
});
|
||||
|
||||
var ApprovedSiteCollection = Backbone.Collection.extend({
|
||||
initialize: function() { },
|
||||
initialize: function() {
|
||||
},
|
||||
|
||||
model: ApprovedSiteModel,
|
||||
url: 'api/approved'
|
||||
});
|
||||
|
||||
|
||||
var ApprovedSiteListView = Backbone.View.extend({
|
||||
tagName: 'span',
|
||||
|
||||
initialize:function(options) {
|
||||
|
||||
initialize: function(options) {
|
||||
this.options = options;
|
||||
},
|
||||
|
||||
load:function(callback) {
|
||||
if (this.model.isFetched &&
|
||||
this.options.clientList.isFetched &&
|
||||
this.options.systemScopeList.isFetched) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
load: function(callback) {
|
||||
if (this.model.isFetched && this.options.clientList.isFetched && this.options.systemScopeList.isFetched) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html(
|
||||
'<span class="label" id="loading-grants">' + $.t('grant.grant-table.approved-sites') + '</span> ' +
|
||||
'<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' +
|
||||
'<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> '
|
||||
);
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html('<span class="label" id="loading-grants">' + $.t('grant.grant-table.approved-sites') + '</span> ' + '<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' + '<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ');
|
||||
|
||||
$.when(this.model.fetchIfNeeded({success:function(e) {$('#loading-grants').addClass('label-success');}, error:app.errorHandlerView.handleError()}),
|
||||
this.options.clientList.fetchIfNeeded({success:function(e) {$('#loading-clients').addClass('label-success');}, error:app.errorHandlerView.handleError()}),
|
||||
this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}, error:app.errorHandlerView.handleError()}))
|
||||
.done(function() {
|
||||
$('#loadingbox').sheet('hide');
|
||||
callback();
|
||||
});
|
||||
},
|
||||
|
||||
events: {
|
||||
"click .refresh-table":"refreshTable"
|
||||
$.when(this.model.fetchIfNeeded({
|
||||
success: function(e) {
|
||||
$('#loading-grants').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
}), this.options.clientList.fetchIfNeeded({
|
||||
success: function(e) {
|
||||
$('#loading-clients').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
}), this.options.systemScopeList.fetchIfNeeded({
|
||||
success: function(e) {
|
||||
$('#loading-scopes').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
})).done(function() {
|
||||
$('#loadingbox').sheet('hide');
|
||||
callback();
|
||||
});
|
||||
},
|
||||
|
||||
render:function (eventName) {
|
||||
|
||||
events: {
|
||||
"click .refresh-table": "refreshTable"
|
||||
},
|
||||
|
||||
render: function(eventName) {
|
||||
$(this.el).html($('#tmpl-grant-table').html());
|
||||
|
||||
|
||||
var approvedSiteCount = 0;
|
||||
|
||||
|
||||
var _self = this;
|
||||
|
||||
|
||||
_.each(this.model.models, function(approvedSite) {
|
||||
// look up client
|
||||
var client = this.options.clientList.getByClientId(approvedSite.get('clientId'));
|
||||
|
||||
|
||||
if (client != null) {
|
||||
|
||||
var view = new ApprovedSiteView({model: approvedSite, client: client, systemScopeList: this.options.systemScopeList});
|
||||
|
||||
var view = new ApprovedSiteView({
|
||||
model: approvedSite,
|
||||
client: client,
|
||||
systemScopeList: this.options.systemScopeList
|
||||
});
|
||||
view.parentView = _self;
|
||||
$('#grant-table', this.el).append(view.render().el);
|
||||
approvedSiteCount = approvedSiteCount + 1;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}, this);
|
||||
|
||||
|
||||
this.togglePlaceholder();
|
||||
$(this.el).i18n();
|
||||
return this;
|
||||
},
|
||||
|
||||
togglePlaceholder:function() {
|
||||
|
||||
togglePlaceholder: function() {
|
||||
// count entries
|
||||
if (this.model.length > 0) {
|
||||
$('#grant-table', this.el).show();
|
||||
|
@ -102,54 +113,62 @@ var ApprovedSiteListView = Backbone.View.extend({
|
|||
$('#grant-table', this.el).hide();
|
||||
$('#grant-table-empty', this.el).show();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
refreshTable:function(e) {
|
||||
e.preventDefault();
|
||||
var _self = this;
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html(
|
||||
'<span class="label" id="loading-grants">' + $.t('grant.grant-table.approved-sites') + '</span> ' +
|
||||
'<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' +
|
||||
'<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> '
|
||||
);
|
||||
|
||||
$.when(this.model.fetch({success:function(e) {$('#loading-grants').addClass('label-success');}, error:app.errorHandlerView.handleError()}),
|
||||
this.options.clientList.fetch({success:function(e) {$('#loading-clients').addClass('label-success');}, error:app.errorHandlerView.handleError()}),
|
||||
this.options.systemScopeList.fetch({success:function(e) {$('#loading-scopes').addClass('label-success');}, error:app.errorHandlerView.handleError()}))
|
||||
.done(function() {
|
||||
$('#loadingbox').sheet('hide');
|
||||
_self.render();
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
refreshTable: function(e) {
|
||||
e.preventDefault();
|
||||
var _self = this;
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html('<span class="label" id="loading-grants">' + $.t('grant.grant-table.approved-sites') + '</span> ' + '<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' + '<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ');
|
||||
|
||||
$.when(this.model.fetch({
|
||||
success: function(e) {
|
||||
$('#loading-grants').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
}), this.options.clientList.fetch({
|
||||
success: function(e) {
|
||||
$('#loading-clients').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
}), this.options.systemScopeList.fetch({
|
||||
success: function(e) {
|
||||
$('#loading-scopes').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
})).done(function() {
|
||||
$('#loadingbox').sheet('hide');
|
||||
_self.render();
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
var ApprovedSiteView = Backbone.View.extend({
|
||||
tagName: 'tr',
|
||||
|
||||
|
||||
initialize: function(options) {
|
||||
this.options = options;
|
||||
this.options = options;
|
||||
if (!this.template) {
|
||||
this.template = _.template($('#tmpl-grant').html());
|
||||
}
|
||||
if (!this.scopeTemplate) {
|
||||
this.scopeTemplate = _.template($('#tmpl-scope-list').html());
|
||||
}
|
||||
if (!this.scopeTemplate) {
|
||||
this.scopeTemplate = _.template($('#tmpl-scope-list').html());
|
||||
}
|
||||
|
||||
if (!this.moreInfoTemplate) {
|
||||
this.moreInfoTemplate = _.template($('#tmpl-client-more-info-block').html());
|
||||
}
|
||||
if (!this.moreInfoTemplate) {
|
||||
this.moreInfoTemplate = _.template($('#tmpl-client-more-info-block').html());
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
render: function() {
|
||||
|
||||
render: function() {
|
||||
|
||||
var creationDate = this.model.get("creationDate");
|
||||
var accessDate = this.model.get("accessDate");
|
||||
var timeoutDate = this.model.get("timeoutDate");
|
||||
|
||||
|
||||
var displayCreationDate = $.t('grant.grant-table.unknown');
|
||||
var hoverCreationDate = "";
|
||||
if ((creationDate != null) && moment(creationDate).isValid()) {
|
||||
|
@ -178,7 +197,7 @@ var ApprovedSiteView = Backbone.View.extend({
|
|||
var hoverTimeoutDate = "";
|
||||
if (timeoutDate == null) {
|
||||
displayTimeoutDate = $.t('grant.grant-table.never');
|
||||
} else if(moment(timeoutDate).isValid()) {
|
||||
} else if (moment(timeoutDate).isValid()) {
|
||||
timeoutDate = moment(timeoutDate);
|
||||
if (moment().diff(timeoutDate, 'months') < 6) {
|
||||
displayTimeoutDate = timeoutDate.fromNow();
|
||||
|
@ -188,62 +207,80 @@ var ApprovedSiteView = Backbone.View.extend({
|
|||
hoverTimeoutDate = timeoutDate.format("LLL");
|
||||
}
|
||||
|
||||
|
||||
var formattedDate = {displayCreationDate: displayCreationDate, hoverCreationDate: hoverCreationDate,
|
||||
displayAccessDate: displayAccessDate, hoverAccessDate: hoverAccessDate,
|
||||
displayTimeoutDate: displayTimeoutDate, hoverTimeoutDate: hoverTimeoutDate};
|
||||
|
||||
var json = {grant: this.model.toJSON(), client: this.options.client.toJSON(), formattedDate: formattedDate};
|
||||
|
||||
var formattedDate = {
|
||||
displayCreationDate: displayCreationDate,
|
||||
hoverCreationDate: hoverCreationDate,
|
||||
displayAccessDate: displayAccessDate,
|
||||
hoverAccessDate: hoverAccessDate,
|
||||
displayTimeoutDate: displayTimeoutDate,
|
||||
hoverTimeoutDate: hoverTimeoutDate
|
||||
};
|
||||
|
||||
var json = {
|
||||
grant: this.model.toJSON(),
|
||||
client: this.options.client.toJSON(),
|
||||
formattedDate: formattedDate
|
||||
};
|
||||
|
||||
this.$el.html(this.template(json));
|
||||
|
||||
$('.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()}));
|
||||
|
||||
this.$('.dynamically-registered').tooltip({title: $.t('grant.grant-table.dynamically-registered')});
|
||||
this.$('.tokens').tooltip({title: $.t('grant.grant-table.active-tokens')});
|
||||
$(this.el).i18n();
|
||||
$('.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()
|
||||
}));
|
||||
|
||||
this.$('.dynamically-registered').tooltip({
|
||||
title: $.t('grant.grant-table.dynamically-registered')
|
||||
});
|
||||
this.$('.tokens').tooltip({
|
||||
title: $.t('grant.grant-table.active-tokens')
|
||||
});
|
||||
$(this.el).i18n();
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
events: {
|
||||
'click .btn-delete': 'deleteApprovedSite',
|
||||
'click .toggleMoreInformation': 'toggleMoreInformation'
|
||||
},
|
||||
|
||||
deleteApprovedSite:function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
deleteApprovedSite: function(e) {
|
||||
e.preventDefault();
|
||||
if (confirm("Are you sure you want to revoke access to this site?")) {
|
||||
var self = this;
|
||||
|
||||
this.model.destroy({
|
||||
dataType: false, processData: false,
|
||||
success:function () {
|
||||
self.$el.fadeTo("fast", 0.00, function () { //fade
|
||||
$(this).slideUp("fast", function () { //slide up
|
||||
$(this).remove(); //then remove from the DOM
|
||||
self.parentView.togglePlaceholder();
|
||||
});
|
||||
});
|
||||
},
|
||||
error:app.errorHandlerView.handleError()
|
||||
});
|
||||
|
||||
this.parentView.delegateEvents();
|
||||
|
||||
this.model.destroy({
|
||||
dataType: false,
|
||||
processData: false,
|
||||
success: function() {
|
||||
self.$el.fadeTo("fast", 0.00, function() { // fade
|
||||
$(this).slideUp("fast", function() { // slide up
|
||||
$(this).remove(); // then remove from the DOM
|
||||
self.parentView.togglePlaceholder();
|
||||
});
|
||||
});
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
});
|
||||
|
||||
this.parentView.delegateEvents();
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
toggleMoreInformation:function(e) {
|
||||
|
||||
toggleMoreInformation: function(e) {
|
||||
e.preventDefault();
|
||||
if ($('.moreInformation', this.el).is(':visible')) {
|
||||
// hide it
|
||||
$('.moreInformation', this.el).hide('fast');
|
||||
$('.toggleMoreInformation i', this.el).attr('class', 'icon-chevron-right');
|
||||
$('.moreInformationContainer', this.el).removeClass('alert').removeClass('alert-info').addClass('muted');
|
||||
|
||||
|
||||
} else {
|
||||
// show it
|
||||
$('.moreInformation', this.el).show('fast');
|
||||
|
@ -251,36 +288,44 @@ var ApprovedSiteView = Backbone.View.extend({
|
|||
$('.moreInformationContainer', this.el).addClass('alert').addClass('alert-info').removeClass('muted');
|
||||
}
|
||||
},
|
||||
|
||||
close:function() {
|
||||
|
||||
close: function() {
|
||||
$(this.el).unbind();
|
||||
$(this.el).empty();
|
||||
}
|
||||
});
|
||||
|
||||
ui.routes.push({path: "user/approved", name: "approvedSites", callback:
|
||||
|
||||
ui.routes.push({
|
||||
path: "user/approved",
|
||||
name: "approvedSites",
|
||||
callback:
|
||||
|
||||
function() {
|
||||
this.breadCrumbView.collection.reset();
|
||||
this.breadCrumbView.collection.add([
|
||||
{text:$.t('admin.home'), href:""},
|
||||
{text:$.t('grant.manage-approved-sites'), href:"manage/#user/approve"}
|
||||
]);
|
||||
|
||||
this.updateSidebar('user/approved');
|
||||
|
||||
var view = new ApprovedSiteListView({model:this.approvedSiteList, clientList: this.clientList, systemScopeList: this.systemScopeList});
|
||||
view.load(
|
||||
function(collection, response, options) {
|
||||
$('#content').html(view.render().el);
|
||||
setPageTitle($.t('grant.manage-approved-sites'));
|
||||
}
|
||||
);
|
||||
this.breadCrumbView.collection.add([{
|
||||
text: $.t('admin.home'),
|
||||
href: ""
|
||||
}, {
|
||||
text: $.t('grant.manage-approved-sites'),
|
||||
href: "manage/#user/approve"
|
||||
}]);
|
||||
|
||||
this.updateSidebar('user/approved');
|
||||
|
||||
var view = new ApprovedSiteListView({
|
||||
model: this.approvedSiteList,
|
||||
clientList: this.clientList,
|
||||
systemScopeList: this.systemScopeList
|
||||
});
|
||||
view.load(function(collection, response, options) {
|
||||
$('#content').html(view.render().el);
|
||||
setPageTitle($.t('grant.manage-approved-sites'));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
ui.templates.push('resources/template/grant.html');
|
||||
|
||||
ui.init.push(function(app) {
|
||||
app.approvedSiteList = new ApprovedSiteCollection();
|
||||
app.approvedSiteList = new ApprovedSiteCollection();
|
||||
});
|
||||
|
|
|
@ -14,21 +14,28 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
ui.routes.push({path: "user/profile", name: "profile", callback:
|
||||
function() {
|
||||
ui.routes.push({
|
||||
path: "user/profile",
|
||||
name: "profile",
|
||||
callback: function() {
|
||||
|
||||
this.breadCrumbView.collection.reset();
|
||||
this.breadCrumbView.collection.add([
|
||||
{text:$.t('admin.home'), href:""},
|
||||
{text:$.t('admin.user-profile.show'), href:"manage/#user/profile"}
|
||||
]);
|
||||
|
||||
this.updateSidebar('user/profile');
|
||||
|
||||
var view = new UserProfileView({model: getUserInfo()});
|
||||
$('#content').html(view.render().el);
|
||||
|
||||
setPageTitle($.t('admin.user-profile.show'));
|
||||
|
||||
}
|
||||
this.breadCrumbView.collection.reset();
|
||||
this.breadCrumbView.collection.add([{
|
||||
text: $.t('admin.home'),
|
||||
href: ""
|
||||
}, {
|
||||
text: $.t('admin.user-profile.show'),
|
||||
href: "manage/#user/profile"
|
||||
}]);
|
||||
|
||||
this.updateSidebar('user/profile');
|
||||
|
||||
var view = new UserProfileView({
|
||||
model: getUserInfo()
|
||||
});
|
||||
$('#content').html(view.render().el);
|
||||
|
||||
setPageTitle($.t('admin.user-profile.show'));
|
||||
|
||||
}
|
||||
});
|
|
@ -15,492 +15,565 @@
|
|||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
var ResRegClient = Backbone.Model.extend({
|
||||
idAttribute: "client_id",
|
||||
idAttribute: "client_id",
|
||||
|
||||
defaults:{
|
||||
client_id:null,
|
||||
client_secret:null,
|
||||
client_name:null,
|
||||
client_uri:null,
|
||||
logo_uri:null,
|
||||
contacts:[],
|
||||
tos_uri:null,
|
||||
token_endpoint_auth_method:null,
|
||||
scope:null,
|
||||
policy_uri:null,
|
||||
|
||||
jwks_uri:null,
|
||||
jwks:null,
|
||||
jwksType:'URI',
|
||||
|
||||
application_type:null,
|
||||
registration_access_token:null,
|
||||
registration_client_uri:null
|
||||
},
|
||||
|
||||
sync: function(method, model, options){
|
||||
if (model.get('registration_access_token')) {
|
||||
var headers = options.headers ? options.headers : {};
|
||||
headers['Authorization'] = 'Bearer ' + model.get('registration_access_token');
|
||||
options.headers = headers;
|
||||
}
|
||||
|
||||
return this.constructor.__super__.sync(method, model, options);
|
||||
},
|
||||
defaults: {
|
||||
client_id: null,
|
||||
client_secret: null,
|
||||
client_name: null,
|
||||
client_uri: null,
|
||||
logo_uri: null,
|
||||
contacts: [],
|
||||
tos_uri: null,
|
||||
token_endpoint_auth_method: null,
|
||||
scope: null,
|
||||
policy_uri: null,
|
||||
|
||||
jwks_uri: null,
|
||||
jwks: null,
|
||||
jwksType: 'URI',
|
||||
|
||||
application_type: null,
|
||||
registration_access_token: null,
|
||||
registration_client_uri: null
|
||||
},
|
||||
|
||||
sync: function(method, model, options) {
|
||||
if (model.get('registration_access_token')) {
|
||||
var headers = options.headers ? options.headers : {};
|
||||
headers['Authorization'] = 'Bearer ' + model.get('registration_access_token');
|
||||
options.headers = headers;
|
||||
}
|
||||
|
||||
return this.constructor.__super__.sync(method, model, options);
|
||||
},
|
||||
|
||||
urlRoot: 'resource'
|
||||
|
||||
urlRoot:'resource'
|
||||
|
||||
});
|
||||
|
||||
var ResRegRootView = Backbone.View.extend({
|
||||
|
||||
|
||||
tagName: 'span',
|
||||
|
||||
initialize:function(options) {
|
||||
this.options = options;
|
||||
|
||||
},
|
||||
|
||||
events:{
|
||||
"click #newreg":"newReg",
|
||||
"click #editreg":"editReg"
|
||||
},
|
||||
|
||||
load:function(callback) {
|
||||
if (this.options.systemScopeList.isFetched) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html('<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ');
|
||||
initialize: function(options) {
|
||||
this.options = options;
|
||||
|
||||
$.when(this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}, error:app.errorHandlerView.handleError()}))
|
||||
.done(function() {
|
||||
$('#loadingbox').sheet('hide');
|
||||
callback();
|
||||
});
|
||||
},
|
||||
|
||||
render:function() {
|
||||
$(this.el).html($('#tmpl-rsreg').html());
|
||||
$(this.el).i18n();
|
||||
return this;
|
||||
|
||||
events: {
|
||||
"click #newreg": "newReg",
|
||||
"click #editreg": "editReg"
|
||||
},
|
||||
|
||||
newReg:function(e) {
|
||||
e.preventDefault();
|
||||
this.remove();
|
||||
app.navigate('dev/resource/new', {trigger: true});
|
||||
|
||||
load: function(callback) {
|
||||
if (this.options.systemScopeList.isFetched) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html('<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ');
|
||||
|
||||
$.when(this.options.systemScopeList.fetchIfNeeded({
|
||||
success: function(e) {
|
||||
$('#loading-scopes').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
})).done(function() {
|
||||
$('#loadingbox').sheet('hide');
|
||||
callback();
|
||||
});
|
||||
},
|
||||
|
||||
editReg:function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
render: function() {
|
||||
$(this.el).html($('#tmpl-rsreg').html());
|
||||
$(this.el).i18n();
|
||||
return this;
|
||||
},
|
||||
|
||||
newReg: function(e) {
|
||||
e.preventDefault();
|
||||
this.remove();
|
||||
app.navigate('dev/resource/new', {
|
||||
trigger: true
|
||||
});
|
||||
},
|
||||
|
||||
editReg: function(e) {
|
||||
e.preventDefault();
|
||||
var clientId = $('#clientId').val();
|
||||
var token = $('#regtoken').val();
|
||||
|
||||
|
||||
var client = new ResRegClient({
|
||||
client_id: clientId,
|
||||
registration_access_token: token
|
||||
});
|
||||
|
||||
|
||||
var self = this;
|
||||
|
||||
|
||||
client.fetch({
|
||||
success: function() {
|
||||
|
||||
if (client.get("jwks")) {
|
||||
client.set({
|
||||
jwksType: "VAL"
|
||||
}, { silent: true });
|
||||
} else {
|
||||
client.set({
|
||||
jwksType: "URI"
|
||||
}, { silent: true });
|
||||
}
|
||||
|
||||
var view = new ResRegEditView({model: client, systemScopeList: app.systemScopeList});
|
||||
|
||||
view.load(function() {
|
||||
$('#content').html(view.render().el);
|
||||
view.delegateEvents();
|
||||
setPageTitle($.t('rsreg.new'));
|
||||
app.navigate('dev/resource/edit', {trigger: true});
|
||||
self.remove();
|
||||
});
|
||||
},
|
||||
error:app.errorHandlerView.handleError({message: $.t('dynreg.invalid-access-token')})
|
||||
|
||||
if (client.get("jwks")) {
|
||||
client.set({
|
||||
jwksType: "VAL"
|
||||
}, {
|
||||
silent: true
|
||||
});
|
||||
} else {
|
||||
client.set({
|
||||
jwksType: "URI"
|
||||
}, {
|
||||
silent: true
|
||||
});
|
||||
}
|
||||
|
||||
var view = new ResRegEditView({
|
||||
model: client,
|
||||
systemScopeList: app.systemScopeList
|
||||
});
|
||||
|
||||
view.load(function() {
|
||||
$('#content').html(view.render().el);
|
||||
view.delegateEvents();
|
||||
setPageTitle($.t('rsreg.new'));
|
||||
app.navigate('dev/resource/edit', {
|
||||
trigger: true
|
||||
});
|
||||
self.remove();
|
||||
});
|
||||
},
|
||||
error: app.errorHandlerView.handleError({
|
||||
message: $.t('dynreg.invalid-access-token')
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
var ResRegEditView = Backbone.View.extend({
|
||||
|
||||
|
||||
tagName: 'span',
|
||||
|
||||
initialize:function(options) {
|
||||
this.options = options;
|
||||
if (!this.template) {
|
||||
this.template = _.template($('#tmpl-rsreg-resource-form').html());
|
||||
}
|
||||
|
||||
this.redirectUrisCollection = new Backbone.Collection();
|
||||
this.scopeCollection = new Backbone.Collection();
|
||||
this.contactsCollection = new Backbone.Collection();
|
||||
this.defaultAcrValuesCollection = new Backbone.Collection();
|
||||
this.requestUrisCollection = new Backbone.Collection();
|
||||
|
||||
this.listWidgetViews = [];
|
||||
},
|
||||
|
||||
load:function(callback) {
|
||||
if (this.options.systemScopeList.isFetched) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
initialize: function(options) {
|
||||
this.options = options;
|
||||
if (!this.template) {
|
||||
this.template = _.template($('#tmpl-rsreg-resource-form').html());
|
||||
}
|
||||
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html('<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ');
|
||||
this.redirectUrisCollection = new Backbone.Collection();
|
||||
this.scopeCollection = new Backbone.Collection();
|
||||
this.contactsCollection = new Backbone.Collection();
|
||||
this.defaultAcrValuesCollection = new Backbone.Collection();
|
||||
this.requestUrisCollection = new Backbone.Collection();
|
||||
|
||||
$.when(this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}, error:app.errorHandlerView.handleError()}))
|
||||
.done(function() {
|
||||
$('#loadingbox').sheet('hide');
|
||||
callback();
|
||||
});
|
||||
},
|
||||
|
||||
events:{
|
||||
"click .btn-save":"saveClient",
|
||||
"click .btn-cancel":"cancel",
|
||||
"click .btn-delete":"deleteClient",
|
||||
"change #logoUri input":"previewLogo",
|
||||
"change #tokenEndpointAuthMethod input:radio":"toggleClientCredentials",
|
||||
"change #jwkSelector input:radio":"toggleJWKSetType"
|
||||
},
|
||||
|
||||
cancel:function(e) {
|
||||
e.preventDefault();
|
||||
app.navigate('dev/resource', {trigger: true});
|
||||
},
|
||||
|
||||
deleteClient:function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
if (confirm($.t('client.client-table.confirm'))) {
|
||||
var self = this;
|
||||
|
||||
this.model.destroy({
|
||||
dataType: false, processData: false,
|
||||
success:function () {
|
||||
self.remove();
|
||||
app.navigate('dev/resource', {trigger: true});
|
||||
},
|
||||
error:app.errorHandlerView.handleError()
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
previewLogo:function() {
|
||||
if ($('#logoUri input', this.el).val()) {
|
||||
$('#logoPreview', this.el).empty();
|
||||
$('#logoPreview', this.el).attr('src', $('#logoUri input', this.el).val());
|
||||
} else {
|
||||
//$('#logoBlock', this.el).hide();
|
||||
$('#logoPreview', this.el).attr('src', 'resources/images/logo_placeholder.gif');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Set up the form based on the current state of the tokenEndpointAuthMethod parameter
|
||||
* @param event
|
||||
*/
|
||||
toggleClientCredentials:function() {
|
||||
|
||||
var tokenEndpointAuthMethod = $('#tokenEndpointAuthMethod input', this.el).filter(':checked').val();
|
||||
|
||||
// show or hide the signing algorithm method depending on what's selected
|
||||
if (tokenEndpointAuthMethod == 'private_key_jwt'
|
||||
|| tokenEndpointAuthMethod == 'client_secret_jwt') {
|
||||
$('#tokenEndpointAuthSigningAlg', this.el).show();
|
||||
} else {
|
||||
$('#tokenEndpointAuthSigningAlg', this.el).hide();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Set up the form based on the JWK Set selector
|
||||
*/
|
||||
toggleJWKSetType:function() {
|
||||
var jwkSelector = $('#jwkSelector input:radio', this.el).filter(':checked').val();
|
||||
|
||||
if (jwkSelector == 'URI') {
|
||||
$('#jwksUri', this.el).show();
|
||||
$('#jwks', this.el).hide();
|
||||
} else if (jwkSelector == 'VAL') {
|
||||
$('#jwksUri', this.el).hide();
|
||||
$('#jwks', this.el).show();
|
||||
} else {
|
||||
$('#jwksUri', this.el).hide();
|
||||
$('#jwks', this.el).hide();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
disableUnsupportedJOSEItems:function(serverSupported, query) {
|
||||
var supported = ['default'];
|
||||
if (serverSupported) {
|
||||
supported = _.union(supported, serverSupported);
|
||||
}
|
||||
$(query, this.$el).each(function(idx) {
|
||||
if(_.contains(supported, $(this).val())) {
|
||||
$(this).prop('disabled', false);
|
||||
} else {
|
||||
$(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
|
||||
defaultToNull:function(value) {
|
||||
if (value == 'default') {
|
||||
return null;
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
},
|
||||
|
||||
saveClient:function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
$('.control-group').removeClass('error');
|
||||
|
||||
// sync any leftover collection items
|
||||
_.each(this.listWidgetViews, function(v) {
|
||||
v.addItem($.Event('click'));
|
||||
});
|
||||
|
||||
// build the scope object
|
||||
var scopes = this.scopeCollection.pluck("item").join(" ");
|
||||
|
||||
var contacts = this.contactsCollection.pluck('item');
|
||||
var userInfo = getUserInfo();
|
||||
if (userInfo && userInfo.email) {
|
||||
if (!_.contains(contacts, userInfo.email)) {
|
||||
contacts.push(userInfo.email);
|
||||
}
|
||||
}
|
||||
|
||||
// process the JWKS
|
||||
var jwksUri = null;
|
||||
var jwks = null;
|
||||
var jwkSelector = $('#jwkSelector input:radio', this.el).filter(':checked').val();
|
||||
|
||||
if (jwkSelector == 'URI') {
|
||||
jwksUri = $('#jwksUri input').val();
|
||||
jwks = null;
|
||||
} else if (jwkSelector == 'VAL') {
|
||||
jwksUri = null;
|
||||
try {
|
||||
jwks = JSON.parse($('#jwks textarea').val());
|
||||
} catch (e) {
|
||||
console.log("An error occurred when parsing the JWK Set");
|
||||
|
||||
//Display an alert with an error message
|
||||
app.errorHandlerView.showErrorMessage($.t("client.client-form.error.jwk-set"), $.t("client.client-form.error.jwk-set-parse"));
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
jwksUri = null;
|
||||
jwks = null;
|
||||
}
|
||||
|
||||
var attrs = {
|
||||
client_name:$('#clientName input').val(),
|
||||
logo_uri:$('#logoUri input').val(),
|
||||
scope: scopes,
|
||||
client_secret: null, // never send a client secret
|
||||
tos_uri: $('#tosUri input').val(),
|
||||
policy_uri: $('#policyUri input').val(),
|
||||
client_uri: $('#clientUri input').val(),
|
||||
application_type: $('#applicationType input').filter(':checked').val(),
|
||||
jwks_uri: jwksUri,
|
||||
jwks: jwks,
|
||||
token_endpoint_auth_method: $('#tokenEndpointAuthMethod input').filter(':checked').val(),
|
||||
contacts: contacts,
|
||||
token_endpoint_auth_signing_alg: this.defaultToNull($('#tokenEndpointAuthSigningAlg select').val())
|
||||
};
|
||||
|
||||
// set all empty strings to nulls
|
||||
for (var key in attrs) {
|
||||
if (attrs[key] === "") {
|
||||
attrs[key] = null;
|
||||
}
|
||||
}
|
||||
|
||||
var _self = this;
|
||||
this.model.save(attrs, {
|
||||
success:function () {
|
||||
// switch to an "edit" view
|
||||
app.navigate('dev/resource/edit', {trigger: true});
|
||||
_self.remove();
|
||||
|
||||
if (_self.model.get("jwks")) {
|
||||
_self.model.set({
|
||||
jwksType: "VAL"
|
||||
}, { silent: true });
|
||||
} else {
|
||||
_self.model.set({
|
||||
jwksType: "URI"
|
||||
}, { silent: true });
|
||||
}
|
||||
|
||||
var view = new ResRegEditView({model: _self.model, systemScopeList: _self.options.systemScopeList});
|
||||
|
||||
view.load(function() {
|
||||
// reload
|
||||
$('#content').html(view.render().el);
|
||||
view.delegateEvents();
|
||||
});
|
||||
},
|
||||
error:app.errorHandlerView.handleError()
|
||||
});
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
render:function() {
|
||||
$(this.el).html(this.template({client: this.model.toJSON(), userInfo: getUserInfo()}));
|
||||
|
||||
this.listWidgetViews = [];
|
||||
|
||||
},
|
||||
|
||||
load: function(callback) {
|
||||
if (this.options.systemScopeList.isFetched) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html('<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ');
|
||||
|
||||
$.when(this.options.systemScopeList.fetchIfNeeded({
|
||||
success: function(e) {
|
||||
$('#loading-scopes').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
})).done(function() {
|
||||
$('#loadingbox').sheet('hide');
|
||||
callback();
|
||||
});
|
||||
},
|
||||
|
||||
events: {
|
||||
"click .btn-save": "saveClient",
|
||||
"click .btn-cancel": "cancel",
|
||||
"click .btn-delete": "deleteClient",
|
||||
"change #logoUri input": "previewLogo",
|
||||
"change #tokenEndpointAuthMethod input:radio": "toggleClientCredentials",
|
||||
"change #jwkSelector input:radio": "toggleJWKSetType"
|
||||
},
|
||||
|
||||
cancel: function(e) {
|
||||
e.preventDefault();
|
||||
app.navigate('dev/resource', {
|
||||
trigger: true
|
||||
});
|
||||
},
|
||||
|
||||
deleteClient: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
if (confirm($.t('client.client-table.confirm'))) {
|
||||
var self = this;
|
||||
|
||||
this.model.destroy({
|
||||
dataType: false,
|
||||
processData: false,
|
||||
success: function() {
|
||||
self.remove();
|
||||
app.navigate('dev/resource', {
|
||||
trigger: true
|
||||
});
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
previewLogo: function() {
|
||||
if ($('#logoUri input', this.el).val()) {
|
||||
$('#logoPreview', this.el).empty();
|
||||
$('#logoPreview', this.el).attr('src', $('#logoUri input', this.el).val());
|
||||
} else {
|
||||
// $('#logoBlock', this.el).hide();
|
||||
$('#logoPreview', this.el).attr('src', 'resources/images/logo_placeholder.gif');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Set up the form based on the current state of the tokenEndpointAuthMethod
|
||||
* parameter
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
toggleClientCredentials: function() {
|
||||
|
||||
var tokenEndpointAuthMethod = $('#tokenEndpointAuthMethod input', this.el).filter(':checked').val();
|
||||
|
||||
// show or hide the signing algorithm method depending on what's
|
||||
// selected
|
||||
if (tokenEndpointAuthMethod == 'private_key_jwt' || tokenEndpointAuthMethod == 'client_secret_jwt') {
|
||||
$('#tokenEndpointAuthSigningAlg', this.el).show();
|
||||
} else {
|
||||
$('#tokenEndpointAuthSigningAlg', this.el).hide();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Set up the form based on the JWK Set selector
|
||||
*/
|
||||
toggleJWKSetType: function() {
|
||||
var jwkSelector = $('#jwkSelector input:radio', this.el).filter(':checked').val();
|
||||
|
||||
if (jwkSelector == 'URI') {
|
||||
$('#jwksUri', this.el).show();
|
||||
$('#jwks', this.el).hide();
|
||||
} else if (jwkSelector == 'VAL') {
|
||||
$('#jwksUri', this.el).hide();
|
||||
$('#jwks', this.el).show();
|
||||
} else {
|
||||
$('#jwksUri', this.el).hide();
|
||||
$('#jwks', this.el).hide();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
disableUnsupportedJOSEItems: function(serverSupported, query) {
|
||||
var supported = ['default'];
|
||||
if (serverSupported) {
|
||||
supported = _.union(supported, serverSupported);
|
||||
}
|
||||
$(query, this.$el).each(function(idx) {
|
||||
if (_.contains(supported, $(this).val())) {
|
||||
$(this).prop('disabled', false);
|
||||
} else {
|
||||
$(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
|
||||
defaultToNull: function(value) {
|
||||
if (value == 'default') {
|
||||
return null;
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
},
|
||||
|
||||
saveClient: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
$('.control-group').removeClass('error');
|
||||
|
||||
// sync any leftover collection items
|
||||
_.each(this.listWidgetViews, function(v) {
|
||||
v.addItem($.Event('click'));
|
||||
});
|
||||
|
||||
// build the scope object
|
||||
var scopes = this.scopeCollection.pluck("item").join(" ");
|
||||
|
||||
var contacts = this.contactsCollection.pluck('item');
|
||||
var userInfo = getUserInfo();
|
||||
if (userInfo && userInfo.email) {
|
||||
if (!_.contains(contacts, userInfo.email)) {
|
||||
contacts.push(userInfo.email);
|
||||
}
|
||||
}
|
||||
|
||||
// process the JWKS
|
||||
var jwksUri = null;
|
||||
var jwks = null;
|
||||
var jwkSelector = $('#jwkSelector input:radio', this.el).filter(':checked').val();
|
||||
|
||||
if (jwkSelector == 'URI') {
|
||||
jwksUri = $('#jwksUri input').val();
|
||||
jwks = null;
|
||||
} else if (jwkSelector == 'VAL') {
|
||||
jwksUri = null;
|
||||
try {
|
||||
jwks = JSON.parse($('#jwks textarea').val());
|
||||
} catch (e) {
|
||||
console.log("An error occurred when parsing the JWK Set");
|
||||
|
||||
// Display an alert with an error message
|
||||
app.errorHandlerView.showErrorMessage($.t("client.client-form.error.jwk-set"), $.t("client.client-form.error.jwk-set-parse"));
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
jwksUri = null;
|
||||
jwks = null;
|
||||
}
|
||||
|
||||
var attrs = {
|
||||
client_name: $('#clientName input').val(),
|
||||
logo_uri: $('#logoUri input').val(),
|
||||
scope: scopes,
|
||||
client_secret: null, // never send a client secret
|
||||
tos_uri: $('#tosUri input').val(),
|
||||
policy_uri: $('#policyUri input').val(),
|
||||
client_uri: $('#clientUri input').val(),
|
||||
application_type: $('#applicationType input').filter(':checked').val(),
|
||||
jwks_uri: jwksUri,
|
||||
jwks: jwks,
|
||||
token_endpoint_auth_method: $('#tokenEndpointAuthMethod input').filter(':checked').val(),
|
||||
contacts: contacts,
|
||||
token_endpoint_auth_signing_alg: this.defaultToNull($('#tokenEndpointAuthSigningAlg select').val())
|
||||
};
|
||||
|
||||
// set all empty strings to nulls
|
||||
for ( var key in attrs) {
|
||||
if (attrs[key] === "") {
|
||||
attrs[key] = null;
|
||||
}
|
||||
}
|
||||
|
||||
var _self = this;
|
||||
this.model.save(attrs, {
|
||||
success: function() {
|
||||
// switch to an "edit" view
|
||||
app.navigate('dev/resource/edit', {
|
||||
trigger: true
|
||||
});
|
||||
_self.remove();
|
||||
|
||||
if (_self.model.get("jwks")) {
|
||||
_self.model.set({
|
||||
jwksType: "VAL"
|
||||
}, {
|
||||
silent: true
|
||||
});
|
||||
} else {
|
||||
_self.model.set({
|
||||
jwksType: "URI"
|
||||
}, {
|
||||
silent: true
|
||||
});
|
||||
}
|
||||
|
||||
var view = new ResRegEditView({
|
||||
model: _self.model,
|
||||
systemScopeList: _self.options.systemScopeList
|
||||
});
|
||||
|
||||
view.load(function() {
|
||||
// reload
|
||||
$('#content').html(view.render().el);
|
||||
view.delegateEvents();
|
||||
});
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
});
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
render: function() {
|
||||
$(this.el).html(this.template({
|
||||
client: this.model.toJSON(),
|
||||
userInfo: getUserInfo()
|
||||
}));
|
||||
|
||||
this.listWidgetViews = [];
|
||||
|
||||
var _self = this;
|
||||
|
||||
// build and bind scopes
|
||||
var scopes = this.model.get("scope");
|
||||
var scopeSet = scopes ? scopes.split(" ") : [];
|
||||
_.each(scopeSet, function (scope) {
|
||||
_self.scopeCollection.add(new Backbone.Model({item:scope}));
|
||||
});
|
||||
|
||||
var scopeView = new ListWidgetView({
|
||||
placeholder: $.t('client.client-form.scope-placeholder'),
|
||||
autocomplete: _.uniq(_.flatten(this.options.systemScopeList.unrestrictedScopes().pluck("value"))),
|
||||
helpBlockText: $.t('rsreg.client-form.scope-help'),
|
||||
collection: this.scopeCollection});
|
||||
$("#scope .controls",this.el).html(scopeView.render().el);
|
||||
this.listWidgetViews.push(scopeView);
|
||||
|
||||
// build and bind contacts
|
||||
_.each(this.model.get('contacts'), function (contact) {
|
||||
_self.contactsCollection.add(new Backbone.Model({item:contact}));
|
||||
});
|
||||
|
||||
var contactView = new ListWidgetView({
|
||||
placeholder: $.t('client.client-form.contacts-placeholder'),
|
||||
helpBlockText: $.t('client.client-form.contacts-help'),
|
||||
collection: this.contactsCollection});
|
||||
$("#contacts .controls", this.el).html(contactView.render().el);
|
||||
this.listWidgetViews.push(contactView);
|
||||
|
||||
|
||||
this.toggleClientCredentials();
|
||||
this.previewLogo();
|
||||
this.toggleJWKSetType();
|
||||
|
||||
// disable unsupported JOSE algorithms
|
||||
this.disableUnsupportedJOSEItems(app.serverConfiguration.token_endpoint_auth_signing_alg_values_supported, '#tokenEndpointAuthSigningAlg option');
|
||||
|
||||
this.$('.nyi').clickover({
|
||||
placement: 'right',
|
||||
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:
|
||||
function() {
|
||||
|
||||
this.breadCrumbView.collection.reset();
|
||||
this.breadCrumbView.collection.add([
|
||||
{text:$.t('admin.home'), href:""},
|
||||
{text:$.t('admin.self-service-resource'), href:"manage/#dev/resource"}
|
||||
]);
|
||||
|
||||
this.updateSidebar('dev/resource');
|
||||
|
||||
var view = new ResRegRootView({systemScopeList: this.systemScopeList});
|
||||
view.load(function() {
|
||||
$('#content').html(view.render().el);
|
||||
|
||||
setPageTitle($.t('admin.self-service-resource'));
|
||||
// build and bind scopes
|
||||
var scopes = this.model.get("scope");
|
||||
var scopeSet = scopes ? scopes.split(" ") : [];
|
||||
_.each(scopeSet, function(scope) {
|
||||
_self.scopeCollection.add(new Backbone.Model({
|
||||
item: scope
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
var scopeView = new ListWidgetView({
|
||||
placeholder: $.t('client.client-form.scope-placeholder'),
|
||||
autocomplete: _.uniq(_.flatten(this.options.systemScopeList.unrestrictedScopes().pluck("value"))),
|
||||
helpBlockText: $.t('rsreg.client-form.scope-help'),
|
||||
collection: this.scopeCollection
|
||||
});
|
||||
$("#scope .controls", this.el).html(scopeView.render().el);
|
||||
this.listWidgetViews.push(scopeView);
|
||||
|
||||
// build and bind contacts
|
||||
_.each(this.model.get('contacts'), function(contact) {
|
||||
_self.contactsCollection.add(new Backbone.Model({
|
||||
item: contact
|
||||
}));
|
||||
});
|
||||
|
||||
var contactView = new ListWidgetView({
|
||||
placeholder: $.t('client.client-form.contacts-placeholder'),
|
||||
helpBlockText: $.t('client.client-form.contacts-help'),
|
||||
collection: this.contactsCollection
|
||||
});
|
||||
$("#contacts .controls", this.el).html(contactView.render().el);
|
||||
this.listWidgetViews.push(contactView);
|
||||
|
||||
this.toggleClientCredentials();
|
||||
this.previewLogo();
|
||||
this.toggleJWKSetType();
|
||||
|
||||
// disable unsupported JOSE algorithms
|
||||
this.disableUnsupportedJOSEItems(app.serverConfiguration.token_endpoint_auth_signing_alg_values_supported, '#tokenEndpointAuthSigningAlg option');
|
||||
|
||||
this.$('.nyi').clickover({
|
||||
placement: 'right',
|
||||
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: function() {
|
||||
|
||||
this.breadCrumbView.collection.reset();
|
||||
this.breadCrumbView.collection.add([{
|
||||
text: $.t('admin.home'),
|
||||
href: ""
|
||||
}, {
|
||||
text: $.t('admin.self-service-resource'),
|
||||
href: "manage/#dev/resource"
|
||||
}]);
|
||||
|
||||
this.updateSidebar('dev/resource');
|
||||
|
||||
var view = new ResRegRootView({
|
||||
systemScopeList: this.systemScopeList
|
||||
});
|
||||
view.load(function() {
|
||||
$('#content').html(view.render().el);
|
||||
|
||||
setPageTitle($.t('admin.self-service-resource'));
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
ui.routes.push({path: "dev/resource/new", name: "newResReg", callback:
|
||||
function() {
|
||||
|
||||
ui.routes.push({
|
||||
path: "dev/resource/new",
|
||||
name: "newResReg",
|
||||
callback: function() {
|
||||
|
||||
this.breadCrumbView.collection.reset();
|
||||
this.breadCrumbView.collection.add([
|
||||
{text:$.t('admin.home'), href:""},
|
||||
{text:$.t('admin.self-service-resource'), href:"manage/#dev/resource"},
|
||||
{text:$.t('rsreg.new'), href:"manage/#dev/resource/new"}
|
||||
]);
|
||||
|
||||
this.updateSidebar('dev/resource');
|
||||
|
||||
this.breadCrumbView.collection.add([{
|
||||
text: $.t('admin.home'),
|
||||
href: ""
|
||||
}, {
|
||||
text: $.t('admin.self-service-resource'),
|
||||
href: "manage/#dev/resource"
|
||||
}, {
|
||||
text: $.t('rsreg.new'),
|
||||
href: "manage/#dev/resource/new"
|
||||
}]);
|
||||
|
||||
this.updateSidebar('dev/resource');
|
||||
|
||||
var client = new ResRegClient();
|
||||
var view = new ResRegEditView({model: client, systemScopeList:this.systemScopeList});
|
||||
|
||||
var view = new ResRegEditView({
|
||||
model: client,
|
||||
systemScopeList: this.systemScopeList
|
||||
});
|
||||
|
||||
view.load(function() {
|
||||
|
||||
|
||||
var userInfo = getUserInfo();
|
||||
var contacts = [];
|
||||
if (userInfo != null && userInfo.email != null) {
|
||||
contacts.push(userInfo.email);
|
||||
}
|
||||
|
||||
|
||||
client.set({
|
||||
scope: _.uniq(_.flatten(app.systemScopeList.defaultUnrestrictedScopes().pluck("value"))).join(" "),
|
||||
token_endpoint_auth_method: 'client_secret_basic',
|
||||
contacts: contacts
|
||||
}, { silent: true });
|
||||
|
||||
scope: _.uniq(_.flatten(app.systemScopeList.defaultUnrestrictedScopes().pluck("value"))).join(" "),
|
||||
token_endpoint_auth_method: 'client_secret_basic',
|
||||
contacts: contacts
|
||||
}, {
|
||||
silent: true
|
||||
});
|
||||
|
||||
$('#content').html(view.render().el);
|
||||
view.delegateEvents();
|
||||
setPageTitle($.t('rsreg.new'));
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
ui.routes.push({path: "dev/resource/edit", name: "editResReg", callback:
|
||||
function() {
|
||||
ui.routes.push({
|
||||
path: "dev/resource/edit",
|
||||
name: "editResReg",
|
||||
callback: function() {
|
||||
|
||||
this.breadCrumbView.collection.reset();
|
||||
this.breadCrumbView.collection.add([
|
||||
{text:$.t('admin.home'), href:""},
|
||||
{text:$.t('admin.self-service-resource'), href:"manage/#dev/resource"},
|
||||
{text:$.t('rsreg.edit'), href:"manage/#dev/resource/edit"}
|
||||
]);
|
||||
|
||||
this.updateSidebar('dev/resource');
|
||||
|
||||
this.breadCrumbView.collection.add([{
|
||||
text: $.t('admin.home'),
|
||||
href: ""
|
||||
}, {
|
||||
text: $.t('admin.self-service-resource'),
|
||||
href: "manage/#dev/resource"
|
||||
}, {
|
||||
text: $.t('rsreg.edit'),
|
||||
href: "manage/#dev/resource/edit"
|
||||
}]);
|
||||
|
||||
this.updateSidebar('dev/resource');
|
||||
|
||||
setPageTitle($.t('rsreg.edit'));
|
||||
// note that this doesn't actually load the client, that's supposed to happen elsewhere...
|
||||
// note that this doesn't actually load the client, that's supposed to
|
||||
// happen elsewhere...
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -17,23 +17,23 @@
|
|||
var SystemScopeModel = Backbone.Model.extend({
|
||||
idAttribute: 'id',
|
||||
|
||||
defaults:{
|
||||
id:null,
|
||||
description:null,
|
||||
icon:null,
|
||||
value:null,
|
||||
defaultScope:false,
|
||||
restricted:false
|
||||
defaults: {
|
||||
id: null,
|
||||
description: null,
|
||||
icon: null,
|
||||
value: null,
|
||||
defaultScope: false,
|
||||
restricted: false
|
||||
},
|
||||
|
||||
|
||||
urlRoot: 'api/scopes'
|
||||
});
|
||||
|
||||
var SystemScopeCollection = Backbone.Collection.extend({
|
||||
idAttribute: 'id',
|
||||
|
||||
|
||||
model: SystemScopeModel,
|
||||
|
||||
|
||||
url: 'api/scopes',
|
||||
|
||||
defaultScopes: function() {
|
||||
|
@ -42,149 +42,164 @@ var SystemScopeCollection = Backbone.Collection.extend({
|
|||
});
|
||||
return new SystemScopeCollection(filtered);
|
||||
},
|
||||
|
||||
|
||||
unrestrictedScopes: function() {
|
||||
filtered = this.filter(function(scope) {
|
||||
return scope.get("restricted") !== true;
|
||||
});
|
||||
return new SystemScopeCollection(filtered);
|
||||
},
|
||||
|
||||
|
||||
defaultUnrestrictedScopes: function() {
|
||||
filtered = this.filter(function(scope) {
|
||||
return scope.get("defaultScope") === true && scope.get("restricted") !== true;
|
||||
});
|
||||
return new SystemScopeCollection(filtered);
|
||||
},
|
||||
|
||||
|
||||
getByValue: function(value) {
|
||||
var scopes = this.where({value: value});
|
||||
var scopes = this.where({
|
||||
value: value
|
||||
});
|
||||
if (scopes.length == 1) {
|
||||
return scopes[0];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
var SystemScopeView = Backbone.View.extend({
|
||||
|
||||
|
||||
tagName: 'tr',
|
||||
|
||||
initialize:function (options) {
|
||||
this.options = options;
|
||||
|
||||
if (!this.template) {
|
||||
this.template = _.template($('#tmpl-system-scope').html());
|
||||
}
|
||||
initialize: function(options) {
|
||||
this.options = options;
|
||||
|
||||
if (!this.template) {
|
||||
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) {
|
||||
e.preventDefault();
|
||||
app.navigate('admin/scope/' + this.model.id, {trigger: true});
|
||||
|
||||
events: {
|
||||
'click .btn-edit': 'editScope',
|
||||
'click .btn-delete': 'deleteScope'
|
||||
},
|
||||
|
||||
render:function (eventName) {
|
||||
this.$el.html(this.template(this.model.toJSON()));
|
||||
|
||||
$('.restricted', this.el).tooltip({title: $.t('scope.system-scope-table.tooltip-restricted')});
|
||||
$('.default', this.el).tooltip({title: $.t('scope.system-scope-table.tooltip-default')});
|
||||
|
||||
$(this.el).i18n();
|
||||
return this;
|
||||
},
|
||||
|
||||
deleteScope:function (e) {
|
||||
e.preventDefault();
|
||||
editScope: function(e) {
|
||||
e.preventDefault();
|
||||
app.navigate('admin/scope/' + this.model.id, {
|
||||
trigger: true
|
||||
});
|
||||
},
|
||||
|
||||
if (confirm($.t("scope.system-scope-table.confirm"))) {
|
||||
var _self = this;
|
||||
render: function(eventName) {
|
||||
this.$el.html(this.template(this.model.toJSON()));
|
||||
|
||||
this.model.destroy({
|
||||
dataType: false, processData: false,
|
||||
success:function () {
|
||||
|
||||
_self.$el.fadeTo("fast", 0.00, function () { //fade
|
||||
$(this).slideUp("fast", function () { //slide up
|
||||
$(this).remove(); //then remove from the DOM
|
||||
_self.parentView.togglePlaceholder();
|
||||
});
|
||||
});
|
||||
},
|
||||
error:app.errorHandlerView.handleError()
|
||||
});
|
||||
$('.restricted', this.el).tooltip({
|
||||
title: $.t('scope.system-scope-table.tooltip-restricted')
|
||||
});
|
||||
$('.default', this.el).tooltip({
|
||||
title: $.t('scope.system-scope-table.tooltip-default')
|
||||
});
|
||||
|
||||
_self.parentView.delegateEvents();
|
||||
}
|
||||
$(this.el).i18n();
|
||||
return this;
|
||||
},
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
close:function () {
|
||||
$(this.el).unbind();
|
||||
$(this.el).empty();
|
||||
}
|
||||
deleteScope: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
if (confirm($.t("scope.system-scope-table.confirm"))) {
|
||||
var _self = this;
|
||||
|
||||
this.model.destroy({
|
||||
dataType: false,
|
||||
processData: false,
|
||||
success: function() {
|
||||
|
||||
_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()
|
||||
});
|
||||
|
||||
_self.parentView.delegateEvents();
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
close: function() {
|
||||
$(this.el).unbind();
|
||||
$(this.el).empty();
|
||||
}
|
||||
});
|
||||
|
||||
var SystemScopeListView = Backbone.View.extend({
|
||||
tagName: 'span',
|
||||
|
||||
initialize:function(options) {
|
||||
this.options = options;
|
||||
},
|
||||
|
||||
load:function(callback) {
|
||||
if (this.model.isFetched) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html(
|
||||
'<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> '
|
||||
);
|
||||
|
||||
$.when(this.model.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}, error:app.errorHandlerView.handleError()}))
|
||||
.done(function() {
|
||||
$('#loadingbox').sheet('hide');
|
||||
callback();
|
||||
});
|
||||
},
|
||||
|
||||
events:{
|
||||
"click .new-scope":"newScope",
|
||||
"click .refresh-table":"refreshTable"
|
||||
initialize: function(options) {
|
||||
this.options = options;
|
||||
},
|
||||
|
||||
newScope:function(e) {
|
||||
load: function(callback) {
|
||||
if (this.model.isFetched) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html('<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ');
|
||||
|
||||
$.when(this.model.fetchIfNeeded({
|
||||
success: function(e) {
|
||||
$('#loading-scopes').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
})).done(function() {
|
||||
$('#loadingbox').sheet('hide');
|
||||
callback();
|
||||
});
|
||||
},
|
||||
|
||||
events: {
|
||||
"click .new-scope": "newScope",
|
||||
"click .refresh-table": "refreshTable"
|
||||
},
|
||||
|
||||
newScope: function(e) {
|
||||
this.remove();
|
||||
app.navigate('admin/scope/new', {trigger: true});
|
||||
app.navigate('admin/scope/new', {
|
||||
trigger: true
|
||||
});
|
||||
},
|
||||
|
||||
refreshTable:function(e) {
|
||||
var _self = this;
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html(
|
||||
'<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> '
|
||||
);
|
||||
|
||||
$.when(this.model.fetch({success:function(e) {$('#loading-scopes').addClass('label-success');}, error:app.errorHandlerView.handleError()}))
|
||||
.done(function() {
|
||||
$('#loadingbox').sheet('hide');
|
||||
_self.render();
|
||||
});
|
||||
refreshTable: function(e) {
|
||||
var _self = this;
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html('<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ');
|
||||
|
||||
$.when(this.model.fetch({
|
||||
success: function(e) {
|
||||
$('#loading-scopes').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
})).done(function() {
|
||||
$('#loadingbox').sheet('hide');
|
||||
_self.render();
|
||||
});
|
||||
},
|
||||
|
||||
togglePlaceholder:function() {
|
||||
|
||||
togglePlaceholder: function() {
|
||||
if (this.model.length > 0) {
|
||||
$('#scope-table', this.el).show();
|
||||
$('#scope-table-empty', this.el).hide();
|
||||
|
@ -193,249 +208,271 @@ var SystemScopeListView = Backbone.View.extend({
|
|||
$('#scope-table-empty', this.el).show();
|
||||
}
|
||||
},
|
||||
|
||||
render: function (eventName) {
|
||||
|
||||
|
||||
render: function(eventName) {
|
||||
|
||||
// append and render the table structure
|
||||
$(this.el).html($('#tmpl-system-scope-table').html());
|
||||
|
||||
|
||||
var _self = this;
|
||||
|
||||
_.each(this.model.models, function (scope) {
|
||||
var view = new SystemScopeView({model: scope});
|
||||
|
||||
_.each(this.model.models, function(scope) {
|
||||
var view = new SystemScopeView({
|
||||
model: scope
|
||||
});
|
||||
view.parentView = _self;
|
||||
$("#scope-table", _self.el).append(view.render().el);
|
||||
}, this);
|
||||
|
||||
|
||||
this.togglePlaceholder();
|
||||
$(this.el).i18n();
|
||||
$(this.el).i18n();
|
||||
return this;
|
||||
}
|
||||
});
|
||||
|
||||
var SystemScopeFormView = Backbone.View.extend({
|
||||
tagName: 'span',
|
||||
|
||||
initialize:function(options) {
|
||||
this.options = options;
|
||||
if (!this.template) {
|
||||
this.template = _.template($('#tmpl-system-scope-form').html());
|
||||
}
|
||||
if (!this.iconTemplate) {
|
||||
this.iconTemplate = _.template($('#tmpl-system-scope-icon').html());
|
||||
}
|
||||
|
||||
// initialize our icon set into slices for the selector
|
||||
if (!this.bootstrapIcons) {
|
||||
this.bootstrapIcons = [];
|
||||
|
||||
var iconList = ['glass', 'music', 'search', 'envelope', 'heart', 'star', 'star-empty',
|
||||
'user', 'film', 'th-large', 'th', 'th-list', 'ok', 'remove', 'zoom-in',
|
||||
'zoom-out', 'off', 'signal', 'cog', 'trash', 'home', 'file', 'time', 'road',
|
||||
'download-alt', 'download', 'upload', 'inbox', 'play-circle', 'repeat',
|
||||
'refresh', 'list-alt', 'lock', 'flag', 'headphones', 'volume-off',
|
||||
'volume-down', 'volume-up', 'qrcode', 'barcode', 'tag', 'tags', 'book',
|
||||
'bookmark', 'print', 'camera', 'font', 'bold', 'italic', 'text-height',
|
||||
'text-width', 'align-left', 'align-center', 'align-right', 'align-justify',
|
||||
'list', 'indent-left', 'indent-right', 'facetime-video', 'picture', 'pencil',
|
||||
'map-marker', 'adjust', 'tint', 'edit', 'share', 'check', 'move', 'step-backward',
|
||||
'fast-backward', 'backward', 'play', 'pause', 'stop', 'forward', 'fast-forward',
|
||||
'step-forward', 'eject', 'chevron-left', 'chevron-right', 'plus-sign',
|
||||
'minus-sign', 'remove-sign', 'ok-sign', 'question-sign', 'info-sign',
|
||||
'screenshot', 'remove-circle', 'ok-circle', 'ban-circle', 'arrow-left',
|
||||
'arrow-right', 'arrow-up', 'arrow-down', 'share-alt', 'resize-full', 'resize-small',
|
||||
'plus', 'minus', 'asterisk', 'exclamation-sign', 'gift', 'leaf', 'fire',
|
||||
'eye-open', 'eye-close', 'warning-sign', 'plane', 'calendar', 'random',
|
||||
'comment', 'magnet', 'chevron-up', 'chevron-down', 'retweet', 'shopping-cart',
|
||||
'folder-close', 'folder-open', 'resize-vertical', 'resize-horizontal',
|
||||
'hdd', 'bullhorn', 'bell', 'certificate', 'thumbs-up', 'thumbs-down',
|
||||
'hand-right', 'hand-left', 'hand-up', 'hand-down', 'circle-arrow-right',
|
||||
'circle-arrow-left', 'circle-arrow-up', 'circle-arrow-down', 'globe',
|
||||
'wrench', 'tasks', 'filter', 'briefcase', 'fullscreen'];
|
||||
|
||||
var size = 3;
|
||||
while (iconList.length > 0) {
|
||||
this.bootstrapIcons.push(iconList.splice(0, size));
|
||||
}
|
||||
var SystemScopeFormView = Backbone.View
|
||||
.extend({
|
||||
tagName: 'span',
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
events:{
|
||||
'click .btn-save':'saveScope',
|
||||
'click .btn-cancel': function() {app.navigate('admin/scope', {trigger: true}); },
|
||||
'click .btn-icon':'selectIcon'
|
||||
},
|
||||
|
||||
load:function(callback) {
|
||||
if (this.model.isFetched) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html(
|
||||
'<span class="label" id="loading-scopes">' + $.t("common.scopes") + '</span> '
|
||||
);
|
||||
initialize: function(options) {
|
||||
this.options = options;
|
||||
if (!this.template) {
|
||||
this.template = _.template($('#tmpl-system-scope-form').html());
|
||||
}
|
||||
if (!this.iconTemplate) {
|
||||
this.iconTemplate = _.template($('#tmpl-system-scope-icon').html());
|
||||
}
|
||||
|
||||
$.when(this.model.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}, error:app.errorHandlerView.handleError()}))
|
||||
.done(function() {
|
||||
$('#loadingbox').sheet('hide');
|
||||
callback();
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
saveScope:function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var value = $('#value input').val();
|
||||
|
||||
if (value == null || value.trim() == "") {
|
||||
// error: can't have a blank scope
|
||||
return false;
|
||||
}
|
||||
|
||||
var valid = this.model.set({
|
||||
value:value,
|
||||
description:$('#description textarea').val(),
|
||||
icon:$('#iconDisplay input').val(),
|
||||
defaultScope:$('#defaultScope input').is(':checked'),
|
||||
restricted:$('#restricted input').is(':checked')
|
||||
});
|
||||
|
||||
if (valid) {
|
||||
|
||||
var _self = this;
|
||||
this.model.save({}, {
|
||||
success:function() {
|
||||
app.systemScopeList.add(_self.model);
|
||||
app.navigate('admin/scope', {trigger: true});
|
||||
// initialize our icon set into slices for the selector
|
||||
if (!this.bootstrapIcons) {
|
||||
this.bootstrapIcons = [];
|
||||
|
||||
var iconList = ['glass', 'music', 'search', 'envelope', 'heart', 'star', 'star-empty', 'user', 'film', 'th-large', 'th', 'th-list', 'ok', 'remove', 'zoom-in', 'zoom-out', 'off', 'signal', 'cog', 'trash', 'home', 'file', 'time', 'road', 'download-alt', 'download', 'upload', 'inbox', 'play-circle', 'repeat', 'refresh', 'list-alt', 'lock',
|
||||
'flag', 'headphones', 'volume-off', 'volume-down', 'volume-up', 'qrcode', 'barcode', 'tag', 'tags', 'book', 'bookmark', 'print', 'camera', 'font', 'bold', 'italic', 'text-height', 'text-width', 'align-left', 'align-center', 'align-right', 'align-justify', 'list', 'indent-left', 'indent-right', 'facetime-video', 'picture',
|
||||
'pencil', 'map-marker', 'adjust', 'tint', 'edit', 'share', 'check', 'move', 'step-backward', 'fast-backward', 'backward', 'play', 'pause', 'stop', 'forward', 'fast-forward', 'step-forward', 'eject', 'chevron-left', 'chevron-right', 'plus-sign', 'minus-sign', 'remove-sign', 'ok-sign', 'question-sign', 'info-sign', 'screenshot',
|
||||
'remove-circle', 'ok-circle', 'ban-circle', 'arrow-left', 'arrow-right', 'arrow-up', 'arrow-down', 'share-alt', 'resize-full', 'resize-small', 'plus', 'minus', 'asterisk', 'exclamation-sign', 'gift', 'leaf', 'fire', 'eye-open', 'eye-close', 'warning-sign', 'plane', 'calendar', 'random', 'comment', 'magnet', 'chevron-up',
|
||||
'chevron-down', 'retweet', 'shopping-cart', 'folder-close', 'folder-open', 'resize-vertical', 'resize-horizontal', 'hdd', 'bullhorn', 'bell', 'certificate', 'thumbs-up', 'thumbs-down', 'hand-right', 'hand-left', 'hand-up', 'hand-down', 'circle-arrow-right', 'circle-arrow-left', 'circle-arrow-up', 'circle-arrow-down', 'globe',
|
||||
'wrench', 'tasks', 'filter', 'briefcase', 'fullscreen'];
|
||||
|
||||
var size = 3;
|
||||
while (iconList.length > 0) {
|
||||
this.bootstrapIcons.push(iconList.splice(0, size));
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
events: {
|
||||
'click .btn-save': 'saveScope',
|
||||
'click .btn-cancel': function() {
|
||||
app.navigate('admin/scope', {
|
||||
trigger: true
|
||||
});
|
||||
},
|
||||
error:app.errorHandlerView.handleError()
|
||||
});
|
||||
}
|
||||
'click .btn-icon': 'selectIcon'
|
||||
},
|
||||
|
||||
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;
|
||||
}
|
||||
});
|
||||
load: function(callback) {
|
||||
if (this.model.isFetched) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html('<span class="label" id="loading-scopes">' + $.t("common.scopes") + '</span> ');
|
||||
|
||||
$.when(this.model.fetchIfNeeded({
|
||||
success: function(e) {
|
||||
$('#loading-scopes').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
})).done(function() {
|
||||
$('#loadingbox').sheet('hide');
|
||||
callback();
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
saveScope: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var value = $('#value input').val();
|
||||
|
||||
if (value == null || value.trim() == "") {
|
||||
// error: can't have a blank scope
|
||||
return false;
|
||||
}
|
||||
|
||||
var valid = this.model.set({
|
||||
value: value,
|
||||
description: $('#description textarea').val(),
|
||||
icon: $('#iconDisplay input').val(),
|
||||
defaultScope: $('#defaultScope input').is(':checked'),
|
||||
restricted: $('#restricted input').is(':checked')
|
||||
});
|
||||
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
||||
ui.routes.push({
|
||||
path: "admin/scope",
|
||||
name: "siteScope",
|
||||
callback: function() {
|
||||
|
||||
ui.routes.push({path: "admin/scope", name: "siteScope", callback:
|
||||
function() {
|
||||
|
||||
if (!isAdmin()) {
|
||||
this.root();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.breadCrumbView.collection.reset();
|
||||
this.breadCrumbView.collection.add([
|
||||
{text:$.t('admin.home'), href:""},
|
||||
{text:$.t('scope.manage'), href:"manage/#admin/scope"}
|
||||
]);
|
||||
|
||||
this.updateSidebar('admin/scope');
|
||||
|
||||
var view = new SystemScopeListView({model:this.systemScopeList});
|
||||
|
||||
this.breadCrumbView.collection.add([{
|
||||
text: $.t('admin.home'),
|
||||
href: ""
|
||||
}, {
|
||||
text: $.t('scope.manage'),
|
||||
href: "manage/#admin/scope"
|
||||
}]);
|
||||
|
||||
this.updateSidebar('admin/scope');
|
||||
|
||||
var view = new SystemScopeListView({
|
||||
model: this.systemScopeList
|
||||
});
|
||||
|
||||
view.load(function() {
|
||||
$('#content').html(view.render().el);
|
||||
view.delegateEvents();
|
||||
setPageTitle($.t('scope.manage'));
|
||||
setPageTitle($.t('scope.manage'));
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
ui.routes.push({path: "admin/scope/new", name:"newScope", callback:
|
||||
function() {
|
||||
|
||||
|
||||
ui.routes.push({
|
||||
path: "admin/scope/new",
|
||||
name: "newScope",
|
||||
callback: function() {
|
||||
|
||||
if (!isAdmin()) {
|
||||
this.root();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.breadCrumbView.collection.reset();
|
||||
this.breadCrumbView.collection.add([
|
||||
{text:$.t('admin.home'), href:""},
|
||||
{text:$.t('scope.manage'), href:"manage/#admin/scope"},
|
||||
{text:$.t('scope.system-scope-form.new'), href:"manage/#admin/scope/new"}
|
||||
]);
|
||||
|
||||
this.updateSidebar('admin/scope');
|
||||
|
||||
this.breadCrumbView.collection.add([{
|
||||
text: $.t('admin.home'),
|
||||
href: ""
|
||||
}, {
|
||||
text: $.t('scope.manage'),
|
||||
href: "manage/#admin/scope"
|
||||
}, {
|
||||
text: $.t('scope.system-scope-form.new'),
|
||||
href: "manage/#admin/scope/new"
|
||||
}]);
|
||||
|
||||
this.updateSidebar('admin/scope');
|
||||
|
||||
var scope = new SystemScopeModel();
|
||||
|
||||
var view = new SystemScopeFormView({model:scope});
|
||||
|
||||
var view = new SystemScopeFormView({
|
||||
model: scope
|
||||
});
|
||||
view.load(function() {
|
||||
$('#content').html(view.render().el);
|
||||
setPageTitle($.t('scope.system-scope-form.new'));
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
ui.routes.push({path: "admin/scope/:id", name: "editScope", callback:
|
||||
function(sid) {
|
||||
ui.routes.push({
|
||||
path: "admin/scope/:id",
|
||||
name: "editScope",
|
||||
callback: function(sid) {
|
||||
|
||||
if (!isAdmin()) {
|
||||
this.root();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.breadCrumbView.collection.reset();
|
||||
this.breadCrumbView.collection.add([
|
||||
{text:$.t('admin.home'), href:""},
|
||||
{text:$.t('scope.manage'), href:"manage/#admin/scope"},
|
||||
{text:$.t('scope.system-scope-form.edit'), href:"manage/#admin/scope/" + sid}
|
||||
]);
|
||||
|
||||
this.updateSidebar('admin/scope');
|
||||
|
||||
this.breadCrumbView.collection.add([{
|
||||
text: $.t('admin.home'),
|
||||
href: ""
|
||||
}, {
|
||||
text: $.t('scope.manage'),
|
||||
href: "manage/#admin/scope"
|
||||
}, {
|
||||
text: $.t('scope.system-scope-form.edit'),
|
||||
href: "manage/#admin/scope/" + sid
|
||||
}]);
|
||||
|
||||
this.updateSidebar('admin/scope');
|
||||
|
||||
var scope = this.systemScopeList.get(sid);
|
||||
if (!scope) {
|
||||
scope = new SystemScopeModel({id: sid});
|
||||
scope = new SystemScopeModel({
|
||||
id: sid
|
||||
});
|
||||
}
|
||||
|
||||
var view = new SystemScopeFormView({model:scope});
|
||||
|
||||
var view = new SystemScopeFormView({
|
||||
model: scope
|
||||
});
|
||||
view.load(function() {
|
||||
$('#content').html(view.render().el);
|
||||
setPageTitle($.t('scope.system-scope-form.new'));
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
ui.templates.push('resources/template/scope.html');
|
||||
|
||||
ui.init.push(function(app) {
|
||||
app.systemScopeList = new SystemScopeCollection();
|
||||
app.systemScopeList = new SystemScopeCollection();
|
||||
});
|
||||
|
|
|
@ -18,59 +18,59 @@
|
|||
var AccessTokenModel = Backbone.Model.extend({
|
||||
idAttribute: 'id',
|
||||
|
||||
defaults:{
|
||||
id:null,
|
||||
value:null,
|
||||
refreshTokenId:null,
|
||||
scopes:[],
|
||||
clientId:null,
|
||||
userId:null,
|
||||
expiration:null
|
||||
defaults: {
|
||||
id: null,
|
||||
value: null,
|
||||
refreshTokenId: null,
|
||||
scopes: [],
|
||||
clientId: null,
|
||||
userId: null,
|
||||
expiration: null
|
||||
},
|
||||
|
||||
|
||||
urlRoot: 'api/tokens/access'
|
||||
});
|
||||
|
||||
var AccessTokenCollection = Backbone.Collection.extend({
|
||||
idAttribute: 'id',
|
||||
|
||||
|
||||
model: AccessTokenModel,
|
||||
|
||||
|
||||
url: 'api/tokens/access'
|
||||
|
||||
|
||||
});
|
||||
|
||||
var AccessTokenView = Backbone.View.extend({
|
||||
|
||||
|
||||
tagName: 'tr',
|
||||
|
||||
initialize:function (options) {
|
||||
this.options = options;
|
||||
|
||||
if (!this.template) {
|
||||
this.template = _.template($('#tmpl-access-token').html());
|
||||
}
|
||||
initialize: function(options) {
|
||||
this.options = options;
|
||||
|
||||
if (!this.scopeTemplate) {
|
||||
this.scopeTemplate = _.template($('#tmpl-scope-list').html());
|
||||
}
|
||||
if (!this.template) {
|
||||
this.template = _.template($('#tmpl-access-token').html());
|
||||
}
|
||||
|
||||
if (!this.moreInfoTemplate) {
|
||||
this.moreInfoTemplate = _.template($('#tmpl-client-more-info-block').html());
|
||||
}
|
||||
if (!this.scopeTemplate) {
|
||||
this.scopeTemplate = _.template($('#tmpl-scope-list').html());
|
||||
}
|
||||
|
||||
this.model.bind('change', this.render, this);
|
||||
|
||||
},
|
||||
|
||||
events: {
|
||||
'click .btn-delete':'deleteToken',
|
||||
'click .token-substring':'showTokenValue',
|
||||
if (!this.moreInfoTemplate) {
|
||||
this.moreInfoTemplate = _.template($('#tmpl-client-more-info-block').html());
|
||||
}
|
||||
|
||||
this.model.bind('change', this.render, this);
|
||||
|
||||
},
|
||||
|
||||
events: {
|
||||
'click .btn-delete': 'deleteToken',
|
||||
'click .token-substring': 'showTokenValue',
|
||||
'click .toggleMoreInformation': 'toggleMoreInformation'
|
||||
},
|
||||
|
||||
render:function (eventName) {
|
||||
|
||||
|
||||
render: function(eventName) {
|
||||
|
||||
var expirationDate = this.model.get("expiration");
|
||||
|
||||
if (expirationDate == null) {
|
||||
|
@ -80,59 +80,70 @@ var AccessTokenView = Backbone.View.extend({
|
|||
} else {
|
||||
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));
|
||||
|
||||
// hide full value
|
||||
$('.token-full', this.el).hide();
|
||||
|
||||
$('.token-full', this.el).hide();
|
||||
|
||||
// show scopes
|
||||
$('.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()}));
|
||||
$('.scope-list', this.el).html(this.scopeTemplate({
|
||||
scopes: this.model.get('scopes'),
|
||||
systemScopes: this.options.systemScopeList
|
||||
}));
|
||||
|
||||
$(this.el).i18n();
|
||||
return this;
|
||||
},
|
||||
|
||||
deleteToken:function (e) {
|
||||
e.preventDefault();
|
||||
$('.client-more-info-block', this.el).html(this.moreInfoTemplate({
|
||||
client: this.options.client.toJSON()
|
||||
}));
|
||||
|
||||
if (confirm($.t("token.token-table.confirm"))) {
|
||||
|
||||
var _self = this;
|
||||
$(this.el).i18n();
|
||||
return this;
|
||||
},
|
||||
|
||||
this.model.destroy({
|
||||
dataType: false, processData: false,
|
||||
success:function () {
|
||||
|
||||
_self.$el.fadeTo("fast", 0.00, function () { //fade
|
||||
$(this).slideUp("fast", function () { //slide up
|
||||
$(this).remove(); //then remove from the DOM
|
||||
// refresh the table in case we removed an id token, too
|
||||
_self.parentView.refreshTable();
|
||||
});
|
||||
});
|
||||
},
|
||||
error:app.errorHandlerView.handleError()
|
||||
});
|
||||
deleteToken: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
this.parentView.delegateEvents();
|
||||
}
|
||||
if (confirm($.t("token.token-table.confirm"))) {
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
toggleMoreInformation:function(e) {
|
||||
var _self = this;
|
||||
|
||||
this.model.destroy({
|
||||
dataType: false,
|
||||
processData: false,
|
||||
success: function() {
|
||||
|
||||
_self.$el.fadeTo("fast", 0.00, function() { // fade
|
||||
$(this).slideUp("fast", function() { // slide up
|
||||
$(this).remove(); // then remove from the DOM
|
||||
// refresh the table in case we removed an id token,
|
||||
// too
|
||||
_self.parentView.refreshTable();
|
||||
});
|
||||
});
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
});
|
||||
|
||||
this.parentView.delegateEvents();
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
toggleMoreInformation: function(e) {
|
||||
e.preventDefault();
|
||||
if ($('.moreInformation', this.el).is(':visible')) {
|
||||
// hide it
|
||||
$('.moreInformation', this.el).hide('fast');
|
||||
$('.toggleMoreInformation i', this.el).attr('class', 'icon-chevron-right');
|
||||
$('.moreInformationContainer', this.el).removeClass('alert').removeClass('alert-info').addClass('muted');
|
||||
|
||||
|
||||
} else {
|
||||
// show it
|
||||
$('.moreInformation', this.el).show('fast');
|
||||
|
@ -141,73 +152,73 @@ var AccessTokenView = Backbone.View.extend({
|
|||
}
|
||||
},
|
||||
|
||||
close:function () {
|
||||
$(this.el).unbind();
|
||||
$(this.el).empty();
|
||||
},
|
||||
|
||||
showTokenValue:function (e) {
|
||||
e.preventDefault();
|
||||
$('.token-substring', this.el).hide();
|
||||
$('.token-full', this.el).show();
|
||||
}
|
||||
close: function() {
|
||||
$(this.el).unbind();
|
||||
$(this.el).empty();
|
||||
},
|
||||
|
||||
showTokenValue: function(e) {
|
||||
e.preventDefault();
|
||||
$('.token-substring', this.el).hide();
|
||||
$('.token-full', this.el).show();
|
||||
}
|
||||
});
|
||||
|
||||
var RefreshTokenModel = Backbone.Model.extend({
|
||||
idAttribute: 'id',
|
||||
|
||||
defaults:{
|
||||
id:null,
|
||||
value:null,
|
||||
scopes:[],
|
||||
clientId:null,
|
||||
userId:null,
|
||||
expiration:null
|
||||
defaults: {
|
||||
id: null,
|
||||
value: null,
|
||||
scopes: [],
|
||||
clientId: null,
|
||||
userId: null,
|
||||
expiration: null
|
||||
},
|
||||
|
||||
|
||||
urlRoot: 'api/tokens/refresh'
|
||||
});
|
||||
|
||||
var RefreshTokenCollection = Backbone.Collection.extend({
|
||||
idAttribute: 'id',
|
||||
|
||||
|
||||
model: RefreshTokenModel,
|
||||
|
||||
|
||||
url: 'api/tokens/refresh'
|
||||
|
||||
|
||||
});
|
||||
|
||||
var RefreshTokenView = Backbone.View.extend({
|
||||
|
||||
|
||||
tagName: 'tr',
|
||||
|
||||
initialize:function (options) {
|
||||
this.options = options;
|
||||
|
||||
if (!this.template) {
|
||||
this.template = _.template($('#tmpl-refresh-token').html());
|
||||
}
|
||||
initialize: function(options) {
|
||||
this.options = options;
|
||||
|
||||
if (!this.scopeTemplate) {
|
||||
this.scopeTemplate = _.template($('#tmpl-scope-list').html());
|
||||
}
|
||||
if (!this.template) {
|
||||
this.template = _.template($('#tmpl-refresh-token').html());
|
||||
}
|
||||
|
||||
if (!this.moreInfoTemplate) {
|
||||
this.moreInfoTemplate = _.template($('#tmpl-client-more-info-block').html());
|
||||
}
|
||||
if (!this.scopeTemplate) {
|
||||
this.scopeTemplate = _.template($('#tmpl-scope-list').html());
|
||||
}
|
||||
|
||||
this.model.bind('change', this.render, this);
|
||||
|
||||
},
|
||||
|
||||
events: {
|
||||
'click .btn-delete':'deleteToken',
|
||||
'click .token-substring':'showTokenValue',
|
||||
if (!this.moreInfoTemplate) {
|
||||
this.moreInfoTemplate = _.template($('#tmpl-client-more-info-block').html());
|
||||
}
|
||||
|
||||
this.model.bind('change', this.render, this);
|
||||
|
||||
},
|
||||
|
||||
events: {
|
||||
'click .btn-delete': 'deleteToken',
|
||||
'click .token-substring': 'showTokenValue',
|
||||
'click .toggleMoreInformation': 'toggleMoreInformation'
|
||||
},
|
||||
|
||||
render:function (eventName) {
|
||||
|
||||
|
||||
render: function(eventName) {
|
||||
|
||||
var expirationDate = this.model.get("expiration");
|
||||
|
||||
if (expirationDate == null) {
|
||||
|
@ -217,53 +228,65 @@ var RefreshTokenView = Backbone.View.extend({
|
|||
} else {
|
||||
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));
|
||||
|
||||
// hide full value
|
||||
$('.token-full', this.el).hide();
|
||||
|
||||
$('.token-full', this.el).hide();
|
||||
|
||||
// show scopes
|
||||
$('.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()}));
|
||||
|
||||
$(this.el).i18n();
|
||||
return this;
|
||||
$('.scope-list', this.el).html(this.scopeTemplate({
|
||||
scopes: this.model.get('scopes'),
|
||||
systemScopes: this.options.systemScopeList
|
||||
}));
|
||||
|
||||
},
|
||||
|
||||
deleteToken:function (e) {
|
||||
e.preventDefault();
|
||||
$('.client-more-info-block', this.el).html(this.moreInfoTemplate({
|
||||
client: this.options.client.toJSON()
|
||||
}));
|
||||
|
||||
if (confirm($.t('token.token-table.confirm-refresh'))) {
|
||||
|
||||
var _self = this;
|
||||
$(this.el).i18n();
|
||||
return this;
|
||||
|
||||
this.model.destroy({
|
||||
dataType: false, processData: false,
|
||||
success:function () {
|
||||
|
||||
_self.$el.fadeTo("fast", 0.00, function () { //fade
|
||||
$(this).slideUp("fast", function () { //slide up
|
||||
$(this).remove(); //then remove from the DOM
|
||||
// refresh the table in case the access tokens have changed, too
|
||||
_self.parentView.refreshTable();
|
||||
});
|
||||
});
|
||||
},
|
||||
error:app.errorHandlerView.handleError()
|
||||
});
|
||||
},
|
||||
|
||||
_self.parentView.delegateEvents();
|
||||
}
|
||||
deleteToken: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
toggleMoreInformation:function(e) {
|
||||
if (confirm($.t('token.token-table.confirm-refresh'))) {
|
||||
|
||||
var _self = this;
|
||||
|
||||
this.model.destroy({
|
||||
dataType: false,
|
||||
processData: false,
|
||||
success: function() {
|
||||
|
||||
_self.$el.fadeTo("fast", 0.00, function() { // fade
|
||||
$(this).slideUp("fast", function() { // slide up
|
||||
$(this).remove(); // then remove from the DOM
|
||||
// refresh the table in case the access tokens have
|
||||
// changed, too
|
||||
_self.parentView.refreshTable();
|
||||
});
|
||||
});
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
});
|
||||
|
||||
_self.parentView.delegateEvents();
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
toggleMoreInformation: function(e) {
|
||||
e.preventDefault();
|
||||
if ($('.moreInformation', this.el).is(':visible')) {
|
||||
// hide it
|
||||
|
@ -279,101 +302,128 @@ var RefreshTokenView = Backbone.View.extend({
|
|||
|
||||
},
|
||||
|
||||
close:function () {
|
||||
$(this.el).unbind();
|
||||
$(this.el).empty();
|
||||
},
|
||||
|
||||
showTokenValue:function (e) {
|
||||
e.preventDefault();
|
||||
$('.token-substring', this.el).hide();
|
||||
$('.token-full', this.el).show();
|
||||
}
|
||||
close: function() {
|
||||
$(this.el).unbind();
|
||||
$(this.el).empty();
|
||||
},
|
||||
|
||||
showTokenValue: function(e) {
|
||||
e.preventDefault();
|
||||
$('.token-substring', this.el).hide();
|
||||
$('.token-full', this.el).show();
|
||||
}
|
||||
});
|
||||
|
||||
var TokenListView = Backbone.View.extend({
|
||||
tagName: 'span',
|
||||
|
||||
initialize:function(options) {
|
||||
this.options = options;
|
||||
},
|
||||
|
||||
events:{
|
||||
"click .refresh-table":"refreshTable",
|
||||
'page .paginator-access':'changePageAccess',
|
||||
'page .paginator-refresh':'changePageRefresh'
|
||||
|
||||
initialize: function(options) {
|
||||
this.options = options;
|
||||
},
|
||||
|
||||
load:function(callback) {
|
||||
if (this.model.access.isFetched &&
|
||||
this.model.refresh.isFetched &&
|
||||
this.options.clientList.isFetched &&
|
||||
this.options.systemScopeList.isFetched) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
events: {
|
||||
"click .refresh-table": "refreshTable",
|
||||
'page .paginator-access': 'changePageAccess',
|
||||
'page .paginator-refresh': 'changePageRefresh'
|
||||
},
|
||||
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html(
|
||||
'<span class="label" id="loading-access">' + $.t('token.token-table.access-tokens') + '</span> ' +
|
||||
'<span class="label" id="loading-refresh">' + $.t('token.token-table.refresh-tokens') + '</span> ' +
|
||||
'<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' +
|
||||
'<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> '
|
||||
);
|
||||
load: function(callback) {
|
||||
if (this.model.access.isFetched && this.model.refresh.isFetched && this.options.clientList.isFetched && this.options.systemScopeList.isFetched) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
$.when(this.model.access.fetchIfNeeded({success:function(e) {$('#loading-access').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
|
||||
this.model.refresh.fetchIfNeeded({success:function(e) {$('#loading-refresh').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
|
||||
this.options.clientList.fetchIfNeeded({success:function(e) {$('#loading-clients').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
|
||||
this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}, error: app.errorHandlerView.handleError()}))
|
||||
.done(function() {
|
||||
$('#loadingbox').sheet('hide');
|
||||
callback();
|
||||
});
|
||||
|
||||
},
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html(
|
||||
'<span class="label" id="loading-access">' + $.t('token.token-table.access-tokens') + '</span> ' + '<span class="label" id="loading-refresh">' + $.t('token.token-table.refresh-tokens') + '</span> ' + '<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' + '<span class="label" id="loading-scopes">'
|
||||
+ $.t('common.scopes') + '</span> ');
|
||||
|
||||
changePageAccess:function(event, num) {
|
||||
$('.paginator-access', this.el).bootpag({page: num});
|
||||
$.when(this.model.access.fetchIfNeeded({
|
||||
success: function(e) {
|
||||
$('#loading-access').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
}), this.model.refresh.fetchIfNeeded({
|
||||
success: function(e) {
|
||||
$('#loading-refresh').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
}), this.options.clientList.fetchIfNeeded({
|
||||
success: function(e) {
|
||||
$('#loading-clients').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
}), this.options.systemScopeList.fetchIfNeeded({
|
||||
success: function(e) {
|
||||
$('#loading-scopes').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
})).done(function() {
|
||||
$('#loadingbox').sheet('hide');
|
||||
callback();
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
changePageAccess: function(event, num) {
|
||||
$('.paginator-access', this.el).bootpag({
|
||||
page: num
|
||||
});
|
||||
$('#access-token-table tbody tr', this.el).each(function(index, element) {
|
||||
if (Math.ceil((index + 1) / 10) != num) {
|
||||
$(element).hide();
|
||||
} else {
|
||||
$(element).show();
|
||||
}
|
||||
$(element).hide();
|
||||
} else {
|
||||
$(element).show();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
changePageRefresh:function(event, num) {
|
||||
$('.paginator-refresh', this.el).bootpag({page: num});
|
||||
|
||||
changePageRefresh: function(event, num) {
|
||||
$('.paginator-refresh', this.el).bootpag({
|
||||
page: num
|
||||
});
|
||||
$('#refresh-token-table tbody tr', this.el).each(function(index, element) {
|
||||
if (Math.ceil((index + 1) / 10) != num) {
|
||||
$(element).hide();
|
||||
} else {
|
||||
$(element).show();
|
||||
}
|
||||
$(element).hide();
|
||||
} else {
|
||||
$(element).show();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
refreshTable:function(e) {
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html(
|
||||
'<span class="label" id="loading-access">' + $.t('token.token-table.access-tokens') + '</span> ' +
|
||||
'<span class="label" id="loading-refresh">' + $.t('token.token-table.refresh-tokens') + '</span> ' +
|
||||
'<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' +
|
||||
'<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> '
|
||||
);
|
||||
var _self = this;
|
||||
$.when(this.model.access.fetch({success:function(e) {$('#loading-access').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
|
||||
this.model.refresh.fetch({success:function(e) {$('#loading-refresh').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
|
||||
this.options.clientList.fetch({success:function(e) {$('#loading-clients').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
|
||||
this.options.systemScopeList.fetch({success:function(e) {$('#loading-scopes').addClass('label-success');}, error: app.errorHandlerView.handleError()}))
|
||||
.done(function(){
|
||||
_self.render();
|
||||
$('#loadingbox').sheet('hide');
|
||||
});
|
||||
|
||||
refreshTable: function(e) {
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html(
|
||||
'<span class="label" id="loading-access">' + $.t('token.token-table.access-tokens') + '</span> ' + '<span class="label" id="loading-refresh">' + $.t('token.token-table.refresh-tokens') + '</span> ' + '<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' + '<span class="label" id="loading-scopes">'
|
||||
+ $.t('common.scopes') + '</span> ');
|
||||
var _self = this;
|
||||
$.when(this.model.access.fetch({
|
||||
success: function(e) {
|
||||
$('#loading-access').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
}), this.model.refresh.fetch({
|
||||
success: function(e) {
|
||||
$('#loading-refresh').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
}), this.options.clientList.fetch({
|
||||
success: function(e) {
|
||||
$('#loading-clients').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
}), this.options.systemScopeList.fetch({
|
||||
success: function(e) {
|
||||
$('#loading-scopes').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
})).done(function() {
|
||||
_self.render();
|
||||
$('#loadingbox').sheet('hide');
|
||||
});
|
||||
},
|
||||
|
||||
togglePlaceholder:function() {
|
||||
|
||||
togglePlaceholder: function() {
|
||||
if (this.model.access.length > 0) {
|
||||
$('#access-token-table', this.el).show();
|
||||
$('#access-token-table-empty', this.el).hide();
|
||||
|
@ -388,122 +438,140 @@ var TokenListView = Backbone.View.extend({
|
|||
$('#refresh-token-table', this.el).hide();
|
||||
$('#refresh-token-table-empty', this.el).show();
|
||||
}
|
||||
|
||||
|
||||
$('#access-token-count', this.el).html(this.model.access.length);
|
||||
$('#refresh-token-count', this.el).html(this.model.refresh.length);
|
||||
},
|
||||
|
||||
render: function (eventName) {
|
||||
|
||||
|
||||
render: function(eventName) {
|
||||
|
||||
// append and render the table structure
|
||||
$(this.el).html($('#tmpl-token-table').html());
|
||||
|
||||
var _self = this;
|
||||
|
||||
// set up pagination
|
||||
var numPagesAccess = Math.ceil(this.model.access.length / 10);
|
||||
if (numPagesAccess > 1) {
|
||||
$('.paginator-access', this.el).show();
|
||||
$('.paginator-access', this.el).bootpag({
|
||||
total: numPagesAccess,
|
||||
page: 1
|
||||
});
|
||||
} else {
|
||||
$('.paginator-access', this.el).hide();
|
||||
}
|
||||
|
||||
// count up refresh tokens
|
||||
var refreshCount = {};
|
||||
|
||||
_.each(this.model.access.models, function (token, index) {
|
||||
var _self = this;
|
||||
|
||||
// set up pagination
|
||||
var numPagesAccess = Math.ceil(this.model.access.length / 10);
|
||||
if (numPagesAccess > 1) {
|
||||
$('.paginator-access', this.el).show();
|
||||
$('.paginator-access', this.el).bootpag({
|
||||
total: numPagesAccess,
|
||||
page: 1
|
||||
});
|
||||
} else {
|
||||
$('.paginator-access', this.el).hide();
|
||||
}
|
||||
|
||||
// count up refresh tokens
|
||||
var refreshCount = {};
|
||||
|
||||
_.each(this.model.access.models, function(token, index) {
|
||||
// look up client
|
||||
var client = _self.options.clientList.getByClientId(token.get('clientId'));
|
||||
var view = new AccessTokenView({model: token, client: client, systemScopeList: _self.options.systemScopeList});
|
||||
var view = new AccessTokenView({
|
||||
model: token,
|
||||
client: client,
|
||||
systemScopeList: _self.options.systemScopeList
|
||||
});
|
||||
view.parentView = _self;
|
||||
var element = view.render().el;
|
||||
$('#access-token-table', _self.el).append(element);
|
||||
if (Math.ceil((index + 1) / 10) != 1) {
|
||||
$(element).hide();
|
||||
}
|
||||
|
||||
//console.log(token.get('refreshTokenId'));
|
||||
var refId = token.get('refreshTokenId');
|
||||
if (refId != null) {
|
||||
if (refreshCount[refId]) {
|
||||
refreshCount[refId] += 1;
|
||||
} else {
|
||||
refreshCount[refId] = 1;
|
||||
}
|
||||
|
||||
}
|
||||
if (Math.ceil((index + 1) / 10) != 1) {
|
||||
$(element).hide();
|
||||
}
|
||||
|
||||
// console.log(token.get('refreshTokenId'));
|
||||
var refId = token.get('refreshTokenId');
|
||||
if (refId != null) {
|
||||
if (refreshCount[refId]) {
|
||||
refreshCount[refId] += 1;
|
||||
} else {
|
||||
refreshCount[refId] = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
//console.log(refreshCount);
|
||||
|
||||
// set up pagination
|
||||
var numPagesRefresh = Math.ceil(this.model.refresh.length / 10);
|
||||
if (numPagesRefresh > 1) {
|
||||
$('.paginator-refresh', this.el).show();
|
||||
$('.paginator-refresh', this.el).bootpag({
|
||||
total: numPagesRefresh,
|
||||
page: 1
|
||||
});
|
||||
} else {
|
||||
$('.paginator-refresh', this.el).hide();
|
||||
}
|
||||
// console.log(refreshCount);
|
||||
|
||||
_.each(this.model.refresh.models, function (token, index) {
|
||||
// set up pagination
|
||||
var numPagesRefresh = Math.ceil(this.model.refresh.length / 10);
|
||||
if (numPagesRefresh > 1) {
|
||||
$('.paginator-refresh', this.el).show();
|
||||
$('.paginator-refresh', this.el).bootpag({
|
||||
total: numPagesRefresh,
|
||||
page: 1
|
||||
});
|
||||
} else {
|
||||
$('.paginator-refresh', this.el).hide();
|
||||
}
|
||||
|
||||
_.each(this.model.refresh.models, function(token, index) {
|
||||
// look up client
|
||||
var client = _self.options.clientList.getByClientId(token.get('clientId'));
|
||||
var view = new RefreshTokenView({model: token, client: client, systemScopeList: _self.options.systemScopeList, accessTokenCount: refreshCount[token.get('id')]});
|
||||
var view = new RefreshTokenView({
|
||||
model: token,
|
||||
client: client,
|
||||
systemScopeList: _self.options.systemScopeList,
|
||||
accessTokenCount: refreshCount[token.get('id')]
|
||||
});
|
||||
view.parentView = _self;
|
||||
var element = view.render().el;
|
||||
$('#refresh-token-table', _self.el).append(element);
|
||||
if (Math.ceil((index + 1) / 10) != 1) {
|
||||
$(element).hide();
|
||||
}
|
||||
if (Math.ceil((index + 1) / 10) != 1) {
|
||||
$(element).hide();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/*
|
||||
_.each(this.model.models, function (scope) {
|
||||
$("#scope-table", this.el).append(new SystemScopeView({model: scope}).render().el);
|
||||
}, this);
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* _.each(this.model.models, function (scope) { $("#scope-table",
|
||||
* this.el).append(new SystemScopeView({model: scope}).render().el); },
|
||||
* this);
|
||||
*/
|
||||
|
||||
this.togglePlaceholder();
|
||||
$(this.el).i18n();
|
||||
$(this.el).i18n();
|
||||
return this;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
ui.routes.push({path: "user/tokens", name: "tokens", callback:
|
||||
function() {
|
||||
ui.routes.push({
|
||||
path: "user/tokens",
|
||||
name: "tokens",
|
||||
callback: function() {
|
||||
this.breadCrumbView.collection.reset();
|
||||
this.breadCrumbView.collection.add([
|
||||
{text:$.t('admin.home'), href:""},
|
||||
{text:$.t('token.manage'), href:"manage/#user/tokens"}
|
||||
]);
|
||||
|
||||
this.updateSidebar('user/tokens');
|
||||
|
||||
var view = new TokenListView({model: {access: this.accessTokensList, refresh: this.refreshTokensList}, clientList: this.clientList, systemScopeList: this.systemScopeList});
|
||||
|
||||
view.load(
|
||||
function(collection, response, options) {
|
||||
$('#content').html(view.render().el);
|
||||
setPageTitle($.t('token.manage'));
|
||||
}
|
||||
);
|
||||
|
||||
this.breadCrumbView.collection.add([{
|
||||
text: $.t('admin.home'),
|
||||
href: ""
|
||||
}, {
|
||||
text: $.t('token.manage'),
|
||||
href: "manage/#user/tokens"
|
||||
}]);
|
||||
|
||||
this.updateSidebar('user/tokens');
|
||||
|
||||
var view = new TokenListView({
|
||||
model: {
|
||||
access: this.accessTokensList,
|
||||
refresh: this.refreshTokensList
|
||||
},
|
||||
clientList: this.clientList,
|
||||
systemScopeList: this.systemScopeList
|
||||
});
|
||||
|
||||
view.load(function(collection, response, options) {
|
||||
$('#content').html(view.render().el);
|
||||
setPageTitle($.t('token.manage'));
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
ui.templates.push('resources/template/token.html');
|
||||
|
||||
ui.init.push(function(app) {
|
||||
app.accessTokensList = new AccessTokenCollection();
|
||||
app.refreshTokensList = new RefreshTokenCollection();
|
||||
app.accessTokensList = new AccessTokenCollection();
|
||||
app.refreshTokensList = new RefreshTokenCollection();
|
||||
});
|
||||
|
|
|
@ -15,94 +15,107 @@
|
|||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
var WhiteListModel = Backbone.Model.extend({
|
||||
|
||||
|
||||
idAttribute: "id",
|
||||
|
||||
initialize: function () { },
|
||||
|
||||
|
||||
initialize: function() {
|
||||
},
|
||||
|
||||
urlRoot: "api/whitelist"
|
||||
|
||||
|
||||
});
|
||||
|
||||
var WhiteListCollection = Backbone.Collection.extend({
|
||||
initialize: function() {
|
||||
//this.fetch();
|
||||
// this.fetch();
|
||||
},
|
||||
|
||||
getByClientId: function(clientId) {
|
||||
var clients = this.where({clientId: clientId});
|
||||
|
||||
getByClientId: function(clientId) {
|
||||
var clients = this.where({
|
||||
clientId: clientId
|
||||
});
|
||||
if (clients.length == 1) {
|
||||
return clients[0];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
model: WhiteListModel,
|
||||
url: "api/whitelist"
|
||||
|
||||
|
||||
});
|
||||
|
||||
var WhiteListListView = Backbone.View.extend({
|
||||
tagName: 'span',
|
||||
|
||||
initialize:function (options) {
|
||||
this.options = options;
|
||||
|
||||
initialize: function(options) {
|
||||
this.options = options;
|
||||
},
|
||||
|
||||
load:function(callback) {
|
||||
if (this.model.isFetched &&
|
||||
this.options.clientList.isFetched &&
|
||||
this.options.systemScopeList.isFetched) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
load: function(callback) {
|
||||
if (this.model.isFetched && this.options.clientList.isFetched && this.options.systemScopeList.isFetched) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html(
|
||||
'<span class="label" id="loading-whitelist">' + $.t('whitelist.whitelist') + '</span> ' +
|
||||
'<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' +
|
||||
'<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> '
|
||||
);
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html('<span class="label" id="loading-whitelist">' + $.t('whitelist.whitelist') + '</span> ' + '<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' + '<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ');
|
||||
|
||||
$.when(this.model.fetchIfNeeded({success:function(e) {$('#loading-whitelist').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
|
||||
this.options.clientList.fetchIfNeeded({success:function(e) {$('#loading-clients').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
|
||||
this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}, error: app.errorHandlerView.handleError()}))
|
||||
.done(function() {
|
||||
$('#loadingbox').sheet('hide');
|
||||
callback();
|
||||
});
|
||||
},
|
||||
|
||||
events:{
|
||||
"click .refresh-table":"refreshTable"
|
||||
$.when(this.model.fetchIfNeeded({
|
||||
success: function(e) {
|
||||
$('#loading-whitelist').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
}), this.options.clientList.fetchIfNeeded({
|
||||
success: function(e) {
|
||||
$('#loading-clients').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
}), this.options.systemScopeList.fetchIfNeeded({
|
||||
success: function(e) {
|
||||
$('#loading-scopes').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
})).done(function() {
|
||||
$('#loadingbox').sheet('hide');
|
||||
callback();
|
||||
});
|
||||
},
|
||||
|
||||
render:function (eventName) {
|
||||
|
||||
events: {
|
||||
"click .refresh-table": "refreshTable"
|
||||
},
|
||||
|
||||
render: function(eventName) {
|
||||
$(this.el).html($('#tmpl-whitelist-table').html());
|
||||
|
||||
|
||||
var _self = this;
|
||||
|
||||
_.each(this.model.models, function (whiteList) {
|
||||
|
||||
|
||||
_.each(this.model.models, function(whiteList) {
|
||||
|
||||
// look up client
|
||||
var client = _self.options.clientList.getByClientId(whiteList.get('clientId'));
|
||||
|
||||
|
||||
// if there's no client ID, this is an error!
|
||||
if (client != null) {
|
||||
var view = new WhiteListView({model: whiteList, client: client, systemScopeList: _self.options.systemScopeList});
|
||||
var view = new WhiteListView({
|
||||
model: whiteList,
|
||||
client: client,
|
||||
systemScopeList: _self.options.systemScopeList
|
||||
});
|
||||
view.parentView = _self;
|
||||
$('#whitelist-table', _self.el).append(view.render().el);
|
||||
}
|
||||
|
||||
|
||||
}, this);
|
||||
|
||||
this.togglePlaceholder();
|
||||
$(this.el).i18n();
|
||||
$(this.el).i18n();
|
||||
return this;
|
||||
},
|
||||
|
||||
togglePlaceholder:function() {
|
||||
togglePlaceholder: function() {
|
||||
if (this.model.length > 0) {
|
||||
$('#whitelist-table', this.el).show();
|
||||
$('#whitelist-table-empty', this.el).hide();
|
||||
|
@ -111,108 +124,129 @@ var WhiteListListView = Backbone.View.extend({
|
|||
$('#whitelist-table-empty', this.el).show();
|
||||
}
|
||||
},
|
||||
|
||||
refreshTable:function(e) {
|
||||
e.preventDefault();
|
||||
var _self = this;
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html(
|
||||
'<span class="label" id="loading-whitelist">' + $.t('whitelist.whitelist') + '</span> ' +
|
||||
'<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' +
|
||||
'<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> '
|
||||
);
|
||||
|
||||
$.when(this.model.fetch({success:function(e) {$('#loading-whitelist').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
|
||||
this.options.clientList.fetch({success:function(e) {$('#loading-clients').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
|
||||
this.options.systemScopeList.fetch({success:function(e) {$('#loading-scopes').addClass('label-success');}, error: app.errorHandlerView.handleError()}))
|
||||
.done(function() {
|
||||
$('#loadingbox').sheet('hide');
|
||||
_self.render();
|
||||
});
|
||||
}
|
||||
refreshTable: function(e) {
|
||||
e.preventDefault();
|
||||
var _self = this;
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html('<span class="label" id="loading-whitelist">' + $.t('whitelist.whitelist') + '</span> ' + '<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' + '<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ');
|
||||
|
||||
$.when(this.model.fetch({
|
||||
success: function(e) {
|
||||
$('#loading-whitelist').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
}), this.options.clientList.fetch({
|
||||
success: function(e) {
|
||||
$('#loading-clients').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
}), this.options.systemScopeList.fetch({
|
||||
success: function(e) {
|
||||
$('#loading-scopes').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
})).done(function() {
|
||||
$('#loadingbox').sheet('hide');
|
||||
_self.render();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
var WhiteListView = Backbone.View.extend({
|
||||
tagName: 'tr',
|
||||
|
||||
initialize:function(options) {
|
||||
this.options = options;
|
||||
|
||||
initialize: function(options) {
|
||||
this.options = options;
|
||||
if (!this.template) {
|
||||
this.template = _.template($('#tmpl-whitelist').html());
|
||||
}
|
||||
|
||||
if (!this.scopeTemplate) {
|
||||
this.scopeTemplate = _.template($('#tmpl-scope-list').html());
|
||||
}
|
||||
|
||||
if (!this.moreInfoTemplate) {
|
||||
this.moreInfoTemplate = _.template($('#tmpl-client-more-info-block').html());
|
||||
}
|
||||
if (!this.scopeTemplate) {
|
||||
this.scopeTemplate = _.template($('#tmpl-scope-list').html());
|
||||
}
|
||||
|
||||
if (!this.moreInfoTemplate) {
|
||||
this.moreInfoTemplate = _.template($('#tmpl-client-more-info-block').html());
|
||||
}
|
||||
|
||||
this.model.bind('change', this.render, this);
|
||||
},
|
||||
|
||||
render:function(eventName) {
|
||||
|
||||
var json = {whiteList: this.model.toJSON(), client: this.options.client.toJSON()};
|
||||
|
||||
|
||||
render: function(eventName) {
|
||||
|
||||
var json = {
|
||||
whiteList: this.model.toJSON(),
|
||||
client: this.options.client.toJSON()
|
||||
};
|
||||
|
||||
this.$el.html(this.template(json));
|
||||
|
||||
$('.scope-list', this.el).html(this.scopeTemplate({scopes: this.model.get('allowedScopes'), systemScopes: this.options.systemScopeList}));
|
||||
|
||||
$('.client-more-info-block', this.el).html(this.moreInfoTemplate({client: this.options.client.toJSON()}));
|
||||
|
||||
this.$('.dynamically-registered').tooltip({title: $.t('common.dynamically-registered')});
|
||||
$('.scope-list', this.el).html(this.scopeTemplate({
|
||||
scopes: this.model.get('allowedScopes'),
|
||||
systemScopes: this.options.systemScopeList
|
||||
}));
|
||||
|
||||
$(this.el).i18n();
|
||||
return this;
|
||||
$('.client-more-info-block', this.el).html(this.moreInfoTemplate({
|
||||
client: this.options.client.toJSON()
|
||||
}));
|
||||
|
||||
this.$('.dynamically-registered').tooltip({
|
||||
title: $.t('common.dynamically-registered')
|
||||
});
|
||||
|
||||
$(this.el).i18n();
|
||||
return this;
|
||||
},
|
||||
|
||||
events:{
|
||||
|
||||
events: {
|
||||
'click .btn-edit': 'editWhitelist',
|
||||
'click .btn-delete': 'deleteWhitelist',
|
||||
'click .toggleMoreInformation': 'toggleMoreInformation'
|
||||
},
|
||||
|
||||
editWhitelist:function(e) {
|
||||
e.preventDefault();
|
||||
app.navigate('admin/whitelist/' + this.model.get('id'), {trigger: true});
|
||||
|
||||
editWhitelist: function(e) {
|
||||
e.preventDefault();
|
||||
app.navigate('admin/whitelist/' + this.model.get('id'), {
|
||||
trigger: true
|
||||
});
|
||||
},
|
||||
|
||||
deleteWhitelist:function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
|
||||
deleteWhitelist: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
if (confirm($.t('whitelist.confirm'))) {
|
||||
var _self = this;
|
||||
|
||||
this.model.destroy({
|
||||
dataType: false, processData: false,
|
||||
success:function () {
|
||||
_self.$el.fadeTo("fast", 0.00, function () { //fade
|
||||
$(this).slideUp("fast", function () { //slide up
|
||||
$(this).remove(); //then remove from the DOM
|
||||
// check the placeholder in case it's empty now
|
||||
_self.parentView.togglePlaceholder();
|
||||
});
|
||||
});
|
||||
},
|
||||
error:app.errorHandlerView.handleError()
|
||||
});
|
||||
|
||||
_self.parentView.delegateEvents();
|
||||
|
||||
this.model.destroy({
|
||||
dataType: false,
|
||||
processData: false,
|
||||
success: function() {
|
||||
_self.$el.fadeTo("fast", 0.00, function() { // fade
|
||||
$(this).slideUp("fast", function() { // slide up
|
||||
$(this).remove(); // then remove from the DOM
|
||||
// check the placeholder in case it's empty now
|
||||
_self.parentView.togglePlaceholder();
|
||||
});
|
||||
});
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
});
|
||||
|
||||
_self.parentView.delegateEvents();
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
toggleMoreInformation:function(e) {
|
||||
|
||||
toggleMoreInformation: function(e) {
|
||||
e.preventDefault();
|
||||
if ($('.moreInformation', this.el).is(':visible')) {
|
||||
// hide it
|
||||
$('.moreInformation', this.el).hide('fast');
|
||||
$('.toggleMoreInformation i', this.el).attr('class', 'icon-chevron-right');
|
||||
$('.moreInformationContainer', this.el).removeClass('alert').removeClass('alert-info').addClass('muted');
|
||||
|
||||
|
||||
} else {
|
||||
// show it
|
||||
$('.moreInformation', this.el).show('fast');
|
||||
|
@ -221,7 +255,7 @@ var WhiteListView = Backbone.View.extend({
|
|||
}
|
||||
},
|
||||
|
||||
close:function() {
|
||||
close: function() {
|
||||
$(this.el).unbind();
|
||||
$(this.el).empty();
|
||||
}
|
||||
|
@ -229,278 +263,333 @@ var WhiteListView = Backbone.View.extend({
|
|||
|
||||
var WhiteListFormView = Backbone.View.extend({
|
||||
tagName: 'span',
|
||||
|
||||
initialize:function (options) {
|
||||
this.options = options;
|
||||
|
||||
initialize: function(options) {
|
||||
this.options = options;
|
||||
if (!this.template) {
|
||||
this.template = _.template($('#tmpl-whitelist-form').html());
|
||||
}
|
||||
|
||||
|
||||
this.scopeCollection = new Backbone.Collection();
|
||||
|
||||
this.listWidgetViews = [];
|
||||
|
||||
|
||||
},
|
||||
|
||||
load:function(callback) {
|
||||
load: function(callback) {
|
||||
|
||||
if (this.options.client) {
|
||||
// we know what client we're dealing with already
|
||||
if (this.model.isFetched &&
|
||||
this.options.client.isFetched) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html(
|
||||
'<span class="label" id="loading-whitelist">' + $.t('whitelist.whitelist') + '</span> ' +
|
||||
'<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' +
|
||||
'<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> '
|
||||
);
|
||||
if (this.model.isFetched && this.options.client.isFetched) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html('<span class="label" id="loading-whitelist">' + $.t('whitelist.whitelist') + '</span> ' + '<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' + '<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ');
|
||||
|
||||
$.when(this.model.fetchIfNeeded({
|
||||
success: function(e) {
|
||||
$('#loading-whitelist').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
}), this.options.client.fetchIfNeeded({
|
||||
success: function(e) {
|
||||
$('#loading-clients').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
}), this.options.systemScopeList.fetchIfNeeded({
|
||||
success: function(e) {
|
||||
$('#loading-scopes').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
})).done(function() {
|
||||
$('#loadingbox').sheet('hide');
|
||||
callback();
|
||||
});
|
||||
|
||||
$.when(this.model.fetchIfNeeded({success:function(e) {$('#loading-whitelist').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
|
||||
this.options.client.fetchIfNeeded({success:function(e) {$('#loading-clients').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
|
||||
this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}, error: app.errorHandlerView.handleError()}))
|
||||
.done(function() {
|
||||
$('#loadingbox').sheet('hide');
|
||||
callback();
|
||||
});
|
||||
|
||||
} else {
|
||||
// we need to get the client information from the list
|
||||
|
||||
if (this.model.isFetched &&
|
||||
this.options.clientList.isFetched &&
|
||||
this.options.systemScopeList.isFetched) {
|
||||
|
||||
|
||||
if (this.model.isFetched && this.options.clientList.isFetched && this.options.systemScopeList.isFetched) {
|
||||
|
||||
var client = this.options.clientList.getByClientId(this.model.get('clientId'));
|
||||
this.options.client = client;
|
||||
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html(
|
||||
'<span class="label" id="loading-whitelist">' + $.t('whitelist.whitelist') + '</span> ' +
|
||||
'<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' +
|
||||
'<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> '
|
||||
);
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
$('#loadingbox').sheet('show');
|
||||
$('#loading').html('<span class="label" id="loading-whitelist">' + $.t('whitelist.whitelist') + '</span> ' + '<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' + '<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> ');
|
||||
|
||||
var _self = this;
|
||||
|
||||
$.when(this.model.fetchIfNeeded({
|
||||
success: function(e) {
|
||||
$('#loading-whitelist').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
}), this.options.clientList.fetchIfNeeded({
|
||||
success: function(e) {
|
||||
$('#loading-clients').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
}), this.options.systemScopeList.fetchIfNeeded({
|
||||
success: function(e) {
|
||||
$('#loading-scopes').addClass('label-success');
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
})).done(function() {
|
||||
|
||||
var client = _self.options.clientList.getByClientId(_self.model.get('clientId'));
|
||||
_self.options.client = client;
|
||||
|
||||
$('#loadingbox').sheet('hide');
|
||||
callback();
|
||||
});
|
||||
|
||||
var _self = this;
|
||||
|
||||
$.when(this.model.fetchIfNeeded({success:function(e) {$('#loading-whitelist').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
|
||||
this.options.clientList.fetchIfNeeded({success:function(e) {$('#loading-clients').addClass('label-success');}, error: app.errorHandlerView.handleError()}),
|
||||
this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}, error: app.errorHandlerView.handleError()}))
|
||||
.done(function() {
|
||||
|
||||
var client = _self.options.clientList.getByClientId(_self.model.get('clientId'));
|
||||
_self.options.client = client;
|
||||
|
||||
$('#loadingbox').sheet('hide');
|
||||
callback();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
},
|
||||
|
||||
events:{
|
||||
'click .btn-save':'saveWhiteList',
|
||||
'click .btn-cancel':'cancelWhiteList',
|
||||
|
||||
|
||||
events: {
|
||||
'click .btn-save': 'saveWhiteList',
|
||||
'click .btn-cancel': 'cancelWhiteList',
|
||||
|
||||
},
|
||||
|
||||
saveWhiteList:function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
saveWhiteList: function(e) {
|
||||
e.preventDefault();
|
||||
$('.control-group').removeClass('error');
|
||||
|
||||
// sync any leftover collection items
|
||||
_.each(this.listWidgetViews, function(v) {
|
||||
v.addItem($.Event('click'));
|
||||
});
|
||||
|
||||
|
||||
// sync any leftover collection items
|
||||
_.each(this.listWidgetViews, function(v) {
|
||||
v.addItem($.Event('click'));
|
||||
});
|
||||
|
||||
// process allowed scopes
|
||||
var allowedScopes = this.scopeCollection.pluck("item");
|
||||
|
||||
this.model.set({clientId: this.options.client.get('clientId')}, {silent: true});
|
||||
|
||||
var allowedScopes = this.scopeCollection.pluck("item");
|
||||
|
||||
this.model.set({
|
||||
clientId: this.options.client.get('clientId')
|
||||
}, {
|
||||
silent: true
|
||||
});
|
||||
|
||||
var valid = this.model.set({
|
||||
allowedScopes: allowedScopes
|
||||
});
|
||||
|
||||
if (valid) {
|
||||
var _self = this;
|
||||
this.model.save({}, {
|
||||
success:function () {
|
||||
app.whiteListList.add(_self.model);
|
||||
app.navigate('admin/whitelists', {trigger:true});
|
||||
},
|
||||
error:app.errorHandlerView.handleError()
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
if (valid) {
|
||||
var _self = this;
|
||||
this.model.save({}, {
|
||||
success: function() {
|
||||
app.whiteListList.add(_self.model);
|
||||
app.navigate('admin/whitelists', {
|
||||
trigger: true
|
||||
});
|
||||
},
|
||||
error: app.errorHandlerView.handleError()
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
},
|
||||
|
||||
cancelWhiteList:function(e) {
|
||||
e.preventDefault();
|
||||
// TODO: figure out where we came from and go back there instead
|
||||
if (this.model.get('id') == null) {
|
||||
// if it's a new whitelist entry, go back to the client listing page
|
||||
app.navigate('admin/clients', {trigger:true});
|
||||
} else {
|
||||
// if we're editing a whitelist, go back to the whitelists page
|
||||
app.navigate('admin/whitelists', {trigger:true});
|
||||
}
|
||||
|
||||
cancelWhiteList: function(e) {
|
||||
e.preventDefault();
|
||||
// TODO: figure out where we came from and go back there instead
|
||||
if (this.model.get('id') == null) {
|
||||
// if it's a new whitelist entry, go back to the client listing page
|
||||
app.navigate('admin/clients', {
|
||||
trigger: true
|
||||
});
|
||||
} else {
|
||||
// if we're editing a whitelist, go back to the whitelists page
|
||||
app.navigate('admin/whitelists', {
|
||||
trigger: true
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
render:function (eventName) {
|
||||
|
||||
var json = {whiteList: this.model.toJSON(), client: this.options.client.toJSON()};
|
||||
|
||||
|
||||
render: function(eventName) {
|
||||
|
||||
var json = {
|
||||
whiteList: this.model.toJSON(),
|
||||
client: this.options.client.toJSON()
|
||||
};
|
||||
|
||||
this.$el.html(this.template(json));
|
||||
|
||||
this.listWidgetViews = [];
|
||||
|
||||
var _self = this;
|
||||
// build and bind scopes
|
||||
_.each(this.model.get("allowedScopes"), function (scope) {
|
||||
_self.scopeCollection.add(new Backbone.Model({item:scope}));
|
||||
});
|
||||
|
||||
var scopeView = new ListWidgetView({
|
||||
placeholder: $.t('whitelist.whitelist-form.scope-placeholder'),
|
||||
autocomplete: this.options.client.get("scope"),
|
||||
helpBlockText: $.t('whitelist.whitelist-form.scope-help'),
|
||||
collection: this.scopeCollection});
|
||||
$("#scope .controls",this.el).html(scopeView.render().el);
|
||||
this.listWidgetViews.push(scopeView);
|
||||
|
||||
$(this.el).i18n();
|
||||
this.listWidgetViews = [];
|
||||
|
||||
var _self = this;
|
||||
// build and bind scopes
|
||||
_.each(this.model.get("allowedScopes"), function(scope) {
|
||||
_self.scopeCollection.add(new Backbone.Model({
|
||||
item: scope
|
||||
}));
|
||||
});
|
||||
|
||||
var scopeView = new ListWidgetView({
|
||||
placeholder: $.t('whitelist.whitelist-form.scope-placeholder'),
|
||||
autocomplete: this.options.client.get("scope"),
|
||||
helpBlockText: $.t('whitelist.whitelist-form.scope-help'),
|
||||
collection: this.scopeCollection
|
||||
});
|
||||
$("#scope .controls", this.el).html(scopeView.render().el);
|
||||
this.listWidgetViews.push(scopeView);
|
||||
|
||||
$(this.el).i18n();
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
ui.routes.push({path: "admin/whitelists", name: "whiteList", callback:
|
||||
function () {
|
||||
ui.routes.push({
|
||||
path: "admin/whitelists",
|
||||
name: "whiteList",
|
||||
callback: function() {
|
||||
|
||||
if (!isAdmin()) {
|
||||
this.root();
|
||||
return;
|
||||
}
|
||||
|
||||
this.updateSidebar('admin/whitelists');
|
||||
|
||||
this.breadCrumbView.collection.reset();
|
||||
this.breadCrumbView.collection.add([
|
||||
{text:$.t('admin.home'), href:""},
|
||||
{text:$.t('whitelist.manage'), href:"manage/#admin/whitelists"}
|
||||
]);
|
||||
|
||||
var view = new WhiteListListView({model:this.whiteListList, clientList: this.clientList, systemScopeList: this.systemScopeList});
|
||||
|
||||
view.load(
|
||||
function() {
|
||||
$('#content').html(view.render().el);
|
||||
view.delegateEvents();
|
||||
setPageTitle($.t('whitelist.manage'));
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
this.updateSidebar('admin/whitelists');
|
||||
|
||||
this.breadCrumbView.collection.reset();
|
||||
this.breadCrumbView.collection.add([{
|
||||
text: $.t('admin.home'),
|
||||
href: ""
|
||||
}, {
|
||||
text: $.t('whitelist.manage'),
|
||||
href: "manage/#admin/whitelists"
|
||||
}]);
|
||||
|
||||
var view = new WhiteListListView({
|
||||
model: this.whiteListList,
|
||||
clientList: this.clientList,
|
||||
systemScopeList: this.systemScopeList
|
||||
});
|
||||
|
||||
view.load(function() {
|
||||
$('#content').html(view.render().el);
|
||||
view.delegateEvents();
|
||||
setPageTitle($.t('whitelist.manage'));
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
ui.routes.push({path: "admin/whitelist/new/:cid", name: "newWhitelist", callback:
|
||||
function(cid) {
|
||||
|
||||
ui.routes.push({
|
||||
path: "admin/whitelist/new/:cid",
|
||||
name: "newWhitelist",
|
||||
callback: function(cid) {
|
||||
|
||||
if (!isAdmin()) {
|
||||
this.root();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.breadCrumbView.collection.reset();
|
||||
this.breadCrumbView.collection.add([
|
||||
{text:$.t('admin.home'), href:""},
|
||||
{text:$.t('whitelist.manage'), href:"manage/#admin/whitelists"},
|
||||
{text:$.t('whitelist.new'), href:"manage/#admin/whitelist/new/" + cid}
|
||||
]);
|
||||
|
||||
this.updateSidebar('admin/whitelists');
|
||||
|
||||
var whiteList = new WhiteListModel();
|
||||
|
||||
var client = this.clientList.get(cid);
|
||||
if (!client) {
|
||||
client = new ClientModel({id: cid});
|
||||
}
|
||||
|
||||
var view = new WhiteListFormView({model: whiteList, client: client, systemScopeList: this.systemScopeList});
|
||||
|
||||
view.load(
|
||||
function() {
|
||||
|
||||
// set the scopes on the model now that everything's loaded
|
||||
whiteList.set({allowedScopes: client.get('scope')}, {silent: true});
|
||||
|
||||
$('#content').html(view.render().el);
|
||||
view.delegateEvents();
|
||||
setPageTitle($.t('whitelist.manage'));
|
||||
}
|
||||
);
|
||||
|
||||
this.breadCrumbView.collection.add([{
|
||||
text: $.t('admin.home'),
|
||||
href: ""
|
||||
}, {
|
||||
text: $.t('whitelist.manage'),
|
||||
href: "manage/#admin/whitelists"
|
||||
}, {
|
||||
text: $.t('whitelist.new'),
|
||||
href: "manage/#admin/whitelist/new/" + cid
|
||||
}]);
|
||||
|
||||
this.updateSidebar('admin/whitelists');
|
||||
|
||||
var whiteList = new WhiteListModel();
|
||||
|
||||
var client = this.clientList.get(cid);
|
||||
if (!client) {
|
||||
client = new ClientModel({
|
||||
id: cid
|
||||
});
|
||||
}
|
||||
|
||||
var view = new WhiteListFormView({
|
||||
model: whiteList,
|
||||
client: client,
|
||||
systemScopeList: this.systemScopeList
|
||||
});
|
||||
|
||||
view.load(function() {
|
||||
|
||||
// set the scopes on the model now that everything's loaded
|
||||
whiteList.set({
|
||||
allowedScopes: client.get('scope')
|
||||
}, {
|
||||
silent: true
|
||||
});
|
||||
|
||||
$('#content').html(view.render().el);
|
||||
view.delegateEvents();
|
||||
setPageTitle($.t('whitelist.manage'));
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
ui.routes.push({path: "admin/whitelist/:id", name: "editWhitelist", callback:
|
||||
function(id) {
|
||||
ui.routes.push({
|
||||
path: "admin/whitelist/:id",
|
||||
name: "editWhitelist",
|
||||
callback: function(id) {
|
||||
|
||||
if (!isAdmin()) {
|
||||
this.root();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.breadCrumbView.collection.reset();
|
||||
this.breadCrumbView.collection.add([
|
||||
{text:$.t('admin.home'), href:""},
|
||||
{text:$.t('whitelist.manage'), href:"manage/#admin/whitelists"},
|
||||
{text:$.t('whitelist.edit'), href:"manage/#admin/whitelist/" + id}
|
||||
]);
|
||||
|
||||
this.updateSidebar('admin/whitelists');
|
||||
|
||||
var whiteList = this.whiteListList.get(id);
|
||||
if (!whiteList) {
|
||||
whiteList = new WhiteListModel({id: id});
|
||||
}
|
||||
|
||||
var view = new WhiteListFormView({model: whiteList, clientList: this.clientList, systemScopeList: this.systemScopeList});
|
||||
|
||||
view.load(
|
||||
function() {
|
||||
$('#content').html(view.render().el);
|
||||
view.delegateEvents();
|
||||
setPageTitle($.t('whitelist.manage'));
|
||||
}
|
||||
);
|
||||
|
||||
this.breadCrumbView.collection.add([{
|
||||
text: $.t('admin.home'),
|
||||
href: ""
|
||||
}, {
|
||||
text: $.t('whitelist.manage'),
|
||||
href: "manage/#admin/whitelists"
|
||||
}, {
|
||||
text: $.t('whitelist.edit'),
|
||||
href: "manage/#admin/whitelist/" + id
|
||||
}]);
|
||||
|
||||
this.updateSidebar('admin/whitelists');
|
||||
|
||||
var whiteList = this.whiteListList.get(id);
|
||||
if (!whiteList) {
|
||||
whiteList = new WhiteListModel({
|
||||
id: id
|
||||
});
|
||||
}
|
||||
|
||||
var view = new WhiteListFormView({
|
||||
model: whiteList,
|
||||
clientList: this.clientList,
|
||||
systemScopeList: this.systemScopeList
|
||||
});
|
||||
|
||||
view.load(function() {
|
||||
$('#content').html(view.render().el);
|
||||
view.delegateEvents();
|
||||
setPageTitle($.t('whitelist.manage'));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
ui.templates.push('resources/template/whitelist.html');
|
||||
|
||||
ui.init.push(function(app) {
|
||||
app.whiteListList = new WhiteListCollection();
|
||||
app.whiteListList = new WhiteListCollection();
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue