Source: form/CheckBox.js

/**
 * Created by seeker910 on 14-1-1.
 * label:{width:'auto'}
 */
Rsd.define('Rsd.form.CheckBox', {
    extend: 'Rsd.form.Input',
    xtype: 'checkbox',
    height: 30,
    widht: 80,
    margin: '4 0 4 0',
    inputType: 'CheckBox',
    ctrlCls: 'x-control-checkbox',
    checked:false,
    model:'value',//check or value
    /**
     * 
     * @param {*} config 
     */
    constructor: function CheckBox(config) {
        config = config || {};
        this.apply(config);
    },
    /**
     * 
     */
    initComponentEx: function initComponentEx() {
        this.callParent();

        var _label = document.createElement('label');
        _label.setAttribute('for',this.ctrl.element.id); 
 
        this.setElStyle(_label,{
            position:"relative",
            display:"inline",
            overflow:"hidden",
            minHeight:28,
            minWidth:28,
            maxWidth:35,
            maxHeight:35,  
            lineHeight:this.height,
            padding:(this.height-30)/2 + 'px', 
            height:'auto',
            width: 'auto'
        }); 
        if(this.readOnly)
        {
            this.setElStyle(_label,{pointerEvents:"none"}); 
        }
        this.__self_label = _label;

        this.setElStyle(this.ctrl.element,{position:'absolute',visibility:'hidden',overflow:'hidden'}); 
        
    },
    /*
    * */
    onAfterInit: function onAfterInit() {

        this.callParent();  
        this.check(this.checked); 
    },
    /*
    * */
    onAfterRender:function onAfterRender()
    {
        this.callParent();
        this.setElStyle(this.ctrl.element,{height:0,width:0});
        this.dom.appendChild(this.__self_label); 
    },
     
    /***
     * checked 和 value 是两个属性值
     */
    getValue: function getValue() {
       
        if(this.model == 'check')
        {
            return this.isChecked();
        }else
        {
            return this.isChecked() ? this.callParent():'';
        }
        
    },
    /**
     * 
     */
    setValue:function setValue(value)
    {
        if(this.model == 'check')
        {
            this.check(value);
        }
        else
        {
            this.callParent(value); 
        }
    },
    /**
     * 
     */
    onAfterLayout:function onAfterLayout() {

        this.callParent();
 
        //调整 label 布局
        var _label = this.__self_label;
        //_label.style.lineHeight = _label.clientWidth + 'px';
        switch (this.label.position) {
            case 'top':
                {
                    _label.style.marginBottom = this.label.space + 'px'; 
                    break;
                }
            case 'bottom':{
                _label.style.marginTop = this.label.space + 'px'; 
                break;
            }
            case 'right': { 
                _label.style.marginRight = this.label.space + 'px';
                break;
            }

            case 'left':
            default: { 
                _label.style.marginLeft = this.label.space + 'px';
                break;
            }
        }

    },
    /*
    * checked 和 value 是两个属性值
    */
    isChecked:function isChecked()
    {
        return this.ctrl.element ? this.ctrl.element.checked : this.checked;
    },

    /*
    *
    * */
    check:function check(check)
    {
        this.checked = check;

        if(this.ctrl.element)
        {
            this.ctrl.element.checked = check;
        }
        
        return check;
    },
    /*
     * 返回 对象或数组
     * */
    makeControl:function makeControl(config,row)
    {
        var _config = config ||{};
        var _editable = _config.editable;
        var _dataIndex = _config.dataIndex|| _config.dataindex || _config.name;
        var _value = row[_dataIndex];
        _config.__index__= _config.__index__||0;
        var _chk = document.createElement('input');

        _chk.classList.add('x-control-checkbox');
        _chk.style.visibility = 'hidden';
        _chk.style.position ='absolute';
        _chk.type = 'checkbox';
        _chk.name = _dataIndex;
       
        _chk.setAttribute('id','__chk__' + _dataIndex + '__' +_config.__index__++);
        var _table = config.table;
        _chk.checked = Rsd.isTrue(_value); 
        _chk.onchange = function () {
      
            if (config.multiple == false && this.checked) {

                for (var i in _table.rows) {
                    var _tbRow =  _table.rows[i];
                    _tbRow[_dataIndex] = false;
                } 
                _table.refresh(_dataIndex);
            }
            _table.rows[this.parentNode.parentNode.id][_dataIndex] = this.checked;
        };
        var _label = document.createElement('label'); 
        Rsd.setElStyle(_label,{
            position:"relative", 
            overflow:"hidden",
            minHeight:24,
            minWidth:24,
            maxWidth:28,
            maxHeight:28,  
            lineHeight: (_chk.clientHeight||24) + 'px',
            height:'auto',
            width: 'auto'
        });
        _label.setAttribute('for',_chk.getAttribute('id'));

        if(_editable)
        {

        }
        else
        {
            _label.onclick=function () {
                return false;
            };

        }
        return [_chk,_label];

    }
});