Macro.js 7.4 KB

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