Tab.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. MWF.require("MWF.widget.Tab", null, false);
  3. /** @class Tab 分页组件。
  4. * @example
  5. * //可以在脚本中获取该组件
  6. * //方法1:
  7. * var tab = this.form.get("fieldId"); //获取组件
  8. * //方法2
  9. * var tab = this.target; //在组件本身的脚本中获取
  10. * @extends MWF.xApplication.process.Xform.$Module
  11. * @o2category FormComponents
  12. * @o2range {Process|CMS|Portal}
  13. * @hideconstructor
  14. */
  15. MWF.xApplication.process.Xform.Tab = MWF.APPTab = new Class(
  16. /** @lends MWF.xApplication.process.Xform.Tab# */
  17. {
  18. Extends: MWF.APP$Module,
  19. _loadUserInterface: function(){
  20. this.elements = [];
  21. this.containers = [];
  22. var style = "form";
  23. if (layout.mobile) style = "mobileForm";
  24. /**
  25. * @summary tab组件,平台使用该组件实现分页组件的功能
  26. * @member {MWF.widget.Tab}
  27. * @example
  28. * //可以在脚本中获取该组件
  29. * var tab = this.form.get("fieldId").tab; //获取组件对象
  30. * var pages = tab.pages //获取每个分页
  31. * pages[1].addEvent("queryShow", function(){
  32. * //添加显示分页前事件
  33. * })
  34. * pages[1].addEvent("postShow", function(){
  35. * //添加显示分页后事件
  36. * })
  37. * pages[1]._showTab(); //显示第2个分页
  38. */
  39. this.tab = new MWF.widget.Tab(this.node, {"style": style});
  40. this._setTabWidgetStyles();
  41. this.tab.tabNodeContainer = this.node.getFirst("div");
  42. this.tab.contentNodeContainer = this.tab.tabNodeContainer.getNext("div");
  43. var lastNode = this.tab.tabNodeContainer.getLast();
  44. var tabs;
  45. if (lastNode && lastNode.hasClass("tabNodeContainerLeft")){
  46. this.tab.tabNodeContainerRight = this.tab.tabNodeContainer.getFirst();
  47. this.tab.tabNodeContainerLeft = lastNode;
  48. this.tab.tabNodeContainerArea = lastNode.getFirst();
  49. var menuNode = this.node.getElement(".MWFMenu");
  50. if (menuNode) menuNode.destroy();
  51. this.tab.load();
  52. tabs = this.tab.tabNodeContainerArea.getChildren("div");
  53. }else{
  54. tabs = this.tab.tabNodeContainer.getChildren("div");
  55. this.tab.load();
  56. }
  57. var contents = this.tab.contentNodeContainer.getChildren("div");
  58. tabs.each(function(tab, idx){
  59. this.tab.rebuildTab(contents[idx], contents[idx].getFirst(), tab);
  60. }.bind(this));
  61. this.tab.pages[0]._showTab();
  62. this.loadSubModule();
  63. },
  64. loadSubModule: function(){
  65. this.tab.pages.each(function(page){
  66. var node = page.tabNode;
  67. var json = this.form._getDomjson(node);
  68. var tab = this;
  69. var module = this.form._loadModule(json, node, function(){
  70. this.tab = tab;
  71. });
  72. this.elements.push(module);
  73. this.form.modules.push(module);
  74. if (page.isShow){
  75. this.showContentModule.call(page, this);
  76. }else{
  77. if (this.json.isDelay){
  78. var _self = this;
  79. page.showContentModuleFun = function(){_self.showContentModule.call(page, _self)};
  80. page.addEvent("show", page.showContentModuleFun);
  81. }else{
  82. this.showContentModule.call(page, this);
  83. }
  84. }
  85. }.bind(this));
  86. },
  87. showContentModule: function(_self){
  88. var node = this.contentNode;
  89. node.isLoadModule = true;
  90. json = _self.form._getDomjson(node);
  91. tab = _self;
  92. module = _self.form._loadModule(json, node, function(){
  93. this.tab = tab;
  94. });
  95. _self.containers.push(module);
  96. _self.form.modules.push(module);
  97. if (this.showContentModuleFun) this.removeEvent("show", this.showContentModuleFun);
  98. },
  99. _setTabWidgetStyles: function(){
  100. if (this.json.tabNodeContainer) this.tab.css.tabNodeContainer = Object.clone(this.json.tabNodeContainer);
  101. if (this.json.contentNodeContainer) this.tab.css.contentNodeContainer = Object.clone(this.json.contentNodeContainer);
  102. this.tab.css.tabNode = Object.clone(this.json.tabStyles);
  103. this.tab.css.tabTextNode = Object.clone(this.json.tabTextStyles);
  104. this.tab.css.tabNodeCurrent = Object.clone(this.json.tabCurrentStyles);
  105. this.tab.css.tabTextNodeCurrent = Object.clone(this.json.tabTextCurrentStyles);
  106. }
  107. });
  108. MWF.xApplication.process.Xform.tab$Page = MWF.APPTab$Page = new Class({
  109. Extends: MWF.APP$Module
  110. });
  111. MWF.xApplication.process.Xform.tab$Content = MWF.APPTab$Content = new Class({
  112. Extends: MWF.APP$Module,
  113. _loadUserInterface: function(){
  114. this.form._loadModules(this.node);
  115. }
  116. });