Tab.js 5.4 KB

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