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

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

        if (f.isValid()) {
            f.submit({
                url: App.url("/order/item/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: 'textarea',
                    fieldLabel: App.localeRes("Item Name"),
                    name: 'name',
                    width: '100%',
                    height: 80,
                    maxLength: 200,
                    allowBlank: false
                },
                {
                    xtype: 'numberfield',
                    fieldLabel: App.localeRes("Unit Price"),
                    name: 'price',
                    width: '100%',
                    value: 0,
                    allowBlank: false,
                    decimalPrecision:2
                }
            ],
        });

        me.callParent(arguments);
    }
});
