StatementSelector.js 7.3 KB

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