Convert view/BasicAuthButton.coffee

This commit is contained in:
Mohsen Azimi
2015-03-12 10:24:20 -07:00
parent f211be40d2
commit 734ad71250
4 changed files with 54 additions and 37 deletions

View File

@@ -27,6 +27,7 @@
"Docs": false,
"SwaggerClient": false,
"Handlebars": false,
"ApiKeyAuthorization": false
"ApiKeyAuthorization": false,
"PasswordAuthorization": false
}
}

View File

@@ -18,8 +18,12 @@ var ApiKeyButton = Backbone.View.extend({ // TODO: append this to global Swagger
applyApiKey: function(){
var authorizations = new ApiKeyAuthorization(this.model.name, $('#input_apiKey_entry').val(), this.model.in);
window.authorizations.add(this.model.name, authorizations);
var keyAuth = new ApiKeyAuthorization(
this.model.name,
$('#input_apiKey_entry').val(),
this.model.in
);
window.authorizations.add(this.model.name, keyAuth);
window.swaggerUi.load();
$('#apikey_container').show();
},

View File

@@ -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

View 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;
}
});