Ext.namespace("Zarafa.plugins.xmpp");Zarafa.plugins.xmpp.ABOUT="";Ext.namespace("Zarafa.plugins.xmpp");
Zarafa.plugins.xmpp.XmppChat=Ext.extend(Ext.util.Observable,{constructor:function(a,b,c){this.xmppPlugin=a;this.id=b;this.jid=c;this.state="";this.messages=[];a={};this.addEvents({messageadded:true,chatclosed:true,statechanged:true});this.listeners=a.listeners;Zarafa.plugins.xmpp.XmppChat.superclass.constructor.call(this,a)},getDisplayTitle:function(){var a=this.xmppPlugin.getRosterManager().getEntryByJID(this.jid);return a?a.getDisplayName():this.jid},addMessage:function(a){this.messages.push(a);
this.fireEvent("messageadded",this,a)},getMessages:function(){return this.messages},sendMessage:function(a){var b=new JSJaCMessage;b.setType("chat");b.setBody(a);b.setTo(this.jid);this.xmppPlugin.getConnection().send(b);b=this.xmppPlugin.getUserJID();b=new Zarafa.plugins.xmpp.XmppChatMessage("",b,this.xmppPlugin.getResource(),a,new Date);this.messages.push(b);this.fireEvent("messageadded",this,b)},close:function(){this.fireEvent("chatclosed",this)},setStatus:function(a){this.status=a;this.fireEvent("statuschanged",
this,a)}});Ext.namespace("Zarafa.plugins.xmpp");
Zarafa.plugins.xmpp.XmppChatManager=Ext.extend(Ext.util.Observable,{constructor:function(a){this.chats={};var b={};this.xmppPlugin=a;this.addEvents({chatcreated:true,chatclosed:true,messagereceived:true});this.listeners=b.listeners;Zarafa.plugins.xmpp.XmppChatManager.superclass.constructor.call(this,b);a=a.getConnection();a.registerHandler("onconnect",this.onConnect.createDelegate(this));a.registerHandler("ondisconnect",this.onDisconnect.createDelegate(this));a.registerHandler("message_in",this.onMessage.createDelegate(this))},
onConnect:function(){},onDisconnect:function(){},createChat:function(a){if(a in this.chats)return this.chats[a];a=this.chats[a]=new Zarafa.plugins.xmpp.XmppChat(this.xmppPlugin,a,a);this.fireEvent("chatcreated",this,a);return a},onMessage:function(a){var b=a.getDoc().firstChild;a=b.getAttribute("id");var c=b.getAttribute("from");c=Zarafa.plugins.xmpp.splitJID(c);var d=this.chats[c.jid];d||(d=this.createChat(c.jid));Ext.each(["active","composing","inactive","paused"],function(g){b.getElementsByTagName(g).length>
0&&d.setStatus(g)});var e=b.getElementsByTagName("body");if(e.length>0){a=new Zarafa.plugins.xmpp.XmppChatMessage(a,c.jid,c.resource,e[0].firstChild.nodeValue,new Date);d.addMessage(a);this.fireEvent("messagereceived",this,d,a)}}});Ext.namespace("Zarafa.plugins.xmpp");
Zarafa.plugins.xmpp.XmppChatMessage=Ext.extend(Object,{constructor:function(a,b,c,d,e){this.id=a;this.jid=b;this.resource=Ext.util.Format.htmlEncode(c);this.body=Ext.util.Format.htmlEncode(d);this.date=e;Zarafa.plugins.xmpp.XmppChatMessage.superclass.constructor.call(this)},getID:function(){return this.id},getJID:function(){return this.jid},getResource:function(){return this.resource},getBody:function(){return this.body},getDate:function(){return this.date}});Ext.namespace("Zarafa.plugins.xmpp");
Zarafa.plugins.xmpp.splitJID=function(a){return a.indexOf("/")==-1?{jid:a,resource:null}:{jid:a.split("/")[0],resource:a.split("/")[1]}};Zarafa.plugins.xmpp.getIconClass=function(a){return{online:"icon_xmpp_online",offline:"icon_xmpp_offline",away:"icon_xmpp_away",xa:"icon_xmpp_away",chat:"icon_xmpp_online",dnd:"icon_xmpp_busy"}[a]};Zarafa.plugins.xmpp.getChildNodeValue=function(a,b){try{return a.getElementsByTagName(b)[0].firstChild.nodeValue}catch(c){return null}};
Zarafa.plugins.xmpp.XmppPlugin=Ext.extend(Zarafa.core.Plugin,{constructor:function(a){this.addEvents(["connect","disconnect","statuschanged","error"]);Zarafa.plugins.xmpp.XmppPlugin.superclass.constructor.call(this,a)},initPlugin:function(){var a=container.getSettingsModel(),b=container.getUser();Zarafa.plugins.xmpp.XmppPlugin.superclass.initPlugin.apply(this,arguments);this.xmppHttpBase=a.get(this.getSettingsBase()+"/httpbase");this.xmppDomain=a.get(this.getSettingsBase()+"/domain");this.xmppUser=
b.getUserName();this.xmppPassword=b.getSessionId();this.xmppResource=a.get(this.getSettingsBase()+"/resource");this.presence=new Zarafa.plugins.xmpp.XmppPresence(null,null);this.connection=this.createConnection();this.rosterManager=new Zarafa.plugins.xmpp.XmppRosterManager(this);this.chatManager=new Zarafa.plugins.xmpp.XmppChatManager(this);this.connect()},createConnection:function(){var a={};a.httpbase=this.xmppHttpBase;a.timerval=2E3;a.oDbg=new JSJaCConsoleLogger;a.oDbg.setLevel(1);a=new JSJaCHttpBindingConnection(a);
a.registerHandler("onConnect",this.handleOnConnect.createDelegate(this));a.registerHandler("onError",this.handleError.createDelegate(this));a.registerHandler("onStatusChanged",this.handleStatusChanged.createDelegate(this));a.registerHandler("onDisconnect",this.handleDisconnected.createDelegate(this));return a},connect:function(){var a={};a.domain=this.xmppDomain;a.username=this.xmppUser;a.resource=this.xmppResource;a.pass=this.xmppPassword;a.register=false;a.authtype=this.authtype;this.connection.connect(a)},
handleOnConnect:function(){this.fireEvent("connect",this);this.rosterManager.setPresence("online","")},handleDisconnected:function(){this.fireEvent("disconnect",this)},handleError:function(a){this.fireEvent("error",this,a)},handleStatusChanged:function(a){this.fireEvent("statuschanged",this,a)},getRosterManager:function(){return this.rosterManager},getChatManager:function(){return this.chatManager},getConnection:function(){return this.connection},getUserJID:function(){return this.xmppUser+"@"+this.xmppDomain},
getResource:function(){return this.xmppResource}});Zarafa.onReady(function(){container.registerPlugin(new Zarafa.core.PluginMetaData({name:"xmpp",displayName:_("XMPP Plugin"),about:Zarafa.plugins.xmpp.ABOUT,pluginConstructor:Zarafa.plugins.xmpp.XmppPlugin}))});Ext.namespace("Zarafa.plugins.xmpp");
Zarafa.plugins.xmpp.XmppPresence=Ext.extend(Object,{constructor:function(a,b){this.show=a;this.setStatus(b);Zarafa.plugins.xmpp.XmppPresence.superclass.constructor.call(this)},getStatus:function(){return this.status},getShow:function(){return this.show},set:function(a,b){this.show=a;this.setStatus(b)},setShow:function(a){this.show=a},setStatus:function(a){this.status=Ext.util.Format.htmlEncode(a)},toJSJacPresence:function(){var a=new JSJaCPresence;this.show!="online"&&this.show!="offline"&&a.setShow(this.show);
a.setStatus(this.status);return a}});Ext.namespace("Zarafa.plugins.xmpp");
Zarafa.plugins.xmpp.XmppRosterEntry=Ext.extend(Object,{constructor:function(a,b,c){this.jid=a;this.setName(b);this.subscription=c;this.groups=[];this.vCard=new Zarafa.plugins.xmpp.XmppVCard;this.presence=new Zarafa.plugins.xmpp.XmppPresence("offline","");Zarafa.plugins.xmpp.XmppRosterEntry.superclass.constructor.call(this)},getJID:function(){return this.jid},getName:function(){return this.name},getDisplayName:function(){return this.getVCard().getFullName()||this.name||this.jid},getSubscription:function(){return this.subscription},
setJID:function(a){this.jid=a},setName:function(a){this.name=Ext.util.Format.htmlEncode(a)},setSubscription:function(a){this.subscription=a},getGroups:function(){return this.groups},clearGroups:function(){this.groups=[]},addGroup:function(a){this.groups.push(Ext.util.Format.htmlEncode(a))},removeGroup:function(a){this.groups.remove(a)},getVCard:function(){return this.vCard},getPresence:function(){return this.presence},setPresence:function(a,b){this.presence.set(a,b)}});Ext.namespace("Zarafa.plugins.xmpp");
Zarafa.plugins.xmpp.XmppRosterManager=Ext.extend(Ext.util.Observable,{constructor:function(a){this.xmppPlugin=a;this.entries={};var b={};this.addEvents({rosterchanged:true,presencechanged:true});this.listeners=b.listeners;Zarafa.plugins.xmpp.XmppRosterManager.superclass.constructor.call(this,b);a=a.getConnection();a.registerHandler("onconnect",this.onConnect.createDelegate(this));a.registerHandler("ondisconnect",this.onDisconnect.createDelegate(this));a.registerHandler("presence",this.onPresence.createDelegate(this));
a.registerHandler("iq",this.onIQ.createDelegate(this))},onConnect:function(){this.queryRoster();this.queryVCard();this.fireEvent("rosterchanged",this,this.entries)},onDisconnect:function(){this.entries={};this.fireEvent("rosterchanged",this,this.entries)},onPresence:function(a){a=a.getDoc().firstChild;var b=a.getAttribute("from");b=Zarafa.plugins.xmpp.splitJID(b).jid;var c=Zarafa.plugins.xmpp.getChildNodeValue(a,"show")||"online",d=Zarafa.plugins.xmpp.getChildNodeValue(a,"status")||"";if(a.getAttribute("type")==
"unavailable")c="offline";var e=this.entries[b];if(!e){e=new Zarafa.plugins.xmpp.XmppRosterEntry(b,null,null);this.entries[b]=e;this.fireEvent("rosterchanged",this,this.entries)}e.getPresence().setShow(c);e.getPresence().setStatus(d);a.getElementsByTagName("x");this.fireEvent("presencechanged",this,e)},queryRoster:function(){var a=new JSJaCIQ;a.setIQ(null,"get","roster_1");a.setQuery(NS_ROSTER);this.xmppPlugin.getConnection().sendIQ(a,{result_handler:this.queryRosterCallback.createDelegate(this)})},
queryRosterCallback:function(a){var b=this.entries||{},c=this.getMe();this.entries={};this.entries[c.getJID()]=c;a=a.getDoc().getElementsByTagName("item");c=0;for(var d;d=a.item(c);c++){var e=d.getAttribute("jid"),g=d.getAttribute("name"),h=d.getAttribute("subscription"),f=b[e];if(f){f.setJID(e);f.setName(g);f.setSubscription(h);f.clearGroups()}else f=new Zarafa.plugins.xmpp.XmppRosterEntry(e,g,h);this.entries[e]=f;this.queryVCard(e);d=d.childNodes;for(e=0;g=d.item(e);e++)g.nodeName=="group"&&f.addGroup(g.firstChild.nodeValue)}this.fireEvent("rosterchanged",
this,this.entries,this.groups)},queryVCard:function(a){var b=new JSJaCIQ;b.setIQ(a,"get",Math.random()*1E7);a=b.getDoc();if(a.createElementNS){var c=a.createElementNS(NS_VCARD,"vCard");a.firstChild.appendChild(c)}else{c=b.appendNode("vcard");c.setAttribute("xmlns",NS_VCARD)}this.xmppPlugin.getConnection().sendIQ(b,{result_handler:this.queryVCardCallback.createDelegate(this)})},queryVCardCallback:function(a){a=a.getDoc().firstChild;var b=a.getAttribute("from");if(b){b=Zarafa.plugins.xmpp.splitJID(b).jid;
this.getEntryByJID(b).getVCard().populate(a.getElementsByTagName("vCard")[0])}},onIQ:function(a){a=a.getDoc().firstChild.getElementsByTagName("query");Ext.each(a,function(b){b.getAttribute("xmlns")==NS_ROSTER&&this.processRosterQuery(b)},this)},processRosterQuery:function(a){Ext.each(a.getElementsByTagName("item"),function(b){var c=b.getAttribute("jid"),d=b.getAttribute("name"),e=b.getAttribute("subscription"),g=this.entries[c];e=="remove"&&g&&delete this.entries[c];if(e!="remove"){if(!g){g=new Zarafa.plugins.xmpp.XmppRosterEntry(c,
d,e);this.entries[c]=g;this.queryVCard(c)}g.clearGroups();Ext.each(b.getElementsByTagName("group"),function(h){g.addGroup(h.firstChild.nodeValue)})}},this);this.fireEvent("rosterchanged",this,this.entries)},getEntries:function(){return this.entries},getEntryByJID:function(a){return this.entries[a]},getEntryByEmail:function(a){for(var b in this.entries)if(this.entries[b].getVCard().containsEmail(a))return this.entries[b]},getMe:function(){var a=this.xmppPlugin.getUserJID(),b=this.entries[a];b||(this.entries[a]=
b=new Zarafa.plugins.xmpp.XmppRosterEntry(a,null,"both"));return b},getMyShow:function(){return this.getMe().getPresence().getShow()},getMyStatus:function(){return this.getMe().getPresence().getStatus()},setPresence:function(a,b){var c=this.getMe();c.getPresence().setShow(a);c.getPresence().setStatus(b);this.xmppPlugin.getConnection().send(c.getPresence().toJSJacPresence());this.fireEvent("presencechanged",this,c)}});Ext.namespace("Zarafa.plugins.xmpp");
Zarafa.plugins.xmpp.XmppVCard=Ext.extend(Object,{constructor:function(){this.populated=false;this.imageData=this.imageType="";this.emailAddresses=[];this.fullName="";Zarafa.plugins.xmpp.XmppVCard.superclass.constructor.call(this)},getEmailAddresses:function(){return this.emailAddresses},getFullName:function(){return this.fullName},containsEmail:function(a){return this.emailAddresses.indexOf(a)!=-1},populateEmail:function(a){a=a.getElementsByTagName("EMAIL");a.length>0&&Ext.each(a[0].childNodes,function(b){b.firstChild&&
this.emailAddresses.push(b.firstChild.nodeValue)},this)},populatePhoto:function(){},populatePersonalInfo:function(a){this.fullName=Zarafa.plugins.xmpp.getChildNodeValue(a,"FN")},populate:function(a){this.populateEmail(a);this.populatePhoto(a);this.populatePersonalInfo(a);this.populated=true},isPopulated:function(){return this.populated}});Ext.namespace("Zarafa.plugins.xmpp");
Zarafa.plugins.xmpp.Widget=Ext.extend(Zarafa.core.ui.widget.Widget,{constructor:function(a){this.hookPlugin();var b=this.xmppPlugin.getRosterManager().getMe().getPresence().getShow();a=a||{};Ext.applyIf(a,{height:400,layout:"fit",tbar:{xtype:"toolbar",items:[{xtype:"tbbutton",text:_("Status"),ref:"../statusToolbarItem",iconCls:Zarafa.plugins.xmpp.getIconClass(b),menu:this.statusMenu=new Ext.menu.Menu({items:[{text:"Available",iconCls:"icon_xmpp_online",handler:function(){this.onStatusMenu("online")},
scope:this},{text:"Free to chat",iconCls:"icon_xmpp_online",handler:function(){this.onStatusMenu("chat")},scope:this},{text:"Away",iconCls:"icon_xmpp_away",handler:function(){this.onStatusMenu("away")},scope:this},{text:"Extended Away",iconCls:"icon_xmpp_away",handler:function(){this.onStatusMenu("xa")},scope:this},{text:"Do not disturb",iconCls:"icon_xmpp_busy",handler:function(){this.onStatusMenu("dnd")},scope:this},this.statusTextField=new Ext.form.TextField({ref:"../../statusTextField",listeners:{change:this.onStatusFieldChange,
specialkey:this.onStatusFieldSpecialKey,scope:this}})]})},{xtype:"tbfill"},{xtype:"tbtext",name:"statusText",ref:"../statusText",text:"..."}]},items:[this.chatPanel=new Zarafa.plugins.xmpp.ui.XmppChatTabPanel({activeTab:0,items:[this.rosterPanel=new Zarafa.plugins.xmpp.ui.XmppRosterPanel({title:"Contacts",listeners:{rowdblclick:this.rosterDoubleClick,scope:this}})]})]});Zarafa.plugins.xmpp.Widget.superclass.constructor.call(this,a)},hookPlugin:function(){if(this.xmppPlugin=container.getPluginByName("xmpp")){this.xmppPlugin.addListener("connect",
this.onConnect,this);this.xmppPlugin.addListener("disconnect",this.onDisconnect,this);this.xmppPlugin.getRosterManager().addListener("presencechanged",this.onPresenceChanged,this)}else throw"XMPP plugin not found";},unhookPlugin:function(){if(this.xmppPlugin){this.xmppPlugin.removeListener("connect",this.onConnect,this);this.xmppPlugin.removeListener("disconnect",this.onDisconnect,this);this.xmppPlugin.getRosterManager().removeListener("presencechanged",this.onPresenceChanged,this)}},onPresenceChanged:function(a,
b){if(b==a.getMe()){var c=b.getPresence().getShow(),d=b.getPresence().getStatus();if(d!==undefined){this.statusTextField.setValue(d);this.statusToolbarItem.setText(d?"Status ("+d+")":"Status")}this.statusToolbarItem.setIconClass(Zarafa.plugins.xmpp.getIconClass(c))}},onStatusMenu:function(a){var b=this.xmppPlugin.getRosterManager();b.setPresence(a,b.getMyStatus())},onStatusFieldChange:function(a){var b=this.xmppPlugin.getRosterManager();b.setPresence(b.getMyShow()||null,a.getValue())},onStatusFieldSpecialKey:function(a,
b){if(b.getKey()==b.ENTER){a.blur();this.statusMenu.hide()}},rosterDoubleClick:function(a,b){var c=this.rosterPanel.getStore().getAt(b);this.chatPanel.selectChat(this.xmppPlugin.getChatManager().createChat(c.data.jid))},onConnect:function(){this.showStatus("connected")},onDisconnect:function(){this.showStatus("disconnected")},showStatus:function(a){this.statusText.setText(a)},destroy:function(){this.unhookPlugin();Zarafa.plugins.xmpp.Widget.superclass.destroy.call(this)}});
Zarafa.onReady(function(){container.getSettingsModel().get("zarafa/v1/plugins/xmpp/enable")===true&&container.registerWidget(new Zarafa.core.ui.widget.WidgetMetaData({name:"chat",displayName:_("Chat"),iconPath:"plugins/xmpp/resources/icons/chat.png",widgetConstructor:Zarafa.plugins.xmpp.Widget}))});Ext.namespace("Zarafa.plugins.xmpp.data");Zarafa.plugins.xmpp.ChatColors=["#8A9B0F","#BD1550","#F8CA00","#78C0A8"];
Zarafa.plugins.xmpp.data.ChatMessageRecord=Ext.data.Record.create([{name:"messageid"},{name:"jid"},{name:"resource"},{name:"color"},{name:"displayname"},{name:"body"},{name:"date"}]);
Zarafa.plugins.xmpp.data.XmppChatStore=Ext.extend(Ext.data.Store,{constructor:function(a){var b={reader:new Ext.data.ArrayReader({idIndex:0},Zarafa.plugins.xmpp.data.ChatMessageRecord)};this.hookChat(a);Zarafa.plugins.xmpp.data.XmppChatStore.superclass.constructor.call(this,b)},load:function(){this.update()},update:function(){var a=[],b=container.getPluginByName("xmpp");if(!b)throw"XMPP plugin not found";var c=b.getRosterManager(),d={},e=0;Ext.each(this.chat.getMessages(),function(g){var h=g.getJID(),
f=c.getEntryByJID(h);f=f?f.getDisplayName():h;h in d||(d[h]=e++);var j=Zarafa.plugins.xmpp.ChatColors[d[h]%Zarafa.plugins.xmpp.ChatColors.length];a.push([g.getID(),h,g.getResource(),j,f,g.getBody(),g.getDate().format("H:i:s")])});this.loadData(a)},hookChat:function(a){this.chat=a;this.chat.addListener("messageadded",this.onMessageAdded,this)},unhookChat:function(){this.chat.removeListener("messageadded",this.onMessageAdded,this)},onMessageAdded:function(){this.update()},destroy:function(){this.unhookChat();
Zarafa.plugins.xmpp.data.XmppChatStore.superclass.destroy.call(this)}});Ext.reg("zarafa.xmppchatstore",Zarafa.plugins.xmpp.data.XmppChatStore);Ext.namespace("Zarafa.plugins.xmpp.data");Zarafa.plugins.xmpp.data.RosterRecord=Ext.data.Record.create([{name:"id"},{name:"jid"},{name:"name"},{name:"subscription"},{name:"show"},{name:"status"},{name:"displayname"},{name:"group"}]);
Zarafa.plugins.xmpp.data.XmppRosterStore=Ext.extend(Ext.data.GroupingStore,{constructor:function(a){a=Ext.applyIf(a||{},{reader:new Ext.data.ArrayReader({idIndex:0},Zarafa.plugins.xmpp.data.RosterRecord),sortInfo:{field:"group",direction:"ASC"},groupOnSort:true,remoteGroup:true,groupField:"group"});this.searchString="";this.showOffline=true;Zarafa.plugins.xmpp.data.XmppRosterStore.superclass.constructor.call(this,a);this.hookPlugin()},load:function(){this.update()},filter:function(a){if(a==this.xmppPlugin.getRosterManager().getMe())return false;
if(!this.showOffline&&a.getPresence().getShow()=="offline")return false;if(this.searchString=="")return true;var b=this.searchString.toLowerCase();if(a.getJID().split("@")[0].toLowerCase().indexOf(b)!=-1)return true;if((a=a.getName())&&a.toLowerCase().indexOf(b)!=-1)return true;return false},update:function(){if(this.rosterManager){var a=[];a.pushEntry=function(h,f){var j=f.getJID()+(h?"/"+h:""),k=f.getName()||f.getJID(),i=f.getPresence().getShow();h||(h="Not in a group");if(i===null)i="online";if(i===
undefined)i="offline";this.push([j,f.getJID(),f.getName(),f.getSubscription(),i,f.getPresence().getStatus(),k,h])};var b=[],c={};for(var d in this.rosterManager.getEntries()){var e=this.rosterManager.getEntries()[d];this.filter(e)&&b.push(e)}Ext.each(b,function(h){h.getGroups().length==0&&a.pushEntry(null,h)});Ext.each(b,function(h){Ext.each(h.getGroups(),function(f){if(c[f]===undefined)c[f]=[];c[f].push(h)})});for(d in c){b=c[d];for(var g=0;e=b[g];g++)a.pushEntry(d,e)}this.loadData(a)}},setSearchString:function(a){this.searchString=
a;this.update()},setShowOffline:function(a){this.showOffline=a;this.update()},hookPlugin:function(){if(this.xmppPlugin=container.getPluginByName("xmpp")){this.rosterManager=this.xmppPlugin.getRosterManager();this.rosterManager.addListener("rosterchanged",this.onRosterChanged,this);this.rosterManager.addListener("presencechanged",this.onPresenceChanged,this);this.update()}else throw"XMPP plugin not found";},unhookPlugin:function(){if(this.xmppPlugin){this.rosterManager.removeListener("rosterchanged",
this.onRosterChanged,this);this.rosterManager.removeListener("presencechanged",this.onPresenceChanged,this)}},onRosterChanged:function(){this.update()},onPresenceChanged:function(){this.update()},destroy:function(){this.unhookPlugin();Zarafa.plugins.xmpp.XmppRosterStore.superclass.destroy()}});Ext.reg("zarafa.xmpprosterstore",Zarafa.plugins.xmpp.data.XmppRosterStore);Ext.namespace("Zarafa.plugins.xmpp.ui");
Zarafa.plugins.xmpp.ui.XmppChatPanel=Ext.extend(Ext.Panel,{constructor:function(a){this.hookChat(a);this.store=new Zarafa.plugins.xmpp.data.XmppChatStore(a);this.store.load();this.store.addListener("load",this.onStoreLoad,this);var b=new Ext.XTemplate('<tpl for=".">','<div class="thumb-wrap" id="{messageid}">','<div style="width:100%">','<span style="font-size: 8px;">{date}</span> ','<span style="text-weight: bold; color: {color}">{displayname}: </span>{body}</div>',"</tpl>",'<div class="x-clear"></div>');
a={title:a.getDisplayTitle(),layout:"border",closable:true,items:[this.dataView=new Ext.DataView({autoScroll:true,store:this.store,tpl:b,itemSelector:"div.thumb-wrap",region:"center"}),{xtype:"textfield",listeners:{specialkey:this.onInputFieldSpecialKey,scope:this},region:"south"},this.statusField=new Ext.form.Label({region:"north",height:12,style:"font-size: 10px"})]};Zarafa.plugins.xmpp.ui.XmppChatPanel.superclass.constructor.call(this,a)},getChat:function(){return this.chat},hookChat:function(a){this.chat=
a;this.chat.addListener("statuschanged",this.onStatusChanged,this)},unhookChat:function(){this.chat.removeListener("statuschanged",this.onStatusChanged,this)},onStoreLoad:function(){this.scrollDown()},scrollDown:function(){var a=this.dataView.getNodes();a.length!=0&&a[a.length-1].scrollIntoView(this.dataView)},setTitleStyle:function(a){a?this.setTitle('<span style="font-weight: bold; color:red">'+this.chat.getDisplayTitle()+"</span>"):this.setTitle(this.chat.getDisplayTitle())},onStatusChanged:function(a,
b){b=="composing"?this.statusField.setText(a.getDisplayTitle()+" is typing ..."):this.statusField.setText("")},onInputFieldSpecialKey:function(a,b){if(b.getKey()==b.ENTER)if(a.getValue()){this.chat.sendMessage(a.getValue());a.setValue("")}},destroy:function(){this.unhookChat();this.store.removeListener("load",this.onStoreLoad(),this);this.store.destroy();Zarafa.plugins.xmpp.ui.XmppChatPanel.superclass.destroy.call(this)}});Ext.namespace("Zarafa.plugins.xmpp.ui");
Zarafa.plugins.xmpp.ui.XmppChatTabPanel=Ext.extend(Ext.TabPanel,{constructor:function(a){a=Ext.applyIf(a||{},{enableTabScroll:true,listeners:{tabchange:this.onTabChanged,scope:this}});this.hookPlugin();Zarafa.plugins.xmpp.ui.XmppChatTabPanel.superclass.constructor.call(this,a)},hookPlugin:function(){if(this.xmppPlugin=container.getPluginByName("xmpp")){this.chatManager=this.xmppPlugin.getChatManager();this.chatManager.addListener("chatcreated",this.onChatCreated,this);this.chatManager.addListener("chatclosed",
this.onChatClosed,this);this.chatManager.addListener("messagereceived",this.onMessageReceived,this)}else throw"XMPP plugin not found";},unhookPlugin:function(){if(this.xmppPlugin){this.chatManager.removeListener("chatcreated",this.onChatCreated,this);this.chatManager.removeListener("chatclosed",this.onChatClosed,this);this.chatManager.removeListener("messagereceived",this.onMessageReceived,this)}},onChatCreated:function(a,b){this.activate(this.createPanel(b))},onChatClosed:function(){},onMessageReceived:function(a,
b){var c=this.findPanel(b);c||(c=this.createPanel(b));if(c!=this.getActiveTab()){c.setTitleStyle(true);this.doLayout()}},findPanel:function(a){for(var b=0,c;c=this.items.items[b];b++)if(c.getChat&&c.getChat()==a)return c},createPanel:function(a){a=new Zarafa.plugins.xmpp.ui.XmppChatPanel(a);this.add(a);this.doLayout();return a},onTabChanged:function(a,b){if(b.scrollDown){b.scrollDown();b.setTitleStyle(false)}},selectChat:function(a){var b=this.findPanel(a);b||(b=this.createPanel(a));this.activate(b)},
destroy:function(){this.unhookPlugin();Zarafa.plugins.xmpp.ui.XmppChatTabPanel.superclass.destroy.call(this)}});Ext.namespace("Zarafa.plugins.xmpp.ui");
Zarafa.plugins.xmpp.ui.XmppRosterPanel=Ext.extend(Ext.grid.GridPanel,{constructor:function(a){var b=new Ext.grid.GroupingView({forceFit:true,groupTextTpl:"{group}"});a=Ext.applyIf(a||{},{layout:"fit",tbar:{xtype:"toolbar",layout:"border",height:24,items:[{xtype:"trigger",region:"center",ref:"../searchField",triggerClass:"x-form-search-trigger",onTriggerClick:this.onSearchFieldTriggerClick.createDelegate(this),enableKeyEvents:true,listeners:{change:this.onSearchFieldChange,specialkey:this.onSearchFieldSpecialKey,
scope:this}},{xtype:"tbbutton",region:"east",text:_("Show"),ref:"../statusToolbarItem",menu:this.statusMenu=new Ext.menu.Menu({items:[{text:"Show offline",iconCls:"icon_xmpp_offline",handler:function(){this.showOffline(true)},scope:this},{text:"Show online",iconCls:"icon_xmpp_online",handler:function(){this.showOffline(false)},scope:this}]})}]},cm:new Ext.grid.ColumnModel([{id:"JID",hidden:true,dataIndex:"jid"},{header:'<p class="icon_xmpp_online">&nbsp;</p>',width:24,fixed:true,dataIndex:"show",
renderer:function(c,d){d.css={online:"icon_xmpp_online",offline:"icon_xmpp_offline",away:"icon_xmpp_away",xa:"icon_xmpp_away",chat:"icon_xmpp_online",dnd:"icon_xmpp_busy"}[c];return""}},{header:"Group",dataIndex:"group",hidden:true},{header:"Name",dataIndex:"displayname",renderer:function(c,d,e){d=e.data.status;c=c;if(d)c+=" ("+d+")";return c}}]),view:b,store:this.store=new Zarafa.plugins.xmpp.data.XmppRosterStore});this.xmppPlugin=container.getPluginByName("xmpp");if(!this.xmppPlugin)throw"XMPP plugin not found";
Zarafa.plugins.xmpp.ui.XmppRosterPanel.superclass.constructor.call(this,a)},onSearchFieldChange:function(a){this.store.setSearchString(a.getValue())},onSearchFieldSpecialKey:function(a,b){if(b.getKey()==b.ENTER){a.blur();this.store.setSearchString(a.getValue())}},onSearchFieldTriggerClick:function(){this.store.setSearchString(this.searchField.getValue())},showOffline:function(a){this.store.setShowOffline(a)}});Ext.namespace("Zarafa.plugins.xmpp");
Zarafa.plugins.xmpp.XmppNotificationPlugin=Ext.extend(Zarafa.core.Plugin,{initPlugin:function(){Zarafa.plugins.xmpp.XmppNotificationPlugin.superclass.initPlugin.apply(this,arguments);var a=container.getPluginByName("xmpp");this.chatManager=a.getChatManager();this.rosterManager=a.getRosterManager();this.chatManager.addListener("messagereceived",this.onMessageReceived,this);this.rosterManager.addListener("presencechanged",this.onPresenceChanged,this);this.registerInsertionPoint("statusbar.left",function(){return new Ext.Toolbar.Item({html:'<div id="xmpp-notification-bar"></div>'})},
this)},doElementAnimation:function(a){a.stopFx();a.fadeIn();a.pause(5);a.fadeOut()},onMessageReceived:function(a,b,c){if(a=Ext.get("xmpp-notification-bar")){var d=c.getJID();d=(b=this.rosterManager.getEntryByJID(d))?b.getDisplayName():d;b=Zarafa.plugins.xmpp.getIconClass(b.getPresence().getShow());a.update('<span style="padding-left: 24px; background-position: left ! important" class="'+b+'"><b>'+d+" says:</b> "+c.getBody()+"</span>");this.doElementAnimation(a)}},onPresenceChanged:function(a,b){var c=
Ext.get("xmpp-notification-bar");if(c){var d=b.getPresence().getShow(),e=Zarafa.plugins.xmpp.getIconClass(d);if(d===undefined)d="offline";if(d===null)d="online";d={online:"changed status to available.",offline:"has gone offline.",away:"is now away.",xa:"is now away.",chat:"is feeling chatty.",dnd:'has changed status to "do not disturb".'}[d];c.update('<span style="padding-left: 24px; background-position: left ! important" class="'+e+'"><b>'+b.getDisplayName()+"</b> "+d+"</span>");this.doElementAnimation(c)}}});
Zarafa.onReady(function(){container.registerPlugin(new Zarafa.core.PluginMetaData({name:"xmpp-notification-plugin",displayName:_("XMPP Notification Plugin"),settingsName:"xmpp",allowUserVisible:false,pluginConstructor:Zarafa.plugins.xmpp.XmppNotificationPlugin}))});Ext.namespace("Zarafa.plugins.xmpp");
Zarafa.plugins.xmpp.XmppPreviewPanelButton=Ext.extend(Ext.Button,{constructor:function(a){this.panel=a.panel;this.model=a.model;a=Ext.applyIf(a,{text:"Lol ik ben een knopje",listeners:{click:this.onClick,scope:this}});Zarafa.plugins.xmpp.XmppPreviewPanelButton.superclass.constructor.call(this,a)},initComponent:function(){Zarafa.plugins.xmpp.XmppPreviewPanelButton.superclass.initComponent.apply(this,arguments);this.setVisible(false);this.panel.addListener("updaterecord",this.onUpdateRecord,this);(this.xmppPlugin=
container.getPluginByName("xmpp"))&&this.model.addListener("previewrecordchange",this.onRecordChange,this)},update:function(a){var b=undefined;if(a!=undefined){a=a.data.sent_representing_email_address;b=this.xmppPlugin.getRosterManager().getEntryByEmail(a)}if(b){this.setIconClass(Zarafa.plugins.xmpp.getIconClass(b.getPresence().getShow()));this.setText(b.getDisplayName());this.setVisible(true)}else this.setVisible(false);this.entry=b},onClick:function(){this.entry&&this.xmppPlugin.getChatManager().createChat(this.entry.getJID())},
onRecordChange:function(a,b){this.update(b)},onUpdateRecord:function(a,b,c){this.update(c)},destroy:function(){this.panel.removeListener("updaterecord",this.onUpdateRecord,this);this.model.removeListener("previewrecordchange",this.onRecordChange,this);Zarafa.plugins.xmpp.XmppPreviewPanelButton.superclass.destroy.call(this)}});Ext.reg("zarafa.xmpp.previewpanelbutton",Zarafa.plugins.xmpp.XmppPreviewPanelButton);
Zarafa.plugins.xmpp.XmppPreviewPanelPlugin=Ext.extend(Zarafa.core.Plugin,{initPlugin:function(){Zarafa.plugins.xmpp.XmppPreviewPanelPlugin.superclass.initPlugin.apply(this,arguments);var a=container.getPluginByName("xmpp");this.chatManager=a.getChatManager();this.rosterManager=a.getRosterManager();this.registerInsertionPoint("previewpanel.toolbar.right",function(b,c,d){return{xtype:"zarafa.xmpp.previewpanelbutton",panel:c,model:d}},this)},onMessageReceived:function(){},onPresenceChanged:function(){}});
Zarafa.onReady(function(){container.registerPlugin(new Zarafa.core.PluginMetaData({name:"xmpp-previewpanel-plugin",displayName:_("XMPP Preview Panel Plugin"),settingsName:"xmpp",allowUserVisible:false,pluginConstructor:Zarafa.plugins.xmpp.XmppPreviewPanelPlugin}))});
