CMSMacro.js 4.3 KB

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