Dedicated module for common js code.

This commit is contained in:
Mikaël Ates 2015-11-03 18:53:01 +01:00
parent afb21954af
commit 7ebdeab35a
1 changed files with 4 additions and 208 deletions

View File

@ -17,209 +17,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
patient_list page specific code
*/
function patient_list(){
/*
Patient searching
*/
var patient_enabled = true;
function show_letters() {
$('.letter').each(function(){
$(this).show();
});
};
function hide_letters() {
$('.letter').each(function(){
($(this).children('div.list').children(':visible').length == 0) ? $(this).hide() : $(this).show();
});
};
function filter_patients(input) {
show_letters();
$('.patient-block').each(function(){
var text = $(this).attr('display-name').toLowerCase();
(text.indexOf(input) == 0
& ((patient_enabled & $(this).hasClass("enabled"))
| (!(patient_enabled) & $(this).hasClass("disabled"))))
? $(this).fadeIn() : $(this).hide();
});
hide_letters();
};
$('input#search').keyup(function(){
var input = $(this).val().toLowerCase();
if (input != '') {
$('i#filter-patient-eraser').show();
} else {
$('i#filter-patient-eraser').hide();
}
filter_patients(input);
});
$('i#filter-patient-eraser').click(function() {
$('input#search').val("");
$('i#filter-patient-eraser').hide();
filter_patients("");
});
$('span#filter-patient-enabled').click(function() {
if($(this).hasClass("enabled")) {
$(this).switchClass("enabled", "disabled", 0);
$(this).children().first().switchClass("fa-folder-open enabled", "fa-folder disabled", 0);
$(this).children().last().switchClass("fa-folder disabled", "fa-folder-open enabled", 0);
patient_enabled = false;
show_letters();
var input = $('input#search').val().toLowerCase();
filter_patients(input);
hide_letters();
} else {
$(this).switchClass("disabled", "enabled", 0);
$(this).children().first().switchClass("fa-folder disabled", "fa-folder-open enabled", 0);
$(this).children().last().switchClass("fa-folder-open enabled", "fa-folder disabled", 0);
patient_enabled = true;
show_letters();
var input = $('input#search').val().toLowerCase();
filter_patients(input);
hide_letters();
}
});
$('i#filter-patient-eraser').hide();
$("div.patient-block.disabled").hide();
hide_letters();
/*
Open/Close patient file
Don't try to grab event on i. It would mean
cheat with stopPropagation and preventDefault to avoid
the redirect due to the parent div click event.
*/
$('div.patient-block').click(function(e) {
var target = $(e.target);
if (target.is("i") & target.hasClass("patients-enabler")){
var value = '';
if (target.hasClass('disabled')) {value = 'on';}
$.ajax({
type: 'post',
url: target.attr('action'),
data: {enabled: value},
success: function() {
if(value == ''){
target.switchClass("fa-folder-open enabled", "fa-folder disabled", 0);
target.parent().switchClass("enabled", "disabled", 0);
target.next().addClass("disabled");
} else {
target.switchClass("fa-folder disabled", "fa-folder-open enabled", 0);
target.parent().switchClass("disabled", "enabled", 0);
target.next().removeClass("disabled");
};
target.parent().fadeOut("slow", function(){
hide_letters();
UTILS.show_message(gettext("Patient record updated."));
});
},
error: function(xhr, ajaxOptions, thrownError) {
UTILS.show_message(gettext("Patient record not updated !"));
}
});
} else {
window.location.href = $(this).attr('action');
}
});
};
/*
patient_detail page specific code
*/
function patient_detail() {
/*
Last visited tab
*/
$("div#tabs").tabs();
var tab_active;
$('a.patient-tab').click(function() {
$.cookie('patient-last-tab', $(this).attr('id'), { path: location.pathname });
tab_active = $(this).attr('id');
if ( tab_active == 'tab-alert' ) {
ALERTS.refresh_alerts();
} else {
ALERTS.stop_refresh_alerts();
}
if ( tab_active == 'tab-dashboard' ) {
DASHBOARD.refresh(true);
} else {
DASHBOARD.stop_refresh(true);
}
});
if ($.cookie('patient-last-tab')) {
tab_active = $.cookie('patient-last-tab');
$('a#' + $.cookie('patient-last-tab')).click();
};
/*
Open/close patient file
$(this) must be referenced for used in ajax callback
functions : http://bugs.jquery.com/ticket/7624
*/
$('i.patient-enabler').click(function() {
var target = $(this);
var value = '';
if (target.hasClass('disabled')) {value = 'on';}
$.ajax({
type: 'post',
url: target.attr('action'),
data: {enabled: value},
success: function() {
if(value == ''){
target.switchClass("fa-folder-open enabled", "fa-folder disabled", 0);
} else {
target.switchClass("fa-folder disabled", "fa-folder-open enabled", 0);
};
UTILS.show_message(gettext("Patient record updated."));
},
error: function(xhr, ajaxOptions, thrownError) {
UTILS.show_message(gettext("Patient record not updated !"));
}
});
});
/*
Refresh open events figures in identification bar
*/
ALERTS.refresh_alerts_stats(true);
/*
Alert tab
*/
/* At beginning hide titles, if episodes they'll be displayed in fine */
$('div#running-alerts span#running').hide();
$('div#closed-alerts span#closed').hide();
};
/*
all_alerts page specific code
*/
function all_alerts() {
/* At beginning hide titles, if episodes they'll be displayed in fine */
$('div#running-alerts span#running').hide();
$('div#closed-alerts span#closed').hide();
/* Run alert stats updating */
ALERTS.refresh_alerts_stats();
/* Run alert table updating */
ALERTS.refresh_alerts();
};
/*
Load in every page
*/
$(document).ready(function(){
(function($) {
$(function() {
/*
Common settings
*/
@ -263,8 +62,5 @@ $(document).ready(function(){
Active li corresponding to the page visited
*/
$('ul#menu li a[href="' + location.pathname + '"]').parent().addClass('active');
// $('div#content-1').css({'height': '100%'});
// $('div#alerts').css({'height': '94%'});
});
})
})(jQuery);