/**
* EMail_Log Manager
*
* @category Final User Manager
* @package WSA/Email/JS
* @version 1.2
* @author Rodrigo Moraes Orph <rodrigo.orph@gmail.com>
* @license Copyright http://www.overflow.biz/
*
*/
var _is_debug = true; // debug switch
var _ajax=[]; // global XMLHttpRequest handler
// support functions
function _dbg(x){
if (_is_debug) {
if (window.console && window.console.firebug) {
console.log(x);
}
}
}
function _ls(x) { // v1.51
/*
@param: (bool) x , 1 = loading, 0 = complete
*/
var r=0;
// check ajax requests
for (var i in _ajax) { // http://www.w3.org/TR/XMLHttpRequest/ ref 4.5
if (_ajax[i].readyState != 4 && _ajax[i].readyState != 0) {
r=1;
break;
}
}
/*
When r && r != x means that there still a query going on due bug or
if there's another query in the background script is trying to close it
so we delay the check using a timeout, check will repeat itself until
the pending request is over, and then finally change the ticker.
-- 100628
*/
if (r && r != x) {
setTimeout('_ls('+x+');',500);
x=r; // r is always more accurate than x
}
if (r == 0) // there's no pending request, clear the array to free memory
_ajax=[];
if (!x) {
/*
With the _ajax engine we now, finally, can have ticker animated proprietly
without the need to put timers and such. Obviously IE users will not see
this, since they suck.
-- 100702
*/
if (!$.browser.msie) {
$("#ld").fadeOut(2000);
} else {
$("#ld").hide();
}
} else {
$("#ld").show();
}
}
// main functions
function _ld_list(page) {
if (typeof page == 'undefined')
page = 0;
_ajax[_ajax.length] = $.ajax({data:"d="+_enc($.toJSON({"q":"list","page":page})),success:function(r,s) {
if (r.error) {
alert(r.error);
} else {
var i = 0,
pg = "",
entries = "";
for (;i < r.r.pages;i++)
pg += i == page ?
parseInt(i + 1)+" "
:
"<a href='#' onClick='return _ld_list(" + i + ");'>" + parseInt(i + 1) + "</a> "
;
$.each(r.r.items,function(i,f) {
entries += "<tr" + (i % 2 == 1 ? " class='alt'" : "") + "><td>" + f.entry + "</td><td>" + f.size + " bytes</td><td>" + f.items + "</td><td><a href='#' onClick='return _ld_date(\""+f.entry+"\");'>Listar</a></tr>"
});
entries = entries != "" ?
"<table border=0 cellpadding=0 cellspacing=0 width=100%><thead><tr><td>Data</td><td>Tamanho</td><td>E-Mails</td><td>Opções</td></tr></thead><tbody>" + entries + "</tbody></table>"
:
"Sem resultados"
;
pg = pg == "" || pg == "1 " ?
""
:
"Páginas: " + pg
;
$("#lst").show();
$("#read").hide();
if (pg == "")
$("#pages").hide();
else
$("#pages").show().html(pg);
$("#entries").html(entries);
}
}});
return false;
}
function _ld_date(date, page) {
if (typeof page == 'undefined')
page = 0;
_ajax[_ajax.length] = $.ajax({data:"d="+_enc($.toJSON({"q":"list_date","date": date, "page":page})),success:function(r,s) {
if (r.error) {
alert(r.error);
} else {
var i = 0,
pg = "",
entries = "";
for (;i < r.r.pages;i++)
pg += i == page ?
parseInt(i + 1)+" "
:
"<a href='#' onClick='return _ld_date(\"" + date + "\"," + i + ");'>" + parseInt(i + 1) + "</a> "
;
$.each(r.r.items,function(i,f) {
f.from = _dec(f.from);
f.to = _dec(f.to);
f.subject = _dec(f.subject);
f.time = _dec(f.time);
f.read = _dec(f.read).substr(0,1);
entries += "<tr class='" + (i % 2 == 1 ? "alt" : "") + (f.read == 0 ? " unread" : "") + "'><td>" + f.time + "</td><td>" + f.from + "</td><td>" + f.to + "</td><td>" + f.subject + "</td><td><a href='#' onClick='return _ld_entry(\""+f.line+"\",\"" + date + "\", " + page + ");'>Ver</a></tr>"
});
entries = entries != "" ?
"<table border=0 cellpadding=0 cellspacing=0 width=100%><thead><tr><td>Enviado</td><td>De</td><td>Para</td><td>Assunto</td><td>Opções</td></tr></thead><tbody>" + entries + "</tbody></table>"
:
"Sem resultados"
;
pg = pg == "" || pg == "1 " ?
""
:
" | Páginas: " + pg
;
$("#lst").show();
$("#read").hide();
$("#pages").show().html("<a href='#' onClick='return _ld_list();'>Voltar</a>" + pg);
$("#entries").html(entries);
}
}});
return false;
}
function _ld_entry(line, date, page) {
if (typeof page == 'undefined')
page = 0;
_ajax[_ajax.length] = $.ajax({data:"d="+_enc($.toJSON({"q":"read","date": date, "line": parseInt(parseInt(line) + 1)})),success:function(r,s) {
if (r.error) {
alert(r.error);
} else {
r.r.from = _dec(r.r.from);
r.r.to = _dec(r.r.to);
r.r.subject = _dec(r.r.subject);
r.r.body = _dec(r.r.body);
r.r.time = _dec(r.r.time);
$("#lst").hide();
$("#read").show();
$("#read").html("<div class='header'><a href='#' onClick='return _ld_date(\"" + date + "\", \"" + page + "\");'>Voltar</a></div><table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td>Data:</td><td> " + date + " " + r.r.time + "</td></tr><tr><td>De:</td><td><a href='mailto:" + r.r.from + "'>" + r.r.from + "</a></td></tr><tr><td>Para:</td><td><a href='mailto:" + r.r.to + "'>" + r.r.to + "</a></td></tr><tr><td>Assunto:</td><td>" + r.r.subject + "</td></tr><tr><td colspan=2>" + r.r.body + "</td></tr></table>");
}
}});
return false;
}
// global functions
$(document).ready(function(){
$.ajaxSetup({
global:true,
type:"POST",
dataType:'json',
cache:false,
async:true,
timeout:10000,
scriptCharset:"UTF-8",
beforeSend:function(){
_ls(1);
},
complete:function(){
_ls(0);
},
error:function(obj,txt,err){
_dbg("ajax error:"+txt+" thrown error:"+err);
}
});
_ld_list();
});
|