296 lines
10 KiB
Haskell
296 lines
10 KiB
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
{-# LANGUAGE PackageImports #-}
|
|
module View.Product where
|
|
|
|
import Servant.Links
|
|
|
|
import Data.String (fromString)
|
|
|
|
import qualified Data.Text as T
|
|
import Data.Text.I18n
|
|
|
|
import Data.Maybe (fromJust, isJust)
|
|
|
|
import qualified Text.Blaze.Html5 as H
|
|
import qualified Text.Blaze.Html5.Attributes as HA
|
|
|
|
-- imports from "mateamt"
|
|
|
|
import qualified "mateamt" Types as MT
|
|
|
|
-- internal imports
|
|
|
|
import Types
|
|
import Util
|
|
import View.Scaffold
|
|
import API
|
|
|
|
productPriceListPage
|
|
:: L10n
|
|
-> Locale
|
|
-> T.Text
|
|
-> Maybe T.Text
|
|
-> [MT.ProductShortOverview]
|
|
-> T.Text
|
|
-> ProductPriceListPage
|
|
productPriceListPage l10n loc version mcookie list symbol =
|
|
scaffold l10n loc version mcookie (initPage $
|
|
translate "Matebeamter" <>
|
|
" - " <>
|
|
translate "Price List"
|
|
) $ do
|
|
H.table $ do
|
|
H.thead $
|
|
H.tr $ do
|
|
H.th (H.toHtml $ translate "ID")
|
|
H.th (H.toHtml $ translate "Name")
|
|
H.th (H.toHtml $ translate "Amount")
|
|
H.th (H.toHtml $ translate "Volume")
|
|
H.th (H.toHtml $ translate "Price")
|
|
mapM_
|
|
(\(MT.ProductShortOverview pid ident price amount ml _) ->
|
|
H.tr $ do
|
|
H.td (H.toHtml $ show pid)
|
|
H.td (H.toHtml ident)
|
|
H.td (H.toHtml $ show amount)
|
|
H.td (H.toHtml $ (fromString $ show ml :: T.Text) <> " ml")
|
|
H.td (H.toHtml $ (formatMoney price) <> symbol)
|
|
)
|
|
list
|
|
where
|
|
translate = localize l10n loc . gettext
|
|
|
|
productRefillPage
|
|
:: L10n
|
|
-> Locale
|
|
-> T.Text
|
|
-> Maybe T.Text
|
|
-> [MT.ProductShortOverview]
|
|
-> ProductRefillPage
|
|
productRefillPage l10n loc version mcookie prodList =
|
|
scaffold l10n loc version mcookie (initPage $
|
|
translate "Matebeamter" <>
|
|
" - " <>
|
|
translate "Refill stock"
|
|
) $
|
|
H.form
|
|
H.! HA.method "post"
|
|
H.! HA.action ("/" <> fromString
|
|
(show $ linkURI productPostRefillLink)
|
|
)
|
|
H.! HA.enctype "application/x-www-form-urlencoded"
|
|
$ do
|
|
mapM_
|
|
(\(MT.ProductShortOverview pid ident price amount ml maid) -> do
|
|
H.div
|
|
H.! HA.class_ "form-group optional"
|
|
H.!?
|
|
( isJust maid
|
|
, productBgStyle (fromString $ show $ fromJust maid)
|
|
)
|
|
$ do
|
|
H.label
|
|
H.! HA.for (
|
|
"amount-refill-product-id-" <>
|
|
fromString (show pid)
|
|
)
|
|
$ H.toHtml ident
|
|
H.input
|
|
H.! HA.id (
|
|
"amount-refill-product-id-" <>
|
|
fromString (show pid)
|
|
)
|
|
H.! HA.class_ "form-control product-select"
|
|
H.! HA.name (
|
|
"amountRefillProductId-" <>
|
|
fromString (show pid)
|
|
)
|
|
H.! HA.type_ "checkbox"
|
|
H.! HA.value "true"
|
|
H.div
|
|
H.! HA.class_ "form-group optional"
|
|
$ do
|
|
H.label
|
|
H.! HA.for (
|
|
"amount-refill-amount-singeles-" <>
|
|
fromString (show pid)
|
|
)
|
|
$ H.toHtml (translate "Amount of single items")
|
|
H.input
|
|
H.! HA.id (
|
|
"amount-refill-amount-singles-" <>
|
|
fromString (show pid)
|
|
)
|
|
H.! HA.class_ "form-control product-amount"
|
|
H.! HA.name (
|
|
"amountRefillAmountSingles-" <>
|
|
fromString (show pid)
|
|
)
|
|
H.! HA.type_ "number"
|
|
H.! HA.min "0"
|
|
H.! HA.step "1"
|
|
H.! HA.value "0"
|
|
H.label
|
|
H.! HA.for (
|
|
"amount-refill-amount-crates-" <>
|
|
fromString (show pid)
|
|
)
|
|
$ H.toHtml (translate "Amount of full crates")
|
|
H.input
|
|
H.! HA.id (
|
|
"amount-refill-amount-crates-" <>
|
|
fromString (show pid)
|
|
)
|
|
H.! HA.class_ "form-control product-amount"
|
|
H.! HA.name (
|
|
"amountRefillAmountCrates-" <>
|
|
fromString (show pid)
|
|
)
|
|
H.! HA.type_ "number"
|
|
H.! HA.min "0"
|
|
H.! HA.step "1"
|
|
H.! HA.value "0"
|
|
)
|
|
prodList
|
|
H.div H.! HA.class_ "form-group optional" $
|
|
H.button
|
|
H.! HA.class_ "btn btn-primary"
|
|
H.! HA.type_ "submit"
|
|
$ H.toHtml $ translate "Submit"
|
|
where
|
|
translate = localize l10n loc . gettext
|
|
|
|
productNewPage
|
|
:: L10n
|
|
-> Locale
|
|
-> T.Text
|
|
-> Maybe T.Text
|
|
-> T.Text
|
|
-> ProductNewPage
|
|
productNewPage l10n loc version mcookie symbol =
|
|
scaffold l10n loc version mcookie (initPage $
|
|
translate "Matebeamter" <>
|
|
" - " <>
|
|
translate "Create new product"
|
|
) $
|
|
H.form
|
|
H.! HA.method "post"
|
|
H.! HA.action ("/" <> fromString
|
|
(show $ linkURI productPostNewLink)
|
|
)
|
|
H.! HA.enctype "application/x-www-form-urlencoded"
|
|
$ do
|
|
H.div H.! HA.class_ "form-group required" $ do
|
|
H.label H.! HA.for "ident" $ H.toHtml $ translate "Product name"
|
|
H.input
|
|
H.! HA.id "ident"
|
|
H.! HA.class_ "form-control"
|
|
H.! HA.name "productSubmitIdent"
|
|
H.! HA.type_ "text"
|
|
H.! HA.value ""
|
|
H.! HA.required ""
|
|
H.div H.! HA.class_ "form-group required" $ do
|
|
H.label H.! HA.for "price" $ H.toHtml $
|
|
translate "Product price in" <> " " <> symbol
|
|
H.input
|
|
H.! HA.id "price"
|
|
H.! HA.class_ "form-control"
|
|
H.! HA.name "productSubmitPrice"
|
|
H.! HA.type_ "number"
|
|
H.! HA.min "0"
|
|
H.! HA.step "0.01"
|
|
H.! HA.value "0"
|
|
H.! HA.required ""
|
|
H.div H.! HA.class_ "form-group required" $ do
|
|
H.label H.! HA.for "ml" $ H.toHtml $
|
|
translate "Product volume in ml"
|
|
H.input
|
|
H.! HA.id "ml"
|
|
H.! HA.class_ "form-control"
|
|
H.! HA.name "productSubmitMl"
|
|
H.! HA.type_ "number"
|
|
H.! HA.min "0"
|
|
H.! HA.step "1"
|
|
H.! HA.value "0"
|
|
H.! HA.required ""
|
|
H.div H.! HA.class_ "form-group required" $ do
|
|
H.label H.! HA.for "max-amount" $ H.toHtml $
|
|
translate "Product maximum stock amount"
|
|
H.input
|
|
H.! HA.id "max-amount"
|
|
H.! HA.class_ "form-control"
|
|
H.! HA.name "productSubmitMaxAmount"
|
|
H.! HA.type_ "number"
|
|
H.! HA.min "0"
|
|
H.! HA.step "1"
|
|
H.! HA.value "0"
|
|
H.! HA.required ""
|
|
H.div H.! HA.class_ "form-group required" $ do
|
|
H.label H.! HA.for "amount-per-crate" $ H.toHtml $
|
|
translate "Product amount per crate"
|
|
H.input
|
|
H.! HA.id "amount-per-crate"
|
|
H.! HA.class_ "form-control"
|
|
H.! HA.name "productSubmitAmountPerCrate"
|
|
H.! HA.type_ "number"
|
|
H.! HA.min "0"
|
|
H.! HA.step "1"
|
|
H.! HA.value "0"
|
|
H.! HA.required ""
|
|
H.div H.! HA.class_ "form-group optional" $ do
|
|
H.label H.! HA.for "price-per-crate" $ H.toHtml $
|
|
translate "Product price per crate"
|
|
H.input
|
|
H.! HA.id "price-per-crate"
|
|
H.! HA.class_ "form-control"
|
|
H.! HA.name "productSubmitPricePerCrate"
|
|
H.! HA.type_ "number"
|
|
H.! HA.min "0"
|
|
H.! HA.step "0.01"
|
|
H.! HA.value "0"
|
|
H.div H.! HA.class_ "form-group optional" $ do
|
|
H.label H.! HA.for "article-number" $ H.toHtml $
|
|
translate "Product article number"
|
|
H.input
|
|
H.! HA.id "article-number"
|
|
H.! HA.class_ "form-control"
|
|
H.! HA.name "productSubmitArtNr"
|
|
H.! HA.type_ "text"
|
|
H.! HA.value ""
|
|
H.! HA.required ""
|
|
{- -- TODO: Create and manage suppliers and avatars
|
|
H.div H.! HA.class_ "form-group optional" $ do
|
|
H.label H.! HA.for "supplier" $ H.toHtml $
|
|
translate "Product supplier"
|
|
H.select
|
|
H.! HA.id "supplier"
|
|
H.! HA.class_ "form-control"
|
|
H.! HA.name "productSubmitSupplier"
|
|
$ do
|
|
H.option
|
|
H.! HA.value ""
|
|
H.! HA.selected ""
|
|
$ toHtml $ translate "None"
|
|
-- TODO: FILL ME!
|
|
H.div H.! HA.class_ "form-group optional" $ do
|
|
H.label H.! HA.for "avatar" $ H.toHtml $
|
|
translate "Product avater"
|
|
H.select
|
|
H.! HA.id "avatar"
|
|
H.! HA.class_ "form-control"
|
|
H.! HA.name "productSubmitAvatar"
|
|
$ do
|
|
H.option
|
|
H.! HA.value ""
|
|
H.! HA.selected ""
|
|
$ toHtml $ translate "None"
|
|
-- TODO: FILL ME!
|
|
-}
|
|
H.div H.! HA.class_ "form-group optional" $
|
|
H.button
|
|
H.! HA.class_ "btn btn-primary"
|
|
H.! HA.type_ "submit"
|
|
$ H.toHtml $ translate "Submit"
|
|
where
|
|
translate = localize l10n loc . gettext
|