Commit 1e200d4c authored by Leigh B Stoller's avatar Leigh B Stoller

Add two new buttons, one to send email to ask for info, and another

to warn user to use their reservation or die.
parent 72dba711
......@@ -99,6 +99,15 @@ $(function ()
DenyReservation($(this).closest('tr'));
return false;
});
// Bind info and warning handler.
$('#' + name + ' .info-button').click(function() {
ReservationInfoOrWarning("info", $(this).closest('tr'));
return false;
});
$('#' + name + ' .warn-button').click(function() {
ReservationInfoOrWarning("warn", $(this).closest('tr'));
return false;
});
}
// This activates the tooltip subsystem.
$('[data-toggle="tooltip"]').tooltip({
......@@ -198,6 +207,59 @@ $(function ()
sup.ShowModal("#deny-modal");
}
/*
* Ask for info about reservation (usage, lack of usage, etc).
*/
function ReservationInfoOrWarning(which, row) {
// This is what we are deleting.
var uuid = $(row).attr('data-uuid');
var pid = $(row).attr('data-pid');
var uid_idx = $(row).attr('data-creator_idx');
var cluster = $(row).attr('data-cluster');
var table = $(row).closest("table");
var warning = (which == "warn" ? 1 : 0);
var modal = (warning ? "#warn-modal" : "#info-modal");
var method = (warning ? "WarnUser" : "RequestInfo");
var callback = function (json) {
sup.HideModal('#waitwait-modal');
console.log("info/warn", json);
if (json.code) {
sup.SpitOops("oops", json.value);
return;
}
};
// Bind the confirm button in the modal.
$(modal + ' .confirm-button').click(function () {
var message = $(modal + ' .user-message').val();
if (!warning && message.trim().length == 0) {
$(modal + ' .nomessage-error').removeClass("hidden");
return;
}
sup.HideModal(modal, function () {
sup.ShowModal('#waitwait-modal');
var xmlthing = sup.CallServerMethod(null, "reserve", method,
{"uuid" : uuid,
"pid" : pid,
"uid_idx" : uid_idx,
"cluster" : cluster,
"message" : message});
xmlthing.done(callback);
});
});
// Handler so we know the user closed the modal. We need to
// clear the confirm button handler.
$(modal).on('hidden.bs.modal', function (e) {
$(modal + ' .nomessage-error').unbind("click");
$(modal).off('hidden.bs.modal');
})
// Hide error
if (!warning) {
$(modal + ' .nomessage-error').addClass("hidden");
}
sup.ShowModal(modal);
}
// Helper.
function decodejson(id) {
return JSON.parse(_.unescape($(id)[0].textContent));
......
......@@ -335,6 +335,102 @@ function Do_Delete()
SPITAJAX_RESPONSE(1);
}
#
# Request info.
#
function Do_InfoOrWarn($warning = false)
{
global $this_user;
global $ajax_args;
global $TB_PROJECT_CREATEEXPT, $suexec_output, $APTBASE, $APTMAIL;
if (!isset($ajax_args["uuid"])) {
SPITAJAX_ERROR(-1, "Missing uuid");
return -1;
}
$uuid = $ajax_args["uuid"];
if (!IsValidUUID($uuid)) {
SPITAJAX_ERROR(-1, "Invalid uuid");
return;
}
if (!isset($ajax_args["cluster"])) {
SPITAJAX_ERROR(-1, "Missing cluster");
return;
}
if (!preg_match("/^[-\w]+$/", $ajax_args["cluster"])) {
SPITAJAX_ERROR(-1, "Invalid cluster name");
return;
}
$nickname = $ajax_args["cluster"];
$aggregate = Aggregate::LookupByNickname($nickname);
if (!$aggregate) {
SPITAJAX_ERROR(-1, "No such cluster");
return;
}
if (!isset($ajax_args["pid"])) {
SPITAJAX_ERROR(-1, "Missing project");
return;
}
$project = Project::Lookup($ajax_args["pid"]);
if (!$project) {
SPITAJAX_ERROR(-1, "No such project");
return;
}
if (!isset($ajax_args["uid_idx"])) {
SPITAJAX_ERROR(-1, "Missing uid idx");
return;
}
$user = User::Lookup($ajax_args["uid_idx"]);
if (!$user) {
SPITAJAX_ERROR(-1, "No such user");
return;
}
if (!warning &&
(!isset($ajax_args["message"]) || $ajax_args["message"] == "")) {
SPITAJAX_ERROR(-1, "Missing message");
return;
}
if (!ISADMIN()) {
SPITAJAX_ERROR(-1, "Only administrators can ask for info or warn");
return;
}
$url = "${APTBASE}/reserve.php?edit=1&cluster=$nickname&uuid=$uuid\n";
if ($warning) {
$subject = "Unused Reservation Warning";
$message = "Your reservation in project $pid is currently either\n".
"underused or unused. Tying up resources in this manner means\n".
"other users may not be able to get their work done. If your\n".
"reservation is still underused in 24 hours, the reservation\n".
"will be deleted.\n\n";
if (isset($ajax_args["message"]) && $ajax_args["message"] != "") {
$message .= $ajax_args["message"] . "\n";
}
$message .= "$url\n";
}
else {
$subject = "Reservation Info Request";
$message = $ajax_args["message"] . "\n\n";
$message .= "$url\n";
}
TBMAIL($user->email(), $subject, $message,
"From: $APTMAIL\n".
"CC: $APTMAIL");
sleep(1);
SPITAJAX_RESPONSE(1);
}
function Do_WarnUser()
{
Do_InfoOrWarn(true);
}
function Do_RequestInfo()
{
Do_InfoOrWarn(false);
}
#
# Approve a reservation.
#
......
......@@ -356,8 +356,10 @@ $routing = array("myprofiles" =>
"Do_GetReservation",
"Approve" =>
"Do_Approve",
"Delete" =>
"Do_Delete",
"WarnUser" =>
"Do_WarnUser",
"RequestInfo" =>
"Do_RequestInfo",
"ReservationInfo" =>
"Do_ReservationInfo")),
"images" =>
......
......@@ -70,7 +70,11 @@
<% _.each(reservations, function(value, uuid) { %>
<tr <% if (showidx) { %> data-uuid="<%- value.uuid %>"
data-pid="<%- value.pid %>"
data-cluster="<%- value.cluster %>"<% } %>>
data-cluster="<%- value.cluster %>"
<% if (value.creator_idx) { %>
data-creator_idx="<%- value.creator_idx %>"
<% } %>
<% } %>>
<% if (showidx) { %>
<td>
<% if (isadmin) { %>
......@@ -96,12 +100,33 @@
<a href="reserve.php?edit=1&cluster=<%- value.cluster %>&uuid=<%- value.uuid %>"
class="edit-button">
<span class='glyphicon glyphicon-pencil pull-left'
style='color: red; margin-bottom: 4px;'
style='color: red; margin-right: 5px;
margin-bottom: 4px;'
data-toggle='tooltip'
data-container="body"
data-trigger="hover"
title='Edit reservation details'></span>
</a>
<% if (value.creator_idx) { %>
<a href="#" class="info-button">
<span class='glyphicon glyphicon-info-sign pull-left'
style='color: red; margin-bottom: 4px;
margin-right: 5px;'
data-toggle='tooltip'
data-container="body"
data-trigger="hover"
title='Send a message to user'></span>
</a>
<a href="#" class="warn-button">
<span class='glyphicon glyphicon-warning-sign pull-left'
style='color: red; margin-bottom: 4px;
margin-right: 0px;'
data-toggle='tooltip'
data-container="body"
data-trigger="hover"
title='Warn user about unused reservaton'></span>
</a>
<% } %>
</td>
<% } %>
<% if (showuser) { %>
......@@ -169,3 +194,41 @@
</div>
</div>
</div>
<div id='info-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 Send Message</h4>
<span class="hidden nomessage-error text-danger">Give me Text!</span>
<div>
<textarea class='form-control user-message'
rows=5></textarea>
</div>
<br>
<button class='btn btn-danger btn-sm confirm-button'>Confirm</button>
</center>
</div>
</div>
</div>
</div>
<div id='warn-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 Send Warning Message</h4>
Additional text to send with warning (no text is okay):</span>
<div>
<textarea class='form-control user-message'
rows=5></textarea>
</div>
<br>
<button class='btn btn-danger btn-sm confirm-button'>Confirm</button>
</center>
</div>
</div>
</div>
</div>
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