forked from verdnatura/hedera-web
123 lines
2.2 KiB
JavaScript
123 lines
2.2 KiB
JavaScript
|
|
Vn.includeCss ('js/hedera/login.css');
|
|
Vn.resource ('js/hedera/login.xml');
|
|
Vn.define (function () {
|
|
|
|
Vn.Login = new Class
|
|
({
|
|
Extends: Htk.Widget,
|
|
Properties:
|
|
{
|
|
conn:
|
|
{
|
|
type: Db.Conn
|
|
,set: function (x)
|
|
{
|
|
this.link ({_conn: x}, {'loading-changed': this._onConnLoadChange});
|
|
/* x.execQuery (
|
|
'SELECT title, link, icon FROM social ORDER BY priority',
|
|
this.onSocialQueryDone.bind (this));
|
|
*/ }
|
|
,get: function ()
|
|
{
|
|
return this._conn;
|
|
}
|
|
}
|
|
}
|
|
|
|
,initialize: function (props)
|
|
{
|
|
this.builderInit ('js/hedera/login.xml');
|
|
|
|
var self = this;
|
|
this.$('form').onsubmit = function ()
|
|
{
|
|
self._onSubmit ();
|
|
return false;
|
|
};
|
|
|
|
this.parent (props);
|
|
}
|
|
|
|
,_onConnLoadChange: function (conn, isLoading)
|
|
{
|
|
this._disableUi (isLoading);
|
|
}
|
|
|
|
,_disableUi: function (disabled)
|
|
{
|
|
if (disabled)
|
|
this.$('spinner').start ();
|
|
else
|
|
this.$('spinner').stop ();
|
|
|
|
this.$('user').disabled = disabled;
|
|
this.$('pass').disabled = disabled;
|
|
this.$('submit').disabled = disabled;
|
|
}
|
|
|
|
,show: function ()
|
|
{
|
|
document.body.appendChild (this.node);
|
|
|
|
if (Vn.Cookie.check ('vn_user'))
|
|
this.$('user').value = Vn.Cookie.get ('vn_user');
|
|
|
|
this._focusUserInput ();
|
|
}
|
|
|
|
,hide: function ()
|
|
{
|
|
Vn.Node.remove (this.node);
|
|
}
|
|
|
|
,_focusUserInput: function ()
|
|
{
|
|
var userEntry = this.$('user');
|
|
userEntry.focus ();
|
|
userEntry.select ();
|
|
}
|
|
|
|
,_onSubmit: function ()
|
|
{
|
|
this._conn.open (
|
|
this.$('user').value,
|
|
this.$('pass').value,
|
|
this.$('remember').checked,
|
|
this._onConnOpen.bind (this)
|
|
);
|
|
}
|
|
|
|
,_onConnOpen: function (conn, success, error)
|
|
{
|
|
this.$('pass').value = '';
|
|
|
|
if (success)
|
|
this.signalEmit ('login');
|
|
else
|
|
this._focusUserInput ();
|
|
}
|
|
|
|
,onSocialQueryDone: function (resultSet)
|
|
{
|
|
var res = resultSet.fetchResult ();
|
|
var social = this.$('social');
|
|
|
|
while (res.next ())
|
|
{
|
|
var a = document.createElement ('a');
|
|
a.href = res.get ('link');
|
|
a.target = '_blank';
|
|
social.appendChild (a);
|
|
|
|
var img = document.createElement ('img');
|
|
imt.src = 'image/social/'+ res.get ('icon');
|
|
img.alt = res.get ('title');
|
|
img.title = res.get ('title');
|
|
a.appendChild (img);
|
|
}
|
|
}
|
|
});
|
|
|
|
});
|