Statement.js 5.7 KB

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