ViewSelector.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. MWF.xApplication.process.Xform.ViewSelector = MWF.APPViewSelector = new Class({
  3. Implements: [Events],
  4. Extends: MWF.xApplication.process.Xform.Button,
  5. _loadUserInterface: function(){
  6. var button = new Element("button");
  7. button.inject(this.node, "after");
  8. this.node.destroy();
  9. this.node = button;
  10. this.node.set({
  11. "id": this.json.id,
  12. "text": this.json.name || this.json.id,
  13. "styles": this.form.css.buttonStyles,
  14. "MWFType": this.json.type
  15. });
  16. this.node.addEvent("click", function(){
  17. this.selectedData = null;
  18. this.selectView(function(data){
  19. this.doResult(data);
  20. }.bind(this));
  21. }.bind(this));
  22. },
  23. doResult: function(data){
  24. if (this.result == "script"){
  25. this.selectedData = data;
  26. return (this.json.selectedScript.code) ? this.form.Macro.exec(this.json.selectedScript.code, this) : "";
  27. }else{
  28. debugger;
  29. Object.each(this.json.selectedSetValues, function(v, k){
  30. var value = "";
  31. data.each(function(d, idx){
  32. Object.each(d.data, function(dv, dk){
  33. if (dk==v) value = (value) ? (value+", "+dv) : dv;
  34. }.bind(this));
  35. }.bind(this));
  36. var field = this.form.all[k];
  37. if (field) field.setData(value);
  38. }.bind(this));
  39. }
  40. },
  41. selectView: function(callback){
  42. debugger;
  43. if (this.json.viewName){
  44. var viewJson = {
  45. "application": this.json.application || this.form.json.application,
  46. "viewName": this.json.viewName || "",
  47. "isTitle": this.json.isTitle || "yes",
  48. "select": this.json.select || "single"
  49. };
  50. var options = {};
  51. var width = options.width || "700";
  52. var height = options.height || "400";
  53. if (layout.mobile){
  54. var size = document.body.getSize();
  55. width = size.x;
  56. height = size.y;
  57. options.style = "viewmobile";
  58. }
  59. width = width.toInt();
  60. height = height.toInt();
  61. var size = this.form.app.content.getSize();
  62. var x = (size.x-width)/2;
  63. var y = (size.y-height)/2;
  64. if (x<0) x = 0;
  65. if (y<0) y = 0;
  66. if (layout.mobile){
  67. x = 20;
  68. y = 0;
  69. }
  70. var _self = this;
  71. MWF.require("MWF.xDesktop.Dialog", function(){
  72. var dlg = new MWF.xDesktop.Dialog({
  73. "title": this.json.title || "select view",
  74. "style": options.style || "view",
  75. "top": y,
  76. "left": x-20,
  77. "fromTop":y,
  78. "fromLeft": x-20,
  79. "width": width,
  80. "height": height,
  81. "html": "<div></div>",
  82. "maskNode": this.form.app.content,
  83. "container": this.form.app.content,
  84. "buttonList": [
  85. {
  86. "text": MWF.LP.process.button.ok,
  87. "action": function(){
  88. //if (callback) callback(_self.view.selectedItems);
  89. if (callback) callback(_self.view.getData());
  90. this.close();
  91. }
  92. },
  93. {
  94. "text": MWF.LP.process.button.cancel,
  95. "action": function(){this.close();}
  96. }
  97. ]
  98. });
  99. dlg.show();
  100. if (layout.mobile){
  101. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  102. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  103. if (backAction) backAction.addEvent("click", function(e){
  104. dlg.close();
  105. }.bind(this));
  106. if (okAction) okAction.addEvent("click", function(e){
  107. //if (callback) callback(this.view.selectedItems);
  108. if (callback) callback(this.view.getData());
  109. dlg.close();
  110. }.bind(this));
  111. }
  112. MWF.xDesktop.requireApp("process.Xform", "widget.View", function(){
  113. this.view = new MWF.xApplication.process.Xform.widget.View(dlg.content.getFirst(), viewJson, {"style": "select"});
  114. }.bind(this));
  115. }.bind(this));
  116. }
  117. }
  118. });