[auth] change show auth popup button depending on logged in auth

This commit is contained in:
bodnia
2016-03-13 22:52:21 +02:00
parent fe9a497b9d
commit 0852d70f41
5 changed files with 28 additions and 8 deletions

16
dist/swagger-ui.js vendored
View File

@@ -19286,6 +19286,7 @@ SwaggerUi.Views.AuthButtonView = Backbone.View.extend({
this.options = opts || {}; this.options = opts || {};
this.options.data = this.options.data || {}; this.options.data = this.options.data || {};
this.isOperation = this.options.isOperation; this.isOperation = this.options.isOperation;
this.model = this.model || {};
this.router = this.options.router; this.router = this.options.router;
this.auths = this.options.data.oauth2.concat(this.options.data.auths); this.auths = this.options.data.oauth2.concat(this.options.data.auths);
}, },
@@ -19293,6 +19294,7 @@ SwaggerUi.Views.AuthButtonView = Backbone.View.extend({
render: function () { render: function () {
var tplName = this.isOperation ? 'authBtnOperation' : 'authBtn'; var tplName = this.isOperation ? 'authBtnOperation' : 'authBtn';
this.$authEl = this.renderAuths(this.auths);
this.$el.html(this.tpls[tplName](this.model)); this.$el.html(this.tpls[tplName](this.model));
return this; return this;
@@ -19305,7 +19307,7 @@ SwaggerUi.Views.AuthButtonView = Backbone.View.extend({
authsModel = { authsModel = {
title: 'Available authorizations', title: 'Available authorizations',
content: this.renderAuths(this.auths) content: this.$authEl
}; };
this.popup = new SwaggerUi.Views.PopupView({model: authsModel}); this.popup = new SwaggerUi.Views.PopupView({model: authsModel});
@@ -19314,12 +19316,19 @@ SwaggerUi.Views.AuthButtonView = Backbone.View.extend({
renderAuths: function (auths) { renderAuths: function (auths) {
var $el = $('<div>'); var $el = $('<div>');
var isLogout = false;
auths.forEach(function (auth) { auths.forEach(function (auth) {
var authEl = new SwaggerUi.Views.AuthView({data: auth, router: this.router}).render().el; var authView = new SwaggerUi.Views.AuthView({data: auth, router: this.router});
var authEl = authView.render().el;
$el.append(authEl); $el.append(authEl);
if (authView.isLogout) {
isLogout = true;
}
}, this); }, this);
this.model.isLogout = isLogout;
return $el; return $el;
} }
@@ -19328,7 +19337,7 @@ SwaggerUi.Views.AuthButtonView = Backbone.View.extend({
'use strict'; 'use strict';
SwaggerUi.Collections.AuthsCollection = Backbone.Collection.extend({ SwaggerUi.Collections.AuthsCollection = Backbone.Collection.extend({
constructor: function(models) { constructor: function() {
var args = Array.prototype.slice.call(arguments); var args = Array.prototype.slice.call(arguments);
args[0] = this.parse(args[0]); args[0] = this.parse(args[0]);
@@ -19501,6 +19510,7 @@ SwaggerUi.Views.AuthView = Backbone.View.extend({
isAuthorized: this.authsCollectionView.collection.isPartiallyAuthorized() isAuthorized: this.authsCollectionView.collection.isPartiallyAuthorized()
})); }));
this.$innerEl = this.$(this.selectors.innerEl); this.$innerEl = this.$(this.selectors.innerEl);
this.isLogout = this.authsCollectionView.collection.isPartiallyAuthorized();
}, },
render: function () { render: function () {

File diff suppressed because one or more lines are too long

View File

@@ -15,6 +15,7 @@ SwaggerUi.Views.AuthButtonView = Backbone.View.extend({
this.options = opts || {}; this.options = opts || {};
this.options.data = this.options.data || {}; this.options.data = this.options.data || {};
this.isOperation = this.options.isOperation; this.isOperation = this.options.isOperation;
this.model = this.model || {};
this.router = this.options.router; this.router = this.options.router;
this.auths = this.options.data.oauth2.concat(this.options.data.auths); this.auths = this.options.data.oauth2.concat(this.options.data.auths);
}, },
@@ -22,6 +23,7 @@ SwaggerUi.Views.AuthButtonView = Backbone.View.extend({
render: function () { render: function () {
var tplName = this.isOperation ? 'authBtnOperation' : 'authBtn'; var tplName = this.isOperation ? 'authBtnOperation' : 'authBtn';
this.$authEl = this.renderAuths(this.auths);
this.$el.html(this.tpls[tplName](this.model)); this.$el.html(this.tpls[tplName](this.model));
return this; return this;
@@ -34,7 +36,7 @@ SwaggerUi.Views.AuthButtonView = Backbone.View.extend({
authsModel = { authsModel = {
title: 'Available authorizations', title: 'Available authorizations',
content: this.renderAuths(this.auths) content: this.$authEl
}; };
this.popup = new SwaggerUi.Views.PopupView({model: authsModel}); this.popup = new SwaggerUi.Views.PopupView({model: authsModel});
@@ -43,12 +45,19 @@ SwaggerUi.Views.AuthButtonView = Backbone.View.extend({
renderAuths: function (auths) { renderAuths: function (auths) {
var $el = $('<div>'); var $el = $('<div>');
var isLogout = false;
auths.forEach(function (auth) { auths.forEach(function (auth) {
var authEl = new SwaggerUi.Views.AuthView({data: auth, router: this.router}).render().el; var authView = new SwaggerUi.Views.AuthView({data: auth, router: this.router});
var authEl = authView.render().el;
$el.append(authEl); $el.append(authEl);
if (authView.isLogout) {
isLogout = true;
}
}, this); }, this);
this.model.isLogout = isLogout;
return $el; return $el;
} }

View File

@@ -38,6 +38,7 @@ SwaggerUi.Views.AuthView = Backbone.View.extend({
isAuthorized: this.authsCollectionView.collection.isPartiallyAuthorized() isAuthorized: this.authsCollectionView.collection.isPartiallyAuthorized()
})); }));
this.$innerEl = this.$(this.selectors.innerEl); this.$innerEl = this.$(this.selectors.innerEl);
this.isLogout = this.authsCollectionView.collection.isPartiallyAuthorized();
}, },
render: function () { render: function () {

View File

@@ -1,7 +1,7 @@
'use strict'; 'use strict';
SwaggerUi.Collections.AuthsCollection = Backbone.Collection.extend({ SwaggerUi.Collections.AuthsCollection = Backbone.Collection.extend({
constructor: function(models) { constructor: function() {
var args = Array.prototype.slice.call(arguments); var args = Array.prototype.slice.call(arguments);
args[0] = this.parse(args[0]); args[0] = this.parse(args[0]);