Changeset 61 for trunk/Sillaj-widget

Show
Ignore:
Timestamp:
05/16/07 20:33:25 (3 years ago)
Author:
johan
Message:

Selected date is same as before only 6 hours into new day, after 6 hours the current date is set..
Fixes and changes in login timeout. PHP by default times session out after 1440 secs, but this is configurable (altough not from gui..) now..

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/Sillaj-widget/Sillaj.wdgt/sillaj.js

    r60 r61  
    11var flipper; 
    22 
    3 var conf = {'baseURL':'', 'username':'', 'password':'', 'round':1}; 
     3var conf = {'baseURL':'', 'username':'', 'password':'', 'round':1, 
     4                                'php_session_timeout':1440}; // the php_session_timeout var should be same as session.gc_maxlifetime in php.ini. Defaults to 1440 seconds 
    45 
    56var loggedIn = null; 
     
    5152} 
    5253 
    53 function postEvent(data, cb, recursive) 
    54 { 
    55         login(); 
    56         doRequest("POST", "index.php", data, function(c) 
    57                 { 
    58                         var r=c.responseText; 
    59                         if(r.match(/login/)) 
    60                         { 
    61                                 // not logged in... 
    62                                 if(recursive == true) 
    63                                 { 
    64                                         // Failed to post event due to login failure... 
    65                                         document.getElementById('status').innerHTML+="Failed to post event!"; 
    66                                 } 
    67                                 else 
    68                                 { 
    69                                         login(true, function(){ 
    70                                                 postEvent(data, cb, true);      // try again 
    71                                                 }); 
    72                                 } 
    73                         }else 
    74                         { 
    75                                 // assume OK 
    76                                 if(cb) 
    77                                         cb(); 
    78                         } 
    79                 } 
    80         ); 
    81 } 
    82  
    8354function login(force, cb) 
    8455{ 
    85         if(force == false && (loggedIn != null && (new Date()).getTime()/1000 < loggedIn.getTime()/100 + 3600)) 
     56        if(force == false && (loggedIn != null && (new Date()).getTime()/1000 < loggedIn.getTime()/1000 + conf['php_session_timeout'])) 
    8657        { 
    8758                if(cb) 
     
    10677} 
    10778 
     79function postEvent(data, cb, recursive) 
     80{ 
     81        login(false, function() 
     82                { 
     83                        doRequest("POST", "index.php", data, function(c) 
     84                                { 
     85                                        var r=c.responseText; 
     86                                        if(r.match(/login/)) 
     87                                        { 
     88                                                // not logged in... 
     89                                                if(recursive == true) 
     90                                                { 
     91                                                        // Failed to post event due to login failure... 
     92                                                        document.getElementById('status').innerHTML+="Failed to post event!"; 
     93                                                } 
     94                                                else 
     95                                                { 
     96                                                        login(true, function(){ 
     97                                                                postEvent(data, cb, true);      // try again 
     98                                                                }); 
     99                                                } 
     100                                        }else 
     101                                        { 
     102                                                // assume OK 
     103                                                if(cb) 
     104                                                        cb(); 
     105                                        } 
     106                                } 
     107                        ); 
     108                } 
     109        ); 
     110} 
     111 
    108112function updateProjects() 
    109113{ 
     
    191195                if(n == lastSel)  
    192196                        newSel = index-1; 
     197        } 
     198 
     199        if(lastSel != null && newSel != 0) 
     200        { 
     201                // Get date of lastSel and compare it to current. if more than 6 hours diff, ignore lastSel 
     202                var dd = sd.options[lastSel].value; 
     203                var d = Date.parse(d) 
     204                if(d.getTime() + 3600*6*1000 < (new Date()).getTime()) 
     205                        newSel = 0; // set current date 
    193206        } 
    194207        sd.selectedIndex = newSel; 
     
    245258 
    246259        var m = d.getMinutes().toString();  
    247         m = Math.round(m / conf.round) * conf.round; 
     260        m = ""+(Math.round(m / conf.round) * conf.round); 
    248261        if (m.length == 1) 
    249262                m = "0" + m;