Main.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. MWF.require("MWF.widget.UUID", null, false);
  2. MWF.xDesktop.requireApp("Template", "MForm", null, false);
  3. MWF.xDesktop.requireApp("Template", "MPopupForm", null, false);
  4. MWF.xApplication.IMV2.Main = new Class({
  5. Extends: MWF.xApplication.Common.Main,
  6. Implements: [Options, Events],
  7. options: {
  8. "style": "default",
  9. "name": "IMV2",
  10. "mvcStyle": "style.css",
  11. "icon": "icon.png",
  12. "width": "1024",
  13. "height": "768",
  14. "isResize": true,
  15. "isMax": true,
  16. "title": MWF.xApplication.IMV2.LP.title,
  17. "conversationId":""
  18. },
  19. onQueryLoad: function () {
  20. this.lp = MWF.xApplication.IMV2.LP;
  21. this.app = this;
  22. this.conversationNodeItemList = [];
  23. this.conversationId = this.options.conversationId || "";
  24. this.messageList = [];
  25. this.emojiList = [];
  26. //添加87个表情
  27. for (var i=1; i < 88; i++) {
  28. var emoji = {
  29. "key" : i > 9 ? "["+i+"]" : "[0"+i+"]",
  30. "path" : i > 9 ? "/x_component_IMV2/$Main/emotions/im_emotion_"+i+".png" : "/x_component_IMV2/$Main/emotions/im_emotion_0"+i+".png",
  31. };
  32. this.emojiList.push(emoji);
  33. }
  34. },
  35. onQueryClose: function(){
  36. this.closeListening()
  37. },
  38. loadApplication: function (callback) {
  39. var url = this.path + this.options.style + "/im.html";
  40. this.content.loadHtml(url, { "bind": { "lp": this.lp, "data": {} }, "module": this }, function () {
  41. //设置content
  42. this.app.content = this.o2ImMainNode;
  43. //启动监听
  44. this.startListening();
  45. //获取会话列表
  46. this.conversationNodeItemList = [];
  47. o2.Actions.load("x_message_assemble_communicate").ImAction.myConversationList(function (json) {
  48. if (json.data && json.data instanceof Array) {
  49. this.loadConversationList(json.data);
  50. }
  51. }.bind(this));
  52. }.bind(this));
  53. },
  54. startListening:function(){
  55. this.messageNumber = layout.desktop.message.items.length;
  56. //查询ws消息 如果增加
  57. if (this.listener) {
  58. clearInterval(this.listener);
  59. }
  60. this.listener = setInterval(function(){
  61. var newNumber = layout.desktop.message.items.length;
  62. //判断是否有新的ws消息
  63. if(newNumber > this.messageNumber) {
  64. //查询会话数据
  65. this._checkConversationMessage();
  66. //查询聊天数据
  67. this._checkNewMessage();
  68. this.messageNumber = newNumber;
  69. }
  70. }.bind(this), 1000);
  71. },
  72. closeListening: function() {
  73. if (this.listener) {
  74. clearInterval(this.listener);
  75. }
  76. },
  77. //加载会话列表
  78. loadConversationList: function (list) {
  79. for (var i = 0; i < list.length; i++) {
  80. var chat = list[i];
  81. var itemNode = this._createConvItemNode(chat);
  82. this.conversationNodeItemList.push(itemNode);
  83. if(this.conversationId && this.conversationId == chat.id) {
  84. this.tapConv(chat);
  85. }
  86. }
  87. },
  88. //分页获取会话的消息列表数据
  89. loadMsgListByConvId: function (page, size, convId) {
  90. var data = { "conversationId": convId };
  91. o2.Actions.load("x_message_assemble_communicate").ImAction.msgListByPaging(page, size, data, function (json) {
  92. var list = json.data;
  93. for (var i = 0; i < list.length; i++) {
  94. this.messageList.push(list[i]);
  95. this._buildMsgNode(list[i], true);
  96. }
  97. }.bind(this), function (error) {
  98. console.log(error);
  99. }.bind(this), false);
  100. },
  101. //点击会话
  102. tapConv: function (conv) {
  103. this._setCheckNode(conv);
  104. var url = this.path + this.options.style + "/chat.html";
  105. var data = { "convName": conv.title };
  106. this.conversationId = conv.id;
  107. this.chatNode.empty();
  108. this.chatNode.loadHtml(url, { "bind": data, "module": this }, function () {
  109. //获取聊天信息
  110. this.messageList = [];
  111. this.loadMsgListByConvId(1, 20, conv.id);
  112. var scrollFx = new Fx.Scroll(this.chatContentNode);
  113. scrollFx.toBottom();
  114. }.bind(this));
  115. },
  116. //点击发送消息
  117. sendMsg: function () {
  118. var text = this.chatBottomAreaTextareaNode.value;
  119. if (text) {
  120. console.log("发送文本消息");
  121. this.chatBottomAreaTextareaNode.value = "";
  122. this._newAndSendTextMsg(text, "text");
  123. } else {
  124. console.log("没有消息内容!");
  125. }
  126. },
  127. //点击表情按钮
  128. showEmojiBox: function() {
  129. if(!this.emojiBoxNode) {
  130. this.emojiBoxNode = new Element("div", { "class": "chat-emoji-box" }).inject(this.chatNode);
  131. var _self = this;
  132. for(var i=0; i<this.emojiList.length; i++) {
  133. var emoji = this.emojiList[i];
  134. var emojiNode = new Element("img", {"src": emoji.path, "class": "chat-emoji-img"}).inject(this.emojiBoxNode);
  135. emojiNode.addEvents({
  136. "mousedown": function (ev) {
  137. _self.sendEmojiMsg(this.emoji);
  138. _self.hideEmojiBox();
  139. }.bind({emoji: emoji})
  140. });
  141. }
  142. }
  143. this.emojiBoxNode.setStyle("display", "block");
  144. this.hideFun = this.hideEmojiBox.bind(this);
  145. document.body.addEvent("mousedown", this.hideFun);
  146. },
  147. hideEmojiBox: function() {
  148. //关闭emojiBoxNode
  149. this.emojiBoxNode.setStyle("display", "none");
  150. document.body.removeEvent("mousedown", this.hideFun);
  151. },
  152. //发送表情消息
  153. sendEmojiMsg: function(emoji) {
  154. console.log("发送表情消息");
  155. this._newAndSendTextMsg(emoji.key, "emoji");
  156. },
  157. //点击创建单聊按钮
  158. tapCreateSingleConv: function () {
  159. var form = new MWF.xApplication.IMV2.SingleForm(this, {}, {}, { app: this.app });
  160. form.create()
  161. },
  162. /**
  163. * 创建会话
  164. * @param {*} persons 人员列表
  165. * @param {*} cType 会话类型 "single" "group"
  166. */
  167. newConversation: function (persons, cType) {
  168. var conv = {
  169. type: cType,
  170. personList: persons,
  171. };
  172. var _self = this;
  173. o2.Actions.load("x_message_assemble_communicate").ImAction.create(conv, function (json) {
  174. var newConv = json.data;
  175. var isOld = false;
  176. for (var i = 0; i < _self.conversationNodeItemList.length; i++) {
  177. var c = _self.conversationNodeItemList[i];
  178. if (newConv.id == c.data.id) {
  179. isOld = true;
  180. _self.tapConv(c);
  181. }
  182. }
  183. if(!isOld) {
  184. var itemNode = _self._createConvItemNode(newConv);
  185. _self.conversationNodeItemList.push(itemNode);
  186. _self.tapConv(newConv);
  187. }
  188. }.bind(this), function (error) {
  189. console.log(error);
  190. }.bind(this))
  191. },
  192. //创建会话ItemNode
  193. _createConvItemNode: function (conv) {
  194. return new MWF.xApplication.IMV2.ConversationItem(conv, this);
  195. },
  196. //会话ItemNode 点击背景色
  197. _setCheckNode: function (conv) {
  198. for (var i = 0; i < this.conversationNodeItemList.length; i++) {
  199. var item = this.conversationNodeItemList[i];
  200. if (item.data.id == conv.id) {
  201. item.addCheckClass();
  202. } else {
  203. item.removeCheckClass();
  204. }
  205. }
  206. },
  207. //创建文本消息 并发送
  208. _newAndSendTextMsg: function (text, type) {
  209. var distinguishedName = layout.session.user.distinguishedName;
  210. var time = this._currentTime();
  211. var body = { "body": text, "type": type };
  212. var bodyJson = JSON.stringify(body);
  213. var uuid = (new MWF.widget.UUID).toString();
  214. var textMessage = {
  215. "id": uuid,
  216. "conversationId": this.conversationId,
  217. "body": bodyJson,
  218. "createPerson": distinguishedName,
  219. "createTime": time,
  220. "sendStatus": 1
  221. };
  222. o2.Actions.load("x_message_assemble_communicate").ImAction.msgCreate(textMessage,
  223. function (json) {
  224. //data = json.data;
  225. console.log("消息发送成功!");
  226. }.bind(this),
  227. function (error) {
  228. console.log(error);
  229. }.bind(this));
  230. this.messageList.push(textMessage);
  231. this._buildSender(body, distinguishedName, false);
  232. this._refreshConvMessage(textMessage);
  233. },
  234. //刷新会话Item里面的最后消息内容
  235. _refreshConvMessage: function(msg) {
  236. for (var i = 0; i < this.conversationNodeItemList.length; i++) {
  237. var node = this.conversationNodeItemList[i];
  238. if (node.data.id == this.conversationId) {
  239. node.refreshLastMsg(msg);
  240. }
  241. }
  242. },
  243. //检查会话列表是否有更新
  244. _checkConversationMessage: function() {
  245. o2.Actions.load("x_message_assemble_communicate").ImAction.myConversationList(function (json) {
  246. if (json.data && json.data instanceof Array) {
  247. var newConList = json.data;
  248. for (var j = 0; j < newConList.length; j++) {
  249. var nCv = newConList[j];
  250. var isNew = true;
  251. for (var i = 0; i < this.conversationNodeItemList.length; i++) {
  252. var cv = this.conversationNodeItemList[i];
  253. if (cv.data.id == nCv.id) {
  254. isNew = false;
  255. //刷新
  256. cv.refreshLastMsg(nCv.lastMessage);
  257. }
  258. }
  259. //新会话 创建
  260. if(isNew) {
  261. var itemNode = this._createConvItemNode(nCv);
  262. this.conversationNodeItemList.push(itemNode);
  263. }
  264. }
  265. //this.loadConversationList(json.data);
  266. }
  267. }.bind(this));
  268. },
  269. //检查是否有新消息
  270. _checkNewMessage: function() {
  271. if (this.conversationId && this.conversationId != "") {//是否有会话窗口
  272. var data = { "conversationId": this.conversationId };
  273. o2.Actions.load("x_message_assemble_communicate").ImAction.msgListByPaging(1, 10, data, function (json) {
  274. var list = json.data;
  275. if(list && list.length > 0) {
  276. var msg = list[0];
  277. //检查聊天框是否有变化
  278. if (this.conversationId == msg.conversationId) {
  279. for (var i = 0; i < list.length; i++) {
  280. var isnew = true;
  281. var m = list[i];
  282. for (var j = 0; j < this.messageList.length; j++) {
  283. if(this.messageList[j].id == m.id) {
  284. isnew = false;
  285. }
  286. }
  287. if(isnew) {
  288. this.messageList.push(m);
  289. this._buildMsgNode(m, false);
  290. // this._refreshConvMessage(m);
  291. }
  292. }
  293. }
  294. }
  295. }.bind(this), function (error) {
  296. console.log(error);
  297. }.bind(this), false);
  298. }
  299. },
  300. //创建消息html节点
  301. _buildMsgNode: function (msg, isTop) {
  302. var createPerson = msg.createPerson;
  303. var jsonbody = msg.body;
  304. var body = JSON.parse(jsonbody);//todo 目前只有一种text类型
  305. var distinguishedName = layout.session.user.distinguishedName;
  306. if (createPerson != distinguishedName) {
  307. this._buildReceiver(body, createPerson, isTop);
  308. } else {
  309. this._buildSender(body, createPerson, isTop);
  310. }
  311. },
  312. /**
  313. * 消息发送体
  314. * @param msgBody 消息体
  315. * @param createPerson 消息人员
  316. * @param isTop 是否放在顶部
  317. */
  318. _buildSender: function (msgBody, createPerson, isTop) {
  319. var receiverBodyNode = new Element("div", { "class": "chat-sender" }).inject(this.chatContentNode, isTop ? "top" : "bottom");
  320. var avatarNode = new Element("div").inject(receiverBodyNode);
  321. var avatarUrl = this._getIcon(createPerson);
  322. var name = createPerson;
  323. if (createPerson.indexOf("@") != -1) {
  324. name = name.substring(0, createPerson.indexOf("@"));
  325. }
  326. var avatarImg = new Element("img", { "src": avatarUrl }).inject(avatarNode);
  327. var nameNode = new Element("div", { "text": name }).inject(receiverBodyNode);
  328. var lastNode = new Element("div").inject(receiverBodyNode);
  329. var lastFirstNode = new Element("div", { "class": "chat-left_triangle" }).inject(lastNode);
  330. //text
  331. if (msgBody.type == "emoji") { // 表情
  332. var img = "";
  333. for (var i=0; i< this.emojiList.length; i++) {
  334. if (msgBody.body == this.emojiList[i].key) {
  335. img = this.emojiList[i].path;
  336. }
  337. }
  338. new Element("img", {"src": img, "class": "chat-content-emoji"}).inject(lastNode);
  339. }else {//text
  340. new Element("span", { "text": msgBody.body }).inject(lastNode);
  341. }
  342. if(!isTop) {
  343. var scrollFx = new Fx.Scroll(this.chatContentNode);
  344. scrollFx.toBottom();
  345. }
  346. },
  347. /**
  348. * 消息接收体
  349. * @param msgBody
  350. * @param createPerson 消息人员
  351. * @param isTop 是否放在顶部
  352. */
  353. _buildReceiver: function (msgBody, createPerson, isTop) {
  354. var receiverBodyNode = new Element("div", { "class": "chat-receiver" }).inject(this.chatContentNode, isTop ? "top" : "bottom");
  355. var avatarNode = new Element("div").inject(receiverBodyNode);
  356. var avatarUrl = this._getIcon(createPerson);
  357. var name = createPerson;
  358. if (createPerson.indexOf("@") != -1) {
  359. name = name.substring(0, createPerson.indexOf("@"));
  360. }
  361. var avatarImg = new Element("img", { "src": avatarUrl }).inject(avatarNode);
  362. var nameNode = new Element("div", { "text": name }).inject(receiverBodyNode);
  363. var lastNode = new Element("div").inject(receiverBodyNode);
  364. var lastFirstNode = new Element("div", { "class": "chat-right_triangle" }).inject(lastNode);
  365. if (msgBody.type == "emoji") { // 表情
  366. var img = "";
  367. for (var i=0; i< this.emojiList.length; i++) {
  368. if (msgBody.body == this.emojiList[i].key) {
  369. img = this.emojiList[i].path;
  370. }
  371. }
  372. new Element("img", {"src": img, "class": "chat-content-emoji"}).inject(lastNode);
  373. }else {//text
  374. new Element("span", { "text": msgBody.body }).inject(lastNode);
  375. }
  376. if(!isTop) {
  377. var scrollFx = new Fx.Scroll(this.chatContentNode);
  378. scrollFx.toBottom();
  379. }
  380. },
  381. //用户头像
  382. _getIcon: function (id) {
  383. var orgAction = MWF.Actions.get("x_organization_assemble_control")
  384. var url = (id) ? orgAction.getPersonIcon(id) : "../x_component_IMV2/$Main/default/icons/group.png";
  385. return url + "?" + (new Date().getTime());
  386. },
  387. //输出特殊的时间格式
  388. _friendlyTime: function (date) {
  389. var day = date.getDate();
  390. var monthIndex = date.getMonth();
  391. var year = date.getFullYear();
  392. var time = date.getTime();
  393. var today = new Date();
  394. var todayDay = today.getDate();
  395. var todayMonthIndex = today.getMonth();
  396. var todayYear = today.getFullYear();
  397. var todayTime = today.getTime();
  398. var retTime = "";
  399. //同一天
  400. if (day === todayDay && monthIndex === todayMonthIndex && year === todayYear) {
  401. var hour = 0;
  402. if (todayTime > time) {
  403. hour = parseInt((todayTime - time) / 3600000);
  404. if (hour == 0) {
  405. retTime = Math.max(parseInt((todayTime - time) / 60000), 1) + "分钟前"
  406. } else {
  407. retTime = hour + "小时前"
  408. }
  409. }
  410. return retTime;
  411. }
  412. var dates = parseInt(time / 86400000);
  413. var todaydates = parseInt(todayTime / 86400000);
  414. if (todaydates > dates) {
  415. var days = (todaydates - dates);
  416. if (days == 1) {
  417. retTime = "昨天";
  418. } else if (days == 2) {
  419. retTime = "前天 ";
  420. } else if (days > 2 && days < 31) {
  421. retTime = days + "天前";
  422. } else if (days >= 31 && days <= 2 * 31) {
  423. retTime = "一个月前";
  424. } else if (days > 2 * 31 && days <= 3 * 31) {
  425. retTime = "2个月前";
  426. } else if (days > 3 * 31 && days <= 4 * 31) {
  427. retTime = "3个月前";
  428. } else {
  429. retTime = this._formatDate(date);
  430. }
  431. }
  432. return retTime;
  433. },
  434. //yyyy-MM-dd
  435. _formatDate: function (date) {
  436. var month = date.getMonth() + 1;
  437. var day = date.getDate();
  438. month = (month.toString().length == 1) ? ("0" + month) : month;
  439. day = (day.toString().length == 1) ? ("0" + day) : day;
  440. return date.getFullYear() + '-' + month + '-' + day;
  441. },
  442. //当前时间 yyyy-MM-dd HH:mm:ss
  443. _currentTime: function () {
  444. var today = new Date();
  445. var year = today.getFullYear(); //得到年份
  446. var month = today.getMonth();//得到月份
  447. var date = today.getDate();//得到日期
  448. var hour = today.getHours();//得到小时
  449. var minu = today.getMinutes();//得到分钟
  450. var sec = today.getSeconds();//得到秒
  451. month = month + 1;
  452. if (month < 10) month = "0" + month;
  453. if (date < 10) date = "0" + date;
  454. if (hour < 10) hour = "0" + hour;
  455. if (minu < 10) minu = "0" + minu;
  456. if (sec < 10) sec = "0" + sec;
  457. return year + "-" + month + "-" + date + " " + hour + ":" + minu + ":" + sec;
  458. }
  459. });
  460. //会话对象
  461. MWF.xApplication.IMV2.ConversationItem = new Class({
  462. initialize: function (data, main) {
  463. this.data = data;
  464. this.main = main;
  465. this.container = this.main.chatItemListNode;
  466. this.load();
  467. },
  468. load: function () {
  469. var avatarDefault = this.main._getIcon();
  470. var convData = {
  471. "id": this.data.id,
  472. "avatarUrl": avatarDefault,
  473. "title": this.data.title,
  474. "time": "",
  475. "lastMessage": "",
  476. "lastMessageType": "text"
  477. };
  478. var distinguishedName = layout.session.user.distinguishedName;
  479. if (this.data.type && this.data.type === "single") {
  480. var chatPerson = "";
  481. if (this.data.personList && this.data.personList instanceof Array) {
  482. for (var j = 0; j < this.data.personList.length; j++) {
  483. var person = this.data.personList[j];
  484. if (person !== distinguishedName) {
  485. chatPerson = person;
  486. }
  487. }
  488. }
  489. convData.avatarUrl = this.main._getIcon(chatPerson);
  490. var name = chatPerson;
  491. if (chatPerson.indexOf("@") != -1) {
  492. name = name.substring(0, chatPerson.indexOf("@"));
  493. }
  494. convData.title = name;
  495. }
  496. if (this.data.lastMessage) {
  497. //todo 其它消息类型
  498. var mBody = JSON.parse(this.data.lastMessage.body);
  499. convData.lastMessage = mBody.body;
  500. if (this.data.lastMessage.createTime) {
  501. var time = this.main._friendlyTime(o2.common.toDate(this.data.lastMessage.createTime));
  502. convData.time = time;
  503. }
  504. if (mBody.type) {
  505. convData.lastMessageType = mBody.type;
  506. }
  507. }
  508. this.node = new Element("div", { "class": "item" }).inject(this.container);
  509. this.nodeBaseItem = new Element("div", { "class": "base" }).inject(this.node);
  510. var avatarNode = new Element("div", { "class": "avatar" }).inject(this.nodeBaseItem);
  511. new Element("img", { "src": convData.avatarUrl, "class": "img" }).inject(avatarNode);
  512. var bodyNode = new Element("div", { "class": "body" }).inject(this.nodeBaseItem);
  513. var bodyUpNode = new Element("div", { "class": "body_up" }).inject(bodyNode);
  514. new Element("div", { "class": "body_title", "text": convData.title }).inject(bodyUpNode);
  515. this.messageTimeNode = new Element("div", { "class": "body_time", "text": convData.time }).inject(bodyUpNode);
  516. if (convData.lastMessageType == "emoji") {
  517. this.lastMessageNode = new Element("div", { "class": "body_down"}).inject(bodyNode);
  518. var imgPath = "";
  519. for(var i = 0; i < this.main.emojiList.length ; i++) {
  520. var emoji = this.main.emojiList[i];
  521. if (emoji.key == convData.lastMessage) {
  522. imgPath = emoji.path;
  523. }
  524. }
  525. new Element("img", {"src": imgPath, "style":"width: 16px;height: 16px;"}).inject(this.lastMessageNode);
  526. }else {
  527. this.lastMessageNode = new Element("div", { "class": "body_down", "text": convData.lastMessage }).inject(bodyNode);
  528. }
  529. var _self = this;
  530. this.node.addEvents({
  531. "click": function () {
  532. _self.main.tapConv(_self.data);
  533. }
  534. });
  535. },
  536. /**
  537. * {
  538. "id": uuid,
  539. "conversationId": this.conversationId,
  540. "body": bodyJson,
  541. "createPerson": distinguishedName,
  542. "createTime": time,
  543. "sendStatus": 1
  544. };
  545. * 刷新会话列表的最后消息内容
  546. * @param {*} lastMessage
  547. */
  548. refreshLastMsg: function(lastMessage) {
  549. //目前是text 类型的消息
  550. var jsonbody = lastMessage.body;
  551. var body = JSON.parse(jsonbody);
  552. if(this.lastMessageNode) {
  553. if (body.type == "emoji") { //表情 消息
  554. var imgPath = "";
  555. for(var i = 0; i < this.main.emojiList.length ; i++) {
  556. var emoji = this.main.emojiList[i];
  557. if (emoji.key == body.body) {
  558. imgPath = emoji.path;
  559. }
  560. }
  561. this.lastMessageNode.empty();
  562. new Element("img", {"src": imgPath, "style":"width: 16px;height: 16px;"}).inject(this.lastMessageNode);
  563. }else { //文本消息
  564. this.lastMessageNode.empty();
  565. this.lastMessageNode.set('text', body.body);
  566. }
  567. }
  568. var time = this.main._friendlyTime(o2.common.toDate(lastMessage.createTime));
  569. if(this.messageTimeNode) {
  570. this.messageTimeNode.set("text", time);
  571. }
  572. },
  573. addCheckClass: function () {
  574. if (this.nodeBaseItem) {
  575. if (!this.nodeBaseItem.hasClass("check")) {
  576. this.nodeBaseItem.addClass("check");
  577. }
  578. }
  579. },
  580. removeCheckClass: function () {
  581. if (this.nodeBaseItem) {
  582. if (this.nodeBaseItem.hasClass("check")) {
  583. this.nodeBaseItem.removeClass("check");
  584. }
  585. }
  586. }
  587. });
  588. //弹出窗 表单 单聊创建的form
  589. MWF.xApplication.IMV2.SingleForm = new Class({
  590. Extends: MPopupForm,
  591. Implements: [Options, Events],
  592. options: {
  593. "style": "minder",
  594. "width": 700,
  595. //"height": 300,
  596. "height": "200",
  597. "hasTop": true,
  598. "hasIcon": false,
  599. "draggable": true,
  600. "title": "创建单聊"
  601. },
  602. _createTableContent: function () {
  603. var html = "<table width='100%' bordr='0' cellpadding='7' cellspacing='0' styles='formTable' style='margin-top: 20px; '>" +
  604. "<tr><td styles='formTableTitle' lable='person' width='25%'></td>" +
  605. " <td styles='formTableValue14' item='person' colspan='3'></td></tr>" +
  606. "</table>";
  607. this.formTableArea.set("html", html);
  608. var me = layout.session.user.distinguishedName;
  609. var exclude = [];
  610. if (me) {
  611. exclude = [me];
  612. }
  613. this.form = new MForm(this.formTableArea, this.data || {}, {
  614. isEdited: true,
  615. style: "minder",
  616. hasColon: true,
  617. itemTemplate: {
  618. person: { text: "选择人员", type: "org", orgType: "person", notEmpty: true, exclude: exclude },
  619. }
  620. }, this.app);
  621. this.form.load();
  622. },
  623. _createBottomContent: function () {
  624. if (this.isNew || this.isEdited) {
  625. this.okActionNode = new Element("button.inputOkButton", {
  626. "styles": this.css.inputOkButton,
  627. "text": "确定"
  628. }).inject(this.formBottomNode);
  629. this.okActionNode.addEvent("click", function (e) {
  630. this.save(e);
  631. }.bind(this));
  632. }
  633. this.cancelActionNode = new Element("button.inputCancelButton", {
  634. "styles": (this.isEdited || this.isNew || this.getEditPermission()) ? this.css.inputCancelButton : this.css.inputCancelButton_long,
  635. "text": "关闭"
  636. }).inject(this.formBottomNode);
  637. this.cancelActionNode.addEvent("click", function (e) {
  638. this.close(e);
  639. }.bind(this));
  640. },
  641. save: function () {
  642. var data = this.form.getResult(true, null, true, false, true);
  643. if (data) {
  644. this.app.newConversation(data.person, "single");
  645. this.close();
  646. }
  647. }
  648. });