Macro.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. MWF.xScript = MWF.xScript || {};
  2. MWF.xScript.Macro = MWF.Macro = {
  3. "swapSpace": {},
  4. expression: function(code, bind){},
  5. runEvent: function(code, bind, arg){},
  6. exec: function(code, bind){
  7. var returnValue;
  8. //try{
  9. if (!bind) bind = window;
  10. if (o2.session.isDebugger){
  11. try {
  12. var f = eval("(function(){return function(){\n"+code+"\n}})();");
  13. returnValue = f.apply(bind);
  14. }catch(e){
  15. console.log(o2.LP.script.error);
  16. if (code.length>500){
  17. var t = code.substr(0,500)+"\n...\n";
  18. console.log(t);
  19. }else{
  20. console.log(code);
  21. }
  22. console.log(e);
  23. //throw e;
  24. }
  25. }else{
  26. try {
  27. var f = eval("(function(){return function(){\n"+code+"\n}})();");
  28. returnValue = f.apply(bind);
  29. }catch(e){
  30. console.log(o2.LP.script.error);
  31. if (code.length>500){
  32. var t = code.substr(0,500)+"\n...\n";
  33. console.log(t);
  34. }else{
  35. console.log(code);
  36. }
  37. console.log(e);
  38. //throw e;
  39. }
  40. }
  41. //}catch(e){}//
  42. // var macroCode = "MWF.Macro.swapSpace.tmpMacroFunction = function (){"+code+"};";
  43. // Browser.exec(macroCode);
  44. // var returnValue;
  45. // if (!bind) bind = window;
  46. //// try {
  47. // returnValue = MWF.Macro.swapSpace.tmpMacroFunction.apply(bind);
  48. //// }catch(e){};
  49. return returnValue;
  50. }
  51. };
  52. MWF.Macro.FormContext = new Class({
  53. macroFunction: null,
  54. environment: {},
  55. initialize: function(form){
  56. this.form = form;
  57. var environment = {
  58. "form": form,
  59. "forms": form.forms,
  60. "all": form.all,
  61. "data": form.businessData.data,
  62. "work": form.businessData.work,
  63. "workCompleted": form.businessData.workCompleted,
  64. "taskList": form.businessData.taskList,
  65. "readList": form.businessData.readList,
  66. "control": form.businessData.control,
  67. "activity": form.businessData.activity,
  68. "task": form.businessData.task,
  69. "taskCompletedList": form.businessData.taskCompletedList,
  70. "workLogList": form.businessData.workLogList,
  71. "recordList": form.businessData.recordList,
  72. "attachmentList": form.businessData.attachmentList,
  73. "inheritedAttachmentList": form.businessData.inheritedAttachmentList,
  74. "formInfor": form.businessData.formInfor,
  75. "status": form.businessData.status,
  76. "target": null,
  77. "event": null
  78. };
  79. MWF.require("MWF.xScript.Environment", null, false);
  80. this.environment = new MWF.xScript.Environment(environment);
  81. },
  82. setTarget: function(target){
  83. if (target){
  84. this.environment.target = target;
  85. }else{
  86. this.environment.target = null;
  87. }
  88. },
  89. setEvent: function(event){
  90. if (event){
  91. this.environment.event = event;
  92. }else{
  93. this.environment.event = null;
  94. }
  95. },
  96. exec: function(code, target){
  97. this.setTarget(target);
  98. var returnValue = MWF.Macro.exec(code, this.environment);
  99. //this.form.businessData.data = Object.merge(this.form.businessData.data, this.environment.data);
  100. return returnValue;
  101. //this.environment.data
  102. },
  103. fire: function(code, target, event){
  104. this.setTarget(target);
  105. this.setEvent(event);
  106. return MWF.Macro.exec(code, this.environment);
  107. }
  108. });
  109. MWF.Macro.PageContext = new Class({
  110. macroFunction: null,
  111. environment: {},
  112. initialize: function(page){
  113. this.form = page;
  114. var environment = {
  115. "form": page,
  116. "forms": page.forms,
  117. "all": page.all,
  118. "data": page.businessData.data,
  119. "status": page.businessData.status,
  120. "pageInfor": page.businessData.pageInfor,
  121. "target": null,
  122. "event": null
  123. };
  124. MWF.require("MWF.xScript.PageEnvironment", null, false);
  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. };