Js to populate not checked alerts in controlbar.

This commit is contained in:
Mikaël Ates 2015-11-09 16:32:42 +01:00
parent 5d0e16e26f
commit e2e33b8bf9
1 changed files with 96 additions and 0 deletions

View File

@ -19,6 +19,10 @@
(function($) {
$(function() {
var
_alerts_not_checked_url = "/alerts/livedata_provider/episodes_not_checked?";
/*
Common settings
*/
@ -27,6 +31,8 @@
window.location.href=$(this).attr('target');
});
$("select").selectmenu();
$('div#controlbar').hide();
$('div#content-1').css({height: "100%"});
/*
Refresh datetime in header
@ -57,5 +63,95 @@
}
},
});
var _after;
function _build_alert_block(alert){
var
seq_id = alert[0],
level = alert[3][0],
metric = alert[3][1],
operator = alert[3][2],
threshold = alert[3][3],
duration = alert[4],
start_date = alert[1],
end_date = alert[2],
checked = alert[6],
id = alert[7],
patient_id = alert[8],
patient_display_name = alert[9],
patient_monitoring_place = alert[10];
content = '<div class="alert-message '+ level.toLowerCase()
+ '" patient-id="' + patient_id + '">'
+ '<p><span id="name">' + patient_display_name + '</span></p>'
+ '<p><span id="location">' + patient_monitoring_place + '</span></p>'
+ '<p><span id="name">';
if ( metric == 'HR' ){
content += '<i class="fa fa-heart"></i>';
} else if ( metric == 'T' ){
content += '<i class="wi wi-thermometer-exterior"></i>';
} else {
content += '<i class="fa fa-question"></i>';
}
content += ' ' + operator + ' ' + threshold
+ '</span></p>'
+ '</div>';
return content;
};
function _refresh_all_alerts(){
var target = _alerts_not_checked_url;
if (_after) {
/* Encode date in iso format */
target += $.param({after: _after}) + '&'
}
target = UTILS.fresh_query(target);
var not_checked = [];
function get_not_checked(target) {
return $.ajax({
type: 'Get',
url: target,
success: function(data) {
not_checked = data.slice();
},
error: function() {
UTILS.show_message(gettext("Database offline."));
}
})
}
function run(){
$.when(get_not_checked(target)).done(function(a1){
var content = ''
if ( not_checked.length ){
_after = not_checked[0][2];
for ( var i = 0; i < not_checked.length; i++ ) {
content += _build_alert_block(not_checked[i]);
}
$('div#controlbar').empty();
$('div#controlbar').append(content);
$('div#content-1').animate({
height: "88%",
}, 300, "linear", function() {
$('div#controlbar').fadeIn();
}
);
} else {
$('div#controlbar').fadeOut(500, function(){
$('div#content-1').animate({
height: "100%",
}, 300, "linear");
});
}
});
}
run()
setTimeout(function(){
_refresh_all_alerts();
}, 2000);
};
_refresh_all_alerts();
$(document).on('click', 'div.alert-message', function(e) {
window.location.href = '/patient/' + $(this).attr('patient-id');
});
})
})(jQuery);