mwf.xdesktop.requireapp("process.xform", "$module", null, false);
mwf.require("mwf.widget.tab", null, false);
/** @class tab 分页组件。
* @o2cn 分页组件
* @example
* //可以在脚本中获取该组件
* //方法1:
* var tab = this.form.get("fieldid"); //获取组件
* //方法2
* var tab = this.target; //在组件本身的脚本中获取
* @extends mwf.xapplication.process.xform.$module
* @o2category formcomponents
* @o2range {process|cms|portal}
* @hideconstructor
*/
mwf.xapplication.process.xform.tab = mwf.apptab = new class(
/** @lends mwf.xapplication.process.xform.tab# */
{
extends: mwf.app$module,
_loaduserinterface: function(){
this.elements = [];
this.containers = [];
var style = "form";
if (layout.mobile) style = "mobileform";
/**
* @summary tab组件,平台使用该组件实现分页组件的功能
* @member {mwf.widget.tab}
* @example
* //可以在脚本中获取该组件
* var tab = this.form.get("fieldid").tab; //获取组件对象
* var pages = tab.pages //获取每个分页
* pages[1].addevent("queryshow", function(){
* //添加显示分页前事件
* })
* pages[1].addevent("postshow", function(){
* //添加显示分页后事件
* })
* pages[1]._showtab(); //显示第2个分页
*/
this.tab = new mwf.widget.tab(this.node, {"style": style});
this._settabwidgetstyles();
this.tab.tabnodecontainer = this.node.getfirst("div");
this.tab.contentnodecontainer = this.tab.tabnodecontainer.getnext("div");
var lastnode = this.tab.tabnodecontainer.getlast();
var tabs;
if (lastnode && lastnode.hasclass("tabnodecontainerleft")){
this.tab.tabnodecontainerright = this.tab.tabnodecontainer.getfirst();
this.tab.tabnodecontainerleft = lastnode;
this.tab.tabnodecontainerarea = lastnode.getfirst();
var menunode = this.node.getelement(".mwfmenu");
if (menunode) menunode.destroy();
this.tab.load();
tabs = this.tab.tabnodecontainerarea.getchildren("div");
}else{
tabs = this.tab.tabnodecontainer.getchildren("div");
this.tab.load();
}
var contents = this.tab.contentnodecontainer.getchildren("div");
tabs.each(function(tab, idx){
this.tab.rebuildtab(contents[idx], contents[idx].getfirst(), tab);
}.bind(this));
if( this.json.defaultindex && this.tab.pages[this.json.defaultindex]){
this.tab.pages[this.json.defaultindex]._showtab();
}else{
this.tab.pages[0]._showtab();
}
this.loadsubmodule();
},
loadsubmodule: function(){
this.tab.pages.each(function(page){
var node = page.tabnode;
var json = this.form._getdomjson(node);
var tab = this;
var module = this.form._loadmodule(json, node, function(){
if( tab.widget )this.widget = tab.widget;
this.tab = tab;
});
this.elements.push(module);
this.form.modules.push(module);
if( json.width && json.width.toint()>60 ){
node.setstyle("width", json.width "px");
}
if( json.description){
node.set("title", json.description);
}
if (page.isshow){
this.showcontentmodule.call(page, this);
}else{
if (this.json.isdelay){
var _self = this;
page.showcontentmodulefun = function(){_self.showcontentmodule.call(page, _self)};
page.addevent("show", page.showcontentmodulefun);
}else{
this.showcontentmodule.call(page, this);
}
}
}.bind(this));
},
showcontentmodule: function(_self){
var page = this;
var node = this.contentnode;
node.isloadmodule = true;
var json = _self.form._getdomjson(node);
var tab = _self;
var module = _self.form._loadmodule(json, node, function(){
if( _self.widget )this.widget = _self.widget;
this.tab = tab;
this.page = page;
});
_self.containers.push(module);
_self.form.modules.push(module);
if (this.showcontentmodulefun) this.removeevent("show", this.showcontentmodulefun);
},
_settabwidgetstyles: function(){
if (this.json.tabnodecontainer) this.tab.css.tabnodecontainer = object.clone(this.json.tabnodecontainer);
if (this.json.contentnodecontainer) this.tab.css.contentnodecontainer = object.clone(this.json.contentnodecontainer);
this.tab.css.tabnode = object.clone(this.json.tabstyles);
this.tab.css.tabtextnode = object.clone(this.json.tabtextstyles);
this.tab.css.tabnodecurrent = object.clone(this.json.tabcurrentstyles);
this.tab.css.tabtextnodecurrent = object.clone(this.json.tabtextcurrentstyles);
}
});
mwf.xapplication.process.xform.tab$page = mwf.apptab$page = new class({
extends: mwf.app$module
});
mwf.xapplication.process.xform.tab$content = mwf.apptab$content = new class({
extends: mwf.app$module,
_loaduserinterface: function(){
var _self = this;
this.form._loadmodules(this.node, function () {
if( _self.widget )this.widget = _self.widget;
});
}
});
source