Ext.define('App.view.ConfirmWithPasswordWindow', {
	extend: 'Ext.window.Window',
	alias: 'widget.confirmWithPasswordWindow',
	scrollable: true,
	constrainHeader: true,
	modal: true,
    layout: 'fit',
    unRead: false,

	initComponent: function() {
		var me = this;
        me.items= [
            {
                xtype: 'form',
                width: '100%',
                height: '100%',
                items:[
                    {
                        xtype: 'textfield',
                        fieldLabel: App.localeRes('Please enter password to confirm'),
                        labelWidth: 200,
                        padding: 16,
                        labelAlign: 'top',
                        inputType: 'password',
                        name: 'confirmValue',
                    }
                ],
                buttons: [
                    {
                        xtype: 'button',
                        text: App.localeRes("Confirm"),
                        ui:'soft-green',
                        handler: function(){
                            Ext.Ajax.request({
                                url: me.authUrl,
                                method: 'POST',
                                params: {
                                    v:me.down('form').getValues().confirmValue
                                },
                                success: function(response, opts) {
                                    var result = Ext.decode(response.responseText);
                                    if(result.success){
                                        if(me.onConfirm){
                                            me.onConfirm();
                                            me.close()
                                        }
                                    }else{
                                        App.showError(
                                            App.localeRes('Please enter password to confirm'),
                                            'Fail'
                                        );
                                    }
                                },
                                failure: function(response, opts) {
                                    App.showError('Fail : ' + response.status);
                                },
                                scope: this
                            });

                        }
                    },
                    {
                        xtype: 'button',
                        text: App.localeRes("Cancel"),
                        handler: function(){
                            me.close();
                        }
                    }
                ]
               
            }
        ];
        me.listeners= {
            close: function(window, eOpts) {
                if (me.callbackOnClose) {
                    me.callbackOnClose();
                }
            },
        },
        me.callParent(arguments);
	}

});
