[auth] renamed AuthView to AuthButtonView

This commit is contained in:
Anna Bodnia
2016-03-03 13:26:53 +02:00
parent 1861ac27ca
commit 0e698af5b1
5 changed files with 27 additions and 76 deletions

4
dist/swagger-ui.js vendored
View File

@@ -19063,7 +19063,7 @@ SwaggerUi.Views.ApiKeyButton = Backbone.View.extend({ // TODO: append this to gl
}); });
'use strict'; 'use strict';
SwaggerUi.Views.AuthView = Backbone.View.extend({ SwaggerUi.Views.AuthButtonView = Backbone.View.extend({
events: { events: {
'click .authorize__btn': 'authorizeBtnClick' 'click .authorize__btn': 'authorizeBtnClick'
}, },
@@ -19319,7 +19319,7 @@ SwaggerUi.Views.MainView = Backbone.View.extend({
authsModel = { auths: this.model.securityDefinitions }; authsModel = { auths: this.model.securityDefinitions };
authsModel.isLogout = !_.isEmpty(window.swaggerUi.api.clientAuthorizations.authz); authsModel.isLogout = !_.isEmpty(window.swaggerUi.api.clientAuthorizations.authz);
this.authView = new SwaggerUi.Views.AuthView({model: authsModel, router: this.router}); this.authView = new SwaggerUi.Views.AuthButtonView({model: authsModel, router: this.router});
this.$('.authorize-wrapper').append(this.authView.render().el); this.$('.authorize-wrapper').append(this.authView.render().el);
} }

File diff suppressed because one or more lines are too long

View File

@@ -23,7 +23,6 @@ SwaggerUi.Views.AuthButtonView = Backbone.View.extend({
authorizeBtnClick: function (e) { authorizeBtnClick: function (e) {
var authsModel; var authsModel;
e.preventDefault(); e.preventDefault();
authsModel = { authsModel = {
@@ -36,14 +35,30 @@ SwaggerUi.Views.AuthButtonView = Backbone.View.extend({
}, },
renderAuths: function (auths) { renderAuths: function (auths) {
var $el = $('<div>'); var name, authEl, authModel;
var el = $('<div>');
var authz = window.swaggerUi.api.clientAuthorizations.authz;
auths.forEach(function (auth) { for (name in auths) {
var authEl = new SwaggerUi.Views.AuthView({data: auth, router: this.router}).render().el; authModel = _.extend({}, auths[name]);
$el.append(authEl);
}, this);
return $el; if (authz[name]) {
_.extend(authModel, {
isLogout: true,
value: authz[name].value
});
}
if (authModel.type === 'apiKey') {
authEl = new SwaggerUi.Views.ApiKeyButton({model: authModel, router: this.router}).render().el;
el.append(authEl);
} else if (authModel.type === 'basic' && el.find('.basic_auth_container').length === 0) {
authEl = new SwaggerUi.Views.BasicAuthButton({model: authModel, router: this.router}).render().el;
el.append(authEl);
}
}
return el;
} }
}); });

View File

@@ -1,64 +0,0 @@
'use strict';
SwaggerUi.Views.AuthView = Backbone.View.extend({
events: {
'click .authorize__btn': 'authorizeBtnClick'
},
tpls: {
popup: Handlebars.templates.popup,
authBtn: Handlebars.templates.auth_button
},
initialize: function(opts) {
this.options = opts || {};
this.router = this.options.router;
},
render: function () {
this.$el.html(this.tpls.authBtn(this.model));
return this;
},
authorizeBtnClick: function (e) {
var authsModel;
e.preventDefault();
authsModel = {
title: 'Available authorizations',
content: this.renderAuths(this.model.auths)
};
this.popup = new SwaggerUi.Views.PopupView({model: authsModel});
this.popup.render();
},
renderAuths: function (auths) {
var name, authEl, authModel;
var el = $('<div>');
var authz = window.swaggerUi.api.clientAuthorizations.authz;
for (name in auths) {
authModel = _.extend({}, auths[name]);
if (authz[name]) {
_.extend(authModel, {
isLogout: true,
value: authz[name].value
});
}
if (authModel.type === 'apiKey') {
authEl = new SwaggerUi.Views.ApiKeyButton({model: authModel, router: this.router}).render().el;
el.append(authEl);
} else if (authModel.type === 'basic' && el.find('.basic_auth_container').length === 0) {
authEl = new SwaggerUi.Views.BasicAuthButton({model: authModel, router: this.router}).render().el;
el.append(authEl);
}
}
return el;
}
});

View File

@@ -93,7 +93,7 @@ SwaggerUi.Views.MainView = Backbone.View.extend({
authsModel = { auths: this.model.securityDefinitions }; authsModel = { auths: this.model.securityDefinitions };
authsModel.isLogout = !_.isEmpty(window.swaggerUi.api.clientAuthorizations.authz); authsModel.isLogout = !_.isEmpty(window.swaggerUi.api.clientAuthorizations.authz);
this.authView = new SwaggerUi.Views.AuthView({model: authsModel, router: this.router}); this.authView = new SwaggerUi.Views.AuthButtonView({model: authsModel, router: this.router});
this.$('.authorize-wrapper').append(this.authView.render().el); this.$('.authorize-wrapper').append(this.authView.render().el);
} }