PDA

View Full Version : Some fundamental problems



stricte
22 Sep 2009, 5:20 PM
Hi,

I have problem with understanding some, I think fundamental, things...

if I have application file:


// reference local blank image
Ext.BLANK_IMAGE_URL = '/extjs/resources/images/default/s.gif';

// create namespace
Ext.namespace('en');

// create application
en.app = function() {
// do NOT access DOM from here; elements don't exist yet

// private variables
var active_subject = 0;


var check_if_logged = function(){
Ext.Ajax.request({
url: '/sessions/check_if_logged',
success:function(result){
var jsonData = Ext.util.JSON.decode(result.responseText);
if (jsonData.success === true){
main_container.show();
}
else{
if(jsonData.login_step == 1){
var ow = new otp_window();
ow.show();
}
else{
var lw = new login_window();
lw.show();
}
}
},
failure:function(){
Ext.Msg.alert('Status', 'Error.');
}
});
};

// private functions

// public space
return {
// public properties, e.g. strings to translate

// public methods
init: function() {
check_if_logged();
}
};
}(); // end of app
and external file with login window class:


var do_login = function(){
login_form.getForm().submit({
method:'POST',
waitTitle:'.....',
waitMsg:'...',

success:function(form, action){
lw.destroy();
obj = Ext.util.JSON.decode(action.response.responseText);
if (obj.login_step == 1){
otp_window.show();
}
else if(obj.login_step == 2){
var mc = new main_container();
mc.show();
}
},

failure:function(form, action){
obj = Ext.util.JSON.decode(action.response.responseText);
Ext.Msg.alert('Failed', obj.msg);
login_form.getForm().reset();
}
});
}

var login_form = new Ext.form.FormPanel({
frame: true,
url: '/sessions/login',
items: [
new Ext.form.TextField({
id:"login",
fieldLabel:"Login",
blankText:"G"
}),
new Ext.form.TextField({
id:"password",
fieldLabel:"Password",
inputType: 'password',
blankText:"P"
})
],
buttons: [{
text: 'Log In',
handler:function(){
do_login();
}
},

{
text: 'Cancel',
handler:function(){
login_form.getForm().reset();
}
}]

});

login_window = function(){
var base_config = {
title: 'Welcome',
layout: 'fit',
height: 160,
width: 320,
closable: false,
resizable: false,
draggable: true,
items: [login_form]
};

login_window.superclass.constructor.call(this,base_config);
}

Ext.extend(login_window, Ext.Window, {});

Problem is with figuring out, how to, from function do_login() which is fired from login_form if success close login_window, which includes login_form. Do I need returning sth to check_if_logged and there destroying login_window? As You see I tried do this from do_login function but this is obvious bad idea.