Message.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. MWF.xDesktop.Message = new Class({
  2. Implements: [Options, Events],
  3. options: {
  4. "style": "default"
  5. },
  6. initialize: function(desktop, options){
  7. this.setOptions(options);
  8. this.desktop = desktop;
  9. this.container = this.desktop.desktopNode;
  10. this.actionNode = this.desktop.top.messageActionNode;
  11. this.css = this.desktop.css;
  12. this.items = [];
  13. this.isShow = false;
  14. this.isMorph = false;
  15. this.unread = 0;
  16. },
  17. load: function(){
  18. this.maskNode = new Element("iframe", {"styles": this.css.messageContainerMaskNode});
  19. this.maskNode.setStyles({
  20. "border": "0px",
  21. "margin": "0px",
  22. "padding": "0px"
  23. });
  24. this.maskNode.inject(this.container);
  25. this.node = new Element("div", {"styles": this.css.messageContainerNode});
  26. this.node.inject(this.container);
  27. this.scrollNode = new Element("div", {"styles": this.css.messageContainersScrollNode}).inject(this.node);
  28. this.contentNode = new Element("div", {"styles": this.css.messageContainerContentNode}).inject(this.scrollNode);
  29. this.operationNode = new Element("div", {"styles": this.css.messageContainersOperationNode}).inject(this.node);
  30. this.clearAction = new Element("div", {"styles": this.css.messageContainersClearActionNode, "text": MWF.LP.desktop.clearMessage}).inject(this.operationNode);
  31. this.clearAction.addEvents({
  32. "mouseover": function(){this.clearAction.setStyles(this.css.messageContainersClearActionNode_over);}.bind(this),
  33. "mouseout": function(){this.clearAction.setStyles(this.css.messageContainersClearActionNode);}.bind(this),
  34. "mousedown": function(){this.clearAction.setStyles(this.css.messageContainersClearActionNode_down);}.bind(this),
  35. "mouseup": function(){this.clearAction.setStyles(this.css.messageContainersClearActionNode_over);}.bind(this),
  36. "click": function(){this.clearMessage();}.bind(this)
  37. });
  38. MWF.require("MWF.widget.ScrollBar", function(){
  39. new MWF.widget.ScrollBar(this.scrollNode, {
  40. "style":"xDesktop_Message", "where": "before", "indent": false, "distance": 100, "friction": 6, "axis": {"x": false, "y": true}
  41. });
  42. }.bind(this));
  43. this.node.addEvent("click", function(e){
  44. e.stopPropagation();
  45. e.preventDefault();
  46. });
  47. this.setPosition();
  48. this.hideMessage = function(){
  49. this.hide();
  50. }.bind(this);
  51. },
  52. clearMessage: function(){
  53. var clearItems = [];
  54. this.items.each(function(item){
  55. if (item.status!="progress") clearItems.push(item);
  56. }.bind(this));
  57. while (clearItems.length){
  58. clearItems[0].close();
  59. clearItems.erase(clearItems[0]);
  60. }
  61. },
  62. setPosition: function(){
  63. var size = this.container.getSize();
  64. var position = this.container.getPosition();
  65. this.maskNode.setStyle("height", ""+size.y+"px");
  66. this.node.setStyle("height", ""+size.y+"px");
  67. var y = size.y - 40;
  68. this.scrollNode.setStyle("height", ""+y+"px");
  69. this.maskNode.position({
  70. relativeTo: this.container,
  71. position: "rightTop",
  72. edge: (this.isShow) ? "rightTop" : "leftTop"
  73. // offset: {"x": 0, "y": -100}
  74. });
  75. this.node.position({
  76. relativeTo: this.container,
  77. position: "rightTop",
  78. edge: (this.isShow) ? "rightTop" : "leftTop"
  79. // offset: {"x": 0, "y": -100}
  80. });
  81. },
  82. show: function(){
  83. var index = MWF.xDesktop.zIndexPool.zIndex
  84. this.css.messageContainerMaskNode["z-index"] = index;
  85. this.css.messageContainerNode["z-index"] = index;
  86. if (!this.isMorph){
  87. this.isMorph = true;
  88. this.setPosition();
  89. if (!this.morph){
  90. this.maskMorph = new Fx.Morph(this.maskNode, {
  91. duration: "200",
  92. transition: Fx.Transitions.Sine.easeOut
  93. });
  94. this.morph = new Fx.Morph(this.node, {
  95. duration: "200",
  96. transition: Fx.Transitions.Sine.easeOut
  97. });
  98. }
  99. this.maskNode.setStyle("display", "block");
  100. this.node.setStyle("display", "block");
  101. var position = this.node.getPosition();
  102. var size = this.node.getSize();
  103. var left = position.x-size.x;
  104. this.maskMorph.start({"left": ""+left+"px", "z-index":index});
  105. this.morph.start({"left": ""+left+"px", "z-index":index}).chain(function(){
  106. this.isShow = true;
  107. this.isMorph = false;
  108. this.desktop.node.addEvent("click", this.hideMessage);
  109. }.bind(this));
  110. }
  111. },
  112. hide: function(){
  113. if (!this.isMorph){
  114. this.isMorph = true;
  115. if (!this.morph){
  116. this.maskMorph = new Fx.Morph(this.maskNode, {
  117. duration: "200",
  118. transition: Fx.Transitions.Sine.easeOut
  119. });
  120. this.morph = new Fx.Morph(this.node, {
  121. duration: "200",
  122. transition: Fx.Transitions.Sine.easeOut
  123. });
  124. }
  125. var position = this.node.getPosition();
  126. var size = this.node.getSize();
  127. var left = position.x+size.x;
  128. this.maskMorph.start({"left": ""+left+"px"}).chain(function(){
  129. this.maskNode.setStyle("display", "none");
  130. }.bind(this));
  131. this.morph.start({"left": ""+left+"px"}).chain(function(){
  132. this.node.setStyle("display", "none");
  133. this.isShow = false;
  134. this.isMorph = false;
  135. this.desktop.node.removeEvent("click", this.hideMessage);
  136. }.bind(this));
  137. }
  138. },
  139. resize: function(){
  140. this.setPosition();
  141. },
  142. addMessage: function(msg){
  143. var item = new MWF.xDesktop.Message.Item(this,msg);
  144. this.items.push(item);
  145. this.addUnread();
  146. return item;
  147. },
  148. addTooltip: function(msg){
  149. var tooltop = new MWF.xDesktop.Message.Tooltip(this,msg);
  150. return tooltop;
  151. },
  152. getUnread: function(){
  153. //获取未读消息列表和数量
  154. return this.unread || 0;
  155. },
  156. setUnread: function(){
  157. //this.actionNode
  158. if (this.unread>0){
  159. if (!this.unreadNode){
  160. this.unreadNode = new Element("div", {"styles": this.css.messageUnreadCountNode}).inject(this.actionNode);
  161. }
  162. this.unreadNode.set("text", this.unread);
  163. }else{
  164. if (this.unreadNode){
  165. this.unreadNode.destroy();
  166. this.unreadNode = null;
  167. delete this.unreadNode;
  168. }
  169. }
  170. },
  171. addUnread: function(count){
  172. var addCount = count || 1;
  173. this.unread = this.unread+addCount;
  174. this.setUnread();
  175. }
  176. });
  177. MWF.xDesktop.Message.Item = new Class({
  178. Implements: [Events],
  179. initialize: function(message, msg){
  180. this.message = message;
  181. this.container = this.message.contentNode;
  182. this.css = this.message.css;
  183. this.msg = msg;
  184. // msg = {
  185. // "subject": "",
  186. // "content": "",
  187. // "type": "",
  188. // "action": {
  189. //
  190. // }
  191. // };
  192. this.load();
  193. },
  194. load: function(){
  195. this.node = new Element("div", {"styles": this.css.messageItemNode});
  196. this.topNode = new Element("div", {"styles": this.css.messageItemTopNode}).inject(this.node);
  197. this.closeNode = new Element("div", {"styles": this.css.messageItemCloseNode}).inject(this.topNode);
  198. this.subjectNode = new Element("div", {"styles": this.css.messageItemSubjectNode}).inject(this.topNode);
  199. this.contentNode = new Element("div", {"styles": this.css.messageItemContentNode}).inject(this.node);
  200. this.bottomNode = new Element("div", {"styles": this.css.messageItemBottomNode}).inject(this.node);
  201. this.dateNode = new Element("div", {"styles": this.css.messageItemDateNode}).inject(this.bottomNode);
  202. this.actionsNode = new Element("div", {"styles": this.css.messageItemActionsNode}).inject(this.bottomNode);
  203. this.subjectNode.set({"text": this.msg.subject, "title": this.msg.subject});
  204. this.contentNode.set({"html": this.msg.content});
  205. this.contentNode.set({"title": this.contentNode.get("text")});
  206. this.dateNode.set("text", (new Date()).format("db"));
  207. this.node.inject(this.container, "top");
  208. this.setEvent();
  209. },
  210. setEvent: function(){
  211. this.closeNode.addEvents({
  212. "click": function(e){
  213. this.close(null, e);
  214. }.bind(this)
  215. });
  216. },
  217. close: function(callback, e){
  218. //flag = true;
  219. //this.fireEvent("close", [flag, e]);
  220. //alert(flag);
  221. //if (flag){
  222. this.closeItem(callback, e);
  223. //}
  224. },
  225. closeItem: function(callback){
  226. var morph = new Fx.Morph(this.node, {
  227. duration: "200"
  228. // transition: Fx.Transitions.Sine.easeOut
  229. });
  230. var size = this.node.getSize();
  231. this.node.setStyle("height", ""+size.y+"px");
  232. this.message.items.erase(this);
  233. morph.start({
  234. "opacity": 0,
  235. "height": "0px"
  236. }).chain(function(){
  237. this.message.addUnread(-1);
  238. this.node.destroy();
  239. if (callback) callback();
  240. delete this;
  241. }.bind(this));
  242. }
  243. });
  244. MWF.xDesktop.Message.Item.tooltips = [];
  245. MWF.xDesktop.Message.tooltipNode = null;
  246. MWF.xDesktop.Message.Tooltip = new Class({
  247. Extends: MWF.xDesktop.Message.Item,
  248. setEvent: function(){
  249. if (!MWF.xDesktop.Message.tooltipNode){
  250. MWF.xDesktop.Message.tooltipNode = new Element("div", {
  251. "styles": this.css.messageTooltipAreaNode
  252. }).inject(this.message.container);
  253. var toNode = this.message.desktop.desktopNode;
  254. MWF.xDesktop.Message.tooltipNode.position({
  255. relativeTo: toNode,
  256. position: "rightTop",
  257. edge: "rightTop"
  258. });
  259. }
  260. this.node.inject(MWF.xDesktop.Message.tooltipNode);
  261. this.node.setStyles(this.css.messageTooltipNode);
  262. //if (MWF.xDesktop.Message.Item.tooltips.length){
  263. // var toNode = MWF.xDesktop.Message.Item.tooltips[MWF.xDesktop.Message.Item.tooltips.length-1].node;
  264. // this.node.position({
  265. // relativeTo: toNode,
  266. // position: "centerBottom",
  267. // edge: "centerTop",
  268. // offset: {"x": 0, "y": 10}
  269. // });
  270. //}else{
  271. // var toNode = this.message.desktop.desktopNode;
  272. // this.node.position({
  273. // relativeTo: toNode,
  274. // position: "rightTop",
  275. // edge: "rightTop",
  276. // offset: {"x": -10, "y": 10}
  277. // });
  278. //}
  279. MWF.xDesktop.Message.Item.tooltips.push(this);
  280. window.setTimeout(function(){
  281. this.close(function(){
  282. MWF.xDesktop.Message.Item.tooltips.erase(this);
  283. }.bind(this));
  284. }.bind(this), 10000);
  285. this.closeNode.addEvents({
  286. "click": function(){
  287. this.close(function(){
  288. MWF.xDesktop.Message.Item.tooltips.erase(this);
  289. }.bind(this));
  290. }.bind(this)
  291. });
  292. },
  293. closeItem: function(callback){
  294. var morph = new Fx.Morph(this.node, {
  295. duration: "200"
  296. // transition: Fx.Transitions.Sine.easeOut
  297. });
  298. var size = this.node.getSize();
  299. this.node.setStyle("height", ""+size.y+"px");
  300. this.message.items.erase(this);
  301. morph.start({
  302. "opacity": 0,
  303. "height": "0px"
  304. }).chain(function(){
  305. //this.message.addUnread(-1);
  306. this.node.destroy();
  307. if (callback) callback();
  308. delete this;
  309. }.bind(this));
  310. }
  311. });