MessageV2.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. //o2.require("o2.xDesktop.Message", null, false);
  2. MWF.xDesktop.MessageV2 = new Class({
  3. // Extends: MWF.xDesktop.Message,
  4. Implements: [Events],
  5. initialize: function(desktop){
  6. this.desktop = desktop;
  7. this.container = this.desktop.contentNode;
  8. this.actionNode = this.desktop.msgActionNode;
  9. this.items = [];
  10. this.isShow = false;
  11. this.isMorph = false;
  12. this.unread = 0;
  13. this.itemTemplate ='<div class="layout_message_item_top" data-o2-element="topNode">'+
  14. ' <div class="layout_message_item_top_close icon_msg_close" data-o2-element="closeNode" data-o2-events="click:closeMsg"></div>'+
  15. ' <div class="layout_message_item_top_subject" data-o2-element="subjectNode" title="{{$.msg.subject}}">{{$.msg.subject}}</div>'+
  16. '</div>'+
  17. '<div class="layout_message_item_content" data-o2-element="contentNode"></div>'+
  18. '<div class="layout_message_item_bottom" data-o2-element="bottomNode">'+
  19. ' <div class="layout_message_item_bottom_date" data-o2-element="dateNode"></div>'+
  20. ' <div class="layout_message_item_bottom_action" data-o2-element="actionsNode"></div>'+
  21. '</div>';
  22. },
  23. load: function(){
  24. //var path = this.desktop.path+this.desktop.options.style+((o2.session.isMobile || layout.mobile) ? "/layout-message-mobile.html" : "/layout-message-pc.html");
  25. var path = this.desktop.path+this.desktop.options.style+"/layout-message-pc.html";
  26. this.container.loadHtml(path, {"bind": {"lp": o2.LP.desktop}, "module": this}, function(){
  27. MWF.require("MWF.widget.ScrollBar", function(){
  28. new MWF.widget.ScrollBar(this.scrollNode, {
  29. "style":"xDesktop_Message", "where": "before", "indent": false, "distance": 100, "friction": 6, "axis": {"x": false, "y": true}
  30. });
  31. }.bind(this));
  32. this.node.addEvent("mousedown", function(e){
  33. e.stopPropagation();
  34. e.preventDefault();
  35. });
  36. this.hideMessage = function(){ this.hide(); }.bind(this);
  37. this.fireEvent("load");
  38. }.bind(this));
  39. },
  40. setPosition: function(){
  41. var size = this.container.getSize();
  42. var position = this.container.getPosition();
  43. this.maskNode.setStyle("height", ""+size.y+"px");
  44. this.node.setStyle("height", ""+size.y+"px");
  45. var y = size.y - 40;
  46. this.scrollNode.setStyle("height", ""+y+"px");
  47. var left = size.x;
  48. var top = position.y
  49. this.maskNode.setStyles({"left": ""+left+"px", "top": "0px"});
  50. this.node.setStyles({"left": ""+left+"px", "top": "0px"});
  51. },
  52. show: function(){
  53. var index = MWF.xDesktop.zIndexPool.zIndex;
  54. // this.css.messageContainerMaskNode["z-index"] = index;
  55. // this.css.messageContainerNode["z-index"] = index;
  56. if (!this.isMorph){
  57. this.isMorph = true;
  58. this.setPosition();
  59. if (!this.morph){
  60. this.maskMorph = new Fx.Morph(this.maskNode, {
  61. duration: "200",
  62. transition: Fx.Transitions.Sine.easeOut
  63. });
  64. this.morph = new Fx.Morph(this.node, {
  65. duration: "200",
  66. transition: Fx.Transitions.Sine.easeOut
  67. });
  68. }
  69. this.maskNode.setStyles({"display": "block", "z-index": index});
  70. this.node.setStyles({"display": "block", "z-index": index});
  71. var position = this.node.getPosition(this.node.getOffsetParent());
  72. var size = this.node.getSize();
  73. var scale = layout.userLayout.scale || 1;
  74. // var left = position.x*scale-size.x;
  75. var left = position.x-size.x;
  76. this.maskMorph.start({"left": ""+left+"px", "z-index":index});
  77. this.morph.start({"left": ""+left+"px", "z-index":index}).chain(function(){
  78. this.isShow = true;
  79. this.isMorph = false;
  80. this.desktop.desktopNode.addEvent("mousedown", this.hideMessage);
  81. this.fireEvent("show");
  82. }.bind(this));
  83. }
  84. },
  85. hide: function(){
  86. if (!this.isMorph){
  87. this.isMorph = true;
  88. if (!this.morph){
  89. this.maskMorph = new Fx.Morph(this.maskNode, {
  90. duration: "200",
  91. transition: Fx.Transitions.Sine.easeOut
  92. });
  93. this.morph = new Fx.Morph(this.node, {
  94. duration: "200",
  95. transition: Fx.Transitions.Sine.easeOut
  96. });
  97. }
  98. var position = this.node.getPosition(this.node.getOffsetParent());
  99. var size = this.node.getSize();
  100. var scale = layout.userLayout.scale || 1;
  101. var left = position.x*scale+size.x;
  102. this.maskMorph.start({"left": ""+left+"px"}).chain(function(){
  103. this.maskNode.setStyle("display", "none");
  104. }.bind(this));
  105. this.morph.start({"left": ""+left+"px"}).chain(function(){
  106. this.node.setStyle("display", "none");
  107. this.isShow = false;
  108. this.isMorph = false;
  109. this.desktop.desktopNode.removeEvent("mousedown", this.hideMessage);
  110. this.fireEvent("hide");
  111. }.bind(this));
  112. }
  113. },
  114. resize: function(){
  115. this.setPosition();
  116. },
  117. clearMessage: function(){
  118. var clearItems = [];
  119. this.items.each(function(item){
  120. if (item.status!="progress") clearItems.push(item);
  121. }.bind(this));
  122. while (clearItems.length){
  123. clearItems[0].close();
  124. clearItems.erase(clearItems[0]);
  125. }
  126. },
  127. addMessage: function(msg, time){
  128. var showTime = (time) ? (new Date()).parse(time) : new Date();
  129. var item = new MWF.xDesktop.Message.Item(this,msg, showTime);
  130. this.items.push(item);
  131. this.addUnread();
  132. return item;
  133. },
  134. addTooltip: function(msg, time){
  135. var showTime = (time) ? (new Date()).parse(time) : new Date();
  136. var tooltop = new MWF.xDesktop.Message.Tooltip(this,msg,showTime);
  137. return tooltop;
  138. },
  139. getUnread: function(){
  140. //获取未读消息列表和数量
  141. return this.unread || 0;
  142. },
  143. setUnread: function(){
  144. //this.actionNode
  145. if (this.unread>0){
  146. if (!this.unreadNode){
  147. this.unreadNode = new Element("div.layout_message_unread_node").inject(this.actionNode);
  148. }
  149. this.unreadNode.set("text", this.unread);
  150. }else{
  151. if (this.unreadNode){
  152. this.unreadNode.destroy();
  153. this.unreadNode = null;
  154. delete this.unreadNode;
  155. }
  156. }
  157. },
  158. addUnread: function(count){
  159. var addCount = count || 1;
  160. this.unread = this.unread+addCount;
  161. this.setUnread();
  162. }
  163. });
  164. MWF.xDesktop.MessageV2.Item = new Class({
  165. Implements: [Events],
  166. initialize: function(message, msg, showTime){
  167. this.message = message;
  168. this.container = this.message.contentNode;
  169. this.css = this.message.css;
  170. this.msg = msg;
  171. this.showTime = showTime;
  172. this.load();
  173. },
  174. load: function(){
  175. //injectHtml
  176. this.node = new Element("div.layout_message_item").inject(this.container, "top");
  177. this.node.injectHtml(this.message.itemTemplate, {"bind": {"msg": this.msg}, "module": this});
  178. this.contentNode.set({"html": this.msg.content});
  179. this.contentNode.set({"title": this.contentNode.get("text")});
  180. this.dateNode.set("text", this.showTime.format("db"));
  181. this.setEvent();
  182. },
  183. setEvent: function(){},
  184. closeMsg: function(e){
  185. this.close(null, e)
  186. },
  187. close: function(callback, e){
  188. //flag = true;
  189. //this.fireEvent("close", [flag, e]);
  190. //alert(flag);
  191. //if (flag){
  192. this.closeItem(callback, e);
  193. //}
  194. },
  195. closeItem: function(callback){
  196. var morph = new Fx.Morph(this.node, {
  197. duration: "200"
  198. // transition: Fx.Transitions.Sine.easeOut
  199. });
  200. var size = this.node.getSize();
  201. this.node.setStyle("height", ""+size.y+"px");
  202. this.message.items.erase(this);
  203. morph.start({
  204. "opacity": 0,
  205. "height": "0px"
  206. }).chain(function(){
  207. this.message.addUnread(-1);
  208. this.node.destroy();
  209. if (callback) callback();
  210. delete this;
  211. }.bind(this));
  212. }
  213. });
  214. MWF.xDesktop.MessageV2.Item.tooltips = [];
  215. MWF.xDesktop.MessageV2.tooltipNode = null;
  216. MWF.xDesktop.MessageV2.Tooltip = new Class({
  217. Extends: MWF.xDesktop.MessageV2.Item,
  218. setEvent: function(){
  219. if (!MWF.xDesktop.MessageV2.tooltipNode){
  220. MWF.xDesktop.MessageV2.tooltipNode = new Element("div.layout_message_tooltipArea").inject(this.message.container);
  221. var toNode = this.message.desktop.contentNode;
  222. MWF.xDesktop.MessageV2.tooltipNode.position({
  223. relativeTo: toNode,
  224. position: "rightTop",
  225. edge: "rightTop"
  226. });
  227. }
  228. this.node.inject(MWF.xDesktop.MessageV2.tooltipNode);
  229. this.node.addClass("layout_message_tooltip_item");
  230. MWF.xDesktop.MessageV2.Item.tooltips.push(this);
  231. window.setTimeout(function(){
  232. this.close(function(){
  233. MWF.xDesktop.MessageV2.Item.tooltips.erase(this);
  234. }.bind(this));
  235. }.bind(this), 10000);
  236. // this.closeNode.addEvents({
  237. // "click": function(){
  238. // this.close(function(){
  239. // MWF.xDesktop.MessageV2.Item.tooltips.erase(this);
  240. // }.bind(this));
  241. // }.bind(this)
  242. // });
  243. },
  244. closeMsg: function(){
  245. this.close(function(){
  246. MWF.xDesktop.MessageV2.Item.tooltips.erase(this);
  247. }.bind(this));
  248. },
  249. closeItem: function(callback){
  250. var morph = new Fx.Morph(this.node, {
  251. duration: "200"
  252. // transition: Fx.Transitions.Sine.easeOut
  253. });
  254. var size = this.node.getSize();
  255. this.node.setStyle("height", ""+size.y+"px");
  256. this.message.items.erase(this);
  257. morph.start({
  258. "opacity": 0,
  259. "height": "0px"
  260. }).chain(function(){
  261. //this.message.addUnread(-1);
  262. this.node.destroy();
  263. if (callback) callback();
  264. delete this;
  265. }.bind(this));
  266. }
  267. });
  268. MWF.xDesktop.Message = MWF.xDesktop.MessageV2;