framework.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. layout.addReady(function(){
  2. if (layout.desktop.type!=="layout" && layout.desktop.type!=="app") layout.app = true;
  3. if (!o2.env){
  4. MWF.require("MWF.xScript.Macro", null, false);
  5. var getPage = function(){
  6. return {
  7. "businessData": {},
  8. "json": {
  9. "application": ""
  10. },
  11. "options": {},
  12. "confirm": o2.xApplication.Common.Main.prototype.confirm,
  13. "alert": function(type, title, text, width, height){
  14. var p = o2.getCenterPosition(document.body, width, height);
  15. var e = {
  16. "event": {
  17. "x": p.x,
  18. "y": p.y,
  19. "clientX": p.x,
  20. "clientY": p.y
  21. }
  22. };
  23. o2.xApplication.Common.Main.prototype.alert(type, e, title, text, width, height);
  24. },
  25. "notice": function(content, type, target, where, offset, option){
  26. o2.xDesktop.notice(type, where, content, target, offset, option);
  27. },
  28. "app": {
  29. "desktop": layout,
  30. "content": document.body,
  31. "toPortal": function(portal, page, par, nohis){
  32. var url = "../x_desktop/portal.html?id="+portal;
  33. if (page) url += "&page="+page;
  34. if (par){
  35. if (o2.typeOf(par)==="object"){
  36. url += "&parameters="+JSON.stringify(par);
  37. }else{
  38. url += "&parameters="+par.toString();
  39. }
  40. }
  41. var a = document.createElement("a");
  42. a.setAttribute("href", o2.filterUrl(url));
  43. a.setAttribute("target", "_blank1");
  44. a.click();
  45. if (a.remove) a.remove();
  46. },
  47. "toPage": function(){}
  48. },
  49. addEvent: function(){}
  50. };
  51. };
  52. var page = getPage();
  53. function createEnvironment(page){
  54. var environment = {
  55. "form": page,
  56. "forms": page.forms,
  57. "all": page.all,
  58. "data": page.businessData.data,
  59. "status": page.businessData.status,
  60. "pageInfor": page.businessData.pageInfor,
  61. "target": null,
  62. "event": null
  63. };
  64. return new MWF.xScript.PageEnvironment(environment);
  65. }
  66. o2.env = createEnvironment(page);
  67. o2.apis = {};
  68. o2.defineProperties(o2, {
  69. "api": {"get": function(){
  70. var app = layout.desktop.currentApp || layout.app;
  71. if (app){
  72. if (app.unique && o2.apis[app.unique]) return o2.apis[app.unique];
  73. var _page = getPage();
  74. var tmpApp = _page.app;
  75. _page.app = app;
  76. if( !_page.app.toPortal )_page.app.toPortal = tmpApp.toPortal;
  77. var api = createEnvironment(_page);
  78. if (!app.unique) app.unique = (new Date()).getTime().toString();
  79. o2.apis[app.unique] = api;
  80. return api;
  81. }
  82. return o2.env;
  83. }}
  84. });
  85. o2.getApi = function(app){
  86. if (app){
  87. if (app.unique && o2.apis[app.unique]) return o2.apis[app.unique];
  88. var _page = getPage();
  89. var tmpApp = _page.app;
  90. _page.app = app;
  91. if( !_page.app.toPortal )_page.app.toPortal = tmpApp.toPortal;
  92. var api = createEnvironment(_page);
  93. if (!app.unique) app.unique = (new Date()).getTime().toString();
  94. o2.apis[app.unique] = api;
  95. return api;
  96. }
  97. return o2.env;
  98. }
  99. }
  100. });