Relatedlink.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. /** @class Relatedlink 相关推荐组件,本组件根据其当前流程实例的相关性分数列式其他流程实例(带权限)。
  3. * @o2cn 相关推荐组件
  4. * @example
  5. * //可以在脚本中获取该组件
  6. * //方法1:
  7. * var relatedlink = this.form.get("relatedlink"); //获取组件
  8. * //方法2
  9. * var relatedlink = this.target; //在组件本身的脚本中获取
  10. * @extends MWF.xApplication.process.Xform.$Module
  11. * @o2category FormComponents
  12. * @since v7.3
  13. * @o2range {Process|CMS|Portal}
  14. * @hideconstructor
  15. */
  16. MWF.xApplication.process.Xform.Relatedlink = MWF.APPRelatedlink = new Class(
  17. /** @lends MWF.xApplication.process.Xform.Relatedlink# */
  18. {
  19. Implements: [Events],
  20. Extends: MWF.xApplication.process.Xform.$Module,
  21. options: {
  22. /**
  23. * 加载数据后事件。
  24. * @event MWF.xApplication.process.Xform.Relatedlink#postLoadData
  25. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  26. * @example
  27. * //触发该事件的时候可以获取到链接数据linkData
  28. * var linkData = this.target.linkData;
  29. * //可以修改linkData达到定制化链接数据的效果
  30. * do something
  31. */
  32. /**
  33. * 创建每行需要导入的数据后触发,this.event指向当前链接对象。
  34. * @event MWF.xApplication.process.Xform.Relatedlink#postLoadLink
  35. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  36. * @example
  37. * <caption>this.event格式如下:</caption>
  38. * {
  39. * node: DomElement,
  40. * data: {
  41. * "title", "标题一",
  42. * ...
  43. * }
  44. * }
  45. */
  46. "moduleEvents": ["queryLoad","postLoad", "afterLoad", "postLoadData", "postLoadLink"]
  47. },
  48. _loadUserInterface: function(){
  49. this.node.empty();
  50. this.node.setStyle("-webkit-user-select", "text");
  51. switch (this.json.activeType) {
  52. case "click":
  53. this.loadButton();
  54. break;
  55. case "delay":
  56. break;
  57. case "immediately":
  58. this.loadContent();
  59. break;
  60. }
  61. },
  62. loadButton: function(){
  63. this.buttonNode = new Element("div.rlbutton", {
  64. "styles": this.json.buttonStyles || {},
  65. "text": this.json.buttonText,
  66. "events":{
  67. click: function () {
  68. this.active();
  69. this.buttonNode.destroy();
  70. this.buttonNode = null;
  71. }.bind(this)
  72. }
  73. }).inject( this.node );
  74. },
  75. /**
  76. * @summary 当相关推荐被设置为延迟激活,通过active方法激活
  77. * @param {Function} callback 激活后的回调
  78. * @example
  79. * var relativeLink = this.form.get("fieldId");
  80. * relativeLink.active(function(){
  81. * //do someting
  82. * })
  83. */
  84. active: function( callback ){
  85. if( !this.loaded ){
  86. this.loadContent( callback );
  87. }else{
  88. if(callback)callback();
  89. }
  90. },
  91. loadContent: function( callback ){
  92. o2.Actions.load("x_query_assemble_surface").MoreLikeThisAction.post({
  93. flag: this.getFlag(),
  94. category: this.getCategory(),
  95. count: (this.json.count || 6).toInt()
  96. }, function(json){
  97. this.linkData = json.data.moreLikeThisList;
  98. this.fireEvent("postLoadData");
  99. this.loadLinks();
  100. this.loaded = true;
  101. this.fireEvent("afterLoad");
  102. if(callback)callback();
  103. }.bind(this));
  104. },
  105. getFlag: function(){
  106. return this.form.businessData.work.id;
  107. // if (this.form.businessData.work && !this.form.businessData.work.completedTime) {
  108. // return this.form.businessData.work.id;
  109. // } else {
  110. // return this.form.businessData.workCompleted.id;
  111. // }
  112. },
  113. getCategory: function(){
  114. return "processPlatform";
  115. },
  116. loadLinks: function(){
  117. switch (this.json.mode){
  118. case "script":
  119. this.loadLinkByScript();
  120. break;
  121. case "text":
  122. this.loadLinkDefault();
  123. break;
  124. default:
  125. this.loadLinkTable();
  126. }
  127. },
  128. loadLinkTable: function(){
  129. var table = new Element("table", {
  130. "styles": this.json.tableStyles || this.form.css.relatedlinkTable,
  131. "border": "0",
  132. "cellSpacing": "0",
  133. "cellpadding": "3px",
  134. "width": "100%"
  135. }).inject(this.node);
  136. var tr = table.insertRow(0); //.setStyles( this.form.css.relatedlinkTableTitleLine );
  137. var lp = MWF.xApplication.process.Xform.LP;
  138. var thStyle = this.json.tableTitleCellStyles || this.form.css.relatedlinkTableTitle;
  139. var td = tr.insertCell(0).setStyles(thStyle);
  140. td.set("text", lp.title);
  141. td = tr.insertCell(1).setStyles(thStyle);
  142. td.set("text", lp.creatorPerson);
  143. td = tr.insertCell(2).setStyles(thStyle);
  144. td.set("text", lp.creatorUnit);
  145. td = tr.insertCell(3).setStyles(thStyle);
  146. td.set("text", lp.createTime);
  147. td = tr.insertCell(4).setStyles(thStyle);
  148. td.set("text", lp.updateTime);
  149. td = tr.insertCell(5).setStyles(thStyle);
  150. td.set("text", lp.score);
  151. var tdStyle = this.json.tableContentCellStyles || this.form.css.relatedlinkTableCell;
  152. this.linkData.each(function (log, idx) {
  153. var tr = table.insertRow(table.rows.length);
  154. tr.setStyles( this.json.tableContentLineStyles || this.form.css.relatedlinkTableLine );
  155. tr.addEvents({
  156. "mouseover": function () {
  157. tr.setStyles( this.json.tableContentLineStyles_over || this.form.css.relatedlinkTableLine_over )
  158. }.bind(this),
  159. "mouseout": function () {
  160. tr.setStyles( this.json.tableContentLineStyles || this.form.css.relatedlinkTableLine )
  161. }.bind(this)
  162. })
  163. var td = tr.insertCell(0).setStyles( tdStyle );
  164. td.set("text", log.title);
  165. td.setStyles( this.json.tableContentCellStyles_title || this.form.css.relatedlinkTableCell_title );
  166. td = tr.insertCell(1).setStyles(tdStyle);
  167. td.set("text", log.creatorPerson);
  168. td = tr.insertCell(2).setStyles(tdStyle);
  169. td.set("text", log.creatorUnit);
  170. td = tr.insertCell(3).setStyles(tdStyle);
  171. td.set("text", log.createTime);
  172. td = tr.insertCell(4).setStyles(tdStyle);
  173. td.set("text", log.updateTime);
  174. td = tr.insertCell(5).setStyles(tdStyle);
  175. td.set("text", log.score);
  176. this.setOpenEvent(tr, log);
  177. this.fireEvent("postLoadLink", [{
  178. node: tr,
  179. data: log
  180. }]);
  181. }.bind(this))
  182. },
  183. loadLinkByScript: function(){
  184. if (this.json.displayScript && this.json.displayScript.code){
  185. var code = this.json.displayScript.code;
  186. this.linkData.each(function(log){
  187. this.form.Macro.environment.link = log;
  188. var r = this.form.Macro.exec(code, this);
  189. var t = o2.typeOf(r);
  190. if (t==="string"){
  191. this.node.appendHTML(r);
  192. }else if (t==="element"){
  193. this.node.appendChild(r);
  194. }
  195. var node = this.node.getLast();
  196. this.setOpenEvent(node, log);
  197. this.fireEvent("postLoadLink", [{
  198. node: node,
  199. data: log
  200. }]);
  201. }.bind(this));
  202. }
  203. },
  204. loadLinkDefault: function(){
  205. var text = this.json.textStyle;
  206. var readPersons = [];
  207. this.lineClass = "relatedlinkNode";
  208. this.linkData.each(function(log, i){
  209. var div = new Element("div", {styles: this.form.css[this.lineClass]}).inject(this.node);
  210. var rightDiv = new Element("div", {styles: this.form.css.relatedlinkTextNode}).inject(div);
  211. var html = text.replace(/{flag}/g, log.flag)
  212. .replace(/{createDate}/g, log.createTime.substring(0.10))
  213. .replace(/{createTime}/g, log.createTime)
  214. .replace(/{updateDate}/g, log.updateTime.substring(0.10))
  215. .replace(/{updateTime}/g, log.updateTime)
  216. .replace(/{creatorUnit}/g, o2.name.cn(log.creatorUnit))
  217. .replace(/{creatorPerson}/g, o2.name.cn(log.creatorPerson))
  218. .replace(/{title}/g, log.title || "");
  219. rightDiv.appendHTML(html);
  220. if (this.lineClass === "relatedlinkNode"){
  221. this.lineClass = "relatedlinkNode_even";
  222. }else{
  223. this.lineClass = "relatedlinkNode";
  224. }
  225. this.setOpenEvent(div, log);
  226. this.fireEvent("postLoadLink", [{
  227. node: div,
  228. data: log
  229. }]);
  230. }.bind(this));
  231. },
  232. setOpenEvent: function(node, data){
  233. node.setStyle("cursor", "pointer");
  234. if (data.category==="cms"){
  235. node.addEvent("click", function(ev){
  236. this.openCMSDocument( data, false);
  237. ev.stopPropagation();
  238. }.bind(this));
  239. }else{
  240. node.addEvent("click", function(ev){
  241. this.openWork(data);
  242. ev.stopPropagation();
  243. }.bind(this));
  244. }
  245. },
  246. openWork: function(data){
  247. var appId = "process.Work"+data.flag;
  248. // if (layout.desktop.apps[appId]){
  249. // if (!layout.desktop.apps[appId].window){
  250. // layout.desktop.apps[appId] = null;
  251. // layout.openApplication(null, layout.desktop.apps[appId].options.name, layout.desktop.apps[appId].options, layout.desktop.apps[appId].options.app, false, this, false);
  252. // }else{
  253. // layout.desktop.apps[appId].setCurrent();
  254. // }
  255. // }else {
  256. var op = {
  257. "jobId": data.flag,
  258. "appId": appId
  259. };
  260. return layout.desktop.openApplication(this.event, "process.Work", op);
  261. // }
  262. },
  263. openCMSDocument : function( data, isEdited ){
  264. var appId = "cms.Document"+data.flag;
  265. // if (layout.desktop.apps[appId]){
  266. // if (!layout.desktop.apps[appId].window){
  267. // layout.desktop.apps[appId] = null;
  268. // layout.openApplication(null, layout.desktop.apps[appId].options.name, layout.desktop.apps[appId].options, layout.desktop.apps[appId].options.app, false, this, false);
  269. // }else{
  270. // layout.desktop.apps[appId].setCurrent();
  271. // }
  272. // }else {
  273. var options = {
  274. "documentId": data.flag,
  275. "appId": appId,
  276. "readonly" : !isEdited
  277. };
  278. layout.desktop.openApplication(null, "cms.Document", options);
  279. // }
  280. }
  281. });