Main.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. MWF.xApplication.Message.options.multitask = true;
  2. MWF.require("MWF.widget.O2Identity", null,false);
  3. MWF.xApplication.Message.Main = new Class({
  4. Extends: MWF.xApplication.Common.Main,
  5. Implements: [Options, Events],
  6. options: {
  7. "style1": "default",
  8. "style": "default",
  9. "name": "Message",
  10. "icon": "icon.png",
  11. "width": "1100",
  12. "height": "700",
  13. "title": MWF.xApplication.Message.LP.title
  14. },
  15. onQueryLoad: function(){
  16. this.lp = MWF.xApplication.Message.LP;
  17. },
  18. loadApplication: function(callback){
  19. this.node = new Element("div", {"styles": {"width": "100%", "height": "100%"}}).inject(this.content);
  20. this.leftNode = new Element("div", {"styles": this.css.leftNode}).inject(this.node);
  21. this.contentNode = new Element("div", {"styles": this.css.contentNode}).inject(this.node);
  22. this.menuNode = new Element("div", {"styles": this.css.menuNode}).inject(this.leftNode);
  23. this.listNode = new Element("div", {"styles": this.css.listNode}).inject(this.leftNode);
  24. this.setListNodeSizeFun = this.setListNodeSize.bind(this);
  25. this.addEvent("resize", this.setListNodeSizeFun);
  26. this.setListNodeSize();
  27. this.loadMenu(function(){
  28. if (MWF.AC.isMessageManager()){
  29. this.initList();
  30. this.loadList();
  31. this.listNode.addEvent("scroll", function(){
  32. var s = this.listNode.getScroll();
  33. var size = this.listNode.getSize();
  34. var sSize = this.listNode.getScrollSize();
  35. if (sSize.y-size.y-s.y<100) if (!this.listAll) this.loadList();
  36. }.bind(this));
  37. if (callback) callback();
  38. }else{
  39. this.createNoAcListNode();
  40. }
  41. }.bind(this));
  42. },
  43. initList: function(){
  44. this.removeItems = [];
  45. this.listItems = [];
  46. this.lastId = "(0)";
  47. this.listCount = 0;
  48. this.listAll = false;
  49. this.listPageCount = this.getPageCount();
  50. },
  51. getPageCount: function(){
  52. var size = this.listNode.getSize();
  53. return (size.y/80).toInt()+5;
  54. },
  55. setListNodeSize: function(){
  56. var menuSize = this.menuNode.getSize();
  57. var size = this.content.getSize();
  58. var y = size.y-menuSize.y;
  59. this.listNode.setStyle("height", ""+y+"px");
  60. },
  61. loadMenu: function(callback){
  62. this.actionArea = new Element("div", {"styles": this.css.actionArea}).inject(this.menuNode);
  63. this.logoArea = new Element("div", {"styles": this.css.logoArea}).inject(this.menuNode);
  64. this.iconNode = new Element("div", {"styles": this.css.logoIconNode}).inject(this.logoArea);
  65. this.titleNode = new Element("div", {"styles": this.css.logoTitleNode}).inject(this.logoArea);
  66. var action = MWF.Actions.get("x_message_assemble_communicate");
  67. action.enableType(function(json){
  68. this.type = json.data.value;
  69. if (this.type==="qiyeweixin"){
  70. this.iconNode.setStyle("background-image", "url("+this.path+this.options.style+"/icon/weixin.png)");
  71. this.titleNode.set("text", this.lp.weixin);
  72. this.loadAddAction();
  73. }else if (this.type==="dingding"){
  74. this.iconNode.setStyle("background-image", "url("+this.path+this.options.style+"/icon/dingding.png)");
  75. this.titleNode.set("text", this.lp.dingding);
  76. this.loadAddAction();
  77. }else{
  78. this.iconNode.setStyle("background-image", "");
  79. this.titleNode.set("text", this.lp.disabled);
  80. }
  81. if (callback) callback();
  82. }.bind(this));
  83. },
  84. loadAddAction: function(){
  85. if (MWF.AC.isMessageManager()){
  86. this.addAction = new Element("div", {"styles": this.css.addAction, "title": this.lp.new}).inject(this.actionArea);
  87. this.addAction.addEvents({
  88. "click": function(){
  89. this.createMessage();
  90. }.bind(this)
  91. });
  92. }
  93. },
  94. loadMenu1: function(){
  95. this.actionArea = new Element("div", {"styles": this.css.actionArea}).inject(this.menuNode);
  96. this.searchArea = new Element("div", {"styles": this.css.searchArea}).inject(this.menuNode);
  97. this.addAction = new Element("div", {"styles": this.css.addAction, "title": this.lp.new}).inject(this.actionArea);
  98. this.searchNode = new Element("div", {"styles": this.css.searchNode}).inject(this.searchArea);
  99. this.searchActionNode = new Element("div", {"styles": this.css.searchActionNode}).inject(this.searchNode);
  100. this.searchBarNode = new Element("div", {"styles": this.css.searchBarNode}).inject(this.searchNode);
  101. this.searchInput = new Element("input", {"styles": this.css.searchInput, "value": this.lp.search}).inject(this.searchBarNode);
  102. this.searchInput.addEvents({
  103. "focus": function(){if (this.searchInput.get("value")===this.lp.search) this.searchInput.set("value", "");}.bind(this),
  104. "blur": function(){if (!this.searchInput.get("value")) this.searchInput.set("value", this.lp.search);}.bind(this),
  105. "keydown": function(e){
  106. if (e.code===13) this.search();
  107. var key = this.searchInput.get("value");
  108. if (key && key!==this.lp.search){
  109. this.showSearchClear();
  110. }else{
  111. this.clearSearch();
  112. this.hideSearchClear();
  113. }
  114. }.bind(this)
  115. });
  116. this.searchActionNode.addEvents({
  117. "mouseover": function(){this.setStyle("background-color", "#eeeeee")},
  118. "mouseout": function(){this.setStyle("background-color", "#ffffff")},
  119. "click": function(){this.search();}.bind(this)
  120. });
  121. this.addAction.addEvents({
  122. "click": function(e){
  123. this.createMessage(e);
  124. }.bind(this)
  125. });
  126. },
  127. loadList: function(){
  128. var action = MWF.Actions.get("x_message_assemble_communicate");
  129. action.list(this.lastId, this.listPageCount, function(json){
  130. var count = json.data.length;
  131. if (!count){
  132. if (this.lastId==="(0)"){
  133. this.createNoListNode();
  134. this.listAll = true;
  135. }
  136. }else{
  137. this.createListNodes(json.data);
  138. this.lastId = json.data[json.data.length-1].id;
  139. }
  140. if (count<this.listPageCount) this.listAll = true;
  141. }.bind(this));
  142. },
  143. createNoListNode: function(){
  144. new Element("div", {"styles": this.css.noListNode, "text": this.lp.noListNode}).inject(this.listNode)
  145. },
  146. createNoAcListNode: function(){
  147. new Element("div", {"styles": this.css.noListNode, "text": this.lp.noAcListNode}).inject(this.listNode)
  148. },
  149. createListNodes: function(items){
  150. items.each(function(item){
  151. this.listItems.push(new MWF.xApplication.Message.Item(item, this));
  152. }.bind(this))
  153. },
  154. showSearchClear: function(){
  155. this.searchArea.setStyles(this.css.searchArea_key);
  156. this.searchBarNode.setStyles(this.css.searchBarNode_key);
  157. if (!this.clearActionNode){
  158. this.clearActionNode = new Element("div", {"styles": this.css.clearActionNode}).inject(this.searchActionNode, "before");
  159. this.clearActionNode.addEvents({
  160. "mouseover": function(){this.setStyle("background-color", "#eeeeee")},
  161. "mouseout": function(){this.setStyle("background-color", "#ffffff")},
  162. "click": function(){
  163. this.searchInput.set("value", this.lp.search);
  164. this.clearSearch();
  165. this.hideSearchClear();
  166. }.bind(this)
  167. });
  168. }
  169. },
  170. hideSearchClear: function(){
  171. if (this.clearActionNode){
  172. this.clearActionNode.destroy();
  173. this.clearActionNode = null;
  174. this.searchArea.setStyles(this.css.searchArea);
  175. this.searchBarNode.setStyles(this.css.searchBarNode);
  176. }
  177. },
  178. search: function(){
  179. var key = this.searchInput.get("value");
  180. if (e.code===13){
  181. if (key && key!==this.lp.search){
  182. this.doSearch(key);
  183. }
  184. }
  185. },
  186. doSearch: function(key){
  187. },
  188. clearSearch: function(){
  189. },
  190. createMessage: function(e){
  191. if (this.currentDocument){
  192. this.currentDocument.close(null, e, function(){
  193. this.currentDocument = new MWF.xApplication.Message.Document(null, this);
  194. }.bind(this));
  195. }else{
  196. this.currentDocument = new MWF.xApplication.Message.Document(null, this);
  197. }
  198. },
  199. checkRemoveAction: function(item){
  200. if (this.removeItems.length){
  201. if (!this.removeAction) this.createRemoveAction();
  202. this.removeAction.position({
  203. relativeTo: item.node,
  204. position: "centerBottom",
  205. edge: "centerTop"
  206. });
  207. }else{
  208. this.deleteRemoveAction();
  209. }
  210. },
  211. createRemoveAction: function(item){
  212. this.removeAction = new Element("div", {"styles": this.css.removeAction}).inject(this.content);
  213. this.removeDeleteAction = new Element("div", {"styles": this.css.removeDeleteAction, "text": this.lp.removeText}).inject(this.removeAction);
  214. this.removeCancelAction = new Element("div", {"styles": this.css.removeCancelAction, "text": this.lp.cancel}).inject(this.removeAction);
  215. this.removeCancelAction.addEvent("click", function(){
  216. while (this.removeItems.length){
  217. this.removeItems[0].readyRemove();
  218. }
  219. }.bind(this));
  220. this.removeDeleteAction.addEvent("click", function(){
  221. this.removeItems.each(function(item){
  222. item.remove(function(){
  223. this.checkRemoveAction();
  224. }.bind(this));
  225. }.bind(this));
  226. }.bind(this));
  227. },
  228. deleteRemoveAction: function(){
  229. if (this.removeAction){
  230. this.removeAction.destroy();
  231. this.removeAction = null;
  232. }
  233. }
  234. });
  235. MWF.xApplication.Message.Document = new Class({
  236. initialize: function(data, app, item){
  237. this.app = app;
  238. this.item = item;
  239. this.data = data || {};
  240. this.data.unitList = this.data.unitList || [];
  241. this.data.identityList = this.data.identityList || [];
  242. this.data.groupList = this.data.groupList || [];
  243. this.data.personList = this.data.personList || [];
  244. this.isNew = (this.data.id) ? false : true;
  245. this.contentNode = this.app.contentNode;
  246. this.css = this.app.css;
  247. this.lp = this.app.lp;
  248. this.load();
  249. },
  250. load: function(){
  251. this.node = new Element("div", {"styles": this.css.documentNode}).inject(this.contentNode);
  252. this.menuNode = new Element("div", {"styles": this.css.documentMenuNode}).inject(this.node);
  253. this.loadMenu();
  254. this.contentNode = new Element("div", {"styles": this.css.documentContentNode}).inject(this.node);
  255. this.setContentNodeSizeFun = this.setContentNodeSize.bind(this);
  256. this.app.addEvent("resize", this.setContentNodeSizeFun);
  257. this.setContentNodeSize();
  258. this.loadContent();
  259. },
  260. loadMenu: function(){
  261. //this.actionArea = new Element("div", {"styles": this.css.documentActionArea}).inject(this.menuNode);
  262. MWF.require("MWF.widget.Toolbar", function(){
  263. this.toolbar = new MWF.widget.Toolbar(this.menuNode, {"style": "message"}, this);
  264. if (this.isNew){
  265. new Element("div", {
  266. "MWFnodeid": "send",
  267. "MWFnodetype": "MWFToolBarButton",
  268. "MWFButtonImage": this.app.path+this.app.options.style+"/icon/send.png",
  269. "title": this.lp.send,
  270. "MWFButtonAction": "send",
  271. "MWFButtonText": this.lp.send
  272. }).inject(this.menuNode);
  273. }else{
  274. new Element("div", {
  275. "MWFnodeid": "resend",
  276. "MWFnodetype": "MWFToolBarButton",
  277. "MWFButtonImage": this.app.path+this.app.options.style+"/icon/send.png",
  278. "title": this.lp.send,
  279. "MWFButtonAction": "resend",
  280. "MWFButtonText": this.lp.resend
  281. }).inject(this.menuNode);
  282. new Element("div", {
  283. "MWFnodeid": "remove",
  284. "MWFnodetype": "MWFToolBarButton",
  285. "MWFButtonImage": this.app.path+this.app.options.style+"/icon/remove.png",
  286. "title": this.lp.remove,
  287. "MWFButtonAction": "remove",
  288. "MWFButtonText": this.lp.remove
  289. }).inject(this.menuNode);
  290. }
  291. new Element("div", {
  292. "MWFnodeid": "close",
  293. "MWFnodetype": "MWFToolBarButton",
  294. "MWFButtonImage": this.app.path+this.app.options.style+"/icon/close.png",
  295. "title": this.lp.close,
  296. "MWFButtonAction": "close",
  297. "MWFButtonText": this.lp.close
  298. }).inject(this.menuNode);
  299. this.toolbar.load();
  300. }.bind(this));
  301. },
  302. loadContent: function(){
  303. if (this.isNew) {
  304. this.loadContentNew();
  305. }else{
  306. this.loadContentRead();
  307. }
  308. },
  309. loadContentNew: function(){
  310. var title = "";
  311. if (this.app.type==="qiyeweixin") title = this.lp.create_weixin;
  312. if (this.app.type==="dingding") title = this.lp.create_dingding;
  313. this.titleNode = new Element("div", {"styles": this.css.documentTitleNode, "text": title}).inject(this.contentNode);
  314. this.sendPersonArea = new Element("div", {"styles": this.css.documentSendPersonNode}).inject(this.contentNode);
  315. this.sendPersonTitle = new Element("div", {"styles": this.css.documentSendTitleNode, "text": this.lp.sendPerson}).inject(this.sendPersonArea);
  316. this.sendPersonSelect = new Element("div", {"styles": this.css.documentSendPersonSelectNode}).inject(this.sendPersonArea);
  317. this.sendPersonInputArea = new Element("div", {"styles": this.css.documentSendPersonInputAreaNode}).inject(this.sendPersonArea);
  318. this.selectAction = new Element("div", {"styles": this.css.documentSendPersonSelectAction, "text": this.lp.select}).inject(this.sendPersonSelect);
  319. this.sendPersonInput = new Element("div", {"styles": this.css.documentSendPersonInputNode}).inject(this.sendPersonInputArea);
  320. this.selectAction.addEvent("click", this.selectPerson.bind(this));
  321. this.sendPersonInput.addEvent("click", this.selectPerson.bind(this));
  322. var values = this.data.unitList.combine(this.data.identityList).combine(this.data.groupList).combine(this.data.personList);
  323. this.loadOrgWidget(values, this.sendPersonInput);
  324. this.sendBodyArea = new Element("div", {"styles": this.css.documentSendBodyNode}).inject(this.contentNode);
  325. this.sendBodyTitle = new Element("div", {"styles": this.css.documentSendTitleNode, "text": this.lp.sendBody}).inject(this.sendBodyArea);
  326. this.sendBodyInputArea = new Element("div", {"styles": this.css.documentSendBodyInputAreaNode}).inject(this.sendBodyArea);
  327. this.sendBodyInput = new Element("textarea", {"styles": this.css.documentSendBodyInputNode}).inject(this.sendBodyInputArea);
  328. if(this.data.body) this.sendBodyInput.set("value", this.data.body);
  329. },
  330. loadContentRead: function(){
  331. var title = "";
  332. if (this.data.type==="qiyeweixin") title = this.lp.open_weixin;
  333. if (this.data.type==="dingding") title = this.lp.open_dingding;
  334. this.titleNode = new Element("div", {"styles": this.css.documentTitleNode, "text": title}).inject(this.contentNode);
  335. this.sendPersonArea = new Element("div", {"styles": this.css.documentSendPersonNode}).inject(this.contentNode);
  336. this.sendPersonTitle = new Element("div", {"styles": this.css.documentSendTitleNode, "text": this.lp.sendPerson}).inject(this.sendPersonArea);
  337. this.sendPersonSelect = new Element("div", {"styles": this.css.documentSendPersonSelectNode}).inject(this.sendPersonArea);
  338. this.sendPersonInputArea = new Element("div", {"styles": this.css.documentSendPersonInputAreaNode}).inject(this.sendPersonArea);
  339. this.sendPersonInput = new Element("div", {"styles": this.css.documentSendPersonInputNode}).inject(this.sendPersonInputArea);
  340. var values = this.data.unitList.combine(this.data.identityList).combine(this.data.groupList).combine(this.data.personList);
  341. this.loadOrgWidget(values, this.sendPersonInput);
  342. this.sendBodyArea = new Element("div", {"styles": this.css.documentSendBodyNode}).inject(this.contentNode);
  343. this.sendBodyTitle = new Element("div", {"styles": this.css.documentSendTitleNode, "text": this.lp.sendBody}).inject(this.sendBodyArea);
  344. this.sendBodyInputArea = new Element("div", {"styles": this.css.documentSendBodyInputAreaNode}).inject(this.sendBodyArea);
  345. this.sendBodyInput = new Element("div", {"styles": this.css.documentSendBodyInputNode}).inject(this.sendBodyInputArea);
  346. this.sendBodyInput.set("text", this.data.body);
  347. },
  348. selectPerson: function(){
  349. MWF.xDesktop.requireApp("Selector", "package", function(){
  350. var values = this.data.unitList.combine(this.data.identityList).combine(this.data.groupList).combine(this.data.personList);
  351. var options = {
  352. "type" : "",
  353. "types": ["identity","unit","person","group"],
  354. "values" : values,
  355. "onComplete": function(items, itemsObject){
  356. this.data.identityList = [];
  357. this.data.unitList = [];
  358. this.data.groupList = [];
  359. this.data.personList = [];
  360. var arr = [];
  361. items.each( function(it){
  362. var id = it.data.distinguishedName;
  363. if (id) {
  364. var flag = id.substr(id.length-1,1);
  365. if (flag==="I") this.data.identityList.push(id);
  366. if (flag==="U") this.data.unitList.push(id);
  367. if (flag==="P") this.data.personList.push(id);
  368. if (flag==="G") this.data.groupList.push(id);
  369. arr.push(id);
  370. }
  371. }.bind(this));
  372. this.sendPersonInput.empty();
  373. this.loadOrgWidget(arr, this.sendPersonInput);
  374. }.bind(this)
  375. };
  376. new MWF.O2Selector(this.app.content, options);
  377. }.bind(this));
  378. },
  379. loadOrgWidget: function(values, node){
  380. var options = {"style": "xform", "canRemove":false , "onRemove" : this.removeItem};
  381. values.each(function(value){
  382. var flag = value.substr(value.length-1, 1);
  383. switch (flag.toLowerCase()){
  384. case "i":
  385. new MWF.widget.O2Identity({"id":value}, node, options );
  386. break;
  387. case "p":
  388. new MWF.widget.O2Person({"id":value}, node, options);
  389. break;
  390. case "u":
  391. new MWF.widget.O2Unit({"id":value}, node, options);
  392. break;
  393. case "g":
  394. new MWF.widget.O2Group({"id":value}, node, options);
  395. break;
  396. default:
  397. new MWF.widget.O2Other({"id":value}, node, options);
  398. }
  399. if( layout.mobile ){
  400. widget.node.setStyles({
  401. "float" : "none"
  402. })
  403. }
  404. }.bind(this));
  405. },
  406. setContentNodeSize: function(){
  407. var menuSize = this.menuNode.getSize();
  408. var size = this.app.content.getSize();
  409. var y = size.y-menuSize.y;
  410. this.contentNode.setStyle("height", ""+y+"px");
  411. },
  412. close: function(bt, e, success, failure){
  413. if (this.isNew){
  414. var _self = this;
  415. this.app.confirm("info", e, this.lp.closeConfirmTitle, this.lp.closeConfirmNew, "500", "120", function(){
  416. _self.doClose();
  417. if (success) success();
  418. this.close();
  419. }, function(){
  420. if (failure) failure();
  421. this.close();
  422. });
  423. }else{
  424. this.doClose();
  425. if (success) success();
  426. }
  427. },
  428. doClose: function(){
  429. if (this.setContentNodeSizeFun) this.app.removeEvent("resize", this.setContentNodeSizeFun);
  430. this.app.currentDocument = null;
  431. this.node.destroy();
  432. if (this.item) this.item.uncurrent();
  433. MWF.release(this);
  434. },
  435. remove: function(bt, e){
  436. var _self = this;
  437. this.app.confirm("info", e, this.lp.removeConfirmTitle, this.lp.removeConfirm, "400", "120", function(){
  438. _self.doRemove();
  439. this.close();
  440. }, function(){
  441. this.close();
  442. });
  443. },
  444. doRemove: function(){
  445. var action = MWF.Actions.get("x_message_assemble_communicate");
  446. action.delete(this.data.id, function(json){
  447. this.app.notice(this.lp.removeSuccess, "success");
  448. if (this.item) this.item.destroy();
  449. this.doClose();
  450. }.bind(this));
  451. },
  452. send: function(bt, e){
  453. if (!this.data.unitList.length && !this.data.identityList.length && !this.data.groupList.length && !this.data.personList.length){
  454. this.app.notice(this.lp.noSendPersonError, "error");
  455. return false;
  456. }
  457. if (!this.sendBodyInput.get("value")){
  458. this.app.notice(this.lp.noSendBodyError, "error");
  459. return false;
  460. }
  461. var _self = this;
  462. this.app.confirm("info", e, this.lp.sendConfirmTitle, this.lp.sendConfirm, "300", "120", function(){
  463. _self.doSend();
  464. this.close();
  465. }, function(){
  466. this.close();
  467. });
  468. },
  469. doSend: function(){
  470. this.data.body = this.sendBodyInput.get("value");
  471. var action = MWF.Actions.get("x_message_assemble_communicate");
  472. action.create(this.data, function(json){
  473. this.app.notice(this.lp.sendSuccess, "success");
  474. if (!this.app.listItems.length) this.app.listNode.empty();
  475. var item = new MWF.xApplication.Message.Item(json.data, this.app);
  476. item.node.inject(this.app.listNode, "top");
  477. this.app.listItems.push(item);
  478. this.doClose();
  479. }.bind(this));
  480. },
  481. resend: function(){
  482. var data = Object.clone(this.data);
  483. data.id = "";
  484. var app = this.app;
  485. this.doClose();
  486. new MWF.xApplication.Message.Document(data, app);
  487. }
  488. });
  489. MWF.xApplication.Message.Item = new Class({
  490. initialize: function(data, app){
  491. this.app = app;
  492. this.data = data;
  493. this.contentNode = this.app.listNode;
  494. this.css = this.app.css;
  495. this.lp = this.app.lp;
  496. this.isRemove = false;
  497. this.load();
  498. },
  499. load: function(){
  500. this.node = new Element("div", {"styles": this.css.listItemNode}).inject(this.contentNode);
  501. this.action = new Element("div", {"styles": this.css.listItemActionNode}).inject(this.node);
  502. this.icon = new Element("div", {"styles": this.css.listItemIconNode}).inject(this.node);
  503. this.content = new Element("div", {"styles": this.css.listItemContentNode}).inject(this.node);
  504. if (this.data.type==="qiyeweixin"){
  505. this.icon.setStyle("background-image", "url("+this.app.path+this.app.options.style+"/icon/weixin32.png)");
  506. }else if (this.data.type==="dingding"){
  507. this.icon.setStyle("background-image", "url("+this.app.path+this.app.options.style+"/icon/dingding32.png)");
  508. }else{
  509. this.icon.setStyle("background-image", "");
  510. }
  511. this.titleLine = new Element("div", {"styles": this.css.listItemTitleLine}).inject(this.content);
  512. this.bodyLine = new Element("div", {"styles": this.css.listItemBodyLine}).inject(this.content);
  513. this.personLine = new Element("div", {"styles": this.css.listItemPersonLine}).inject(this.content);
  514. new Element("div", {"styles": this.css.listItemTitleLineTextLeft, "text": this.data.createTime}).inject(this.titleLine);
  515. new Element("div", {"styles": this.css.listItemTitleLineTextRight, "text": MWF.name.cn(this.data.creatorPerson)}).inject(this.titleLine);
  516. new Element("div", {"text": this.data.body}).inject(this.bodyLine);
  517. var values = this.data.unitList.combine(this.data.identityList).combine(this.data.groupList).combine(this.data.personList);
  518. new Element("div", {"text": this.lp.sendPerson+MWF.name.cns(values).join(", ")}).inject(this.personLine);
  519. this.setEvent();
  520. },
  521. setEvent: function(){
  522. this.node.addEvents({
  523. "mouseover": function(){
  524. if (!this.isRemove){
  525. this.action.fade("in");
  526. if (!this.app.currentDocument || this.app.currentDocument.data.id!==this.data.id) this.node.setStyle("background-color", "#eaf2fb");
  527. }
  528. }.bind(this),
  529. "mouseout": function(){
  530. if (!this.isRemove){
  531. this.action.fade("out");
  532. if (!this.app.currentDocument || this.app.currentDocument.data.id!==this.data.id) this.node.setStyle("background-color", "#ffffff");
  533. }
  534. }.bind(this),
  535. "click": function(e){
  536. if (!this.isRemove) this.node.setStyle("background-color", "#dcecfd");
  537. this.open(e);
  538. }.bind(this)
  539. });
  540. this.action.addEvents({
  541. "click": function(e){
  542. e.stopPropagation();
  543. this.readyRemove();
  544. }.bind(this)
  545. });
  546. },
  547. readyRemove: function(){
  548. if (this.isRemove){
  549. this.action.setStyles(this.css.listItemActionNode);
  550. this.action.fade("out");
  551. if (this.app.currentDocument && this.app.currentDocument.data.id===this.data.id){
  552. this.node.setStyle("background-color", "#dcecfd");
  553. }else{
  554. this.node.setStyle("background-color", "#ffffff");
  555. }
  556. this.isRemove = false;
  557. this.app.removeItems.erase(this);
  558. }else{
  559. this.action.setStyles(this.css.listItemActionNode_remove);
  560. this.node.setStyle("background-color", "#fed1d1");
  561. this.app.removeItems.push(this);
  562. this.isRemove = true;
  563. }
  564. this.app.checkRemoveAction(this);
  565. },
  566. uncurrent: function(){
  567. if (this.app.currentDocument && this.app.currentDocument.data.id===this.data.id) this.app.currentDocument = null;
  568. this.node.setStyle("background-color", "#ffffff");
  569. },
  570. open: function(e){
  571. if (this.app.currentDocument){
  572. this.app.currentDocument.close(null, e, function(){
  573. this.app.currentDocument = new MWF.xApplication.Message.Document(this.data, this.app, this);
  574. }.bind(this));
  575. }else{
  576. this.app.currentDocument = new MWF.xApplication.Message.Document(this.data, this.app, this);
  577. }
  578. },
  579. remove: function(callback){
  580. if (this.app.currentDocument && this.app.currentDocument.data.id===this.data.id){
  581. this.app.currentDocument.doClose();
  582. this.app.currentDocument = null;
  583. }
  584. var action = MWF.Actions.get("x_message_assemble_communicate");
  585. action.delete(this.data.id, function(json){
  586. this.destroy();
  587. if (callback) callback();
  588. }.bind(this), function(){
  589. if (callback) callback();
  590. });
  591. },
  592. destroy: function(){
  593. this.uncurrent();
  594. this.node.destroy();
  595. this.app.removeItems.erase(this);
  596. this.app.listItems.erase(this);
  597. MWF.release(this);
  598. }
  599. });