[auth] moved logic for auths collections into AuthsCollection

This commit is contained in:
bodnia
2016-03-09 03:18:26 +02:00
parent e7d5ad6d2e
commit c3d4bcca3d
10 changed files with 175 additions and 53 deletions

View File

@@ -0,0 +1,41 @@
'use strict';
SwaggerUi.Collections.AuthsCollection = Backbone.Collection.extend({
add: function (model) {
var args = Array.prototype.slice.call(arguments);
if (Array.isArray(model)) {
args[0] = _.map(model, function(val) {
return this.handleOne(val);
}, this);
} else {
args[0] = this.handleOne(model);
}
Backbone.Collection.prototype.add.apply(this, args);
},
handleOne: function (model) {
var result = model;
if (! (model instanceof Backbone.Model) ) {
switch (model.type) {
case 'oauth2':
result = new SwaggerUi.Models.Oauth2Model(model);
break;
default:
result = new Backbone.Model(model);
}
}
return result;
},
isValid: function () {
return this.length === this.where({ valid: true }).length;
},
isAuthorized: function () {
return this.length === this.where({ isLogout: true }).length;
}
});