$(document).ready(function(){ $.ajax({ "url":'/ajax/displayNotifications', "success":function(data){ var content = $.parseJSON(data); // Get the notifications var notifications = content.notifications; $("#notifcaitons_display_area").html(notifications); //Get the documents var documents = content.documents; $("#documents_display_area").html(documents); // Display modal if( notifications != '' || documents != '' ){ $("div#notifcations_display_modal").modal('show'); }else{ //Display Login odometer for PTO/TO if they log in the first time on the day showLoginOdometerReading(); } } }); }); // Display all related notifications to a user e.g. Admin, Facility Staff, PTO/TO function displayAllRelatedNotifications(btn){ var user_id = $("input[name=user_id]").val(); $.ajax({ "url":'/ajax/displayAllRelatedNotifications', "data" : { user_id : user_id }, "success":function(data){ var content = $.parseJSON(data); // Get the notifications var notifications = content.notifications; $("#notifcaitons_display_area2").html(notifications); //Get the documents var documents = content.documents; $("#documents_display_area2").html(documents); // Display modal $("div#notifcations_by_click_modal").modal('show'); } }); } //When notification board dismissed $("#notifcations_display_modal").on("hidden.bs.modal", function(e){ var isChecked = $("input#is_notification_read").prop('checked'); if( !isChecked ){ $("#notifcations_display_modal").modal('show'); }else{ //Display Login odometer for PTO/TO if they log in the first time on the day showLoginOdometerReading(); } }); function updateNotificationReadTime(btn){ var user_id = $("input[name=user_id]").val(); var isChecked = $("input#is_notification_read").prop('checked'); if(!isChecked ){ return false; }else{ $.ajax({ "url":'/ajax/updateNotificationReadingTime', "data" : { user_id : user_id }, "success":function(data){ } }); } } // When odometer reading modal dismissed $("#login_trunk_odometer_reading_modal").on("hidden.bs.modal", function(e){ var odometer = $.trim($("input[name=login_trunk_odometer_reading_modal_value]").val()); // get the odometer reading var user_id = $("input[name=user_id]").val(); if( odometer =='' || !$.isNumeric(odometer) || odometer < 0 ){ alert('Please enter a valid odometer reading.'); $("#login_trunk_odometer_reading_modal").modal('show'); }else{ $.ajax({ "url":'/ajax/updateLoginOdometerReading', "data" : { user_id : user_id, odometer : odometer }, "success":function(data){ if(data == 1){ toastr.success("Login odometer has been recorded successfully."); $("input[name=login_trunk_odometer_reading_modal_value]").val(''); }else{ toastr.error("Login odometer cannot be recorded for some reason. Please refresh the page and try again later."); } } }); } }); function showLoginOdometerReading(){ var user_level = $("input[name=user_access_level]").val(); var user_id = $("input[name=user_id]").val(); // Only displayed to PTO/TO if( user_level == 2 ){ $.ajax({ "url":'/ajax/checkLoginOdometerReading', "data" : { user_id : user_id }, "success":function(data){ if(data == 0) $("#login_trunk_odometer_reading_modal").modal('show'); } }); } return true; }