var $,disable_links,exports,request_json;$=jQuery;exports=this;exports.already_run=false;exports.setitems_url=setitems_url;disable_links=function(e){if(exports.inprogress)e.preventDefault();return 1;};request_json=function(){var row;row='<tr class="{{style}}_row"><td class="date_td">'+'<a href="/messages/detail/{{id}}">{{timestamp}}</a></td>'+'<td class="from_td"><a href="/messages/detail/{{id}}">{{from_address}}</a></td>'+'<td class="to_td"><a href="/messages/detail/{{id}}">{{to_address}}</a></td>'+'<td class="subject_td"><a href="/messages/detail/{{id}}">{{{subject}}}</a></td>'+'<td class="size_td"><a href="/messages/detail/{{id}}">{{size}}</a></td>'+'<td class="score_td"><a href="/messages/detail/{{id}}">{{sascore}}</a></td>'+'<td class="status_td"><a href="/messages/detail/{{id}}">{{status}}</a></td></tr>';$.ajax(location.pathname+'.json',{type:'GET',cache:false,dataType:'json',beforeSend:function(XHR,settings){return XHR.setRequestHeader("X-Last-Timestamp",exports.last_ts);},error:function(XHR,textStatus,errorThrown){var html;if(XHR.status===200)window.location=location.href;html=$.mustache(exports.errmsgbox,{msg:errorThrown||gettext('network connection failure, reconnecting in 60 seconds')});if($('#alertmsg').length){$('#alertmsg').empty();$('#alertmsg').remove();}return $('#heading').after(html);},success:function(data,textStatus,XHR){var alt,index,replacement,rows,selector,simg,statusimg,tmp;if($('#alertmsg').length){$('#alertmsg').empty();$('#alertmsg').remove();}if($('.notice').length)$('.notice').remove();if(data.items.length){rows=[];exports.last_ts=data.items[0].timestamp;$.each(data.items,function(i,n){var html;n.timestamp=BaruwaDateString(n.timestamp);html=$.mustache(row,n);return rows.push(html);});replacement=rows.join('');if((data.num_items!==data.items.length)&&exports.already_run){$('tbody tr:first').before(replacement);index=data.num_items-1;selector="tbody tr:gt("+index+")";$(selector).remove();}else $('tbody').empty().append(replacement);$('a').click(disable_links);}$('#inq a').text(data.inbound);$('#outq a').text(data.outbound);$('#smailtotal').text(data.totals[0]);if(data.totals[4])$('#sspamtotal').text(data.totals[4]);if(data.totals[2])$('#svirustotal').text(data.totals[2]);if(data.status){simg='active.png';alt=gettext('OK');}else{simg='inactive.png';alt=gettext('FAULTY');}tmp="{{media_url}}imgs/{{simg}}";statusimg=$.mustache(tmp,{media_url:exports.media_url,simg:simg});$('#statusimg').attr('src',statusimg).attr('alt',alt);return 1;},complete:function(XHR,textStatus){exports.inprogress=false;exports.already_run=true;exports.auto_refresh=setTimeout(request_json,60000);return 1;}});return 1;};$(document).ready(function(){exports.last_ts='';exports.inprogress=false;$('#spinner').ajaxStart(function(){exports.inprogress=true;return $(this).show();}).ajaxStop(function(){return $(this).hide();}).ajaxError(function(){return $(this).hide();});$('a').click(disable_links);exports.auto_refresh=setTimeout(request_json,60000);$('#num_items').change(function(){var n;n=$(this).val();return location.href=""+exports.setitems_url+"?n="+n;});return 1;});