Statement.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. //MWF.xDesktop.requireApp("process.Xform", "widget.View", null, false);
  3. /** @class Statement 查询视图组件。
  4. * @example
  5. * //可以在脚本中获取该组件
  6. * //方法1:
  7. * var statement = this.form.get("fieldId"); //获取组件
  8. * //方法2
  9. * var statement = 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.Statement = MWF.APPStatement = new Class(
  16. /** @lends MWF.xApplication.process.Xform.Statement# */
  17. {
  18. Extends: MWF.APP$Module,
  19. options: {
  20. /**
  21. * 异步加载查询视图后完成。
  22. * @event MWF.xApplication.process.Xform.Statement#loadView
  23. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  24. */
  25. /**
  26. * 选中查询视图中的一条记录后执行。
  27. * @event MWF.xApplication.process.Xform.Statement#select
  28. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  29. */
  30. /**
  31. * 打开查询视图中的一条记录后执行。
  32. * @event MWF.xApplication.process.Xform.Statement#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", "Statement", null, false);
  39. this.node.empty();
  40. },
  41. _afterLoaded: function(){
  42. if (this.json.queryStatement){
  43. this.loadView();
  44. }
  45. },
  46. /**
  47. * @summary 重新加载查询视图
  48. * @example
  49. * this.form.get("fieldId").reload()
  50. */
  51. reload: function(){
  52. if (this.view){
  53. if (this.view.loadViewRes && this.view.loadViewRes.res) if (this.view.loadViewRes.res.isRunning()) this.view.loadViewRes.res.cancel();
  54. if (this.view.getViewRes && this.view.getViewRes.res) if (this.view.getViewRes.res.isRunning()) this.view.getViewRes.res.cancel();
  55. }
  56. this.node.empty();
  57. this.loadView();
  58. },
  59. /**
  60. * @summary 当查询视图被设置为延迟加载(未立即载入),通过active方法激活
  61. * @example
  62. * this.form.get("fieldId").active()
  63. */
  64. active: function(){
  65. if (this.view){
  66. if (!this.view.loadingAreaNode) this.view.loadView();
  67. }else{
  68. this.loadView();
  69. }
  70. },
  71. loadView: function(){
  72. if (!this.json.queryStatement) return "";
  73. var filter = null;
  74. if (this.json.filterList && this.json.filterList.length){
  75. filter = [];
  76. this.json.filterList.each(function(entry){
  77. entry.value = this.form.Macro.exec(entry.code.code, this);
  78. //delete entry.code;
  79. filter.push(entry);
  80. }.bind(this));
  81. }
  82. //var data = JSON.parse(this.json.data);
  83. var viewJson = {
  84. "application": (this.json.queryStatement) ? this.json.queryStatement.appName : this.json.application,
  85. "statementName": (this.json.queryStatement) ? this.json.queryStatement.name : this.json.statementName,
  86. "statementId": (this.json.queryStatement) ? this.json.queryStatement.id : this.json.statementId,
  87. "isTitle": this.json.isTitle || "yes",
  88. "select": this.json.select || "none",
  89. "titleStyles": this.json.titleStyles,
  90. "itemStyles": this.json.itemStyles,
  91. "isExpand": this.json.isExpand || "no",
  92. "showActionbar" : this.json.actionbar === "show",
  93. "filter": filter,
  94. "defaultSelectedScript" : this.json.defaultSelectedScript ? this.json.defaultSelectedScript.code : null,
  95. "selectedAbleScript" : this.json.selectedAbleScript ? this.json.selectedAbleScript.code : null
  96. };
  97. //MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  98. /**
  99. * @summary Statement组件,平台使用该组件实现查询视图的功能
  100. * @member {MWF.xApplication.query.Query.Statement}
  101. * @example
  102. * //可以在脚本中获取该组件
  103. * var view = this.form.get("fieldId").view; //获取组件对象
  104. */
  105. this.view = new MWF.xApplication.query.Query.Statement(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. /**
  126. * @summary 获取查询视图被选中行的数据
  127. * @return {Object[]} 被选中行的数据
  128. * @example
  129. * var data = this.form.get("fieldId").getData();
  130. */
  131. getData: function(){
  132. if (this.view.selectedItems.length){
  133. var arr = [];
  134. this.view.selectedItems.each(function(item){
  135. arr.push(item.data);
  136. });
  137. return arr;
  138. }else{
  139. return [];
  140. }
  141. }
  142. });