Ext.define("App.view.SettingWindow_SMTP", {
    extend: "Ext.window.Window",
    alias: "widget.settingWindow_SMTP",
    title: App.localeRes("SMTP Setting"),
    modal: true,
    resizable: true,
    width: 600,
    layout: "fit",
    constrainHeader: true,

    loadWindow: function () {
        var me = this;
        me.down("form").load({
            url: App.url("/user/sys-group/smtp/load"),
            method: 'POST',
            success: function(form, action) {
            }
        });
    },
    onSave: function(){
        var me = this;
        var f = me.down("form");
        var params = f.getValues();
        if (f.isValid()) {
            Ext.Ajax.request({
                url: App.url("/user/sys-group/smtp/save"),
                method: 'POST',
                params: params,
                success: function(response, opts) {
                    me.close();
                },
                failure: function(response, opts) {
                },
                scope: this
            });
        }
    },

    initComponent: function () {
        var me = this;
        Ext.apply(me, {
            items: [
                {
                    xtype: "form",
                    padding: '16 16 0 16',
                    params: {},
                    defaults: {
                        width: '100%'
                    },
                    items:[
                        {
                            xtype: 'textfield',
                            name: 'smtp_host',
                            maxLength: 200,
                            fieldLabel: App.localeRes("Host"),
                        },
                        {
                            xtype: 'numberfield',
                            name: 'smtp_port',
                            maxLength: 5,
                            fieldLabel: App.localeRes("Port"),
                        },
                        {
                            xtype: 'textfield',
                            name: 'smtp_username',
                            maxLength: 200,
                            fieldLabel: App.localeRes("Username"),
                        },
                        {
                            xtype: 'textfield',
                            name: 'smtp_password',
                            inputType: 'password',
                            maxLength: 200,
                            fieldLabel: App.localeRes("Password"),
                        },
                    ],
                    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();
                                }
                            }
                        ]
                    },
                }
            ],
            listeners: {
                show: function () {
                    me.loadWindow();
                },
                close: function (window, opts) {
                    if (me.callbackOnClose) {
                        me.callbackOnClose();
                    }
                }
            }
        });
        me.callParent(arguments);
    }
});
