Ext.ns('Hdv.lot.detail');

Hdv.lot.detail.Info = Ext.extend(Ext.Panel, {

    tplInfo: new Ext.XTemplate(
        '<div class="non-ext">',
            '<dl>',
                '<dt>Categorie</dt>', '<dd>{category}</dd>',
                '<dt>Vacation</dt>', '<dd>{vacation}</dd>',
                '<dt>Numero de lot</dt>', '<dd>{lot}</dd>',
                '<dt>Description</dt>', '<dd>{description}</dd>',
                '<dt>Estimation</dt>', '<dd>{estimation}</dd>',
                '<tpl if="result"><dt>Résultat</dt>', '<dd>{result}</dd></tpl>',
            '</dl>',
        '</div>'
    ),

    tplInfoSilent: new Ext.XTemplate(
        '<div class="non-ext">',
            '<dl>',
                '<dt>Categorie</dt>', '<dd>{category}</dd>',
                '<dt>Vacation</dt>', '<dd>{vacation}</dd>',
                '<dt>Numero de lot</dt>', '<dd>{lot}</dd>',
                '<dt>Description</dt>', '<dd>{description}</dd>',
                '<dt>Estimation</dt>', '<dd>{estimation}</dd>',
                '<dt>Réserve</dt>', '<dd>{reserve}</dd>',
                '<tpl if="result"><dt>Résultat</dt>', '<dd>{result}</dd></tpl>',
            '</dl>',
        '</div>'
    ),

    setInfoBody: function(bdInfo) {
        if (!bdInfo) {
            var tds = this.infoEls.lot.select('td');
            this.tplInfo.overwrite(this.body, {
                category    : this.infoEls.category.dom.innerHTML,
                vacation    : this.infoEls.vacation,
                lot         : tds.item(1).dom.innerHTML,
                description : tds.item(2).dom.innerHTML,
                estimation  : tds.item(3).dom.innerHTML
            });
        } else {
            var tpl = this.tplInfo;
            var tva_full = bdInfo.get('tva_full') ? "*" : "";
            var config = {
                category    : bdInfo.get('category'),
                vacation    : bdInfo.get('vacation'),
                lot         : bdInfo.get('lot') + tva_full,
                description : bdInfo.get('description'),
                estimation  : bdInfo.get('estimation'),
                result      : bdInfo.get('result')
            };
            if (bdInfo.get('silent') == true) {
                tpl = this.tplInfoSilent;
                Ext.apply(config, {
                    reserve : bdInfo.get('reserve')
                });
            }
            tpl.overwrite(this.body, config);
        }
    },

    onBtnOrder: function() {
        this.fireEvent('buttonorder', this);
    },

    initMenuItems: function() {
        return [{
            text    : this.config.wording.lot_detail_info_menu_order,
            iconCls : 'lot-item-order',
            cls     : 'lot-item-btn',
            hidden  : false,
            scope   : this,
            handler : this.onBtnOrder
        }];
    },

    initBbar: function() {
        var bbar = [{
            xtype     : 'buttongroup',
            columns   : 1,
            title     : this.config.wording.lot_detail_info_menu,
            defaults  : {
                width: this.width - 14
            },
            items   : this.initMenuItems()
        }];
        return null;
    },

    initComponent: function() {

        this.addEvents(
            'buttonorder'
        );

        Ext.applyIf(this, {
            cls       : 'img-lot',
            iconCls   : 'lot-window-info',
            title     : this.config.wording.lot_detail_info_title,
            autoScroll: true,
            bbar      : this.initBbar()
        });

        Hdv.lot.detail.Info.superclass.initComponent.call(this);
    }

});

Ext.reg('hdvlotdetailinfo', Hdv.lot.detail.Info);