From fafb1548cb84379c7adc540e308eeeaed25bc966 Mon Sep 17 00:00:00 2001 From: Astro Date: Tue, 21 Jul 2015 01:14:21 +0200 Subject: [PATCH] barcode: switch to location with user --- Application.hs | 1 + Handler/Barcode.hs | 10 ++++++++++ config/routes | 1 + static/js/barcode.js | 5 ++++- templates/select.hamlet | 2 ++ yammat.cabal | 1 + 6 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 Handler/Barcode.hs diff --git a/Application.hs b/Application.hs index a1ee869..1a42a61 100644 --- a/Application.hs +++ b/Application.hs @@ -36,6 +36,7 @@ import Handler.Summary import Handler.Modify import Handler.CashCheck import Handler.Avatar +import Handler.Barcode -- This line actually creates our YesodDispatch instance. It is the second half -- of the call to mkYesodData which occurs in Foundation.hs. Please see the diff --git a/Handler/Barcode.hs b/Handler/Barcode.hs new file mode 100644 index 0000000..460419f --- /dev/null +++ b/Handler/Barcode.hs @@ -0,0 +1,10 @@ +module Handler.Barcode where + +import Import +import Handler.Common +import qualified Data.Text as T +import Text.Blaze.Internal +import Text.Shakespeare.Text + +getBarcodeR :: UserId -> Text -> Handler Html +getBarcodeR uId barcode = undefined diff --git a/config/routes b/config/routes index bdf8cc7..0a6fa2e 100644 --- a/config/routes +++ b/config/routes @@ -30,3 +30,4 @@ /avatar/#AvatarId/modify ModifyAvatarR GET POST /avatar/#AvatarId/delete AvatarDeleteR GET /newavatar NewAvatarR GET POST +/user/#UserId/barcode/#Text BarcodeR GET diff --git a/static/js/barcode.js b/static/js/barcode.js index 0ccfea4..d7a533f 100644 --- a/static/js/barcode.js +++ b/static/js/barcode.js @@ -11,7 +11,10 @@ function showBarcode(text) { function barcodeKeyPress(event) { var key = String.fromCharCode(event.charCode) if (event.keyCode === 13) { - // window.location = "" + barcodeBuf + var uid = document.getElementById('uid').getAttribute('value') + if (uid) { + window.location = "/user/" + encodeURIComponent(uid) + "/barcode/" + encodeURIComponent(barcodeBuf) + } barcodeBuf = "" event.preventDefault() } else { diff --git a/templates/select.hamlet b/templates/select.hamlet index 2ffdf8a..073d285 100644 --- a/templates/select.hamlet +++ b/templates/select.hamlet @@ -25,3 +25,5 @@ $forall (Entity bId bev) <- beverages $else

#{beverageIdent bev} + + diff --git a/yammat.cabal b/yammat.cabal index ba960c1..ed1ada5 100644 --- a/yammat.cabal +++ b/yammat.cabal @@ -31,6 +31,7 @@ library Handler.Modify Handler.CashCheck Handler.Avatar + Handler.Barcode if flag(dev) || flag(library-only) cpp-options: -DDEVELOPMENT