App.Telefonliste.Mail = function(){
    
    var _MailAdress;
    var _UserId;
    
    return{
        
        wakeup: function(id){
            App.setTrace('App.Telefonliste.Mail.wakeup');
            
            
            this.myMemory = id;
            
            if(!this.WindowContent){
                this.buildWindow.add(this.buildForm);
                this.WindowContent = true;
            }
            
            Ext.Ajax.request({
                url: 'frontend/controler/app.php',
                method: 'post',
                params: {
                    modul: 'telefonliste_mail',
                    aktion: 'holen',
                    id: id
                },
                success: function(result,request){
                    
                    var wert = Ext.util.JSON.decode(result.responseText);
                    
                    if(!wert.data){
                        Ext.getCmp('Telefonliste_Mail').hide();
                        App.information('Keine Mailadresse vorhanden');
                        
                    }
                    else{
                        _MailAdress = wert.data.email;
                        _UserId = wert.data.id;
                        
                        Ext.getCmp('Telefonliste_MailForm').getForm().findField('kennung').setValue(wert.data.kennung);
                    }

                    return;
                }
                
                
                
            });
            
            
            this.buildWindow.show();
            
            
            return;
        },
        
        myMemory: 0,
        
        WindowContent: false,
        
        buildForm: {
            "xtype": "form",
            "labelWidth": 100,
            "labelAlign": "left",
            "layout": "form",
            "width": 650,
            "autoHeight": true,
            "padding": 10,
            "buttonAlign": "center",
            id: 'Telefonliste_MailForm',
            "items": [
                {
                    "xtype": "displayfield",
                    "name": "kennung",
                    "width": 400,
                    cls: 'viewDisplayfield'
                },
                {
                    "xtype": "textfield",
                    "fieldLabel": "Betreff",
                    "name": "betreff",
                    allowBlank: false,
                    helpText: 'Inhalt Betreffzeile',
                    "width": 400
                },
                {
                    "xtype": "textarea",
                    "fieldLabel": "Information",
                    "width": 400,
                    name: 'information',
                    allowBlank: false,
                    helpText: 'Information eingeben',
                    "height": 200,
                    grow: true,
                    preventScrollbars: true
                }
            ],
            fbar: {
                "xtype": "toolbar",
                "items": [{
                        "xtype": "tbseparator"
                    },{
                        "xtype": "button",
                        "text": "versenden",
                        cls: 'x-btn-text-icon',
                        icon: 'library/icons/button_ok.png',
                        handler: function(){
                            App.Telefonliste.Mail.sendMail();
                        }
                    },{
                        "xtype": "tbseparator"
                    }]
            }
        },
        
        sendMail: function(){
            App.setTrace('App.Telefonliste.Mail.sendMail');
            
            var FormPanel = Ext.getCmp('Telefonliste_MailForm');            
            
            FormPanel.getForm().submit({
                url: 'frontend/controler/app.php',
                method: 'Post',
                params: {
                    modul: 'telefonliste_mail',
                    aktion: 'senden',
                    mail: _MailAdress,
                    user: _UserId
                },
                success: function(form,action){
                    FormPanel.getForm().reset();
                    App.information('Mail wurde versandt');
                    Ext.getCmp('Telefonliste_Mail').hide();
                    
                }
            });
            
            return;
        },
        
        buildWindow: new Ext.Window({
            title: 'Mail versenden',
            width: 655,
            x: 120,
            y: 85,
            iconCls: 'icon-telefonliste_mail',
            modal: true,
            id: 'Telefonliste_Mail',
            draggable: true,
            closeAction: 'hide',
            resizable: false,
            autoHeight: true,
            // height: 400,
            closeAction: 'hide',
            shadow: false
        })
        
        
    }

}();
