Skip to content

Commit

Permalink
Issue #133: Create auth fields in js when needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
mk23 committed Nov 16, 2016
1 parent 5257a25 commit c0706a5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 20 deletions.
2 changes: 0 additions & 2 deletions src/main/resources/assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@ <h3 class="modal-title">Endpoint Authentication</h3>
<span class="input-group-addon">
<span class="glyphicon glyphicon-user"></span>
</span>
<input id="endpoint-user" class="form-control" type="text" placeholder="username">
</div>
<div class="input-group">
<span class="input-group-addon">
<span class="glyphicon glyphicon-lock"></span>
</span>
<input id="endpoint-pass" class="form-control" type="password" placeholder="password">
</div>
<button class="btn btn-default" type="submit">
<span class="glyphicon glyphicon-log-in"></span>
Expand Down
55 changes: 37 additions & 18 deletions src/main/resources/assets/js/jmxproxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -755,27 +755,48 @@ var endpointHostClass = function(prefix, host) {
checkHost();
};

var setupAuth = function(jqXHR) {
if (jqXHR.status == 401) {
$('#endpoint-auth').modal();
$('#endpoint-creds .input-group:nth(0)')
.find('input')
.remove()
.end()
.append(
$('<input/>')
.addClass('form-control')
.attr({
id: 'endpoint-user',
type: 'text',
placeholder: 'username',
})
);
$('#endpoint-creds .input-group:nth(1)')
.find('input')
.remove()
.end()
.append(
$('<input/>')
.addClass('form-control')
.attr({
id: 'endpoint-pass',
type: 'password',
placeholder: 'password',
})
);
$('#endpoint-user').focus();
} else if (jqXHR.status == 404) {
displayError('Selected endpoint is unavailable.');
}
};

var fetchData = function(item, callback) {
if (creds != null) {
$.post(prefix+'/jmxproxy/'+host+item, creds, callback)
.fail(function(jqXHR) {
if (jqXHR.status == 401) {
$('#endpoint-auth').modal();
$('#endpoint-user').focus();
} else if (jqXHR.status == 404) {
displayError('Selected endpoint is unavailable.');
}
});
.fail(setupAuth);
} else {
$.getJSON(prefix+'/jmxproxy/'+host+item, callback)
.fail(function(jqXHR) {
if (jqXHR.status == 401) {
$('#endpoint-auth').modal();
$('#endpoint-user').focus();
} else if (jqXHR.status == 404) {
displayError('Selected endpoint is unavailable.');
}
});
.fail(setupAuth);
}
};

Expand Down Expand Up @@ -851,7 +872,6 @@ $(document).ready(function() {
$('#endpoint-combo button').prop('disabled', true);
}
} else if (!$(this).data('changing')) {
console.log($(this).data('changing'));
endpointHost = endpointHostClass(prefix, data.text);
$('#endpoint-combo').data('changing', false);
}
Expand All @@ -873,7 +893,6 @@ $(document).ready(function() {
$('#endpoint-combo').data('changing', $(this).val() != '');
})
.blur(function(e) {
console.log('hi');
$('#endpoint-combo').data('changing', false);
});

Expand Down

0 comments on commit c0706a5

Please sign in to comment.