refs #3971 Form input locking when loading
gitea/hedera-web/pipeline/head This commit looks good Details

This commit is contained in:
Juan Ferrer 2023-01-16 16:57:48 +01:00
parent be43a38b38
commit c463e967ca
6 changed files with 83 additions and 82 deletions

2
debian/changelog vendored
View File

@ -1,4 +1,4 @@
hedera-web (22.48.7) stable; urgency=low hedera-web (22.48.8) stable; urgency=low
* Initial Release. * Initial Release.

View File

@ -28,46 +28,53 @@ export default new Class({
} }
,async onPassModifyClick() { ,async onPassModifyClick() {
var oldPassword = this.$.oldPassword.value; const form = this.$.changePassword.node;
var newPassword = this.$.newPassword.value; Vn.Node.disableInputs(form);
var repeatedPassword = this.$.repeatPassword.value;
try { try {
if (newPassword == '' && repeatedPassword == '') const oldPassword = this.$.oldPassword.value;
throw new Error(_('Passwords empty')); const newPassword = this.$.newPassword.value;
if (newPassword !== repeatedPassword) const repeatedPassword = this.$.repeatPassword.value;
throw new Error(_('Passwords doesn\'t match'));
} catch (err) {
return Htk.Toast.showError(err.message);
}
var verificationToken = this.hash.$.verificationToken; try {
var params = {newPassword}; if (newPassword == '' && repeatedPassword == '')
throw new Error(_('Passwords empty'));
try { if (newPassword !== repeatedPassword)
if (verificationToken) { throw new Error(_('Passwords doesn\'t match'));
params.verificationToken = verificationToken; } catch (err) {
await this.conn.send('user/restore-password', params); return Htk.Toast.showError(err.message);
} else {
let userId = this.gui.user.id;
params.oldPassword = oldPassword;
await this.conn.patch(
`Accounts/${userId}/changePassword`, params);
} }
} catch(err) {
Htk.Toast.showError(err.message); const verificationToken = this.hash.$.verificationToken;
const params = {newPassword};
if (this.hash.$.verificationToken) try {
this.$.newPassword.select(); if (verificationToken) {
else params.verificationToken = verificationToken;
this.$.oldPassword.select(); await this.conn.send('user/restore-password', params);
} else {
let userId = this.gui.user.id;
params.oldPassword = oldPassword;
await this.conn.patch(
`Accounts/${userId}/changePassword`, params);
}
} catch(err) {
Htk.Toast.showError(err.message);
return; if (verificationToken)
this.$.newPassword.select();
else
this.$.oldPassword.select();
return;
}
this.hash.unset('verificationToken');
await this.conn.open(this.gui.user.name, newPassword);
this.$.changePassword.hide();
} finally {
Vn.Node.disableInputs(form, false);
} }
this.$.changePassword.hide();
this.hash.unset('verificationToken');
await this.conn.open(this.gui.user.name, newPassword);
Htk.Toast.showMessage(_('Password changed!')); Htk.Toast.showMessage(_('Password changed!'));
} }

View File

@ -89,11 +89,13 @@
<input <input
id="new-password" id="new-password"
type="password" type="password"
placeholder="_New password"/> placeholder="_New password"
autocomplete="new-password"/>
<input <input
id="repeat-password" id="repeat-password"
type="password" type="password"
placeholder="_Repeat password"/> placeholder="_Repeat password"
autocomplete="new-password"/>
</div> </div>
<div class="button-bar"> <div class="button-bar">
<button class="thin" on-click="this.onPassModifyClick()"> <button class="thin" on-click="this.onPassModifyClick()">

View File

@ -111,19 +111,14 @@ export default new Class({
}, },
async onConfirmClick() { async onConfirmClick() {
this.disableButtons(true); Vn.Node.disableInputs(this.node);
try { try {
await this.conn.execQuery('CALL myBasket_confirm'); await this.conn.execQuery('CALL myBasket_confirm');
this.$.successDialog.show(); this.$.successDialog.show();
} finally { } finally {
this.disableButtons(false); Vn.Node.disableInputs(this.node, false);
} }
}, },
disableButtons(disable) {
this.$.modify.disabled = disable;
this.$.confirm.disabled = disable;
},
async onDialogResponse() { async onDialogResponse() {
if (this.$.payMethod.value === 'CARD') { if (this.$.payMethod.value === 'CARD') {

View File

@ -1,66 +1,63 @@
module.exports = module.exports = {
{ removeChilds(node) {
removeChilds: function (node)
{
var childs = node.childNodes; var childs = node.childNodes;
if (childs) if (childs)
while (childs.length > 0) while (childs.length > 0)
node.removeChild (childs[0]); node.removeChild(childs[0]);
} },
,remove: function (node) remove(node) {
{
if (node.parentNode) if (node.parentNode)
node.parentNode.removeChild (node); node.parentNode.removeChild(node);
} },
,setText: function (node, text) setText(node, text) {
{ Vn.Node.removeChilds(node);
Vn.Node.removeChilds (node);
if (text) if (text)
node.appendChild ( node.appendChild(
node.ownerDocument.createTextNode (text)); node.ownerDocument.createTextNode(text));
} },
,addClass: function (node, className) addClass(node, className) {
{ /* var classes = node.className.split(' ');
/* var classes = node.className.split (' ');
if (classes.split (' ').indexOf (className) == -1) if (classes.split(' ').indexOf(className) == -1)
*/ node.className = className +' '+ node.className; */ node.className = className +' '+ node.className;
} },
,removeClass: function (node, className) removeClass(node, className) {
{
var index = 0; var index = 0;
var found = false; var found = false;
var classes = node.className.split (' '); var classes = node.className.split(' ');
while ((index = classes.indexOf (className, index)) != -1) while ((index = classes.indexOf(className, index)) != -1) {
{ classes.splice(index, 1);
classes.splice (index, 1);
found = true; found = true;
} }
if (found) if (found)
node.className = classes.join (' '); node.className = classes.join(' ');
} },
,hide: function (node) hide: function(node) {
{
node.style.display = 'none'; node.style.display = 'none';
} },
,show: function (node) show: function(node) {
{
node.style.display = 'block'; node.style.display = 'block';
},
disableInputs(formNode, disable = true) {
const inputs = formNode
.querySelectorAll('input, textarea, button, select');
for (const input of inputs)
input.disabled = disable;
} }
}; };
$ = function (id) $ = function(id) {
{ return document.getElementById(id);
return document.getElementById (id);
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "hedera-web", "name": "hedera-web",
"version": "22.48.7", "version": "22.48.8",
"description": "Verdnatura web page", "description": "Verdnatura web page",
"license": "GPL-3.0", "license": "GPL-3.0",
"repository": { "repository": {