Statement.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. //MWF.xDesktop.requireApp("process.Xform", "widget.View", null, false);
  3. /** @class Statement 查询视图组件。
  4. * @o2cn 查询视图
  5. * @example
  6. * //可以在脚本中获取该组件
  7. * //方法1:
  8. * var statement = this.form.get("fieldId"); //获取组件
  9. * //方法2
  10. * var statement = 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.Statement = MWF.APPStatement = new Class(
  17. /** @lends MWF.xApplication.process.Xform.Statement# */
  18. {
  19. Extends: MWF.APP$Module,
  20. options: {
  21. /**
  22. * 视图参数(options)已经准备好,还未加载视图时执行。可以通过this.event得到视图参数,并可修改this.event修改视图的加载。
  23. * @event MWF.xApplication.process.Xform.Statement#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.Statement#loadViewLayout
  29. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  30. */
  31. /**
  32. * 异步加载查询视图后执行。
  33. * @event MWF.xApplication.process.Xform.Statement#loadView
  34. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  35. */
  36. /**
  37. * 选中查询视图中的一条记录后执行。
  38. * @event MWF.xApplication.process.Xform.Statement#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.Statement#unselect
  45. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  46. */
  47. /**
  48. * 打开查询视图中的一条记录后执行。
  49. * @event MWF.xApplication.process.Xform.Statement#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", "Statement", null, false);
  56. this.node.empty();
  57. },
  58. _afterLoaded: function(){
  59. if (this.json.queryStatement){
  60. this.loadView();
  61. }
  62. },
  63. /**
  64. * @summary 重新加载查询视图
  65. * @example
  66. * this.form.get("fieldId").reload()
  67. */
  68. reload: function( callback ){
  69. if (this.view){
  70. if (this.view.loadViewRes && this.view.loadViewRes.res) if (this.view.loadViewRes.res.isRunning()) this.view.loadViewRes.res.cancel();
  71. if (this.view.getViewRes && this.view.getViewRes.res) if (this.view.getViewRes.res.isRunning()) this.view.getViewRes.res.cancel();
  72. }
  73. this.node.empty();
  74. this.loadView( callback );
  75. },
  76. /**
  77. * @summary 当查询视图被设置为延迟加载(未立即载入),通过active方法激活
  78. * @example
  79. * this.form.get("fieldId").active()
  80. */
  81. active: function( callback ){
  82. if (this.view){
  83. if (!this.view.loadingAreaNode) this.view.loadView( callback );
  84. }else{
  85. this.loadView( callback );
  86. }
  87. },
  88. loadView: function( callback ){
  89. if (!this.json.queryStatement) return "";
  90. var filter = null;
  91. if (this.json.filterList && this.json.filterList.length){
  92. filter = [];
  93. this.json.filterList.each(function(entry){
  94. entry.value = this.form.Macro.exec(entry.code.code, this);
  95. //delete entry.code;
  96. filter.push(entry);
  97. }.bind(this));
  98. }
  99. var parameter = null;
  100. if( this.json.parameterList && this.json.parameterList.length ){
  101. parameter = {};
  102. this.json.parameterList.each(function(entry){
  103. parameter[entry.parameter] = this.parseParameter(entry);
  104. }.bind(this));
  105. }
  106. //var data = JSON.parse(this.json.data);
  107. var viewJson = {
  108. "application": (this.json.queryStatement) ? this.json.queryStatement.appName : this.json.application,
  109. "statementName": (this.json.queryStatement) ? this.json.queryStatement.name : this.json.statementName,
  110. "statementId": (this.json.queryStatement) ? this.json.queryStatement.id : this.json.statementId,
  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. "parameter": parameter,
  119. "parameterList": this.json.parameterList,
  120. "defaultSelectedScript" : this.json.defaultSelectedScript ? this.json.defaultSelectedScript.code : null,
  121. "selectedAbleScript" : this.json.selectedAbleScript ? this.json.selectedAbleScript.code : null
  122. };
  123. this.fireEvent("beforeLoadView", [viewJson]);
  124. //MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  125. /**
  126. * @summary Statement组件,平台使用该组件实现查询视图的功能
  127. * @member {MWF.xApplication.query.Query.Statement}
  128. * @example
  129. * //可以在脚本中获取该组件
  130. * var view = this.form.get("fieldId").view; //获取组件对象
  131. */
  132. this.view = new MWF.xApplication.query.Query.Statement(this.node, viewJson, {
  133. "isload": (this.json.loadView!=="no"),
  134. "resizeNode": (this.node.getStyle("height").toString().toLowerCase()!=="auto" && this.node.getStyle("height").toInt()>0),
  135. "onLoadLayout": function () {
  136. this.fireEvent("loadViewLayout");
  137. }.bind(this),
  138. "onLoadView": function(){
  139. this.fireEvent("loadView");
  140. if(callback)callback();
  141. }.bind(this),
  142. "onSelect": function(item){
  143. this.fireEvent("select", [item]);
  144. }.bind(this),
  145. "onUnselect": function(item){
  146. this.fireEvent("unselect", [item]);
  147. }.bind(this),
  148. "onOpenDocument": function(options, item){
  149. this.openOptions = {
  150. "options": options,
  151. "item": item
  152. };
  153. this.fireEvent("openDocument", [this.openOptions]);
  154. this.openOptions = null;
  155. }.bind(this)
  156. }, this.form.app, this.form.Macro);
  157. //}.bind(this));
  158. },
  159. /**
  160. * @summary 获取查询视图被选中行的数据
  161. * @return {Object[]} 被选中行的数据
  162. * @example
  163. * var data = this.form.get("fieldId").getData();
  164. */
  165. getData: function(){
  166. if (this.view.selectedItems.length){
  167. var arr = [];
  168. this.view.selectedItems.each(function(item){
  169. arr.push(item.data);
  170. });
  171. return arr;
  172. }else{
  173. return [];
  174. }
  175. },
  176. parseParameter: function (f) {
  177. var value = f.value;
  178. if( f.valueType === "script" ){
  179. value = this.form.Macro.exec(f.valueScript ? f.valueScript.code : "", this);
  180. }
  181. return value;
  182. // 后面的放在 queryStatement中解析了
  183. // if (typeOf(value) === "date") {
  184. // value = value.format("db");
  185. // }
  186. // var user = layout.user;
  187. // switch (value) {
  188. // case "@person":
  189. // value = user.distinguishedName;
  190. // break;
  191. // case "@identityList":
  192. // value = user.identityList.map(function (d) {
  193. // return d.distinguishedName;
  194. // });
  195. // break;
  196. // case "@unitList":
  197. // o2.Actions.load("x_organization_assemble_express").UnitAction.listWithPerson({"personList": [user.distinguishedName]}, function (json) {
  198. // value = json.unitList;
  199. // }, null, false);
  200. // break;
  201. // case "@unitAllList":
  202. // o2.Actions.load("x_organization_assemble_express").UnitAction.listWithIdentitySupNested({"personList": [user.distinguishedName]}, function (json) {
  203. // value = json.unitList;
  204. // }, null, false);
  205. // break;
  206. // case "@year":
  207. // value = (new Date().getFullYear()).toString();
  208. // break;
  209. // case "@season":
  210. // var m = new Date().format("%m");
  211. // if (["01", "02", "03"].contains(m)) {
  212. // value = "1"
  213. // } else if (["04", "05", "06"].contains(m)) {
  214. // value = "2"
  215. // } else if (["07", "08", "09"].contains(m)) {
  216. // value = "3"
  217. // } else {
  218. // value = "4"
  219. // }
  220. // break;
  221. // case "@month":
  222. // value = new Date().format("%Y-%m");
  223. // break;
  224. // case "@time":
  225. // value = new Date().format("db");
  226. // break;
  227. // case "@date":
  228. // value = new Date().format("%Y-%m-%d");
  229. // break;
  230. // default:
  231. // }
  232. //
  233. // if (f.formatType === "dateTimeValue" || f.formatType === "datetimeValue") {
  234. // value = "{ts '" + value + "'}"
  235. // } else if (f.formatType === "dateValue") {
  236. // value = "{d '" + value + "'}"
  237. // } else if (f.formatType === "timeValue") {
  238. // value = "{t '" + value + "'}"
  239. // }
  240. // return value;
  241. }
  242. });