Ignore:
Timestamp:
07/12/12 11:34:27 (12 years ago)
Author:
thiago
Message:

Ticket #2951 - Criterios e nova mensagem agora com alerta.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sandbox/2.4.2-expresso1/expressoMail1_2/js/main.js

    r6753 r6765  
    1010var checkAlarmsFilter = false; 
    1111 
     12var auxNotificationCriteriaVetor = []; 
     13var auxNotification; 
     14 
    1215var notifyNewMessage = []; 
     16var notifyNewMessageFilter = []; 
    1317 
    1418var dynamicPersonalContacts = new Array(); 
     
    558562 
    559563//here 
    560  
     564var window_focus; 
    561565function Notifier() {} 
    562566 
     567function refreshCriteria(){ 
     568        if(auxNotificationCriteriaVetor.length > 0){ 
     569                for(var i=0; i<auxNotificationCriteriaVetor.length; i++){ 
     570                        auxNotificationCriteriaVetor[i].cancel(); 
     571                } 
     572        } 
     573} 
     574function refreshNewMsg(){ 
     575        if(auxNotification){ 
     576                auxNotification.cancel(); 
     577                notifyNewMessage = []; 
     578        } 
     579} 
     580 
    563581$(document).ready( function(){ 
     582 
     583        $(window).focus(function() { 
     584                window_focus = true; 
     585        }).blur(function() { 
     586                window_focus = false; 
     587        }); 
    564588         
    565     // Returns "true" if this browser supports notifications. 
    566589    Notifier.prototype.HasSupport = function() { 
    567590      if (window.webkitNotifications)  
     
    572595    } 
    573596 
    574     // Request permission for this page to send notifications. If allowed, 
    575     // calls function "cb" with true. 
    576597    Notifier.prototype.RequestPermission = function(cb) { 
    577598      window.webkitNotifications.requestPermission(); 
    578599    } 
    579600 
    580     // Popup a notification with icon, title, and body. Returns false if 
    581     // permission was not granted. 
    582601    Notifier.prototype.Notify = function(icon, title, body) { 
    583602      if (window.webkitNotifications.checkPermission() == 0) { 
     
    594613    $(function() { 
    595614                var notifier = new Notifier(); 
    596                 /*if(notifier.HasSupport){ 
    597                         alert("Seu navegador não dá suporte!"); 
    598                         //firefox/downloads/latest/221523/addon-221523-latest.xpi?src=dp-btn-primary 
    599                 }*/ 
    600615                 
    601616                if (window.webkitNotifications.checkPermission() != 0){ 
     
    611626} 
    612627 
    613 var auxNotification; 
    614  
    615 function refresh(alert_new_msg, notification){ 
     628function notificationFilter(data, notifyCriteria){ 
     629         
     630        if(parseInt(notifyCriteria)  && data.length > 0 && !window_focus ){ 
     631         
     632                var howManyCriteria = $('div.gray.filtersDeadline .message-list li').length; 
     633                var differenceOfNewCriteria = data.length - howManyCriteria; 
     634                 
     635                if(differenceOfNewCriteria > 0){ 
     636                        for(var i=data.length - differenceOfNewCriteria; i < data.length; i++){ 
     637                 
     638                        notificationCriteriaVetor = webkitNotifications.createNotification("","Critério de filtro",data[i].from+" - "+data[i].subject); 
     639                        notificationCriteriaVetor.onclick = function(){ 
     640                                window.focus(); 
     641                                this.cancel(); 
     642                        }; 
     643                         
     644                        notificationCriteriaVetor.show(); 
     645                        auxNotificationCriteriaVetor.push(notificationCriteriaVetor); 
     646                        } 
     647                } 
     648         
     649        } 
     650 
     651} 
     652 
     653function refresh(alert_new_msg, notifyPermission){ 
     654 
     655        if(window_focus){ 
     656                setTimeout('refreshCriteria()', 5000); 
     657                setTimeout('refreshNewMsg()', 5000); 
     658        } 
    616659 
    617660        getFromAlertRules(); 
    618661        var handler_refresh = function(data){ 
    619                 if(checkAlarmsFilter){ 
    620                         handlerMessageFilter = function (data) { 
     662                handlerMessageFilter = function (data) { 
     663                        notificationFilter(data, notifyPermission); 
     664                        if(checkAlarmsFilter){ 
    621665                                alarmFollowupflagged('filtersAlarms', data); 
    622666                        } 
    623                         /* Busca  nas pastas indexadas para ver se há novas mensagens com a flag $FilteredMessage */ 
    624                         cExecute ("$this.imap_functions.getFlaggedAlertMessages&folders="+fromRules, handlerMessageFilter); 
    625                 } 
    626                 checkAlarmsFilter = true; 
     667                        checkAlarmsFilter = true; 
     668                         
     669                } 
     670                /* Busca  nas pastas indexadas para ver se há novas mensagens com a flag $FilteredMessage */ 
     671                cExecute ("$this.imap_functions.getFlaggedAlertMessages&folders="+fromRules, handlerMessageFilter); 
     672 
    627673                if(data['msg_range_end']) 
    628674                        if(data['msg_range_end'] > 0) 
     
    766812                                select_msg("null","reload_msg","null"); 
    767813                 
    768                         if(parseInt(alert_new_msg) && data.new_msgs > 0) 
     814                        if(parseInt(alert_new_msg) && data.new_msgs > 0 && window_focus) 
    769815                                alert(data['new_msgs'] > 1 ? get_lang("You have %1 new messages", data['new_msgs']) + "!" : get_lang("You have 1 new message") +"!"); 
    770816                         
    771817                         
    772                         if(parseInt(notification)  && (data.new_msgs > 0 || notifyNewMessage.length > 0) ){ 
     818                        if(parseInt(notifyPermission)  && (data.new_msgs > 0 || notifyNewMessage.length > 0) && !window_focus ){ 
    773819                         
    774                         for(var i=0; i<data.length; i++){ 
     820                                for(var i=0; i<data.length; i++){ 
    775821                                        notifyNewMessage.push(true); 
    776822                                } 
     
    782828                                                notifyNewMessage = []; 
    783829                                        }; 
     830                                         
     831                                        notification.onclose = function(){ 
     832                                                notifyNewMessage = []; 
     833                                        } 
    784834                                         
    785835                                        if(auxNotification) 
Note: See TracChangeset for help on using the changeset viewer.