Convert view/BasicAuthButton.coffee
This commit is contained in:
@@ -27,6 +27,7 @@
|
|||||||
"Docs": false,
|
"Docs": false,
|
||||||
"SwaggerClient": false,
|
"SwaggerClient": false,
|
||||||
"Handlebars": false,
|
"Handlebars": false,
|
||||||
"ApiKeyAuthorization": false
|
"ApiKeyAuthorization": false,
|
||||||
|
"PasswordAuthorization": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,8 +18,12 @@ var ApiKeyButton = Backbone.View.extend({ // TODO: append this to global Swagger
|
|||||||
|
|
||||||
|
|
||||||
applyApiKey: function(){
|
applyApiKey: function(){
|
||||||
var authorizations = new ApiKeyAuthorization(this.model.name, $('#input_apiKey_entry').val(), this.model.in);
|
var keyAuth = new ApiKeyAuthorization(
|
||||||
window.authorizations.add(this.model.name, authorizations);
|
this.model.name,
|
||||||
|
$('#input_apiKey_entry').val(),
|
||||||
|
this.model.in
|
||||||
|
);
|
||||||
|
window.authorizations.add(this.model.name, keyAuth);
|
||||||
window.swaggerUi.load();
|
window.swaggerUi.load();
|
||||||
$('#apikey_container').show();
|
$('#apikey_container').show();
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
class BasicAuthButton extends Backbone.View
|
|
||||||
initialize: ->
|
|
||||||
|
|
||||||
render: ->
|
|
||||||
template = @template()
|
|
||||||
$(@el).html(template(@model))
|
|
||||||
|
|
||||||
@
|
|
||||||
|
|
||||||
events:
|
|
||||||
"click #basic_auth_button" : "togglePasswordContainer"
|
|
||||||
"click #apply_basic_auth" : "applyPassword"
|
|
||||||
|
|
||||||
applyPassword: ->
|
|
||||||
username = $(".input_username").val()
|
|
||||||
password = $(".input_password").val()
|
|
||||||
window.authorizations.add(@model.type, new PasswordAuthorization("basic", username, password))
|
|
||||||
window.swaggerUi.load()
|
|
||||||
elem = $('#basic_auth_container').hide()
|
|
||||||
|
|
||||||
|
|
||||||
togglePasswordContainer: ->
|
|
||||||
if $('#basic_auth_container').length > 0
|
|
||||||
elem = $('#basic_auth_container').show()
|
|
||||||
if elem.is ':visible'
|
|
||||||
elem.slideUp()
|
|
||||||
else
|
|
||||||
# hide others
|
|
||||||
$('.auth_container').hide()
|
|
||||||
elem.show()
|
|
||||||
|
|
||||||
template: ->
|
|
||||||
Handlebars.templates.basic_auth_button_view
|
|
||||||
|
|
||||||
46
src/main/coffeescript/view/BasicAuthButton.js
Normal file
46
src/main/coffeescript/view/BasicAuthButton.js
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var BasicAuthButton = Backbone.View.extend({
|
||||||
|
|
||||||
|
|
||||||
|
initialize: function () {},
|
||||||
|
|
||||||
|
render: function(){
|
||||||
|
var template = this.template();
|
||||||
|
$(this.el).html(template(this.model));
|
||||||
|
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
|
||||||
|
events: {
|
||||||
|
'click #basic_auth_button' : 'togglePasswordContainer',
|
||||||
|
'click #apply_basic_auth' : 'applyPassword'
|
||||||
|
},
|
||||||
|
|
||||||
|
applyPassword: function(){
|
||||||
|
var username = $('.input_username').val();
|
||||||
|
var password = $('.input_password').val();
|
||||||
|
var basicAuth = new PasswordAuthorization('basic', username, password);
|
||||||
|
window.authorizations.add(this.model.type, basicAuth);
|
||||||
|
window.swaggerUi.load();
|
||||||
|
$('#basic_auth_container').hide();
|
||||||
|
},
|
||||||
|
|
||||||
|
togglePasswordContainer: function(){
|
||||||
|
if ($('#basic_auth_container').length > 0) {
|
||||||
|
var elem = $('#basic_auth_container').show();
|
||||||
|
if (elem.is(':visible')){
|
||||||
|
elem.slideUp();
|
||||||
|
} else {
|
||||||
|
// hide others
|
||||||
|
$('.auth_container').hide();
|
||||||
|
elem.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
template: function(){
|
||||||
|
return Handlebars.templates.basic_auth_button_view;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user