ViewSelector.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. Object.each(this.json.selectedSetValues, function(v, k){
  29. var value = "";
  30. data.each(function(d, idx){
  31. Object.each(d.data, function(dv, dk){
  32. if (dk==v) value = (value) ? (value+", "+dv) : dv;
  33. }.bind(this));
  34. }.bind(this));
  35. var field = this.form.all[k];
  36. if (field) field.setData(value);
  37. }.bind(this));
  38. }
  39. },
  40. selectView: function(callback){
  41. if (this.json.viewName){
  42. var viewJson = {
  43. "application": this.json.application || this.form.json.application,
  44. "viewName": this.json.viewName || "",
  45. "isTitle": this.json.isTitle || "yes",
  46. "select": this.json.select || "single"
  47. };
  48. var options = {};
  49. var width = options.width || "700";
  50. var height = options.height || "400";
  51. if (layout.mobile){
  52. var size = document.body.getSize();
  53. width = size.x;
  54. height = size.y;
  55. options.style = "viewmobile";
  56. }
  57. width = width.toInt();
  58. height = height.toInt();
  59. var size = this.form.app.content.getSize();
  60. var x = (size.x-width)/2;
  61. var y = (size.y-height)/2;
  62. if (x<0) x = 0;
  63. if (y<0) y = 0;
  64. if (layout.mobile){
  65. x = 20;
  66. y = 0;
  67. }
  68. var _self = this;
  69. MWF.require("MWF.xDesktop.Dialog", function(){
  70. var dlg = new MWF.xDesktop.Dialog({
  71. "title": this.json.title || "select view",
  72. "style": options.style || "view",
  73. "top": y,
  74. "left": x-20,
  75. "fromTop":y,
  76. "fromLeft": x-20,
  77. "width": width,
  78. "height": height,
  79. "html": "<div></div>",
  80. "maskNode": this.form.app.content,
  81. "container": this.form.app.content,
  82. "buttonList": [
  83. {
  84. "text": MWF.LP.process.button.ok,
  85. "action": function(){
  86. //if (callback) callback(_self.view.selectedItems);
  87. if (callback) callback(_self.view.getData());
  88. this.close();
  89. }
  90. },
  91. {
  92. "text": MWF.LP.process.button.cancel,
  93. "action": function(){this.close();}
  94. }
  95. ]
  96. });
  97. dlg.show();
  98. if (layout.mobile){
  99. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  100. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  101. if (backAction) backAction.addEvent("click", function(e){
  102. dlg.close();
  103. }.bind(this));
  104. if (okAction) okAction.addEvent("click", function(e){
  105. //if (callback) callback(this.view.selectedItems);
  106. if (callback) callback(this.view.getData());
  107. dlg.close();
  108. }.bind(this));
  109. }
  110. MWF.xDesktop.requireApp("process.Xform", "widget.View", function(){
  111. this.view = new MWF.xApplication.process.Xform.widget.View(dlg.content.getFirst(), viewJson, {"style": "select"});
  112. }.bind(this));
  113. }.bind(this));
  114. }
  115. }
  116. });