Convert view/ApiKeyButton.coffee

This commit is contained in:
Mohsen Azimi
2015-03-12 10:18:20 -07:00
parent 15d1e22dbf
commit f211be40d2
3 changed files with 49 additions and 32 deletions

View File

@@ -26,6 +26,7 @@
"MainView": false,
"Docs": false,
"SwaggerClient": false,
"Handlebars": false
"Handlebars": false,
"ApiKeyAuthorization": false
}
}

View File

@@ -1,31 +0,0 @@
class ApiKeyButton extends Backbone.View
initialize: ->
render: ->
template = @template()
$(@el).html(template(@model))
@
events:
"click #apikey_button" : "toggleApiKeyContainer"
"click #apply_api_key" : "applyApiKey"
applyApiKey: ->
window.authorizations.add(@model.name, new ApiKeyAuthorization(@model.name, $("#input_apiKey_entry").val(), @model.in))
window.swaggerUi.load()
elem = $('#apikey_container').show()
toggleApiKeyContainer: ->
if $('#apikey_container').length > 0
elem = $('#apikey_container').first()
if elem.is ':visible'
elem.hide()
else
# hide others
$('.auth_container').hide()
elem.show()
template: ->
Handlebars.templates.apikey_button_view

View File

@@ -0,0 +1,47 @@
'use strict';
var ApiKeyButton = Backbone.View.extend({ // TODO: append this to global SwaggerUi
events:{
'click #apikey_button' : 'toggleApiKeyContainer',
'click #apply_api_key' : 'applyApiKey'
},
initialize: function(){},
render: function(){
var template = this.template();
$(this.el).html(template(this.model));
return this;
},
applyApiKey: function(){
var authorizations = new ApiKeyAuthorization(this.model.name, $('#input_apiKey_entry').val(), this.model.in);
window.authorizations.add(this.model.name, authorizations);
window.swaggerUi.load();
$('#apikey_container').show();
},
toggleApiKeyContainer: function(){
if ($('#apikey_container').length > 0) {
var elem = $('#apikey_container').first();
if (elem.is(':visible')){
elem.hide();
} else {
// hide others
$('.auth_container').hide();
elem.show();
}
}
},
template: function(){
return Handlebars.templates.apikey_button_view;
}
});