diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2011-06-09 18:09:52 +0100 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2011-06-09 18:09:52 +0100 |
commit | 495c44445642cfae8f23fadde299ad5307f5be58 (patch) | |
tree | 0104c9eef164235aa5ab05b126c8f63e52fb8624 /static/mauve_utils.js | |
parent | 0c88fcc91db1b003cd5d5311f62700c7867b4099 (diff) |
Big commit
--HG--
rename : views/please_authenticate.haml => views/login.haml
Diffstat (limited to 'static/mauve_utils.js')
-rw-r--r-- | static/mauve_utils.js | 152 |
1 files changed, 13 insertions, 139 deletions
diff --git a/static/mauve_utils.js b/static/mauve_utils.js index 2a14dc2..8a4a9db 100644 --- a/static/mauve_utils.js +++ b/static/mauve_utils.js @@ -1,150 +1,24 @@ -// rather simple first stab at automating image rollovers - any image with -// a class of auto_hover will set its source to be the original name + _hover.png -// when rolled over, and back again when the mouse moves away. -// -// need to initialise by calling addAutoHover() after document has loaded. -// -function addAutoHover() { - $$('img.auto_hover').each(function(image) { - image.observe('mouseover', function(event) { - image.src = image.src.gsub(".png", "_hover.png"); - }); - image.observe('mouseout', function(event) { - image.src = image.src.gsub("_hover.png", ".png"); - }); - preload = new Image(); - preload.src = image.src.gsub(".png", "_hover.png"); - }); -}; -function addRefresh() { - updater1 = new Ajax.PeriodicalUpdater("alert_summary", "/_alert_summary", - { method: 'get', frequency: 120 }); - updater2 = new Ajax.PeriodicalUpdater("alert_counts", "/_alert_counts", - { method: 'get', frequency: 120 }); -} +// Controls the showing of details on alerts. -// Pop up the big white box at the top when something goes wrong, scroll so -// user can see it. -// -function reportError(message) { - $('errors_list').insert('<li>'+message+'</li>'); - $('errors').show(); - $('errors').scrollTo(); +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; + } } -// Hide the big white box again -// -function clearErrors() { $('errors').hide(); } -// Wrapper around reportError to report an error in updating a particular -// alert. -// -function acknowledgeFailed(id, message) { - if (message) - reportError("<strong>Couldn't update alert "+id+":</strong> "+message); - else - reportError("<strong>Couldn't update alert "+id+"</strong>"); +function is_daytime_hour(d) { + return (d.getHours() => 8 and d.getHours() <= 17); } -// Updates the page from a JSON representation of a particular alert. -// -function updateAlert(alert) { - var strip = $('alert_'+alert.id); - if (!strip) { - reportError("Alert "+id+" not rendered - bug?"); - return; - } - - image = strip.down(".acknowledge img"); - image.src = alert.acknowledged_at ? - "/images/acknowledge_acknowledged.png" : - "/images/acknowledge_unacknowledged.png" - - if (strip.down(".source")) - strip.down(".source").update(alert.source); - if (strip.down(".subject")) - strip.down(".subject").update(alert.subject); - if (strip.down(".summary") && strip.down(".summary").down()) - strip.down(".summary").down().update(alert.summary); - strip.next().update(alert.detail); - - if (alert.acknowledged_at) - strip.next().hide(); -} -// called when user hits the acknowledge button for an alert - makes a callback -// to the server to communicate the change, and updates the button -// appropriately. -// -function toggleAcknowledge(id) { - updater = new Ajax.Request('/alert/'+id+'/acknowledge', { - - method: 'post', - - // ignored by server, see http://www.ruby-forum.com/topic/162976 for why - postBody: 'x', - - onFailure: function(xhr) { acknowledgeFailed(id, "Failure - "+xhr.statusText); }, - - onException: function(xhr, ex) { acknowledgeFailed(id, Dumper(ex)); }, - - onSuccess: function(xhr) { - if (xhr.status == 200) { - content_type = xhr.getResponseHeader("Content-Type"); - if (content_type != "application/json") { - acknowledgeFailed(id, "Got "+content_type+" not application/json from server"); - } else { - updateAlert(xhr.responseText.evalJSON()); - } - } else { - acknowledgeFailed(id, "Connection problem"); - } - } - }); -}; +function next_working_hour(d) { -// Controls the showing of details on alerts. -function toggleDetailView(id) { - updater = new Ajax.Request('/alert/'+id+'/toggleDetailView', { - method: 'post', - postBody: 'x', - onFailure: function(xhr) { acknowledgeFailed(id, "Failure - "+xhr.statusText); }, - onException: function(xhr, ex) { acknowledgeFailed(id, Dumper(ex)); }, - onSuccess: function(xhr) { - if (xhr.status == 200) { - content_type = xhr.getResponseHeader("Content-Type"); - if (content_type != "application/json") { - acknowledgeFailed(id, "Got "+content_type+" not application/json from server"); - } else { - //updateAlert(xhr.responseText.evalJSON()); - } - } else { - acknowledgeFailed(id, "Connection problem"); - } - } - }); } - -// Controls the showing of folding on alerts. -function toggleFoldingView(subject) { - updater = new Ajax.Request('/alert/fold/'+subject, { - method: 'post', - postBody: 'x', - onFailure: function(xhr) { acknowledgeFailed(subject, "Failure - "+xhr.statusText); }, - onException: function(xhr, ex) { acknowledgeFailed(subject, Dumper(ex)); }, - onSuccess: function(xhr) { - if (xhr.status == 200) { - content_type = xhr.getResponseHeader("Content-Type"); - if (content_type != "application/json") { - acknowledgeFailed(subject, "Got "+content_type+" not application/json from server"); - } else { - //updateAlert(xhr.responseText.evalJSON()); - } - } else { - acknowledgeFailed(subject, "Connection problem"); - } - } - }); -} |