CMSMacro.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. MWF.xScript = MWF.xScript || {};
  2. MWF.require("MWF.xScript.CMSEnvironment", null, false);
  3. MWF.xScript.CMSMacro = MWF.CMSMacro = {
  4. "swapSpace": {},
  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. 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. }
  24. }else{
  25. try {
  26. var f = eval("(function(){return function(){\n"+code+"\n}})();");
  27. returnValue = f.apply(bind);
  28. }catch(e){
  29. console.log(o2.LP.script.error);
  30. if (code.length>500){
  31. var t = code.substr(0,500)+"\n...\n";
  32. console.log(t);
  33. }else{
  34. console.log(code);
  35. }
  36. console.log(e);
  37. }
  38. }
  39. return returnValue;
  40. }
  41. };
  42. MWF.CMSMacro.CMSFormContext = new Class({
  43. macroFunction: null,
  44. environment: {},
  45. initialize: function(form){
  46. this.form = form;
  47. var environment = {
  48. "form": form,
  49. "forms": form.forms,
  50. "all": form.all,
  51. "data": form.businessData.data,
  52. "document": form.businessData.document,
  53. "control": form.businessData.control,
  54. "attachmentList": form.businessData.attachmentList,
  55. "status": form.businessData.status,
  56. "formInfor": form.businessData.formInfor,
  57. "target": null,
  58. "event": null
  59. };
  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. };