| 1 |
- MWF.xApplication.Execution.Chat=new Class({Extends:MWF.widget.Common,Implements:[Options,Events],options:{style:"default",documentId:""},initialize:function(t,e,i,s,n,o){this.setOptions(o);this.dialogContainer=$(t);this.editorContainer=$(e);this.app=i;this.actions=s;this.lp=n;this.userName=layout.desktop.session.user.name;this.path="/x_component_Execution/$Chat/"+this.options.style+"/";this.actionSettingPath=MWF.defaultPath+"/widget/$SimpleEditor/"+this.options.style+"/ActionSetting.js";this.cssPath=this.path+"css.wcss";this._loadCss()},load:function(){this._loadEmotionSetting();if(this.dialogContainer){this.dialogNode=new Element("div.dialogNode",{styles:this.css.dialogNode}).inject(this.dialogContainer);var t=this;MWF.require("MWF.widget.ScrollBar",function(){this.scrollObj=new MWF.widget.ScrollBar(this.dialogContainer,{indent:false,style:"default",where:"before",distance:60,friction:4,axis:{x:false,y:true},onScroll:function(e){if(e==0){if(!t.isItemsLoaded)t.loadDialog()}}})}.bind(this),false);this.items=[];this.isItemsLoaded=false;this.isItemLoadding=false;this.loadDialog(function(){this.scrollToLater()}.bind(this))}if(this.editorContainer){this.loadEditor(this.editorContainer,"")}},scrollToLater:function(){setTimeout(function(){var t=this.scrollObj.node.getSize();if(!this.scrollObj.scrollVNode)this.scrollObj.checkScroll();if(this.scrollObj.scrollVNode){var e=this.scrollObj.scrollVNode.getSize();var i=t.y.toFloat()-e.y.toFloat();this.scrollObj.scroll(i,null)}}.bind(this),500)},_loadEmotionSetting:function(){if(this.emotionSetting)return;var t=new Request({url:this.actionSettingPath,async:false,method:"get",onSuccess:function(t,e){this.emotionSetting=MWF.widget.SimpleEditor.Actions.setting.emotion}.bind(this),onFailure:function(t){alert(t.responseText)}});t.send()},loadDialog:function(t){if(!this.isItemsLoaded){if(!this.isItemLoadding){this.isItemLoadding=true;this.getCurrentPageData(function(e){var i=e.count;if(i<=this.items.length){this.isItemsLoaded=true}e.data.each(function(t){this.loadDialogItem(t)}.bind(this));this.isItemLoadding=false;if(t)t()}.bind(this),10)}}},loadDialogItem:function(t,e){this.items.push(t.id);var i=t.senderName==this.userName;var s=new Element("div.msg_li",{styles:this.css.msg_li}).inject(this.dialogNode,e||"top");var n=new Element("div",{styles:this.css.msg_item}).inject(s);var o=new Element("div",{styles:this.css[i?"msg_person_right":"msg_person_left"]}).inject(n);var a=new Element("img",{styles:this.css.msg_face}).inject(o);this.setUserFace(t.senderName,a);if(!i){var r=new Element("div",{styles:this.css.msg_person_name,text:t.senderName}).inject(o)}var l=new Element("div",{styles:this.css[i?"msg_arrow_right":"msg_arrow_left"]}).inject(n);var h=new Element("div",{styles:this.css[i?"msg_content_body_right":"msg_content_body_left"]}).inject(n);var d=new Element("div",{styles:this.css.msg_content_area}).inject(h);var c=new Element("p",{styles:this.css.msg_content_text,html:this.parseEmotion(t.content)}).inject(d);var m=new Element("p",{styles:this.css.msg_content_time,text:t.createTime}).inject(d)},parseEmotion:function(t){return t.replace(/\[emotion=(.*?)\]/g,function(t,e){return"<img imagename='"+e+"' style='cursor:pointer;border:0;padding:2px;' "+" class='MWF_editor_emotion' src='"+this.emotionSetting.imagesPath+e+this.emotionSetting.fileExt+"'>"}.bind(this))},getCurrentPageData:function(t,e){if(!e)e=5;var i=this.items&&this.items.length?this.items[this.items.length-1]:"(0)";var s={workId:this.options.workId}||{};this.actions.getChatListNext(i,e,s,function(e){if(t)t(e)}.bind(this),null,false)},setUserFace:function(t,e){this.getUserData(t,function(t){var i;if(t.icon){i="data:image/png;base64,"+t.icon}else{i=this.path+(t.genderType=="f"?"female.png":"man.png")}e.set("src",i)})},getUserData:function(t,e){this.userData=this.userData||{};if(this.userData[t]){if(e)e(this.userData[t])}else{this.actions.getPerson(function(i){this.userData[t]=i.data;if(e)e(i.data)}.bind(this),null,t,false)}},sendMessage:function(t,e){var i={workId:this.options.workId,createTime:(new Date).format("db"),content:t,targetIdentity:this.app.identity,senderName:this.userName};this.actions.submitChat(i,function(t){}.bind(this),function(t,e,i){var s=i;if(t)errorMessage=t.responseText;var n=JSON.parse(errorMessage);if(n.message){this.app.notice(n.message,"error")}else{this.app.notice(s,"error")}}.bind(this),false);this.loadDialogItem(i,"bottom");if(e)e()},loadEditor:function(t,e){MWF.require("MWF.widget.SimpleEditor",function(){this.editor=new MWF.widget.SimpleEditor({style:"chatReceive",hasHeadNode:false,hasTitleNode:false,editorDisabled:false,hasToolbar:true,toolbarDisable:false,hasSubmit:true,submitDisable:false,hasCustomArea:true,paragraphise:false,minHeight:100,maxHeight:100,overFlow:"visible",width:"100%",action:"Emotion",limit:255,onQueryLoad:function(){return true},onPostLoad:function(t){t.setCustomInfo("")},onSubmitForm:function(t){var e=t.getContent(true);if(e.trim()!="<br>"&&e.trim()!=""){this.sendMessage(e,function(){t.setContent("");this.scrollToLater()}.bind(this))}else{this.app.notice("不能发送空消息","error")}}.bind(this)},t,e||"",null,null);this.editor.load()}.bind(this))}});
|