/**
 * @author schiesser
 */
Ext.ns('efiport.book.view');

efiport.book.view.commit = function(widget){
    var that = {
        viewName: 'Bestellbestätigung'
	};
    
    that.content = new Ext.Panel({
        border: false
    });
    
    var agbRadio = new Ext.form.Checkbox({
        boxLabel: 'Ja, '
    });
	agbRadio.on('check', function() {
		Ext.form.Field.prototype.clearInvalid.call(agbRadio);
	});
    
    that.panel = new Ext.FormPanel({
        hideLabels: true,
        border: false,
        header: false,
        
        items: [that.content, agbRadio, {
			border: false,
			html: widget.commitCheckText
		}]
    
    });
	that.panel.addButton('Zurück', function() {
		Extreme.util.ViewHelper.previousView(widget.element);
	});
    that.panel.addButton('Bestellen', function(){
		if(agbRadio.checked){ 
			widget.controller.commit.buy();
		} else {
			agbRadio.msgTarget = 'under';
			Ext.form.Field.prototype.markInvalid.call(agbRadio,widget.commitNotCheckedText);
		}
    });
    
    widget.model.itemToBook.addListener('load', function(){
		var partner = widget.model.authPartner.getAt(0).data;
		// prepare commit data object
		var data = {};
		data.partner = efiport.templates.partner.apply(partner);
		data.wbt = efiport.templates.wbt.apply(widget.model.itemToBook.getAt(0).data); 
		data.paymentType = widget.model.paymentType;
		data.accountNumber = partner.accountNumber;
		data.nameOfBank = partner.nameOfBank;
		data.bankCode = partner.bankCode;
		// do template
        var html = efiport.templates.commit.apply(data);
        that.content.body.update(widget.commitText + html);
    });
	widget.model.itemToBook.load({
		params: {
			goid: widget.itemToBook
		}
	});
    
    return that;
};


