hedera-web/web/js/hedera/app.js

170 lines
2.8 KiB
JavaScript
Raw Normal View History

Vn.App = new Class
({
2015-11-09 08:14:33 +00:00
Extends: Vn.Object
2015-12-10 13:48:43 +00:00
,_guestLogged: false
2015-11-09 08:14:33 +00:00
,initialize: function ()
{
2015-12-10 13:48:43 +00:00
window.onerror = this._onWindowError.bind (this);
window.onunload = this._onWindowUnload.bind (this);
Vn.Hash.initialize ();
2015-12-10 13:48:43 +00:00
this._isGuest = new Vn.HashParam
({
type: Boolean,
key: 'guest'
});
this._isGuest.on ('changed', this._onGuestChange, this);
this._conn = new Db.Conn ();
}
,run: function ()
{
if (Vn.Cookie.check ('vn_pass'))
{
2015-12-10 13:48:43 +00:00
this._conn.open (null, null, null,
this._onAutoLogin.bind (this));
}
else if (this._isGuest.value || Vn.Cookie.check ('hedera_guest'))
{
this._guestLogin ();
}
else
{
2015-12-10 13:48:43 +00:00
var login = this._login = new Vn.Login ({conn: this._conn});
login.on ('login', this._onLogin, this);
login.show ();
}
}
2015-12-10 13:48:43 +00:00
,_onGuestChange: function ()
{
if (this._isGuest.value)
this._guestLogin ();
}
,_guestLogin: function ()
{
this._conn.open (
null,
null,
null,
this._onGuestLogin.bind (this),
true
);
}
,_onGuestLogin: function (conn, success)
{
if (!success)
{
this._isGuest.value = false;
Vn.Cookie.unset ('hedera_guest');
this.run ();
}
else
{
this._guestLogged = true;
Vn.Cookie.set ('hedera_guest', true);
this._showGui ();
}
}
,_onAutoLogin: function (success)
{
if (!success)
{
Vn.Cookie.unset ('vn_pass');
this.run ();
}
else
2015-12-10 13:48:43 +00:00
this._showGui ();
}
2015-12-10 13:48:43 +00:00
,_onLogin: function ()
{
2015-12-10 13:48:43 +00:00
this._freeLogin ();
this._showGui ();
}
2015-12-10 13:48:43 +00:00
,_showGui: function ()
{
var gui = this._gui = new Vn.Gui ({conn: this._conn});
gui.on ('logout', this._onLogout, this);
gui.show ();
}
2015-12-10 13:48:43 +00:00
,_onLogout: function (gui)
{
2015-12-10 13:48:43 +00:00
this._freeGui ();
this._guestLogged = false;
Vn.Cookie.unset ('hedera_guest');
Vn.Cookie.unset ('vn_pass');
2015-12-10 13:48:43 +00:00
Vn.Hash.set (null);
this.run ();
}
2015-12-10 13:48:43 +00:00
,_onWindowError: function (message, file, line)
{
var error = new Error (message);
error.fileName = file;
error.lineNumber = line;
2015-11-19 13:57:23 +00:00
Htk.Toast.showError (_('There was an internal error'));
2015-12-10 13:48:43 +00:00
this._notifyError (error);
}
2015-12-10 13:48:43 +00:00
,_onWindowUnload: function ()
{
this.unref ();
}
,_notifyError: function (error)
{
if (error instanceof Error)
{
var httpRequest = new Vn.HttpRequest ()
httpRequest.add
({
'file': error.fileName
,'line': error.lineNumber
,'message': error.message
,'stack': error.stack
});
httpRequest.send ('log.php');
}
}
2015-12-10 13:48:43 +00:00
,_freeLogin: function ()
{
if (this._login)
{
this._login.disconnectByInstance (this);
this._login.hide ();
this._login.unref ();
this._login = null;
}
}
,_freeGui: function ()
{
if (this._gui)
{
this._gui.disconnectByInstance (this);
this._gui.hide ();
this._gui.unref ();
this._gui = null;
}
}
,_destroy: function ()
{
2015-12-10 13:48:43 +00:00
this._freeLogin ();
this._freeGui ();
this._conn.unref ();
}
});