multiview¶
-
class
webix.ui.
multiview
(data)¶ Arguments: - data (object) – A configuration object
Multiview view.
References¶
- views
baselayout()
.- helpers
animate()
,breakLine()
,formLine()
,isSupported()
,assert()
,debug_size_box_end()
,debug_size_box_start()
,delay()
,extend()
,protoUI()
,each()
.
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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | webix.protoUI({
name:"multiview",
defaults:{
animate:{
}
},
setValue:function(val){
webix.$$(val).show();
},
getValue:function(){
return this.getActiveId();
},
$init:function(){
this._active_cell = 0;
this._vertical_orientation = 1;
this._viewobj.style.position = "relative";
this._viewobj.className += " webix_multiview";
this._back_queue = [];
},
_ask_render:function(cell_id, view_id){
var cell = webix.$$(cell_id);
if (!cell._render_hash){
cell._render_queue = [];
cell._render_hash = {};
}
if (!cell._render_hash[view_id]){
cell._render_hash[view_id]=true;
cell._render_queue.push(view_id);
}
},
_render_activation:function(cell_id){
var cell = webix.$$(cell_id);
if(this._settings.keepViews)
cell._viewobj.style.display = "";
/*back array*/
if(this._back_queue[this._back_queue.length-2]!=cell_id){
if(this._back_queue.length==10)
this._back_queue.splice(0,1);
this._back_queue.push(cell_id);
}
else
this._back_queue.splice(this._back_queue.length-1,1);
if (cell._render_hash){
for (var i=0; i < cell._render_queue.length; i++){
var subcell = webix.$$(cell._render_queue[i]);
//cell can be already destroyed
if (subcell)
subcell.render();
}
cell._render_queue = [];
cell._render_hash = {};
}
},
addView:function(){
var id = webix.ui.baselayout.prototype.addView.apply(this, arguments);
if(this._settings.keepViews)
webix.$$(id)._viewobj.style.display = "none";
else
webix.html.remove(webix.$$(id)._viewobj);
return id;
},
_beforeRemoveView:function(index, view){
//removing current view
if (index == this._active_cell){
var next = Math.max(index-1, 0);
if (this._cells[next]){
this._in_animation = false;
this._show(this._cells[next], false);
}
}
if (index < this._active_cell)
this._active_cell--;
},
//necessary, as we want to ignore hide calls for elements in multiview
_hide:function(){},
_parse_cells:function(collection){
collection = collection || this._collection;
for (var i=0; i < collection.length; i++)
collection[i]._inner = this._settings.borderless?{top:1, left:1, right:1, bottom:1}:(this._settings._inner||{});
webix.ui.baselayout.prototype._parse_cells.call(this, collection);
for (var i=1; i < this._cells.length; i++){
if(this._settings.keepViews)
this._cells[i]._viewobj.style.display = "none";
else
webix.html.remove(this._cells[i]._viewobj);
}
for (var i=0; i<collection.length; i++){
var cell = this._cells[i];
if (cell._cells && !cell._render_borders) continue;
var _inner = cell._settings._inner;
if (_inner.top)
cell._viewobj.style.borderTopWidth="0px";
if (_inner.left)
cell._viewobj.style.borderLeftWidth="0px";
if (_inner.right)
cell._viewobj.style.borderRightWidth="0px";
if (_inner.bottom)
cell._viewobj.style.borderBottomWidth="0px";
cell._viewobj.setAttribute("role", "tabpanel");
}
this._render_activation(this.getActiveId());
},
cells_setter:function(value){
webix.assert(value && value.length,"Multiview must have at least one view in 'cells'");
this._collection = value;
},
_getDirection:function(next, active){
var dir = (this._settings.animate || {}).direction;
var vx = (dir == "top" || dir == "bottom");
return next < active ? (vx?"bottom":"right"):(vx?"top":"left");
},
_show:function(obj, animation_options){
var parent = this.getParentView();
if (parent && parent.getTabbar)
parent.getTabbar().setValue(obj._settings.$id || obj._settings.id);
if (this._in_animation)
return webix.delay(this._show, this,[obj, animation_options],100);
var _next_cell = -1;
for (var i=0; i < this._cells.length; i++)
if (this._cells[i]==obj){
_next_cell = i;
break;
}
if (_next_cell < 0 || _next_cell == this._active_cell)
return;
var prev = this._cells[this._active_cell];
var next = this._cells[ _next_cell ];
var size = prev.$getSize(0,0);
//need to be moved in animate
if((animation_options||typeof animation_options=="undefined")&&webix.animate.isSupported() && this._settings.animate) {
var aniset = webix.extend({}, this._settings.animate);
if(this._settings.keepViews)
aniset.keepViews = true;
aniset.direction = this._getDirection(_next_cell,this._active_cell);
aniset = webix.Settings._mergeSettings(animation_options||{}, aniset);
var line = webix.animate.formLine(
next._viewobj,
prev._viewobj,
aniset);
next.$getSize(0,0);
next.$setSize(this._content_width,this._content_height);
var callback_original = aniset.callback;
aniset.callback = function(){
webix.animate.breakLine(line,this._settings.keepViews);
this._in_animation = false;
if (callback_original) callback_original.call(this);
callback_original = aniset.master = aniset.callback = null;
this.resize();
};
aniset.master = this;
this._active_cell = _next_cell;
this._render_activation(this.getActiveId());
webix.animate(line, aniset);
this._in_animation = true;
}
else { // browsers which don't support transform and transition
if(this._settings.keepViews){
prev._viewobj.style.display = "none";
}
else{
webix.html.remove(prev._viewobj);
this._viewobj.appendChild(this._cells[i]._viewobj);
}
this._active_cell = _next_cell;
prev.resize();
this._render_activation(this.getActiveId());
}
if (next.callEvent){
next.callEvent("onViewShow",[]);
webix.ui.each(next, this._signal_hidden_cells);
}
this.callEvent("onViewChange",[prev._settings.id, next._settings.id]);
},
$getSize:function(dx, dy){
webix.debug_size_box_start(this, true);
var size = this._cells[this._active_cell].$getSize(0, 0);
if (this._settings.fitBiggest){
for (var i=0; i<this._cells.length; i++)
if (i != this._active_cell){
var other = this._cells[i].$getSize(0, 0);
for (var j = 0; j < 4; j++)
size[j] = Math.max(size[j], other[j]);
}
}
//get layout sizes
var self_size = webix.ui.baseview.prototype.$getSize.call(this, 0, 0);
//use child settings if layout's one was not defined
if (self_size[1] >= 100000) self_size[1]=0;
if (self_size[3] >= 100000) self_size[3]=0;
self_size[0] = (self_size[0] || size[0] ) +dx;
self_size[1] = (self_size[1] || size[1] ) +dx;
self_size[2] = (self_size[2] || size[2] ) +dy;
self_size[3] = (self_size[3] || size[3] ) +dy;
webix.debug_size_box_end(this, self_size);
return self_size;
},
$setSize:function(x,y){
this._layout_sizes = [x,y];
webix.ui.baseview.prototype.$setSize.call(this,x,y);
this._cells[this._active_cell].$setSize(x,y);
},
isVisible:function(base_id, cell_id){
if (cell_id && cell_id != this.getActiveId()){
if (base_id)
this._ask_render(cell_id, base_id);
return false;
}
return webix.ui.view.prototype.isVisible.call(this, base_id, this._settings.id);
},
getActiveId:function(){
return this._cells.length?this._cells[this._active_cell]._settings.id:null;
},
back:function(step){
step=step||1;
if(this.callEvent("onBeforeBack",[this.getActiveId(), step])){
if(this._back_queue.length>step){
var viewId = this._back_queue[this._back_queue.length-step-1];
webix.$$(viewId).show();
return viewId;
}
return null;
}
return null;
}
},webix.ui.baselayout);
|