206 lines
6.4 KiB
Ruby
Executable File
206 lines
6.4 KiB
Ruby
Executable File
#!/usr/bin/env ruby
|
|
|
|
module Drugstore::Views
|
|
# Layout for all sites
|
|
def layout
|
|
html do
|
|
head do
|
|
title HeadTitle
|
|
style do
|
|
text 'h1{background-color:grey;color:white;padding-left:8px;margin-left:-8px;margin-right:-8px;}'
|
|
text '.greenbutton{background-color:green;font-weight:bold;color:white;}'
|
|
text 'table,th,td{border:1px dotted;border-collapse:collapse;padding:8px;}'
|
|
text 'th,td{text-align:center;}'
|
|
text '.redbutton{background-color:red;font-weight:bold;color:white;}'
|
|
text '.boldgreen{font-weight:bold;color:green;}'
|
|
text '.boldred{font-weight:bold;color:red;}'
|
|
text 'fieldset{width:32em;}'
|
|
text 'fieldset label{display:inline;float:left;width:12em;}'
|
|
end
|
|
end
|
|
body do
|
|
center 'This is NOT a real drugstore. This site just exists for educational purpose!', :class => "boldred"
|
|
h1 HeaderH1
|
|
self << yield
|
|
hr
|
|
p do
|
|
text '(c) 2016 - '
|
|
a 'The Onion Root', :href => 'mailto:the-onion-root@riseup.net'
|
|
end
|
|
center 'This is NOT a real drugstore. This site just exists for educational purpose!', :class => "boldred"
|
|
end
|
|
end
|
|
end
|
|
|
|
# Index and Catalog
|
|
def index
|
|
if @products.empty?
|
|
h2 'No products found'
|
|
p do
|
|
text 'Could not find any products.'
|
|
br
|
|
text 'Please try again later.'
|
|
end
|
|
else
|
|
h2 'Products'
|
|
if @cart == 0
|
|
p { text 'Items on cart: ' + @cart.to_s }
|
|
else
|
|
p do
|
|
a 'Items on cart: ' + @cart.to_s, :href => "/cart"
|
|
if @state.info
|
|
span @state.info, :class => "boldgreen"
|
|
@state.info = nil
|
|
end
|
|
end
|
|
end
|
|
@products.each do |product|
|
|
hr
|
|
_product( product )
|
|
end
|
|
end
|
|
end
|
|
|
|
# Cart
|
|
def card
|
|
h2 'Cart'
|
|
p { a '<- Back to the calalog' + @cart.to_s, :href => "/" }
|
|
hr
|
|
unless @products.empty?
|
|
form :action => "/cart", :method => 'post' do
|
|
input :name => 'cleanup', :type => 'hidden', :value => "all"
|
|
input :type => 'submit', :value => 'Delete Cart', :class => "redbutton"
|
|
end
|
|
br
|
|
table do
|
|
tr do
|
|
th 'Quantity (Gramm)'
|
|
th 'Title'
|
|
th 'Price (Bitcoin)'
|
|
th 'Subtotal (Bitcoin)'
|
|
th 'Action'
|
|
end
|
|
@products.each do |product|
|
|
tr do
|
|
td product[ "quantity" ]
|
|
td product[ "title" ]
|
|
td product[ "price" ]
|
|
td do
|
|
b product[ "subtotal" ]
|
|
end
|
|
td do
|
|
form :action => "/cart", :method => 'post' do
|
|
input :name => 'cleanup', :type => 'hidden', :value => product[ "id" ]
|
|
input :type => 'submit', :value => 'Delete product', :class => "redbutton"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
p do
|
|
text 'Total: '
|
|
span @sum.to_s, :class => "boldred"
|
|
text ' BTC'
|
|
end
|
|
form :action => "/checkout" do
|
|
input :type => "submit", :value => "Checkout", :class => "greenbutton"
|
|
end
|
|
p 'Hint: the max of gramms per product per order is set at 10.'
|
|
else
|
|
p 'Cart is empty.'
|
|
end
|
|
end
|
|
|
|
def checkout
|
|
h2 'Checkout'
|
|
p { a '<- Back to the cart', :href => "/cart" }
|
|
hr
|
|
if @error
|
|
p @error, :class => "boldred"
|
|
end
|
|
form :action => "/checkout", :method => 'post', :id => "shippingaddress" do
|
|
label 'Shipping Address:', :form => "shippingaddress"
|
|
fieldset do
|
|
label 'Full Name:', :for => 'fullname', :class => 'boldred'
|
|
input :name => 'fullname', :type => 'text', :size => "30", :value => @input.fullname
|
|
br
|
|
label 'Address Line 1:', :for => 'addrline1', :class => 'boldred'
|
|
input :name => 'addrline1', :type => 'text', :size => "30", :value => @input.addrline1
|
|
br
|
|
label 'Address Line 2:', :for => 'addrline2'
|
|
input :name => 'addrline2', :type => 'text', :size => "30", :value => @input.addrline2
|
|
br
|
|
label 'City:', :for => 'city', :class => 'boldred'
|
|
input :name => 'city', :type => 'text', :size => "30", :value => @input.city
|
|
br
|
|
label 'State/Province/Region:', :for => 'stateprovinceregion'
|
|
input :name => 'stateprovinceregion', :type => 'text', :size => "30", :value => @input.stateprovinceregion
|
|
br
|
|
label 'ZIP/Postal Code:', :for => 'zippostalcode', :class => 'boldred'
|
|
input :name => 'zippostalcode', :type => 'text', :size => "30", :value => @input.zippostalcode
|
|
br
|
|
label 'Country:', :for => 'country', :class => 'boldred'
|
|
input :name => 'country', :type => 'text', :size => "30", :value => @input.country
|
|
br
|
|
label 'Email:', :for => 'email'
|
|
input :name => 'email', :type => 'text', :size => "30", :value => @input.email
|
|
br
|
|
end
|
|
br
|
|
input :type => 'submit', :value => 'Place order', :class => "greenbutton"
|
|
end
|
|
p do
|
|
text 'Some hints:'
|
|
ul do
|
|
li { span 'Fields with a bold red label are mandatory fields!', :class => "boldred" }
|
|
li 'After successfully placing the order you will get a bitcoin address.'
|
|
li 'Shipping will be done after you have proceeded a transaction to that address.'
|
|
li 'Unpayed orders will be deleted in the database after the request expires (1 day).'
|
|
end
|
|
end
|
|
end
|
|
|
|
def bitcoin
|
|
h2 'Bitcoin'
|
|
p { a '<- Back to the calalog' + @cart.to_s, :href => "/" }
|
|
hr
|
|
br
|
|
br
|
|
br
|
|
center do
|
|
p '15zveKrrJWbp3BVpv36VWr1kPq3opNK6xf'
|
|
img :src => "img/15zveKrrJWbp3BVpv36VWr1kPq3opNK6xf.png", :alt => 'QR code'
|
|
end
|
|
br
|
|
br
|
|
br
|
|
p do
|
|
text 'Hint: '
|
|
span "This bitcoin address has expired. DON'T use it!", :class => "boldred"
|
|
end
|
|
end
|
|
|
|
# Partials
|
|
def _product( product )
|
|
img :src => product.image_url, :alt => product.title
|
|
h3 product.title
|
|
p do
|
|
b 'Description'
|
|
text ': ' + product.description
|
|
br
|
|
br
|
|
b 'Price per gramm'
|
|
text ': ' + product.price.to_s + ' Bitcoin(s)'
|
|
end
|
|
form :action => "/", :method => 'post' do
|
|
input :name => 'product_id', :type => 'hidden', :value => product.id
|
|
tag! :select, :name => 'quantity' do
|
|
(1..10).each do |q|
|
|
tag! :option, q
|
|
end
|
|
end
|
|
input :type => 'submit', :value => 'Add to card', :class => "greenbutton"
|
|
end
|
|
end
|
|
end
|