StatementSelector.js 6.8 KB

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