/*
 * IMPORTANT: This file gets included in the brodos framework so any overrides placed here will be global!
 */

/*
 * Text will always be selected on focus of Ext.form.TextField's or any component which extends it. 
 */
Ext.override(Ext.form.TextField, {
    selectOnFocus: true
});

/*
 * Extends Ext.form.Field components by the following methods:
 *  hideCt/showCt: Hides/shows not only the field but also the label
 *  setFieldLabel: Changes the field label to given string and also adds the label separator
 */
Ext.override(Ext.form.Field, {
    hideCt: function(){
        var ct = this.el.findParent('div.x-form-item', 5, true);
        ct.addClass('x-hide-' + this.hideMode);  
    },
 
    showCt: function(){
        var ct = this.el.findParent('div.x-form-item', 5, true);
        ct.removeClass('x-hide-' + this.hideMode);             
    },
    setFieldLabel: function(text) {
        var ct = this.el.findParent('div.x-form-item', 5, true);
        var label = ct.first('label.x-form-item-label');
 
        if (this.rendered) {
            var labelSeparator = this.labelSeparator;
   
            if (typeof labelSeparator == 'undefined') {
                if (this.ownerCt && this.ownerCt.layout && typeof this.ownerCt.layout.labelSeparator != 'undefined') {
                    labelSeparator = this.ownerCt.layout.labelSeparator;
                }
                else {
                    labelSeparator = '';
                }
            }
   
        label.update(text + labelSeparator);
   
        }
        else {
            label.update(text);
        }
    }
});

Ext.grid.GridView.override({
    scrollToBottom : function() {
	    if (this.rendered) {
            var s = this.scroller.dom;
            s.scrollTop = s.scrollHeight;
            s.scrollLeft = 0;
        }
    },
    templates : {
        cell: new Ext.Template(
            '<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} x-selectable {css}" style="{style}" tabIndex="0" {cellAttr}>',
            '<div class="x-grid3-cell-inner x-grid3-col-{id}" {attr}>{value}</div>',
            '</td>'
        )
    }
});