Commit a7e92983 authored by Leigh B Stoller's avatar Leigh B Stoller

I changed NVD3 to return extra info to determine type when clicking in a

reservation graph.
parent 2f9907d0
...@@ -78,7 +78,7 @@ $(function () ...@@ -78,7 +78,7 @@ $(function ()
"showhelp" : true, "showhelp" : true,
"showfullscreen" : true}); "showfullscreen" : true});
}); });
$('#reservation-lists .reservation-div').html(html); $('#reservation-lists').html(html);
// Handler for the Help button // Handler for the Help button
$('#reservation-help-button').click(function (event) { $('#reservation-help-button').click(function (event) {
...@@ -262,29 +262,38 @@ $(function () ...@@ -262,29 +262,38 @@ $(function ()
"Validate", checkonly_callback); "Validate", checkonly_callback);
} }
// Call back from the graphs to change the dates on a blank form // Call back from the graphs to change the dates on a blank form
function SetDates(when) function GraphClick(when, type)
{ {
//console.info("dates", when); //console.info("graphclick", when, type);
// Bump to next hour. Will be confusing at midnight. // Bump to next hour. Will be confusing at midnight.
when.setHours(when.getHours() + 1); when.setHours(when.getHours() + 1);
if (! editing) { if (! editing) {
$("#reserve-request-form #start_day").datepicker("setDate", when); $("#reserve-request-form #start_day").datepicker("setDate", when);
//$("#reserve-request-form #end_day").datepicker("setDate", when);
$("#reserve-request-form [name=start_hour]").val(when.getHours()); $("#reserve-request-form [name=start_hour]").val(when.getHours());
//$("#reserve-request-form [name=end_hour]").val(when.getHours()); if (type !== undefined) {
if ($('#reserve-request-form ' +
'[name=type] option:selected').val() != type) {
$('#reserve-request-form ' +
'[name=type] option:selected').removeAttr('selected');
$('#reserve-request-form [name=type] ' +
'option[value="' + type + '"]')
.prop("selected", "selected");
}
}
$('#reserve-request-form [name=count]').focus();
aptforms.MarkFormUnsaved(); aptforms.MarkFormUnsaved();
} }
} }
// Set the cluster after clicking on a graph. // Set the cluster after clicking on a graph.
function SetCluster(nickname, urn) function SetCluster(nickname, urn)
{ {
//console.info("SetCluster", nickname);
var id = "resgraph-" + nickname; var id = "resgraph-" + nickname;
$('#reserve-request-form [name=cluster] option[value="' + urn + '"]')
.prop("selected", "selected");
if ($('#reservation-lists :first-child').attr("id") != id) { if ($('#reservation-lists :first-child').attr("id") != id) {
$('#' + id).fadeOut("fast", function () { $('#' + id).fadeOut("fast", function () {
if ($(window).scrollTop()) { if ($(window).scrollTop()) {
...@@ -303,9 +312,17 @@ $(function () ...@@ -303,9 +312,17 @@ $(function ()
} }
}); });
} }
if ($('#reserve-request-form ' +
'[name=cluster] option:selected').val() != urn) {
$('#reserve-request-form ' +
'[name=cluster] option:selected').removeAttr('selected');
$('#reserve-request-form ' +
'[name=cluster] option[value="' + urn + '"]')
.prop("selected", "selected");
HandleClusterChange(urn); HandleClusterChange(urn);
aptforms.MarkFormUnsaved(); aptforms.MarkFormUnsaved();
} }
}
/* /*
* Load anonymized reservations from each am in the list and * Load anonymized reservations from each am in the list and
...@@ -326,18 +343,16 @@ $(function () ...@@ -326,18 +343,16 @@ $(function ()
details.name + ": " + json.value); details.name + ": " + json.value);
return; return;
} }
// When clicking on a graph, make it the current cluster.
if (!editing) {
$('#' + id + ' .panel-body')
.click(function (event) {
SetCluster(details.nickname, urn);
});
}
ShowResGraph({"forecast" : json.value.forecast, ShowResGraph({"forecast" : json.value.forecast,
"selector" : id, "selector" : id,
"skiptypes" : skiptypes, "skiptypes" : skiptypes,
"click_callback" : SetDates}); "click_callback" : function(when, type) {
if (!editing) {
SetCluster(details.nickname, urn);
}
GraphClick(when, type);
}});
$('#' + id + ' .resgraph-fullscreen') $('#' + id + ' .resgraph-fullscreen')
.click(function (event) { .click(function (event) {
...@@ -352,7 +367,7 @@ $(function () ...@@ -352,7 +367,7 @@ $(function ()
ShowResGraph({"forecast" : json.value.forecast, ShowResGraph({"forecast" : json.value.forecast,
"selector" : "resgraph-modal", "selector" : "resgraph-modal",
"skiptypes" : skiptypes, "skiptypes" : skiptypes,
"click_callback" : SetDates}); "click_callback" : GraphClick});
}); });
sup.ShowModal('#resgraph-modal', function () { sup.ShowModal('#resgraph-modal', function () {
$('#resgraph-modal').off('shown.bs.modal'); $('#resgraph-modal').off('shown.bs.modal');
......
...@@ -288,8 +288,15 @@ window.ShowResGraph = (function () ...@@ -288,8 +288,15 @@ window.ShowResGraph = (function ()
*/ */
if (click_callback) { if (click_callback) {
chart.lines.dispatch.on("elementClick", function(e) { chart.lines.dispatch.on("elementClick", function(e) {
console.info(e); //console.info(e);
click_callback(new Date(e[0].point.x)); var type = undefined;
// Find the "selected" type (if click near enough).
for (var i = 0; i < e.length; i++) {
if (e[i].selected) {
type = e[i].series.key;
}
}
click_callback(new Date(e[0].point.x), type);
}); });
} }
window.nv.utils.windowResize(chart.update); window.nv.utils.windowResize(chart.update);
......
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