View.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. //MWF.xDesktop.requireApp("process.Xform", "widget.View", null, false);
  3. /** @class View 视图组件。
  4. * @example
  5. * //可以在脚本中获取该组件
  6. * //方法1:
  7. * var view = this.form.get("fieldId"); //获取组件
  8. * //方法2
  9. * var view = this.target; //在组件本身的脚本中获取
  10. * @extends MWF.xApplication.process.Xform.$Module
  11. * @o2category FormComponents
  12. * @o2range {Process|CMS|Portal}
  13. * @hideconstructor
  14. */
  15. MWF.xApplication.process.Xform.View = MWF.APPView = new Class(
  16. /** @lends MWF.xApplication.process.Xform.View# */
  17. {
  18. Extends: MWF.APP$Module,
  19. options: {
  20. /**
  21. * 异步加载视图后完成。
  22. * @event MWF.xApplication.process.Xform.View#loadView
  23. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  24. */
  25. /**
  26. * 选中视图中的一条记录后执行。
  27. * @event MWF.xApplication.process.Xform.View#select
  28. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  29. */
  30. /**
  31. * 打开视图中的一条记录后执行。
  32. * @event MWF.xApplication.process.Xform.View#openDocument
  33. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  34. */
  35. "moduleEvents": ["load", "loadView", "queryLoad", "postLoad", "select", "openDocument"]
  36. },
  37. _loadUserInterface: function(){
  38. MWF.xDesktop.requireApp("query.Query", "Viewer", null, false);
  39. this.node.empty();
  40. },
  41. _afterLoaded: function(){
  42. if (this.json.queryView){
  43. this.loadView();
  44. }else{
  45. if (this.json.selectViewType==="cms"){
  46. this.loadCMSView();
  47. }else if (this.json.selectViewType==="process"){
  48. this.loadPrcessView();
  49. }else{
  50. this.loadView();
  51. }
  52. }
  53. },
  54. /**
  55. * @summary 重新加载视图
  56. * @example
  57. * this.form.get("fieldId").reload()
  58. */
  59. reload: function(){
  60. if (this.view){
  61. if (this.view.loadViewRes && this.view.loadViewRes.res) if (this.view.loadViewRes.res.isRunning()) this.view.loadViewRes.res.cancel();
  62. if (this.view.getViewRes && this.view.getViewRes.res) if (this.view.getViewRes.res.isRunning()) this.view.getViewRes.res.cancel();
  63. }
  64. this.node.empty();
  65. this.loadView();
  66. },
  67. /**
  68. * @summary 当视图被设置为延迟加载(未立即载入),通过active方法激活
  69. * @example
  70. * this.form.get("fieldId").active()
  71. */
  72. active: function(){
  73. if (this.view){
  74. if (!this.view.loadingAreaNode) this.view.loadView();
  75. }else{
  76. this.loadView();
  77. }
  78. },
  79. loadView: function(){
  80. if (!this.json.queryView || !this.json.queryView.name || !this.json.queryView.appName) return "";
  81. var filter = null;
  82. if (this.json.filterList && this.json.filterList.length){
  83. filter = [];
  84. this.json.filterList.each(function(entry){
  85. entry.value = this.form.Macro.exec(entry.code.code, this);
  86. //delete entry.code;
  87. filter.push(entry);
  88. }.bind(this));
  89. }
  90. //var data = JSON.parse(this.json.data);
  91. var viewJson = {
  92. "application": (this.json.queryView) ? this.json.queryView.appName : this.json.application,
  93. "viewName": (this.json.queryView) ? this.json.queryView.name : this.json.viewName,
  94. "isTitle": this.json.isTitle || "yes",
  95. "select": this.json.select || "none",
  96. "titleStyles": this.json.titleStyles,
  97. "itemStyles": this.json.itemStyles,
  98. "isExpand": this.json.isExpand || "no",
  99. "showActionbar" : this.json.actionbar === "show",
  100. "filter": filter,
  101. "defaultSelectedScript" : this.json.defaultSelectedScript ? this.json.defaultSelectedScript.code : null,
  102. "selectedAbleScript" : this.json.selectedAbleScript ? this.json.selectedAbleScript.code : null
  103. };
  104. //MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  105. this.view = new MWF.xApplication.query.Query.Viewer(this.node, viewJson, {
  106. "isload": (this.json.loadView!=="no"),
  107. "resizeNode": (this.node.getStyle("height").toString().toLowerCase()!=="auto" && this.node.getStyle("height").toInt()>0),
  108. "onLoadView": function(){
  109. this.fireEvent("loadView");
  110. }.bind(this),
  111. "onSelect": function(){
  112. this.fireEvent("select");
  113. }.bind(this),
  114. "onOpenDocument": function(options, item){
  115. this.openOptions = {
  116. "options": options,
  117. "item": item
  118. };
  119. this.fireEvent("openDocument");
  120. this.openOptions = null;
  121. }.bind(this)
  122. }, this.form.app, this.form.Macro);
  123. //}.bind(this));
  124. },
  125. loadPrcessView: function(){
  126. var filter = null;
  127. if (this.json.filterList && this.json.filterList.length){
  128. filter = [];
  129. this.json.filterList.each(function(entry){
  130. entry.value = this.form.Macro.exec(entry.code.code, this);
  131. //delete entry.code;
  132. filter.push(entry);
  133. }.bind(this));
  134. }
  135. var viewJson = {
  136. "application": this.json.processView.application,
  137. "viewName": this.json.processView.name,
  138. "isTitle": this.json.isTitle || "yes",
  139. "select": this.json.select || "none",
  140. "titleStyles": this.json.titleStyles,
  141. "itemStyles": this.json.itemStyles,
  142. "isExpand": this.json.isExpand || "no",
  143. "showActionbar" : this.json.actionbar === "show",
  144. "filter": filter
  145. };
  146. MWF.xDesktop.requireApp("process.Application", "Viewer", function(){
  147. this.view = new MWF.xApplication.process.Application.Viewer(this.node, viewJson, {
  148. "resizeNode": (this.node.getStyle("height").toString().toLowerCase()!=="auto" && this.node.getStyle("height").toInt()>0),
  149. "onSelect": function(){
  150. this.fireEvent("select");
  151. }.bind(this)
  152. });
  153. }.bind(this));
  154. },
  155. loadCMSView: function(){
  156. var filter = null;
  157. if (this.json.filterList && this.json.filterList.length){
  158. filter = [];
  159. this.json.filterList.each(function(entry){
  160. entry.value = this.form.Macro.exec(entry.code.code, this);
  161. //delete entry.code;
  162. filter.push(entry);
  163. }.bind(this));
  164. }
  165. var viewJson = {
  166. "application": this.json.cmsView.appId,
  167. "viewName": this.json.cmsView.name,
  168. "isTitle": this.json.isTitle || "yes",
  169. "select": this.json.select || "none",
  170. "titleStyles": this.json.titleStyles,
  171. "itemStyles": this.json.itemStyles,
  172. "isExpand": this.json.isExpand || "no",
  173. "showActionbar" : this.json.actionbar === "show",
  174. "filter": filter
  175. };
  176. MWF.xDesktop.requireApp("process.Application", "Viewer", function(){
  177. /**
  178. * @summary view组件,平台使用该组件实现视图的功能
  179. * @member {MWF.xApplication.process.Application.Viewer}
  180. * @example
  181. * //可以在脚本中获取该组件
  182. * var view = this.form.get("fieldId").view; //获取组件对象
  183. */
  184. this.view = new MWF.xApplication.process.Application.Viewer(this.node, viewJson, {
  185. "actions": {
  186. "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  187. "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  188. },
  189. "actionRoot": "x_cms_assemble_control",
  190. "resizeNode": (this.node.getStyle("height").toString().toLowerCase()!=="auto" && this.node.getStyle("height").toInt()>0),
  191. "onSelect": function(){
  192. this.fireEvent("select");
  193. }.bind(this)
  194. });
  195. }.bind(this));
  196. },
  197. /**
  198. * @summary 获取视图被选中行的数据
  199. * @return {Object[]} 被选中行的数据
  200. * @example
  201. * var data = this.form.get("fieldId").getData();
  202. */
  203. getData: function(){
  204. if (this.view.selectedItems.length){
  205. var arr = [];
  206. this.view.selectedItems.each(function(item){
  207. arr.push(item.data);
  208. });
  209. return arr;
  210. }else{
  211. return [];
  212. }
  213. }
  214. });