Macro.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. MWF.xScript = MWF.xScript || {};
  2. MWF.xScript.Macro = MWF.Macro = {
  3. "swapSpace": {},
  4. "scriptSpace": {},
  5. expression: function(code, bind){},
  6. runEvent: function(code, bind, arg){},
  7. run: function(code, bind){
  8. },
  9. exec: function(code, bind){
  10. debugger;
  11. var returnValue;
  12. //try{
  13. if (!bind) bind = window;
  14. var n = 0;
  15. var o = "f"+"_"+n;
  16. while (MWF.Macro.scriptSpace[o]){ n++; o = "f"+"_"+n; }
  17. //MWF.Macro.scriptSpace[o] = bind;
  18. if (o2.session.isDebugger){
  19. var f = "MWF.Macro.scriptSpace[\""+o+"\"] = function(){\n"+code+"\n}";
  20. Browser.exec(f);
  21. returnValue = o2.Macro.scriptSpace[o].apply(bind);
  22. }else{
  23. var f = "MWF.Macro.scriptSpace[\""+o+"\"] = function(){try{\n"+code+"\n}catch(e){console.error(e)}}";
  24. Browser.exec(f);
  25. returnValue = o2.Macro.scriptSpace[o].apply(bind);
  26. }
  27. o2.Macro.scriptSpace[o] = null;
  28. // if (o2.session.isDebugger){
  29. // this.run(code, bind)
  30. // }else{
  31. // try {
  32. // var n = 0;
  33. // var o = "o"+"_"+n;
  34. // while (MWF.Macro.swapSpace[o]){
  35. // n++;
  36. // o = "o"+"_"+n;
  37. // }
  38. // MWF.Macro.swapSpace[o] = bind;
  39. // var f = "try {(function(){\n"+code+"\n}).apply(MWF.Macro.swapSpace[\""+o+"\"])} catch(e){console.log(e);}";
  40. // Browser.exec(f);
  41. // o2.Macro.swapSpace[o] = null;
  42. // }catch(e){
  43. // console.log(o2.LP.script.error);
  44. // if (code.length>500){
  45. // var t = code.substr(0,500)+"\n...\n";
  46. // console.log(t);
  47. // }else{
  48. // console.log(code);
  49. // }
  50. //
  51. // console.log(e);
  52. // //throw e;
  53. // }
  54. // }
  55. return returnValue;
  56. }
  57. };
  58. //try {
  59. // var f = eval("(function(){return function(){\n"+code+"\n}})();");
  60. // returnValue = f.apply(bind);
  61. // }catch(e){
  62. // console.log(o2.LP.script.error);
  63. // if (code.length>500){
  64. // var t = code.substr(0,500)+"\n...\n";
  65. // console.log(t);
  66. // }else{
  67. // console.log(code);
  68. // }
  69. //
  70. // console.log(e);
  71. // debugger;
  72. // throw e;
  73. // }
  74. MWF.Macro
  75. MWF.Macro.FormContext = new Class({
  76. macroFunction: null,
  77. environment: {},
  78. initialize: function(form){
  79. this.form = form;
  80. var environment = {
  81. "form": form,
  82. "forms": form.forms,
  83. "all": form.all,
  84. "data": form.businessData.data,
  85. "work": form.businessData.work,
  86. "workCompleted": form.businessData.workCompleted,
  87. "taskList": form.businessData.taskList,
  88. "readList": form.businessData.readList,
  89. "control": form.businessData.control,
  90. "activity": form.businessData.activity,
  91. "task": form.businessData.task,
  92. "taskCompletedList": form.businessData.taskCompletedList,
  93. "workLogList": form.businessData.workLogList,
  94. "recordList": form.businessData.recordList,
  95. "attachmentList": form.businessData.attachmentList,
  96. "inheritedAttachmentList": form.businessData.inheritedAttachmentList,
  97. "formInfor": form.businessData.formInfor,
  98. "status": form.businessData.status,
  99. "target": null,
  100. "event": null
  101. };
  102. MWF.require("MWF.xScript.Environment", null, false);
  103. this.environment = new MWF.xScript.Environment(environment);
  104. },
  105. setTarget: function(target){
  106. if (target){
  107. this.environment.target = target;
  108. }else{
  109. this.environment.target = null;
  110. }
  111. },
  112. setEvent: function(event){
  113. if (event){
  114. this.environment.event = event;
  115. }else{
  116. this.environment.event = null;
  117. }
  118. },
  119. exec: function(code, target){
  120. this.setTarget(target);
  121. var returnValue = MWF.Macro.exec(code, this.environment);
  122. //this.form.businessData.data = Object.merge(this.form.businessData.data, this.environment.data);
  123. return returnValue;
  124. //this.environment.data
  125. },
  126. fire: function(code, target, event){
  127. this.setTarget(target);
  128. this.setEvent(event);
  129. return MWF.Macro.exec(code, this.environment);
  130. }
  131. });
  132. MWF.Macro.PageContext = new Class({
  133. macroFunction: null,
  134. environment: {},
  135. initialize: function(page){
  136. this.form = page;
  137. var environment = {
  138. "form": page,
  139. "forms": page.forms,
  140. "all": page.all,
  141. "data": page.businessData.data,
  142. "status": page.businessData.status,
  143. "pageInfor": page.businessData.pageInfor,
  144. "target": null,
  145. "event": null
  146. };
  147. MWF.require("MWF.xScript.PageEnvironment", null, false);
  148. this.environment = new MWF.xScript.PageEnvironment(environment);
  149. },
  150. setTarget: function(target){
  151. if (target){
  152. this.environment.target = target;
  153. }else{
  154. this.environment.target = null;
  155. }
  156. },
  157. setEvent: function(event){
  158. if (event){
  159. this.environment.event = event;
  160. }else{
  161. this.environment.event = null;
  162. }
  163. },
  164. exec: function(code, target){
  165. this.setTarget(target);
  166. var returnValue = MWF.Macro.exec(code, this.environment);
  167. //this.form.businessData.data = Object.merge(this.form.businessData.data, this.environment.data);
  168. return returnValue;
  169. //this.environment.data
  170. },
  171. fire: function(code, target, event){
  172. this.setTarget(target);
  173. this.setEvent(event);
  174. return MWF.Macro.exec(code, this.environment);
  175. }
  176. });
  177. if( !MWF.Macro.ViewContext ) {
  178. MWF.Macro.ViewContext = new Class({
  179. macroFunction: null,
  180. environment: {},
  181. initialize: function (view) {
  182. this.form = view;
  183. var environment = {
  184. "view": view,
  185. "viewInfor": view.viewInfor,
  186. "target": null,
  187. "event": null
  188. };
  189. MWF.require("MWF.xScript.ViewEnvironment", null, false);
  190. this.environment = new MWF.xScript.ViewEnvironment(environment);
  191. },
  192. setTarget: function (target) {
  193. if (target) {
  194. this.environment.target = target;
  195. } else {
  196. this.environment.target = null;
  197. }
  198. },
  199. setEvent: function (event) {
  200. if (event) {
  201. this.environment.event = event;
  202. } else {
  203. this.environment.event = null;
  204. }
  205. },
  206. exec: function (code, target) {
  207. this.setTarget(target);
  208. var returnValue = MWF.Macro.exec(code, this.environment);
  209. //this.form.businessData.data = Object.merge(this.form.businessData.data, this.environment.data);
  210. return returnValue;
  211. //this.environment.data
  212. },
  213. fire: function (code, target, event) {
  214. this.setTarget(target);
  215. this.setEvent(event);
  216. return MWF.Macro.exec(code, this.environment);
  217. }
  218. });
  219. }
  220. JSONObject = function(o){
  221. };