MWF.xDesktop.requireApp("IM", "Actions.RestActions", null, false); MWF.require("MWF.xDesktop.UserData", null, false); MWF.xApplication.IM = MWF.xApplication.IM || {}; MWF.xApplication.IM.IMWidget = new Class({ Extends: MWF.xApplication.Common.Widget, Implements: [Options, Events], options: { "style": "default", "appName": "IM", "name": "IMWidget" }, initialize: function(desktop, options){ this.setOptions(options); this.desktop = desktop; }, loadContent: function(callback){ this.ssoCount = 0; this.widget.node.setStyle("display", "none"); this.userAction = new MWF.xApplication.IM.Actions.RestActions(); this.users = {}; this.unShowMessage = {}; ////this.setTimeout(); //this.action = new MWF.xApplication.VsettanMail.Actions.RestActions(); //if (this.desktop.session.user.name!="xadmin") this.getUnreadCount(); //this.doUnreadMessages(); this.widget.close() }, doUnreadMessages: function(){ this.unShowMessage = MWF.UD.getDataJson("unreadChat") || {}; layout.desktop.addEvent("unload", function(){ MWF.UD.putData("unreadChat", this.unShowMessage); }.bind(this)); }, getOwner: function(callback){ if (this.owner){ if (callback) callback(); }else{ this.userAction.getPerson(function(json){ this.owner = json.data; if (callback) callback(); }.bind(this), null, layout.desktop.session.user.id); } }, getPerson: function(id, callback){ if (this.users[id]){ if (callback) callback(); }else{ this.userAction.getPerson(function(json){ this.users[id] = json.data; if (callback) callback(); }.bind(this), null, id); } }, getDialogue: function(chat, key, data, callback){ var dialogue = chat.dialogues[key]; if (!dialogue){ this.getPerson(data.from, function(){ dialogue = chat.addDialogueBack(this.owner, [this.users[data.from]]); if (callback) callback(dialogue); }.bind(this)); }else{ if (callback) callback(dialogue); } }, receiveChatMessage: function(data){ this.getOwner(function(){ var chat = layout.desktop.apps["Chat"]; //var im = layout.desktop.apps["IM"]; if (chat){ if (layout.desktop.currentApp==chat){ var key = data.from+layout.desktop.session.user.distinguishedName; this.getDialogue(chat, key, data, function(dialogue){ if (chat.current != dialogue){ this.receiveMessageRecod(data); dialogue.addUnreadMessage(data); }else{ dialogue.showMessage(data, data.from); layout.desktop.playMessageAudio(); } }.bind(this)); }else{ var key = data.from+layout.desktop.session.user.distinguishedName; this.getDialogue(chat, key, data, function(dialogue){ if (chat.current != dialogue){ this.receiveMessageRecod(data); dialogue.addUnreadMessage(data); }else{ dialogue.showMessage(data, data.from); layout.desktop.playMessageAudio(); } }.bind(this)); this.sendTooltipMessage(data); layout.desktop.playMessageAudio(); } }else{ this.receiveMessageRecod(data); } }.bind(this)); }, receiveMessageRecod: function(data){ var key = data.from+layout.desktop.session.user.distinguishedName; if (!this.unShowMessage[key]) this.unShowMessage[key] = []; this.unShowMessage[key].push(data); //var userItem = this.users["online"+data.fromPerson]; //if (userItem){ // userItem.addUnreadMessage(data); //}else{ // this.users["online"+data.fromPerson] = new MWF.xDesktop.UserPanel.User(this.userListOnlineAreaNode, this, data.fromPerson); // userItem = this.users["online"+data.fromPerson]; // userItem.addUnreadMessage(data); //} this.setUnread(); this.sendTooltipMessage(data); layout.desktop.playMessageAudio(); }, sendTooltipMessage: function(data){ var content = "