tabview¶
-
class
webix.ui.
tabview
(data)¶ Arguments: - data (object) – A configuration object
Tabview view.
External references¶
Code¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | webix.protoUI({
name:"tabview",
defaults:{
type:"clean"
},
setValue:function(val){
this._cells[0].setValue(val);
},
getValue:function(){
return this._cells[0].getValue();
},
getTabbar:function(){
return this._cells[0];
},
getMultiview:function(){
return this._cells[1];
},
addView:function(obj){
var id = obj.body.id = obj.body.id || webix.uid();
this.getMultiview().addView(obj.body);
obj.id = obj.body.id;
obj.value = obj.header;
delete obj.body;
delete obj.header;
var t = this.getTabbar();
t.addOption(obj);
return id;
},
removeView:function(id){
var t = this.getTabbar();
t.removeOption(id);
t.refresh();
},
$init:function(config){
this.$ready.push(this._init_tabview_handlers);
var cells = config.cells;
var tabs = [];
webix.assert(cells && cells.length, "tabview must have cells collection");
for (var i = cells.length - 1; i >= 0; i--){
var view = cells[i].body||cells[i];
if (!view.id) view.id = "view"+webix.uid();
tabs[i] = { value:cells[i].header, id:view.id, close:cells[i].close, width:cells[i].width, hidden: !!cells[i].hidden};
cells[i] = view;
}
var tabbar = { view:"tabbar", multiview:true };
var mview = { view:"multiview", cells:cells, animate:(!!config.animate) };
if (config.value)
tabbar.value = config.value;
if (config.tabbar)
webix.extend(tabbar, config.tabbar, true);
if (config.multiview)
webix.extend(mview, config.multiview, true);
tabbar.options = tabbar.options || tabs;
config.rows = [
tabbar, mview
];
delete config.cells;
delete config.tabs;
},
_init_tabview_handlers:function(){
this.getTabbar().attachEvent("onOptionRemove", function(id){
var view = webix.$$(id);
if (view)
view.destructor();
});
}
}, webix.ui.layout);
(function(){
function _tagname(el) {
if (!el.tagName) return null;
return el.tagName.toLowerCase();
}
function _attribute(el, name) {
if (!el.getAttribute) return null;
var attr = el.getAttribute(name);
return attr ? attr.toLowerCase() : null;
}
function _get_html_value() {
var tagname = _tagname(this);
if (_get_value[tagname])
return _get_value[tagname](this);
return _get_value.other(this);
}
var _get_value = {
radio: function(el){
for (var i = 0; i < el.length; i++)
if (el[i].checked) return el[i].value;
return "";
},
input: function(el) {
var type = _attribute(el, 'type');
if (type === 'checkbox')
return el.checked;
return el.value;
},
textarea: function(el) {
return el.value;
},
select: function(el) {
var index = el.selectedIndex;
return el.options[index].value;
},
other: function(el) {
return el.innerHTML;
}
};
function _set_html_value(value) {
var tagname = _tagname(this);
if (_set_value[tagname])
return _set_value[tagname]( this, value);
return _set_value.other( this, value);
}
var _set_value = {
radio:function(el, value){
for (var i = 0; i < el.length; i++)
el[i].checked = (el[i].value == value);
},
input: function(el, value) {
var type = _attribute(el, 'type');
if (type === 'checkbox')
el.checked = (value) ? true : false;
else
el.value = value;
},
textarea: function(el, value) {
el.value = value;
},
select: function(el, value) {
//select first option if no provided and if possible
el.value = value?value:el.firstElementChild.value||value;
},
other: function(el, value) {
el.innerHTML = value;
}
};
|