/* RSence
* Copyright 2008 Riassence Inc.
* http://riassence.com/
*
* You should have received a copy of the GNU General Public License along
* with this software package. If not, contact licensing@riassence.com
*/
/*** = Description
** HTabView
**
**
***/
var//RSence.Controls
HTabView = HView.extend({
/** = Description
* draw function
*
**/
draw: function(){
var _isDrawn = this.drawn;
this.base();
if(!_isDrawn){
var i=0,_styles = [
['overflow','auto']
];
for(i;i<_styles.length;i++){
this.setStyle(_styles[i][0],_styles[i][1]);
}
this.hide();
}
}
});
/** = Description
* HTab
*
**/
var//RSence.Controls
HTab = HControl.extend({
componentName: "tab",
refreshOnValueChange: true,
refreshOnLabelChange: false,
controlDefaults: (HControlDefaults.extend({
constructor: function(_ctrl){
this.tabInit(_ctrl);
},
tabInit: function(_ctrl){
_ctrl.tabs = [];
_ctrl.tabLabels = [];
_ctrl.tabLabelBounds = [];
_ctrl.tabLabelStrings = [];
}
})),
rightmostPx: 0,
selectIdx: -1,
// overridden in the template
tabLabelHeight: 20,
// overridden in the template
tabLabelLeftEdge: 4,
// overridden in the template
tabLabelRightEdge: 4,
// overridden in the template
fontStyle: 'font-family:Arial,sans-serif;font-size:13px;',
tabLabelHTMLPrefix1: '
',
tabLabelHTMLSuffix: '
',
tabLabelParentElem: 'label',
tabLabelElementTagName: 'div',
tabLabelAlign: 'left',
tabLabelFillBg: false,
tabTriggerLink: true,
tabLabelNoHTMLPrefix: false,
/** = Description
* refreshValue function
*
**/
refreshValue: function(){
var _value = this.value;
if(typeof _value === 'number'){
var _index = parseInt(_value,10);
if(_index=_labelBounds[0]){
this.selectTab(i);
return;
}
}
}
}
},
/** = Description
* removeTab function
*
* = Parameters
* +_tabIdx+::
*
**/
removeTab: function(_tabIdx){
var _selIdx = this.selectIdx,
_tabViewId = this.tabs[_tabIdx],
_tabLabelElemId = this.tabViews[_tabIdx];
this.tabs.splice(_tabIdx,1);
this.tabLabels.splice(_tabIdx,1);
this.tabLabelBounds.splice(_tabIdx,1);
this.tabLabelStrings.splice(_tabIdx,1);
if(_tabIdx===_selIdx){
this.selectIdx=-1;
if(_tabIdx===0&&this.tabs.length===0){
this.selectTab(-1);
}
else if(_tabIdx===(this.tabs.length-1)){
this.selectTab(_tabIdx-1);
}
else{
this.selectTab(_tabIdx);
}
}
else if(_tabIdx<_selIdx){
this.selectIdx--;
}
ELEM.del(_tabLabelElemId);
HSystem.views[_tabViewId].die();
}
});
/** = Description
* HTabItem is a wrapper for creating tabs as subviews when using JSONRenderer.
* rect is ignored
* parent is the HTab instance
* options may contain the following:
* select: true|false, passed on to addTab
* label: true|false, passed on to addTab
*
* = Returns
* a new HTabView instance returned by addTab
*
**/
var//RSence.Controls
HTabItem = {
nu: function(_rect, _parent, _options){
if( _rect.hasAncestor && _rect.hasAncestor( HView ) ){
_options = _parent;
_parent = _rect;
}
else {
console.warn && console.warn( "Warning: the rect constructor argument of HTabItem is deprecated." );
}
return _parent.addTab( _options.label, _options.select );
}
};
var//RSence.Controls
GUITreeTabView = HControl.extend({
controlDefaults: HControlDefaults.extend({
visible: false,
autoCreate: false,
autoDestroy: true
}),
jsonRenderer: false,
createJSONRenderer: function(){
var
_this = this,
_value = _this.value,
_progressView = HView.nu( [4,0, 150, 34, 0, null], _this ),
// _indicatorPhases = ['/','-','\\','|','/','-','\\','|'], // ascii
// _indicatorPhases = ['◴','◷','◶','◵'], // unicode sector ball
// _indicatorPhases = ['◑','◒','◐','◓'], // unicode half ball
// _indicator = HStringView.nu( [ 2, 2, 32, 32 ], _progressView, { value: _indicatorPhases[0], style: { 'font-size': '24px' } } ),
// _indicatorTimeout = setInterval( function(){
// _indicatorPhase = _indicatorPhases.shift();
// _indicatorPhases.push( _indicatorPhase );
// _indicator.setValue( _indicatorPhase );
// }, 100 ),
_indicatorStr = HStringView.nu( [ 34, 12, 100, 20, 4, null ], _progressView, { value: 'Rendering' } );
_this.destroyJSONRenderer();
if( _value.type === undefined || _value.version === undefined ){
_value = {
'type': 'GUITree',
'version': 0.9,
'class': 'HView',
'rect': [0,0, null,null, 0,0],
'options': { 'style': { 'overflow': 'auto' } },
'subviews': _value
};
}
setTimeout( function(){
_this.jsonRenderer = JSONRenderer.nu( _value, _this );
// clearTimeout( _indicatorTimeout );
_progressView.die();
}, 10 );
},
destroyJSONRenderer: function(){
if( this.jsonRenderer ){
this.jsonRenderer.die();
this.jsonRenderer = false;
}
},
drawSubviews: function(){
if( this.options.autoCreate ){
this.createJSONRenderer();
}
},
show: function(){
this.base();
if(!this.jsonRenderer){
this.createJSONRenderer();
}
},
hide: function(){
this.base();
if( this.options.autoDestroy ){
this.destroyJSONRenderer();
}
},
die: function(){
this.destroyJSONRenderer();
this.base();
}
});
var//RSence.Controls
GUITreeTabItem = {
nu: function( _rect, _parent, _options ){
if( _rect.hasAncestor && _rect.hasAncestor( HView ) ){
_options = _parent;
_parent = _rect;
}
else {
console.warn && console.warn( "Warning: the rect constructor argument of GUITreeTabItem is deprecated." );
}
return _parent.addTab( _options.label, _options.select, GUITreeTabView, _options );
}
};