﻿ var BugReportDialog = function(){
    var dialog, showBtn;
    
    return {
        init : function(){
             showBtn = Ext.get('lnkReportABug');
             showBtn.on('click', this.showDialog, this);
        },
       
        showDialog : function(){
            if(!dialog){ 
                dialog = new Ext.Window({
                        el: 'bugReport-dlg',
                        resizable:false,
                        width:450,
                        height:350,
                        closeAction:'hide',
                        layout: 'fit',
                        
                        items: new Ext.Panel({
                            contentEl: 'divBugBody',
                            deferredRender:false,
                            border:false
                        }),
                        
                        buttons: [{
                            text:'Send',
                            handler: function(){ 
                                onBtnSaveBugClick();
                                dialog.hide();
                            }
                        },{
                            text: 'Cancel',
                            handler: function(){
                                dialog.hide();
                            }
                        }]
 
                });
            }
            dialog.show(this);
            dialog.setPosition(document.body.clientWidth / 2 - 220, 200);
        }
    };
}();

Ext.onReady(BugReportDialog.init, BugReportDialog, true);

function onBtnSaveBugClick()
{
    var userName = document.getElementById("ctl00_ctl14_txtUserName");
    var userEmail = document.getElementById("ctl00_ctl14_txtEmail");
    var bugDescription = document.getElementById("ctl00_ctl14_txtDescription");
    var bugReproductionSteps = document.getElementById("ctl00_ctl14_txtReproductionSteps");
    if (bugDescription.value.length > 0)
    {
        Rijden.Webservices.SaveNota.SaveBugReport(userName.value,userEmail.value,window.location.href,"",bugDescription.value,bugReproductionSteps.value);
        userName.value = "";
        userEmail.value = "";
        bugDescription.value = "";
        bugReproductionSteps.value = "";
    }
}
