Macro.js 6.7 KB

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