StatementSelector.js 6.9 KB

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