Macro.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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.FormContext = new Class({
  73. macroFunction: null,
  74. environment: {},
  75. initialize: function(form){
  76. this.form = form;
  77. var environment = {
  78. "form": form,
  79. "forms": form.forms,
  80. "all": form.all,
  81. "data": form.businessData.data,
  82. "work": form.businessData.work,
  83. "workCompleted": form.businessData.workCompleted,
  84. "taskList": form.businessData.taskList,
  85. "readList": form.businessData.readList,
  86. "control": form.businessData.control,
  87. "activity": form.businessData.activity,
  88. "task": form.businessData.task,
  89. "taskCompletedList": form.businessData.taskCompletedList,
  90. "workLogList": form.businessData.workLogList,
  91. "recordList": form.businessData.recordList,
  92. "attachmentList": form.businessData.attachmentList,
  93. "inheritedAttachmentList": form.businessData.inheritedAttachmentList,
  94. "formInfor": form.businessData.formInfor,
  95. "status": form.businessData.status,
  96. "target": null,
  97. "event": null
  98. };
  99. MWF.require("MWF.xScript.Environment", null, false);
  100. this.environment = new MWF.xScript.Environment(environment);
  101. },
  102. setTarget: function(target){
  103. if (target){
  104. this.environment.target = target;
  105. }else{
  106. this.environment.target = null;
  107. }
  108. },
  109. setEvent: function(event){
  110. if (event){
  111. this.environment.event = event;
  112. }else{
  113. this.environment.event = null;
  114. }
  115. },
  116. exec: function(code, target){
  117. this.setTarget(target);
  118. var returnValue = MWF.Macro.exec(code, this.environment);
  119. //this.form.businessData.data = Object.merge(this.form.businessData.data, this.environment.data);
  120. return returnValue;
  121. //this.environment.data
  122. },
  123. fire: function(code, target, event){
  124. this.setTarget(target);
  125. this.setEvent(event);
  126. return MWF.Macro.exec(code, this.environment);
  127. }
  128. });
  129. MWF.Macro.PageContext = new Class({
  130. macroFunction: null,
  131. environment: {},
  132. initialize: function(page){
  133. this.form = page;
  134. var environment = {
  135. "form": page,
  136. "forms": page.forms,
  137. "all": page.all,
  138. "data": page.businessData.data,
  139. "status": page.businessData.status,
  140. "pageInfor": page.businessData.pageInfor,
  141. "target": null,
  142. "event": null
  143. };
  144. MWF.require("MWF.xScript.PageEnvironment", null, false);
  145. this.environment = new MWF.xScript.PageEnvironment(environment);
  146. },
  147. setTarget: function(target){
  148. if (target){
  149. this.environment.target = target;
  150. }else{
  151. this.environment.target = null;
  152. }
  153. },
  154. setEvent: function(event){
  155. if (event){
  156. this.environment.event = event;
  157. }else{
  158. this.environment.event = null;
  159. }
  160. },
  161. exec: function(code, target){
  162. this.setTarget(target);
  163. var returnValue = MWF.Macro.exec(code, this.environment);
  164. //this.form.businessData.data = Object.merge(this.form.businessData.data, this.environment.data);
  165. return returnValue;
  166. //this.environment.data
  167. },
  168. fire: function(code, target, event){
  169. this.setTarget(target);
  170. this.setEvent(event);
  171. return MWF.Macro.exec(code, this.environment);
  172. }
  173. });
  174. if( !MWF.Macro.ViewContext ) {
  175. MWF.Macro.ViewContext = new Class({
  176. macroFunction: null,
  177. environment: {},
  178. initialize: function (view) {
  179. this.form = view;
  180. var environment = {
  181. "view": view,
  182. "viewInfor": view.viewInfor,
  183. "target": null,
  184. "event": null
  185. };
  186. MWF.require("MWF.xScript.ViewEnvironment", null, false);
  187. this.environment = new MWF.xScript.ViewEnvironment(environment);
  188. },
  189. setTarget: function (target) {
  190. if (target) {
  191. this.environment.target = target;
  192. } else {
  193. this.environment.target = null;
  194. }
  195. },
  196. setEvent: function (event) {
  197. if (event) {
  198. this.environment.event = event;
  199. } else {
  200. this.environment.event = null;
  201. }
  202. },
  203. exec: function (code, target) {
  204. this.setTarget(target);
  205. var returnValue = MWF.Macro.exec(code, this.environment);
  206. //this.form.businessData.data = Object.merge(this.form.businessData.data, this.environment.data);
  207. return returnValue;
  208. //this.environment.data
  209. },
  210. fire: function (code, target, event) {
  211. this.setTarget(target);
  212. this.setEvent(event);
  213. return MWF.Macro.exec(code, this.environment);
  214. }
  215. });
  216. }
  217. JSONObject = function(o){
  218. };