Macro.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. MWF.xScript = MWF.xScript || {};
  2. MWF.require("MWF.xScript.Environment", null, false);
  3. MWF.require("MWF.xScript.PageEnvironment", null, false);
  4. MWF.xScript.Macro = MWF.Macro = {
  5. "swapSpace": {},
  6. expression: function(code, bind){},
  7. runEvent: function(code, bind, arg){},
  8. exec: function(code, bind){
  9. var returnValue;
  10. //try{
  11. if (!bind) bind = window;
  12. //try {
  13. var f = eval("(function(){return function(){\n"+code+"\n}})();");
  14. returnValue = f.apply(bind);
  15. // }catch(e){
  16. // console.log(o2.LP.script.error);
  17. // if (code.length>500){
  18. // var t = code.substr(0,500)+"\n...\n";
  19. // console.log(t);
  20. // }else{
  21. // console.log(code);
  22. // }
  23. //
  24. // console.log(e);
  25. // throw e;
  26. // }
  27. //}catch(e){}//
  28. // var macroCode = "MWF.Macro.swapSpace.tmpMacroFunction = function (){"+code+"};";
  29. // Browser.exec(macroCode);
  30. // var returnValue;
  31. // if (!bind) bind = window;
  32. //// try {
  33. // returnValue = MWF.Macro.swapSpace.tmpMacroFunction.apply(bind);
  34. //// }catch(e){};
  35. return returnValue;
  36. }
  37. };
  38. MWF.Macro.FormContext = new Class({
  39. macroFunction: null,
  40. environment: {},
  41. initialize: function(form){
  42. this.form = form;
  43. var environment = {
  44. "form": form,
  45. "forms": form.forms,
  46. "all": form.all,
  47. "data": form.businessData.data,
  48. "work": form.businessData.work,
  49. "workCompleted": form.businessData.workCompleted,
  50. "taskList": form.businessData.taskList,
  51. "readList": form.businessData.readList,
  52. "control": form.businessData.control,
  53. "activity": form.businessData.activity,
  54. "task": form.businessData.task,
  55. "taskCompletedList": form.businessData.taskCompletedList,
  56. "workLogList": form.businessData.workLogList,
  57. "attachmentList": form.businessData.attachmentList,
  58. "inheritedAttachmentList": form.businessData.inheritedAttachmentList,
  59. "formInfor": form.businessData.formInfor,
  60. "status": form.businessData.status,
  61. "target": null,
  62. "event": null
  63. };
  64. this.environment = new MWF.xScript.Environment(environment);
  65. },
  66. setTarget: function(target){
  67. if (target){
  68. this.environment.target = target;
  69. }else{
  70. this.environment.target = null;
  71. }
  72. },
  73. setEvent: function(event){
  74. if (event){
  75. this.environment.event = event;
  76. }else{
  77. this.environment.event = null;
  78. }
  79. },
  80. exec: function(code, target){
  81. this.setTarget(target);
  82. var returnValue = MWF.Macro.exec(code, this.environment);
  83. //this.form.businessData.data = Object.merge(this.form.businessData.data, this.environment.data);
  84. return returnValue;
  85. //this.environment.data
  86. },
  87. fire: function(code, target, event){
  88. this.setTarget(target);
  89. this.setEvent(event);
  90. return MWF.Macro.exec(code, this.environment);
  91. }
  92. });
  93. MWF.Macro.PageContext = new Class({
  94. macroFunction: null,
  95. environment: {},
  96. initialize: function(page){
  97. this.form = page;
  98. var environment = {
  99. "form": page,
  100. "forms": page.forms,
  101. "all": page.all,
  102. "data": page.businessData.data,
  103. "status": page.businessData.status,
  104. "pageInfor": page.businessData.pageInfor,
  105. "target": null,
  106. "event": null
  107. };
  108. this.environment = new MWF.xScript.PageEnvironment(environment);
  109. },
  110. setTarget: function(target){
  111. if (target){
  112. this.environment.target = target;
  113. }else{
  114. this.environment.target = null;
  115. }
  116. },
  117. setEvent: function(event){
  118. if (event){
  119. this.environment.event = event;
  120. }else{
  121. this.environment.event = null;
  122. }
  123. },
  124. exec: function(code, target){
  125. this.setTarget(target);
  126. var returnValue = MWF.Macro.exec(code, this.environment);
  127. //this.form.businessData.data = Object.merge(this.form.businessData.data, this.environment.data);
  128. return returnValue;
  129. //this.environment.data
  130. },
  131. fire: function(code, target, event){
  132. this.setTarget(target);
  133. this.setEvent(event);
  134. return MWF.Macro.exec(code, this.environment);
  135. }
  136. });
  137. JSONObject = function(o){
  138. };