From fc0327f91fb134e1df994143a78c22df7d8f62e4 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Wed, 15 Jun 2011 19:47:24 +0100 Subject: Big interface clear up --- static/mauve_utils.js | 60 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 14 deletions(-) (limited to 'static/mauve_utils.js') diff --git a/static/mauve_utils.js b/static/mauve_utils.js index 8a4a9db..3012ca3 100644 --- a/static/mauve_utils.js +++ b/static/mauve_utils.js @@ -1,24 +1,56 @@ -// Controls the showing of details on alerts. - -function next_date(n, d, when) { - switch(when) { - case "daytime" - next_daytime_hour(d) + n; - case "working" - next_working_hour(d) + n; - default - d + n; - } +function updateDate() { + // + // Date.getTime() returns *milliseconds* + // + var this_date = workoutDate( $('#n_hours').val(), $('#type_hours').val() ); + $('#ack_until_text').html("(until "+humanDate(this_date)+")"); + $('#ack_until').val(this_date.getTime()/1000); + + return false; } -function is_daytime_hour(d) { - return (d.getHours() => 8 and d.getHours() <= 17); +function workoutDate(h, t) { + var new_date = null; + + // + // Use a synchronous ajax request to fetch the date. Note that + // Date.getTime() returns milliseconds.. + // + $.ajax({ + url: '/ajax/time_in_x_hours/'+h+"/"+t, + async: false, + success: function(data) { new_date = new Date ( new Number(data) * 1000 ); } + }); + + return new_date; } -function next_working_hour(d) { +function humanDate(d) { + var new_date = null; + // + // Use a synchronous ajax convert a date to a human string. NB Date.getTime() + // returns *milliseconds* + // + $.ajax({ + url: '/ajax/time_to_s_human/'+d.getTime()/1000, + async: false, + success: function(data) { new_date = data; } + }); + + return new_date; +} +function fetchDetail(a) { + // Use a synchronous ajax request to fetch the date. + $.get('/ajax/alerts_table_alert_detail/'+a, + function(data) { + $('#tr_summary_'+a).after(data); + // Only fetch the data once. + $('#a_detail_'+a).attr("onclick",null).click(function() { $('#tr_detail_'+a).toggle(); return false; }); + }); + return false; } -- cgit v1.2.1