Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function capitalizeFirstLetter(string) {
- return string.charAt(0).toUpperCase() + string.slice(1);
- }
- $(async function() {
- $('#notificationBell').hide();
- $('#loader').show();
- let town;
- if (environment.login_name.indexOf("_") !== -1) {
- town = '&town='+capitalizeFirstLetter(environment.login_name.split('_')[0])
- }
- else{
- town = ''
- }
- let previousTotal = localStorage.getItem('previousTotal') ? parseInt(localStorage.getItem('previousTotal') - 1) : 0;
- let soundEnabled = false;
- function updateEventData() {
- $.ajax({
- url: environment.base_url+"/"+'?do=api&fn=last_statistic'+town,
- type: 'GET',
- dataType: "json",
- success: function(data) {
- let eventData = data.rows[0]
- var eventList = $('#eventList');
- eventList.empty();
- eventList.append('<li>'+i18next.t("Power Failure")+': ' + eventData.PowerFailureCount + '</li>');
- eventList.append('<li>Device Alarm: ' + eventData.EquipmentFailureCount + '</li>');
- eventList.append('<li>SIP: ' + eventData.SipFailureCount + '</li>');
- eventList.append('<li>IP: ' + eventData.IpFailureCount + '</li>');
- eventList.append('<li>Time Alert Count: ' + eventData.TimeAlertFailureCount + '</li>');
- eventList.append('<li>Controller Count: ' + eventData.ControllerFailureCount + '</li>');
- eventList.append('<li>Door Open Count: ' + eventData.DoorOpenCount + '</li>');
- eventList.append('<li>Sync Failure Count: ' + eventData.SyncFailureCount + '</li>');
- const total = eventData.PowerFailureCount + eventData.EquipmentFailureCount + eventData.SipFailureCount + eventData.IpFailureCount + eventData.TimeAlertFailureCount + eventData.ControllerFailureCount + eventData.DoorOpenCount + eventData.SyncFailureCount;
- $('#eventCount').text(total)
- $('#loader').hide();
- $('#notificationBell').show();
- if(total > 100){
- $('.notification-container').addClass('large')
- }
- console.log(total,previousTotal)
- if (total > previousTotal && soundEnabled) {
- $('#notificationSound')[0].play();
- }
- previousTotal = total;
- localStorage.setItem('previousTotal', previousTotal);
- }
- });
- }
- setInterval(updateEventData, 2000);
- $('#eventCount').click(function() {
- $('#eventDropdown').toggle();
- });
- $('#notificationBell').click(function() {
- soundEnabled = true;
- $('#notificationBell').removeClass('disabled').addClass('active');
- });
- $(document).click(function(event) {
- if (!$(event.target).closest('#eventCount').length) {
- if ($('#eventDropdown').is(":visible")) {
- $('#eventDropdown').hide();
- }
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement