github.com/qubitproducts/logspray@v0.2.14/server/swagger-ui/src/main/javascript/view/BasicAuthView.js (about) 1 'use strict'; 2 3 SwaggerUi.Views.BasicAuthView = Backbone.View.extend({ 4 5 initialize: function (opts) { 6 this.options = opts || {}; 7 this.router = this.options.router; 8 }, 9 10 events: { 11 'change .auth_input': 'inputChange' 12 }, 13 14 selectors: { 15 usernameInput: '.basic_auth__username', 16 passwordInput: '.basic_auth__password' 17 }, 18 19 cls: { 20 error: 'error' 21 }, 22 23 template: Handlebars.templates.basic_auth, 24 25 render: function(){ 26 $(this.el).html(this.template(this.model.toJSON())); 27 28 return this; 29 }, 30 31 inputChange: function (e) { 32 var $el = $(e.target); 33 var val = $el.val(); 34 var attr = $el.prop('name'); 35 36 if (val) { 37 $el.removeClass(this.cls.error); 38 } 39 40 this.model.set(attr, val); 41 }, 42 43 isValid: function () { 44 return this.model.validate(); 45 }, 46 47 highlightInvalid: function () { 48 if (!this.model.get('username')) { 49 this.$(this.selectors.usernameInput).addClass(this.cls.error); 50 } 51 } 52 });