i18n/src/messenger/webim/js/164/users.js

28 lines
8.6 KiB
JavaScript
Raw Normal View History

/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
Ajax.PeriodicalUpdater=Class.create();
Class.inherit(Ajax.PeriodicalUpdater,Ajax.Base,{initialize:function(a){this.setOptions(a);this._options.onComplete=this.requestComplete.bind(this);this._options.onException=this.handleException.bind(this);this._options.onTimeout=this.handleTimeout.bind(this);this._options.timeout=5E3;this.frequency=this._options.frequency||2;this.updater={};this.update()},handleException:function(){this._options.handleError&&this._options.handleError("offline, reconnecting");this.stopUpdate();this.timer=setTimeout(this.update.bind(this),
1E3)},handleTimeout:function(){this._options.handleError&&this._options.handleError("timeout, reconnecting");this.stopUpdate();this.timer=setTimeout(this.update.bind(this),1E3)},stopUpdate:function(){if(this.updater._options)this.updater._options.onComplete=void 0;clearTimeout(this.timer)},update:function(){if(this._options.updateParams)this._options.parameters=this._options.updateParams();this.updater=new Ajax.Request(this._options.url,this._options)},requestComplete:function(a){try{var b=Ajax.getXml(a);
b?(this._options.updateContent||Ajax.emptyFunction)(b):this._options.handleError&&this._options.handleError("reconnecting")}catch(c){}this.timer=setTimeout(this.update.bind(this),this.frequency*1E3)}});
var HtmlGenerationUtils={popupLink:function(a,b,c,d,e,l,j){return'<a href="'+a+'"'+(j!=null?' class="'+j+'"':"")+' target="_blank" title="'+b+'" onclick="this.newWindow = window.open(\''+a+"', '"+c+"', 'toolbar=0,scrollbars=0,location=0,status=1,menubar=0,width="+e+",height="+l+",resizable=1');this.newWindow.focus();this.newWindow.opener=window;return false;\">"+d+"</a>"},generateOneRowTable:function(a){return'<table class="inner"><tr>'+a+"</tr></table>"},viewOpenCell:function(a,b,c,d,e,l,j,n){var l=
2,b=b+"?thread="+c,g="<td>";g+=e||d?HtmlGenerationUtils.popupLink(n||!d?b:b+"&viewonly=true",localized[e?0:1],"ImCenter"+c,a,640,480,null):'<a href="#">'+a+"</a>";g+="</td>";e&&(g+='<td class="icon">',g+=HtmlGenerationUtils.popupLink(b,localized[0],"ImCenter"+c,'<img src="'+webimRoot+'/images/tbliclspeak.gif" width="15" height="15" border="0" alt="'+localized[0]+'">',640,480,null),g+="</td>",l++);d&&(g+='<td class="icon">',g+=HtmlGenerationUtils.popupLink(b+"&viewonly=true",localized[1],"ImCenter"+
c,'<img src="'+webimRoot+'/images/tbliclread.gif" width="15" height="15" border="0" alt="'+localized[1]+'">',640,480,null),g+="</td>",l++);j!=""&&(g+='</tr><tr><td class="firstmessage" colspan="'+l+'"><a href="javascript:void(0)" title="'+j+'" onclick="alert(this.title);return false;">',g+=j.length>30?j.substring(0,30)+"...":j,g+="</a></td>");return HtmlGenerationUtils.generateOneRowTable(g)},banCell:function(a,b){return'<td class="icon">'+HtmlGenerationUtils.popupLink(webimRoot+"/operator/ban.php?"+
(b?"id="+b:"thread="+a),localized[2],"ban"+a,'<img src="'+webimRoot+'/images/ban.gif" width="15" height="15" border="0" alt="'+localized[2]+'">',720,480,null)+"</td>"}};Ajax.ThreadListUpdater=Class.create();
Class.inherit(Ajax.ThreadListUpdater,Ajax.Base,{initialize:function(a){this.setOptions(a);this._options.updateParams=this.updateParams.bind(this);this._options.handleError=this.handleError.bind(this);this._options.updateContent=this.updateContent.bind(this);this._options.lastrevision=0;this.threadTimers={};this.delta=0;this.t=this._options.table;this.periodicalUpdater=new Ajax.PeriodicalUpdater(this._options)},updateParams:function(){return"since="+this._options.lastrevision+"&status="+this._options.istatus+
(this._options.showonline?"&showonline=1":"")},setStatus:function(a){this._options.status.innerHTML=a},handleError:function(a){this.setStatus(a)},updateThread:function(a){function b(a,b,c,d){if(a=CommonUtils.getCell(c,b,a))a.innerHTML=d}for(var c,d,e,l=!1,j=!1,n=!1,g=null,o=null,f=0;f<a.attributes.length;f++){var m=a.attributes[f];if(m.nodeName=="id")c=m.nodeValue;else if(m.nodeName=="stateid")d=m.nodeValue;else if(m.nodeName=="state")e=m.nodeValue;else if(m.nodeName=="canopen")j=!0;else if(m.nodeName==
"canview")l=!0;else if(m.nodeName=="canban")n=!0;else if(m.nodeName=="ban")g=m.nodeValue;else if(m.nodeName=="banid")o=m.nodeValue}f=CommonUtils.getRow("thr"+c,this.t);if(d=="closed")f&&this.t.deleteRow(f.rowIndex),this.threadTimers[c]=null;else{var m=NodeUtils.getNodeValue(a,"name"),s=NodeUtils.getNodeValue(a,"addr"),q=NodeUtils.getNodeValue(a,"time"),t=NodeUtils.getNodeValue(a,"agent"),r=NodeUtils.getNodeValue(a,"modified"),u=NodeUtils.getNodeValue(a,"message"),p="<td>"+NodeUtils.getNodeValue(a,
"useragent")+"</td>";g!=null&&(p="<td>"+NodeUtils.getNodeValue(a,"reason")+"</td>");n&&(p+=HtmlGenerationUtils.banCell(c,o));p=HtmlGenerationUtils.generateOneRowTable(p);a=CommonUtils.getRow("t"+d,this.t);n=CommonUtils.getRow("t"+d+"end",this.t);if(f!=null&&(f.rowIndex<=a.rowIndex||f.rowIndex>=n.rowIndex))this.t.deleteRow(f.rowIndex),f=this.threadTimers[c]=null;if(f==null){if(f=this.t.insertRow(a.rowIndex+1),f.className=g=="blocked"&&d!="chat"?"ban":"in"+d,f.id="thr"+c,this.threadTimers[c]=[q,r,d],
CommonUtils.insertCell(f,"name","visitor",null,null,HtmlGenerationUtils.viewOpenCell(m,this._options.agentservl,c,l,j,g,u,d!="chat")),CommonUtils.insertCell(f,"contid","visitor","center",null,s),CommonUtils.insertCell(f,"state","visitor","center",null,e),CommonUtils.insertCell(f,"op","visitor","center",null,t),CommonUtils.insertCell(f,"time","visitor","center",null,this.getTimeSince(q)),CommonUtils.insertCell(f,"wait","visitor","center",null,d!="chat"?this.getTimeSince(r):"-"),CommonUtils.insertCell(f,
"etc","visitor","center",null,p),d=="wait"||d=="prio")return!0}else this.threadTimers[c]=[q,r,d],f.className=g=="blocked"&&d!="chat"?"ban":"in"+d,b(this.t,f,"name",HtmlGenerationUtils.viewOpenCell(m,this._options.agentservl,c,l,j,g,u,d!="chat")),b(this.t,f,"contid",s),b(this.t,f,"state",e),b(this.t,f,"op",t),b(this.t,f,"time",this.getTimeSince(q)),b(this.t,f,"wait",d!="chat"?this.getTimeSince(r):"-"),b(this.t,f,"etc",p);return!1}},updateQueueMessages:function(){function a(a,b){var c=$(b),j=$(b+"end");
if(c==null||j==null)return!1;return c.rowIndex+1<j.rowIndex}var b=$("statustd");if(b){var c=a(this.t,"twait")||a(this.t,"tprio")||a(this.t,"tchat");b.innerHTML=c?"":this._options.noclients;b.height=c?5:30}},getTimeSince:function(a){var a=Math.floor(((new Date).getTime()-a-this.delta)/1E3),b=Math.floor(a/60),c="";a%=60;a<10&&(a="0"+a);b>=60&&(c=Math.floor(b/60),b%=60,b<10&&(b="0"+b),c+=":");return c+b+":"+a},updateTimers:function(){for(var a in this.threadTimers)if(this.threadTimers[a]!=null){var b=
this.threadTimers[a],c=CommonUtils.getRow("thr"+a,this.t);if(c!=null){var d=function(a,b,c,d){if(a=CommonUtils.getCell(c,b,a))a.innerHTML=d};d(this.t,c,"time",this.getTimeSince(b[0]));d(this.t,c,"wait",b[2]!="chat"?this.getTimeSince(b[1]):"-")}}},updateThreads:function(a){var b=!1,c=NodeUtils.getAttrValue(a,"time"),d=NodeUtils.getAttrValue(a,"revision");if(c)this.delta=(new Date).getTime()-c;if(d)this._options.lastrevision=d;for(c=0;c<a.childNodes.length;c++)d=a.childNodes[c],d.tagName=="thread"&&
this.updateThread(d)&&(b=!0);this.updateQueueMessages();this.updateTimers();this.setStatus(this._options.istatus?"Away":"Up to date");b&&(playSound(webimRoot+"/sounds/new_user.wav"),window.focus(),updaterOptions.showpopup&&alert(localized[5]))},updateOperators:function(a){var b=$("onlineoperators");if(b){for(var c=[],d=0;d<a.childNodes.length;d++){var e=a.childNodes[d];if(e.tagName=="operator"){var l=NodeUtils.getAttrValue(e,"name"),e=NodeUtils.getAttrValue(e,"away")!=null;c[c.length]='<img src="'+
webimRoot+"/images/op"+(e?"away":"online")+'.gif" width="12" height="12" border="0" alt="'+localized[1]+'"> '+l}}b.innerHTML=c.join(", ")}},updateContent:function(a){if(a.tagName=="update")for(var b=0;b<a.childNodes.length;b++){var c=a.childNodes[b];c.tagName=="threads"?this.updateThreads(c):c.tagName=="operators"&&this.updateOperators(c)}else a.tagName=="error"?this.setStatus(NodeUtils.getNodeValue(a,"descr")):this.setStatus("reconnecting")}});
function togglemenu(){if($("sidebar")&&$("wcontent")&&$("togglemenu"))$("wcontent").className=="contentnomenu"?($("sidebar").style.display="block",$("wcontent").className="contentinner",$("togglemenu").innerHTML=localized[4]):($("sidebar").style.display="none",$("wcontent").className="contentnomenu",$("togglemenu").innerHTML=localized[3])}var webimRoot="";Behaviour.register({"#togglemenu":function(a){a.onclick=function(){togglemenu()}}});
EventHelper.register(window,"onload",function(){webimRoot=updaterOptions.wroot;new Ajax.ThreadListUpdater({table:$("threadlist"),status:$("connstatus"),istatus:0}.extend(updaterOptions||{}));updaterOptions.havemenu||togglemenu()});