Ext.define("App.view.OrderPaymentForm", {
    extend: "Ext.form.Panel",
    xtype: "orderPaymentForm",
    params: {},
    layout: "vbox",
    scrollable: true,

    onSave: function () {
        var me = this,
        f = me.getForm();

        if (f.isValid()) {
            f.submit({
                url: App.url("/order/payment/save"),
                method: 'POST',
                submitEmptyText: false,
                success: function (form, action) {
                    App.showMsg('Saved');
                    if(me.callbackOnSave)
                        me.callbackOnSave();
                }
            });
        }
    },

    initComponent: function () {
        var me = this;

        Ext.apply(me, {
            bbar: {
                defaultButtonUI: 'default',
                layout: 'hbox',
                padding: 0,
                items: [
                    '->',
                    {
                        xtype: 'button',
                        text: App.localeRes('Save & Close'),
                        ui: "blue",
                        margin: '0 0 16 0',
                        formBind: true,
                        handler: function(button, event){
                            me.onSave();
                        }
                    }
                ]
            },
            items: [
                {
                    xtype: 'hidden',
                    name: 'id'
                },
                {
                    xtype: 'hidden',
                    name: 'orderId',
                    itemId: 'orderId'
                },
                {
                    xtype: 'datefield',
                    name: 'date',
                    fieldLabel: App.localeRes('Payment Date'),
                    allowBlank: false,
                    value: new Date()
                },
                {
                    xtype: 'numberfield',
                    fieldLabel: App.localeRes("Amount"),
                    name: 'amount',
                    width: '100%',
                    value: 0,
                    allowBlank: false,
                    decimalPrecision:2
                },
                {
                    xtype: 'paymentTypeCombo',
                    fieldLabel: App.localeRes("Payment Method"),
                    width: '100%',
                    allowBlank: false,
                },
                {
                    xtype: 'textfield',
                    name: 'refNo',
                    fieldLabel: App.localeRes('Reference No.'),
                    width: '100%',
                    maxLength: 200
                }
            ],
        });

        me.callParent(arguments);
    }
});
