Macro.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. console.log(e);
  24. }
  25. //}catch(e){}//
  26. // var macroCode = "MWF.Macro.swapSpace.tmpMacroFunction = function (){"+code+"};";
  27. // Browser.exec(macroCode);
  28. // var returnValue;
  29. // if (!bind) bind = window;
  30. //// try {
  31. // returnValue = MWF.Macro.swapSpace.tmpMacroFunction.apply(bind);
  32. //// }catch(e){};
  33. return returnValue;
  34. }
  35. };
  36. MWF.Macro.FormContext = new Class({
  37. macroFunction: null,
  38. environment: {},
  39. initialize: function(form){
  40. this.form = form;
  41. var environment = {
  42. "form": form,
  43. "forms": form.forms,
  44. "all": form.all,
  45. "data": form.businessData.data,
  46. "work": form.businessData.work,
  47. "workCompleted": form.businessData.workCompleted,
  48. "taskList": form.businessData.taskList,
  49. "readList": form.businessData.readList,
  50. "control": form.businessData.control,
  51. "activity": form.businessData.activity,
  52. "task": form.businessData.task,
  53. "taskCompletedList": form.businessData.taskCompletedList,
  54. "workLogList": form.businessData.workLogList,
  55. "attachmentList": form.businessData.attachmentList,
  56. "inheritedAttachmentList": form.businessData.inheritedAttachmentList,
  57. "formInfor": form.businessData.formInfor,
  58. "status": form.businessData.status,
  59. "target": null,
  60. "event": null
  61. };
  62. this.environment = new MWF.xScript.Environment(environment);
  63. },
  64. setTarget: function(target){
  65. if (target){
  66. this.environment.target = target;
  67. }else{
  68. this.environment.target = null;
  69. }
  70. },
  71. setEvent: function(event){
  72. if (event){
  73. this.environment.event = event;
  74. }else{
  75. this.environment.event = null;
  76. }
  77. },
  78. exec: function(code, target){
  79. this.setTarget(target);
  80. var returnValue = MWF.Macro.exec(code, this.environment);
  81. //this.form.businessData.data = Object.merge(this.form.businessData.data, this.environment.data);
  82. return returnValue;
  83. //this.environment.data
  84. },
  85. fire: function(code, target, event){
  86. this.setTarget(target);
  87. this.setEvent(event);
  88. return MWF.Macro.exec(code, this.environment);
  89. }
  90. });
  91. MWF.Macro.PageContext = new Class({
  92. macroFunction: null,
  93. environment: {},
  94. initialize: function(page){
  95. this.form = page;
  96. var environment = {
  97. "form": page,
  98. "forms": page.forms,
  99. "all": page.all,
  100. "data": page.businessData.data,
  101. "status": page.businessData.status,
  102. "pageInfor": page.businessData.pageInfor,
  103. "target": null,
  104. "event": null
  105. };
  106. this.environment = new MWF.xScript.PageEnvironment(environment);
  107. },
  108. setTarget: function(target){
  109. if (target){
  110. this.environment.target = target;
  111. }else{
  112. this.environment.target = null;
  113. }
  114. },
  115. setEvent: function(event){
  116. if (event){
  117. this.environment.event = event;
  118. }else{
  119. this.environment.event = null;
  120. }
  121. },
  122. exec: function(code, target){
  123. this.setTarget(target);
  124. var returnValue = MWF.Macro.exec(code, this.environment);
  125. //this.form.businessData.data = Object.merge(this.form.businessData.data, this.environment.data);
  126. return returnValue;
  127. //this.environment.data
  128. },
  129. fire: function(code, target, event){
  130. this.setTarget(target);
  131. this.setEvent(event);
  132. return MWF.Macro.exec(code, this.environment);
  133. }
  134. });
  135. JSONObject = function(o){
  136. };