View.js 8.8 KB

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