StatementSelector.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. MWF.xDesktop.requireApp("process.Xform", "ViewSelector", null, false);
  3. /** @class ViewSelector 查询视图选择组件。
  4. * @example
  5. * //可以在脚本中获取该组件
  6. * //方法1:
  7. * var statementSelector = this.form.get("fieldId"); //获取组件
  8. * //方法2
  9. * var statementSelector = this.target; //在组件本身的脚本中获取
  10. * @extends MWF.xApplication.process.Xform.ViewSelector
  11. * @category FormComponents
  12. * @hideconstructor
  13. */
  14. MWF.xApplication.process.Xform.StatementSelector = MWF.APPStatementSelector = new Class({
  15. Implements: [Events],
  16. Extends: MWF.xApplication.process.Xform.ViewSelector,
  17. doResult: function(data){
  18. if (this.json.result === "script"){
  19. this.selectedData = data;
  20. return (this.json.selectedScript.code) ? this.form.Macro.exec(this.json.selectedScript.code, this) : "";
  21. }else{
  22. Object.each(this.json.selectedSetValues, function(v, k){
  23. var value = "";
  24. data.each(function(d, idx){
  25. // Object.each(d, function(dv, dk){
  26. // if (dk===v) value = (value) ? (value+", "+dv) : dv;
  27. // }.bind(this));
  28. var pathList = v.split(".");
  29. for( var i=0; i<pathList.length; i++ ){
  30. var p = pathList[i];
  31. if( (/(^[1-9]\d*$)/.test(p)) )p = p.toInt();
  32. if( d[ p ] ){
  33. d = d[ p ];
  34. }else{
  35. d = "";
  36. break;
  37. }
  38. }
  39. if( typeOf(d) === "array" || typeOf(d) === "object" ) {
  40. d = JSON.stringify(d);
  41. }
  42. value = (value) ? (value+", "+d) : d;
  43. }.bind(this));
  44. var field = this.form.all[k];
  45. if (field){
  46. field.setData(value);
  47. if (value){
  48. if (field.descriptionNode) field.descriptionNode.setStyle("display", "none");
  49. }else{
  50. if (field.descriptionNode) field.descriptionNode.setStyle("display", "block");
  51. }
  52. }
  53. }.bind(this));
  54. }
  55. },
  56. selectView: function(callback){
  57. var viewData = this.json.queryStatement;
  58. if (viewData){
  59. var filter = null;
  60. if (this.json.filterList && this.json.filterList.length){
  61. filter = [];
  62. this.json.filterList.each(function(entry){
  63. entry.value = this.form.Macro.exec(entry.code.code, this);
  64. //delete entry.code;
  65. filter.push(entry);
  66. }.bind(this));
  67. }
  68. var viewJson = {
  69. "application": viewData.appName,
  70. "statementName": viewData.name,
  71. "statementId": viewData.id,
  72. "isTitle": this.json.isTitle || "yes",
  73. "select": this.json.select || "single",
  74. "titleStyles": this.json.titleStyles,
  75. "itemStyles": this.json.itemStyles,
  76. "isExpand": this.json.isExpand || "no",
  77. "showActionbar" : this.json.actionbar === "show",
  78. "filter": filter,
  79. "defaultSelectedScript" : this.json.defaultSelectedScript ? this.json.defaultSelectedScript.code : null,
  80. "selectedAbleScript" : this.json.selectedAbleScript ? this.json.selectedAbleScript.code : null
  81. };
  82. var options = {};
  83. var width = options.width || "850";
  84. var height = options.height || "700";
  85. if (layout.mobile){
  86. var size = document.body.getSize();
  87. width = size.x;
  88. height = size.y;
  89. options.style = "viewmobile";
  90. }
  91. width = width.toInt();
  92. height = height.toInt();
  93. var size = this.form.app.content.getSize();
  94. var x = (size.x-width)/2;
  95. var y = (size.y-height)/2;
  96. if (x<0) x = 0;
  97. if (y<0) y = 0;
  98. if (layout.mobile){
  99. x = 20;
  100. y = 0;
  101. }
  102. var _self = this;
  103. MWF.require("MWF.xDesktop.Dialog", function(){
  104. var dlg = new MWF.xDesktop.Dialog({
  105. "title": this.json.title || "select view",
  106. "style": options.style || "view",
  107. "top": y,
  108. "left": x-20,
  109. "fromTop":y,
  110. "fromLeft": x-20,
  111. "width": width,
  112. "height": height,
  113. "html": "",
  114. "maskNode": layout.mobile?$(document.body) : this.form.app.content,
  115. "container": layout.mobile?$(document.body) : this.form.app.content,
  116. "buttonList": [
  117. {
  118. "text": MWF.LP.process.button.ok,
  119. "action": function(){
  120. //if (callback) callback(_self.view.selectedItems);
  121. if (callback) callback(_self.view.getData());
  122. this.close();
  123. }
  124. },
  125. {
  126. "text": MWF.LP.process.button.cancel,
  127. "action": function(){this.close();}
  128. }
  129. ],
  130. "onPostShow": function(){
  131. if(layout.mobile){
  132. dlg.node.setStyle("z-index",200);
  133. }
  134. MWF.xDesktop.requireApp("query.Query", "Statement", function(){
  135. this.view = new MWF.xApplication.query.Query.Statement(dlg.content, viewJson, {"style": "select"}, this.form.app, this.form.Macro );
  136. }.bind(this));
  137. }.bind(this)
  138. });
  139. dlg.show();
  140. if (layout.mobile){
  141. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  142. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  143. if (backAction) backAction.addEvent("click", function(e){
  144. dlg.close();
  145. }.bind(this));
  146. if (okAction) okAction.addEvent("click", function(e){
  147. //if (callback) callback(this.view.selectedItems);
  148. if (callback) callback(this.view.getData());
  149. dlg.close();
  150. }.bind(this));
  151. }
  152. // MWF.xDesktop.requireApp("process.Xform", "widget.View", function(){
  153. // this.view = new MWF.xApplication.process.Xform.widget.View(dlg.content.getFirst(), viewJson, {"style": "select"});
  154. // }.bind(this));
  155. // MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  156. // this.view = new MWF.xApplication.query.Query.Viewer(dlg.content, viewJson, {"style": "select"});
  157. // }.bind(this));
  158. }.bind(this));
  159. }
  160. }
  161. });