Pressing enter inside input now posts, further improvements

This commit is contained in:
ElPumpo
2018-06-09 19:00:29 +02:00
parent f4291d1564
commit 4433dbd68d
6 changed files with 38 additions and 6 deletions
+9
View File
@@ -132,4 +132,13 @@ Citizen.CreateThread(function()
end
end
end
end)
-- close the menu when script is restarting to avoid being stuck in NUI focus
AddEventHandler('onResourceStop', function(resource)
if resource == GetCurrentResourceName() then
if menuIsShowed then
TriggerEvent('esx_atm:closeATM')
end
end
end)
+19
View File
@@ -34,10 +34,29 @@ $(window).ready(function () {
$('#deposit_amount').val(0);
})
$('#deposit_amount').on("keyup", function(e) {
if (e.keyCode == 13) {
$.post('http://esx_atm/deposit', JSON.stringify({
amount: $('#deposit_amount').val()
}));
$('#deposit_amount').val(0);
}
});
$('#withdraw_btn').on('click', function () {
$.post('http://esx_atm/withdraw', JSON.stringify({
amount: $('#withdraw_amount').val()
}));
$('#withdraw_amount').val(0);
});
$('#withdraw_amount').on("keyup", function(e) {
if (e.keyCode == 13) {
$.post('http://esx_atm/withdraw', JSON.stringify({
amount: $('#withdraw_amount').val()
}));
$('#withdraw_amount').val(0);
}
});
});
+2 -2
View File
@@ -14,12 +14,12 @@
</div>
<div id="menu">
<div>
<input type="number" id="deposit_amount"/>
<input type="number" id="deposit_amount" tabindex="1" onClick="this.select();"/>
<button id="deposit_btn">D&eacute;poser</button>
</div>
<br><br>
<div>
<input type="number" id="withdraw_amount"/>
<input type="number" id="withdraw_amount" tabindex="2" onClick="this.select();"/>
<button id="withdraw_btn">Retirer</button>
</div>
</div>
+2 -2
View File
@@ -14,12 +14,12 @@
</div>
<div id="menu">
<div>
<input type="number" id="deposit_amount"/>
<input type="number" id="deposit_amount" tabindex="1" onClick="this.select();"/>
<button id="deposit_btn">Einzahlen</button>
</div>
<br><br>
<div>
<input type="number" id="withdraw_amount"/>
<input type="number" id="withdraw_amount" tabindex="2" onClick="this.select();"/>
<button id="withdraw_btn">Abheben</button>
</div>
</div>
+2 -2
View File
@@ -14,12 +14,12 @@
</div>
<div id="menu">
<div>
<input type="number" id="deposit_amount"/>
<input type="number" id="deposit_amount" tabindex="1" onClick="this.select();"/>
<button id="deposit_btn">Deposit</button>
</div>
<br><br>
<div>
<input type="number" id="withdraw_amount"/>
<input type="number" id="withdraw_amount" tabindex="2" onClick="this.select();"/>
<button id="withdraw_btn">Withdraw</button>
</div>
</div>
+4
View File
@@ -6,6 +6,8 @@ AddEventHandler('esx_atm:deposit', function(amount)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
amount = tonumber(amount)
if not tonumber(amount) then return end
amount = round(amount)
if amount == nil or amount <= 0 or amount > xPlayer.getMoney() then
TriggerClientEvent('esx:showNotification', _source, _U('invalid_amount'))
@@ -21,6 +23,8 @@ AddEventHandler('esx_atm:withdraw', function(amount)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
amount = tonumber(amount)
if not tonumber(amount) then return end
amount = round(amount)
local accountMoney = 0
accountMoney = xPlayer.getAccount('bank').money