Tab.js 4.6 KB

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