View.js 10 KB

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