Commit f01c86be authored by Leigh Stoller's avatar Leigh Stoller

UI changes; add an approve button, most reservation can be approved from

the listing without going to the edit page. Also hide the approve/deny
icons on approved reservations.
parent 8b287210
......@@ -30,10 +30,13 @@ $(function ()
function LoadData()
{
var amcount = Object.keys(amlist).length;
var rescount = 0;
var rescount = 0;
_.each(amlist, function(urn, name) {
var callback = function(json) {
var error = null;
var reservations = null;
console.log("LoadData", json);
// Kill the spinner.
......@@ -44,17 +47,19 @@ $(function ()
if (json.code) {
console.log("Could not get reservation data for " +
name + ": " + json.value);
return;
error = json.value;
}
var reservations = json.value.reservations;
rescount += reservations.length;
else {
reservations = json.value.reservations;
rescount += reservations.length;
if (reservations.length == 0) {
if (amcount == 0 && rescount == 0) {
// No reservations at all, show the message.
$('#noreservations').removeClass("hidden");
if (reservations.length == 0) {
if (amcount == 0 && rescount == 0) {
// No reservations at all, show the message.
$('#noreservations').removeClass("hidden");
}
return;
}
return;
}
// Generate the main template.
......@@ -67,6 +72,7 @@ $(function ()
"anonymous" : false,
"name" : name,
"isadmin" : window.ISADMIN,
"error" : error,
});
html =
"<div class='row' id='" + name + "'>" +
......@@ -76,6 +82,10 @@ $(function ()
$('#main-body').prepend(html);
// On error, no need for the rest of this.
if (error)
return;
// Show the proper status now, we might change it later.
_.each(reservations, function(value, uuid) {
var id = '#' + name +
......@@ -89,6 +99,24 @@ $(function ()
}
else {
$(id + " .status-pending").removeClass("hidden");
if (window.ISADMIN) {
id = '#' + name +
' tr[data-uuid="' + uuid + '"] ';
// Bind a deny handler,
$(id + ' .deny-button').click(function() {
DenyReservation($(this).closest('tr'));
return false;
});
$(id + ' .deny-button').removeClass("invisible");
// Bind an approve handler
$(id + ' .approve-button').click(function() {
ApproveReservation($(this).closest('tr'));
return false;
});
$(id + ' .approve-button').removeClass("invisible");
}
}
});
......@@ -111,11 +139,6 @@ $(function ()
return false;
});
if (window.ISADMIN) {
// Bind a deny handler.
$('#' + name + ' .deny-button').click(function() {
DenyReservation($(this).closest('tr'));
return false;
});
// Bind info and warning handler.
$('#' + name + ' .info-button').click(function() {
ReservationInfoOrWarning("info", $(this).closest('tr'));
......@@ -289,6 +312,48 @@ $(function ()
sup.ShowModal("#deny-modal");
}
/*
* Approve a reservation.
*/
function ApproveReservation(row) {
// This is what we are deleting.
var uuid = $(row).attr('data-uuid');
var cluster = $(row).attr('data-cluster');
var callback = function (json) {
sup.HideModal('#waitwait-modal');
console.log("approve", json);
if (json.code) {
sup.SpitOops("oops", json.value);
return;
}
$(row).find(".status-column .status-pending")
.addClass("hidden");
$(row).find(".status-column .status-approved")
.removeClass("hidden");
$(row).find('.approve-button').addClass("invisible");
$(row).find('.deny-button').addClass("invisible");
};
// Bind the confirm button in the modal. Do the approval.
$('#approve-modal #confirm-approve').click(function () {
sup.HideModal('#approve-modal', function () {
sup.ShowModal('#waitwait-modal');
var xmlthing = sup.CallServerMethod(null, "reserve",
"Approve",
{"uuid" : uuid,
"cluster" : cluster});
xmlthing.done(callback);
});
});
// Handler so we know the user closed the modal. We need to
// clear the confirm button handler.
$('#approve-modal').on('hidden.bs.modal', function (e) {
$('#approve-modal #confirm-approve').unbind("click");
$('#approve-modal').off('hidden.bs.modal');
})
sup.ShowModal("#approve-modal");
}
/*
* Ask for info about reservation (usage, lack of usage, etc).
*/
......@@ -306,7 +371,7 @@ $(function ()
var callback = function (json) {
sup.HideModal('#waitwait-modal');
console.log("info/warn", json);
console.log(method, json);
if (json.code) {
sup.SpitOops("oops", json.value);
return;
......
......@@ -42,6 +42,9 @@
</h5>
</div>
<div class='panel-body panel-body-dashboard'>
<% if (error) { %>
<div class="text-center text-danger"><%- error %></div>
<% } else { %>
<table class='tablesorter' id='reservations-table-<%- name %>'>
<thead>
<tr>
......@@ -71,7 +74,7 @@
<% if (showidx) { %>
<td style='white-space: nowrap;'>
<% if (isadmin) { %>
<a href="#" class="deny-button">
<a href="#" class="deny-button invisible">
<span class='glyphicon glyphicon-thumbs-down pull-left'
style='color: red; margin-left: 0px;
margin-bottom: 4px;'
......@@ -80,6 +83,15 @@
data-trigger="hover"
title='Deny with reason'></span>
</a>
<a href="#" class="approve-button invisible">
<span class='glyphicon glyphicon-thumbs-up pull-left'
style='color: red; margin-left: 5px;
margin-bottom: 4px;'
data-toggle='tooltip'
data-container="body"
data-trigger="hover"
title='Approve reservation'></span>
</a>
<% } %>
<a href="#" class="delete-button">
<span class='glyphicon glyphicon-remove pull-left'
......@@ -196,6 +208,7 @@
<% }); %>
</tbody>
</table>
<% } %>
</div>
</div>
</div>
......@@ -220,6 +233,21 @@
</div>
</div>
</div>
<div id='approve-modal' class='modal fade'>
<div class='modal-dialog'>
<div class='modal-content'>
<div class='modal-body'>
<button type='button' class='close' data-dismiss='modal'
aria-hidden='true'>&times;</button>
<center><h4>Confirm to Approve Reservation</h4>
<br>
<button class='btn btn-danger btn-sm'
id='confirm-approve'>Confirm</a>
</center>
</div>
</div>
</div>
</div>
<div id='info-modal' class='modal fade'>
<div class='modal-dialog'>
<div class='modal-content'>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment