hedera-web/package/usr/share/hedera-web/forms/account/account.js

86 lines
2.0 KiB
JavaScript
Executable File

Vn.Account = new Class
({
Extends: Vn.Module
,activate: function ()
{
var model = this.$('user-model');
model.setTableInfo ('u', 'user_view');
model.setTableInfo ('c', 'customer_view');
this.$('user-form').on ('iter-changed', this.onUserDataReady, this);
this.$('new-password').addEventListener ('change', this.onPasswordChange.bind (this));
this.$('repeat-password').addEventListener ('change', this.onPasswordChange.bind (this));
this.$('user-name').addEventListener ('change', this.onUserChange.bind (this));
}
,onUserDataReady: function (form)
{
this.$('user-name').value = form.get ('name');
}
,onUserChange: function ()
{
if (!confirm (_('MustReloginIfChange')))
return;
var batch = new Sql.Batch ();
batch.addValue ('name', this.$('user-name').value);
var query = 'UPDATE user_view SET name = #name '
+'WHERE id = account.user_get_id () LIMIT 1';
this.conn.execQuery (query, this.onUserUpdate.bind (this), batch);
}
,onUserUpdate: function (resultSet)
{
if (!resultSet.fetchResult ())
return;
location.reload ();
}
,onPasswordChange: function ()
{
var newPassword = this.$('new-password').value;
var repeatedPassword = this.$('repeat-password').value;
if (newPassword != '' && repeatedPassword != '')
{
if (newPassword === repeatedPassword)
{
var batch = new Sql.Batch ();
batch.addValue ('password', newPassword);
var query = 'UPDATE user_view SET password = MD5(#password) '
+'WHERE id = account.user_get_id () LIMIT 1';
this.conn.execQuery (query, this.onPasswordUpdate.bind (this), batch);
}
else
(new Htk.Toast ()).showError (_('PasswordsDoesntMatch'));
}
}
,onPasswordUpdate: function (resultSet)
{
if (!resultSet.fetchResult ())
return;
this.relogin ();
(new Htk.Toast ()).showMessage (_('PasswordsChanged'));
}
,relogin: function ()
{
this.conn.open (
this.$('user-form').get ('name')
,this.$('new-password').value
,Vn.Cookie.check ('vn_pass')
);
}
});