CMSMacro.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. MWF.xScript = MWF.xScript || {};
  2. MWF.xScript.CMSMacro = MWF.CMSMacro = {
  3. "swapSpace": {},
  4. "scriptSpace": {},
  5. expression: function(code, bind){},
  6. runEvent: function(code, bind, arg){},
  7. exec: function(code, bind){
  8. var returnValue;
  9. if (!bind) bind = window;
  10. var n = 0;
  11. var o = "f"+"_"+n;
  12. while (MWF.CMSMacro.scriptSpace[o]){ n++; o = "f"+"_"+n; }
  13. if (o2.session.isDebugger){
  14. var f = "MWF.CMSMacro.scriptSpace[\""+o+"\"] = function(){\n"+code+"\n}";
  15. Browser.exec(f);
  16. returnValue = (o2.CMSMacro.scriptSpace[o]) ? o2.CMSMacro.scriptSpace[o].apply(bind) : null;
  17. }else{
  18. var f = "MWF.CMSMacro.scriptSpace[\""+o+"\"] = function(){try{\n"+code+"\n}catch(e){console.error(e)}}";
  19. Browser.exec(f);
  20. returnValue = (o2.CMSMacro.scriptSpace[o]) ? o2.CMSMacro.scriptSpace[o].apply(bind) : null;
  21. }
  22. o2.CMSMacro.scriptSpace[o] = null;
  23. return returnValue;
  24. }
  25. };
  26. MWF.CMSMacro.CMSFormContext = new Class({
  27. macroFunction: null,
  28. environment: {},
  29. initialize: function(form){
  30. this.form = form;
  31. var environment = {
  32. "form": form,
  33. "forms": form.forms,
  34. "all": form.all,
  35. "data": form.businessData.data,
  36. "document": form.businessData.document,
  37. "control": form.businessData.control,
  38. "attachmentList": form.businessData.attachmentList,
  39. "status": form.businessData.status,
  40. "formInfor": form.businessData.formInfor,
  41. "target": null,
  42. "event": null
  43. };
  44. MWF.require("MWF.xScript.CMSEnvironment", null, false);
  45. this.environment = new MWF.xScript.CMSEnvironment(environment);
  46. },
  47. setTarget: function(target){
  48. if (target){
  49. this.environment.target = target;
  50. }else{
  51. this.environment.target = null;
  52. }
  53. },
  54. setEvent: function(event){
  55. if (event){
  56. this.environment.event = event;
  57. }else{
  58. this.environment.event = null;
  59. }
  60. },
  61. exec: function(code, target){
  62. this.setTarget(target);
  63. var returnValue = MWF.CMSMacro.exec(code, this.environment);
  64. //this.form.businessData.data = Object.merge(this.form.businessData.data, this.environment.data);
  65. return returnValue;
  66. //this.environment.data
  67. },
  68. fire: function(code, target, event){
  69. this.setTarget(target);
  70. this.setEvent(event);
  71. return MWF.CMSMacro.exec(code, this.environment);
  72. }
  73. });
  74. if( !MWF.CMSMacro.ViewContext ){
  75. MWF.CMSMacro.ViewContext = new Class({
  76. macroFunction: null,
  77. environment: {},
  78. initialize: function(view){
  79. this.form = view;
  80. var environment = {
  81. "view": view,
  82. "viewInfor": view.viewInfor,
  83. "target": null,
  84. "event": null
  85. };
  86. MWF.require("MWF.xScript.ViewEnvironment", null, false);
  87. this.environment = new MWF.xScript.ViewEnvironment(environment);
  88. },
  89. setTarget: function(target){
  90. if (target){
  91. this.environment.target = target;
  92. }else{
  93. this.environment.target = null;
  94. }
  95. },
  96. setEvent: function(event){
  97. if (event){
  98. this.environment.event = event;
  99. }else{
  100. this.environment.event = null;
  101. }
  102. },
  103. exec: function(code, target){
  104. this.setTarget(target);
  105. var returnValue = MWF.CMSMacro.exec(code, this.environment);
  106. //this.form.businessData.data = Object.merge(this.form.businessData.data, this.environment.data);
  107. return returnValue;
  108. //this.environment.data
  109. },
  110. fire: function(code, target, event){
  111. this.setTarget(target);
  112. this.setEvent(event);
  113. return MWF.CMSMacro.exec(code, this.environment);
  114. }
  115. });
  116. }
  117. JSONObject = function(o){
  118. };