aboutsummaryrefslogtreecommitdiff
path: root/static/mauve.js
blob: 0cc32ec7117e5602caafa8a317679f5be3391767 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*
 * This contains all the 'clever' javascript used on the page.
 */
var mouse_is_inside = false;

/*
try {
  $("#myselector").click (function () {});    //my jQuery code here
} catch (e) {
  //this executes if jQuery isn't loaded
  alert(e.message 
      + "\nCould be a network error leading to jquery not being loaded!\n"
      + "Reloading the page.");
  window.location.reload(true);
}
*/

////////////////////////////////////////////////////////////////////////////////
// Treeview data.
$(document).ready(function(){
	$("#blackAck").treeview({
		control: "#treecontrolAck",
		persist: "cookie",
		cookieId: "treeview-black"
	});

});
$(document).ready(function(){
	$("#blackNew").treeview({
		control: "#treecontrolNew",
		persist: "cookie",
		cookieId: "treeview-black"
	});
});

$(document).ready(function(){

  ////////////////////////////////////////////////////////////////////////////////
  // This allows pop! to do its thing, used for details.
  $.pop(); 

  ////////////////////////////////////////////////////////////////////////////////
  // Countdown code.
  
  /*
  // This binds to the timer that reloads the page every 300 seconds via callback.
  $('#reloadPage').countdown({until: +300, onExpiry: liftOff, format: 'MS'});

  // This is the callback that reloads the page.
  function liftOff() { 
    window.location.reload(true);
  }
  */


  ////////////////////////////////////////////////////////////////////////////////
  // Mouse outside of changeStatus form.
  // See url http://stackoverflow.com/questions/1403615/use-jquery-to-hide-div-when-click-outside-it
  $('.updateAlertStatus').hover(function(){ 
    mouse_is_inside=true; 
  }, function(){ 
    mouse_is_inside=false; 
  });
  $('body').mouseup(function(){ 
    if(! mouse_is_inside) 
    {
      //$(".updateAlertStatus").fadeOut(1000);
      //$('.darkMask').fadeOut(1000);
      $(".updateAlertStatus").hide();
      $('.darkMask').hide();
    }
  });
});

////////////////////////////////////////////////////////////////////////////////
// Acknowledge status functions.


////////////////////////////////////////////////////////////////////////////////
// Standards are there to be violated...
function mouseX(evt) {
  if (evt.pageX) return evt.pageX;
  else if (evt.clientX)
     return evt.clientX + (document.documentElement.scrollLeft ?
     document.documentElement.scrollLeft :
     document.body.scrollLeft);
  else return null;
}

////////////////////////////////////////////////////////////////////////////////
// Standards are there to be violated...
function mouseY(evt) {
  if (evt.pageY) return evt.pageY;
  else if (evt.clientY)
     return evt.clientY + (document.documentElement.scrollTop ?
     document.documentElement.scrollTop :
     document.body.scrollTop);
  else return null;
}

////////////////////////////////////////////////////////////////////////////////
// Shows the updateAlertStatus div where the mouse clicked and mask the rest of
// page.
function showAcknowledgeStatus (e, id, ackTime) {

  // Build the form.
  document.changeAlertStatusForm.AlertID.value = id;
  document.changeAlertStatusForm.AlertDefaultAcknowledgeTime.value = ackTime;
  var myselect=document.getElementById("sample");
  myselect.remove(0);
  str = returnTimeString(ackTime);
  myselect.add(new Option(str, ackTime, true, true), myselect.options[0])

  // Show the form.
  //leftVal = mouseX(e);
  leftVal = 2
  topVal = mouseY(e);
  $('.updateAlertStatus').css({left:leftVal,top:topVal}).fadeIn(500);
  $('.darkMask').css({height:$(document).height()}).show();
}

// Returns the default time. 
function returnTimeString (time) {
  hrs = time / 3600
  if (1 == hrs)
  {
    str = "1 hour"
  }
  else if (24 > hrs && 1 > hrs)
  {
    str = hrs + " hours"
  }
  else if (24 == hrs)
  {
    str = "1 day"
  }
  else if (24 < hrs && 168 > hrs)
  {
    str = hrs / 24 + " days"
  }
  else if (168 == hrs)
  {
    str = "1 week"
  }
  else 
  {
    str = hrs / 168 + " weeks"
  }
  return str + ", default."
}

////////////////////////////////////////////////////////////////////////////////
// Shows the updateAlertSatus div for group of alerts. 
function showBulkAcknowledgeStatus(e, ids, ackTime)
{
  for (i in ids) 
  {
    changeAcknowledgeStatusCall(ids[i], ackTime);
  }
  //window.location.reload(true);
  tmp = $('#firstAlert'+ids[0]);
  tmp.remove()
}

function changeAcknowledgeStatusCall (id, acknowledgedUntil) {
  $.post('/alert/acknowledge/'+id+'/'+acknowledgedUntil);
  tmp = $('#alert'+id)
  tmp.remove();
  tmp.appendTo('#blackAck');
}

////////////////////////////////////////////////////////////////////////////////
// Actually gets the alert updated and moves it to the right list.
// Note that id is a numberical ID of the alert.
// Note that acknowledgedUntil is a number of seconds. 
function changeAcknowledgeStatus (id, acknowledgedUntil) {
  if (-1 != id)
  {
    changeAcknowledgeStatusCall(id, acknowledgedUntil);
  }
  $(".updateAlertStatus").hide();
  $('.darkMask').hide();
}

////////////////////////////////////////////////////////////////////////////////
// Clears (aka trash aka delete) an alert.
// THIS IS NOT WHAT YOU WANT
// url http://stackoverflow.com/questions/95600/jquery-error-option-in-ajax-utility
// url http://stackoverflow.com/questions/377644/jquery-ajax-error-handling-show-custom-exception-messages
function clearAlert (id) {
  $.post('/alert/'+id+'/clear');
  $(".updateAlertStatus").hide();
  $('.darkMask').hide();
  tmp = $('#alert'+id)
  tmp.remove();
}

////////////////////////////////////////////////////////////////////////////////
// Raises (aka unacknowledge) an alert.
function raiseAlert (id) {
  $.post('/alert/'+id+'/raise');
  $(".updateAlertStatus").hide();
  $('.darkMask').hide();
  tmp = $('#alert'+id)
  tmp.remove();
  tmp.appendTo('#blackNew');
}


////////////////////////////////////////////////////////////////////////////////
// EOF