Add data entry page
This commit is contained in:
parent
46bc6dcbf3
commit
2178a07ced
3 changed files with 103 additions and 1 deletions
22
script.js
Normal file
22
script.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
function setData(selectedObject) {
|
||||
var optionData = selectedObject.options[selectedObject.selectedIndex].dataset
|
||||
if (selectedObject.value == 0) {
|
||||
var balance = ""
|
||||
var href = ""
|
||||
var proedreio = (optionData.proedreio == 'false');
|
||||
var asylia = (optionData.asylia == 'false');
|
||||
var banned = (optionData.banned == 'false');
|
||||
} else {
|
||||
var balance = "€" + optionData.balance;
|
||||
var href = "/user?uid=" + selectedObject.value;
|
||||
var proedreio = (optionData.proedreio == 'true');
|
||||
var asylia = (optionData.asylia == 'true');
|
||||
var banned = (optionData.banned == 'true');
|
||||
}
|
||||
|
||||
document.getElementById('balance').innerHTML = balance;
|
||||
document.getElementById('user-link').href = href;
|
||||
document.getElementById('proedreio').checked = proedreio;
|
||||
document.getElementById('asylia').checked = asylia;
|
||||
document.getElementById('ban').checked = banned;
|
||||
}
|
36
server.rb
36
server.rb
|
@ -10,7 +10,8 @@ DB = Sequel.connect('sqlite://database.db')
|
|||
|
||||
set :port, 8091
|
||||
set :nav, [
|
||||
{ title: 'Χρήστες', href: '/users' }
|
||||
{ title: 'Χρήστες', href: '/users' },
|
||||
{ title: 'Συνέλευση', href: '/input' }
|
||||
]
|
||||
|
||||
get '/users' do
|
||||
|
@ -38,3 +39,36 @@ post '/user' do
|
|||
)
|
||||
redirect '/user?uid=' + params['uid']
|
||||
end
|
||||
|
||||
get '/' do
|
||||
redirect '/input'
|
||||
end
|
||||
|
||||
get '/input' do
|
||||
l = {}
|
||||
l[:users] = DB[:user].all
|
||||
slim :input, locals: l
|
||||
end
|
||||
|
||||
post '/save' do
|
||||
DB[:log_entry].insert(
|
||||
timestamp: DateTime.now,
|
||||
id: params['user'].to_i,
|
||||
amount_paid: params['amount_paid'].to_f,
|
||||
amount_donated: params['amount_donated'].to_f,
|
||||
comments: params['comments'].to_s,
|
||||
ban: params['ban'] == 'on',
|
||||
apousia: params['apousia'] == 'on',
|
||||
asylia: params['asylia'] == 'on',
|
||||
proedreio: params['proedreio'] == 'on'
|
||||
)
|
||||
DB[:user].where(id: params['user']).update(
|
||||
# TODO: wtf why integer
|
||||
balance: Sequel[:balance] - params[:amount_paid].to_i,
|
||||
asylia: params['asylia'] == 'on',
|
||||
proedreio: params['proedreio'] == 'on',
|
||||
banned: params['ban'] == 'on',
|
||||
active: params['ban'] != 'on'
|
||||
)
|
||||
redirect '/input'
|
||||
end
|
||||
|
|
46
views/input.slim
Normal file
46
views/input.slim
Normal file
|
@ -0,0 +1,46 @@
|
|||
doctype html
|
||||
html
|
||||
head
|
||||
include head
|
||||
body
|
||||
include nav
|
||||
.container role="main"
|
||||
form method="post" action="/save"
|
||||
div.form-group.row
|
||||
label.col-form-label.col-sm-2 for="sel" Όνομα
|
||||
div#sel.dropdown.bootstrap-select.col-sm-4
|
||||
select.selectpicker data-live-search="true" name="user" onchange="setData(this)"
|
||||
option value="0" Επιλέξτε Χρήστη
|
||||
- users.each do |u|
|
||||
option value="#{u[:id]}" data-balance="#{u[:balance]}" data-proedreio="#{u[:proedreio]}" data-banned="#{u[:banned]}" data-asylia="#{u[:asylia]}"=u[:name]
|
||||
a#user-link Ρυθμίσεις Χρήστη
|
||||
div.row style="padding-bottom:1em"
|
||||
span.col-sm-2 Ποσό οφειλής
|
||||
span#balance.col-sm-2
|
||||
div.form-group.row
|
||||
label.col-form-label.col-sm-2 for="amount_paid" Ποσό πληρωμής
|
||||
.input-group.col-sm-2
|
||||
.input-group-prepend
|
||||
span.input-group-text €
|
||||
input#amount_paid.form-control.col-sm-4 type="number" name="amount_paid"
|
||||
div.form-group.row
|
||||
label.col-form-label.col-sm-2 for="amount_donated" Ποσό δωρεάς
|
||||
.input-group.col-sm-2
|
||||
.input-group-prepend
|
||||
span.input-group-text €
|
||||
input#amount_donated.form-control.col-sm-4 type="number" name="amount_donated"
|
||||
div.input-group.form-group.row
|
||||
label.col-form-label.col-sm-2 for="comments" Σχόλια
|
||||
input#comments.form-control.col-sm-6 type="textarea" name="comments"
|
||||
//
|
||||
div.form-group
|
||||
div.input-group.custom-control.custom-switch.custom-control-inline
|
||||
input#proedreio.custom-control-input.pull-right type="checkbox" name="proedreio"
|
||||
label.custom-control-label.col-form-label for="proedreio" Proedreio
|
||||
div.input-group.custom-control.custom-switch.custom-control-inline
|
||||
input#asylia.custom-control-input type="checkbox" name="asylia"
|
||||
label.col-form-label.custom-control-label.col-form-label for="asylia" Ασυλία
|
||||
div.input-group.custom-control.custom-switch.custom-control-inline
|
||||
input#ban.custom-control-input type="checkbox" name="ban"
|
||||
label.col-form-label.custom-control-label.col-form-label for="ban" Ban
|
||||
button.btn.btn-primary name="submit" type="submit" Υποβολή
|
Reference in a new issue