Ext.define('TradePortal.store.Register', {
    extend: 'Ext.data.Store',
    model: 'TradePortal.model.Valid',
    storeId: 'Register',
    proxy: {
        type: 'jsonajax',
        url: BASE_URL + '/fluid/FluidAppServerProxy?ipApi=presenter&ipService=Frameworks.Interfaces.Mobile.TradePortal&ipFunction=registerForAccess'
    },
    listeners: {
        load: {
            fn: function (store, records, options) {
                if (store.data.items.length > 0) {
                    if (!records[0].data.errorTable) {
                        Ext.getCmp('register_form').down('form').getForm().reset()
                        Ext.getCmp('register_form').hide();
                        Ext.getCmp('login_form').show();
                        Ext.Msg.alert('Alert', "Registration Completed. You may now login with your specified username and password", Ext.emptyFn);
                    } else {
                        Ext.Msg.alert('Alert', records[0].data.errorTable[0].msg, Ext.emptyFn);
                    }
                } else {
                    Ext.Msg.alert('Alert', 'Unable to connect to the service.', Ext.emptyFn);
                }
                Ext.getCmp('viewport').setLoading(false);
            }
        }
    }
});
