Macro.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. o2.widget = o2.widget || {};
  2. o2.require("o2.xScript.Environment", null, false);
  3. o2.widget.Macro = o2.Macro = {
  4. "swapSpace": {},
  5. expression: function(code, bind){},
  6. runEvent: function(code, bind, arg){},
  7. exec: function(code, bind){
  8. var macroCode = "o2.Macro.swapSpace.tmpMacroFunction = function (){\n"+code+"\n};";
  9. Browser.exec(macroCode);
  10. var returnValue;
  11. if (!bind) bind = window;
  12. // try {
  13. returnValue = o2.Macro.swapSpace.tmpMacroFunction.apply(bind);
  14. // }catch(e){};
  15. return returnValue;
  16. }
  17. };
  18. o2.Macro.FormContext = new Class({
  19. macroFunction: null,
  20. environment: {},
  21. initialize: function(form){
  22. var environment = {
  23. "form": form,
  24. "forms": form.forms,
  25. "all": form.all,
  26. "data": form.businessData.data,
  27. "work": form.businessData.work,
  28. "taskList": form.businessData.taskList,
  29. "control": form.businessData.control,
  30. "activity": form.businessData.activity,
  31. "task": form.businessData.task,
  32. "workLogList": form.businessData.workLogList,
  33. "attachmentList": form.businessData.attachmentList,
  34. "status": form.businessData.status,
  35. "target": null,
  36. "event": null
  37. }
  38. this.environment = new o2.xScript.Environment(environment);
  39. },
  40. setTarget: function(target){
  41. if (target){
  42. this.environment.target = target;
  43. }else{
  44. this.environment.target = null;
  45. }
  46. },
  47. setEvent: function(event){
  48. if (event){
  49. this.environment.event = event;
  50. }else{
  51. this.environment.event = null;
  52. }
  53. },
  54. exec: function(code, target){
  55. this.setTarget(target);
  56. return o2.Macro.exec(code, this.environment);
  57. },
  58. fire: function(code, target, event){
  59. this.setTarget(target);
  60. this.setEvent(event);
  61. return o2.Macro.exec(code, this.environment);
  62. }
  63. });