diff options
| author | Gregor Kleen <gkleen@yggdrasil.li> | 2017-03-14 01:06:28 +0100 |
|---|---|---|
| committer | Gregor Kleen <gkleen@yggdrasil.li> | 2017-03-14 01:06:28 +0100 |
| commit | d84b462a711ce95593ff05a7581e722562c3835a (patch) | |
| tree | 41e5af455fea925b2680b29718b24ba2876e803a /Handler/UpdateItem.hs | |
| download | bar-d84b462a711ce95593ff05a7581e722562c3835a.tar bar-d84b462a711ce95593ff05a7581e722562c3835a.tar.gz bar-d84b462a711ce95593ff05a7581e722562c3835a.tar.bz2 bar-d84b462a711ce95593ff05a7581e722562c3835a.tar.xz bar-d84b462a711ce95593ff05a7581e722562c3835a.zip | |
Implement old bar.hs
Diffstat (limited to 'Handler/UpdateItem.hs')
| -rw-r--r-- | Handler/UpdateItem.hs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Handler/UpdateItem.hs b/Handler/UpdateItem.hs new file mode 100644 index 0000000..353572b --- /dev/null +++ b/Handler/UpdateItem.hs | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | module Handler.UpdateItem where | ||
| 2 | |||
| 3 | import Import | ||
| 4 | |||
| 5 | import Handler.Common | ||
| 6 | |||
| 7 | getUpdateItemR, postUpdateItemR :: ItemId -> Handler TypedContent | ||
| 8 | getUpdateItemR = postUpdateItemR | ||
| 9 | postUpdateItemR fsUpdateItem = do | ||
| 10 | Just entity <- fmap (Entity fsUpdateItem) <$> runDB (get fsUpdateItem) | ||
| 11 | |||
| 12 | ((updateResult, fsUpdateForm), fsUpdateEncoding) <- runFormPost . itemForm . Just $ entityVal entity | ||
| 13 | |||
| 14 | mapM_ (addMessage "formError" . toHtml) =<< case updateResult of | ||
| 15 | FormSuccess Item{..} -> [] <$ runDB (update fsUpdateItem [ ItemKind =. itemKind | ||
| 16 | , ItemNormKind =. normalizeKind itemKind | ||
| 17 | , ItemBought =. itemBought | ||
| 18 | , ItemExpires =. itemExpires | ||
| 19 | , ItemOpened =. itemOpened | ||
| 20 | ]) | ||
| 21 | FormFailure errors -> return errors | ||
| 22 | _ -> return [] | ||
| 23 | |||
| 24 | selectRep $ do | ||
| 25 | provideRep $ case updateResult of | ||
| 26 | FormSuccess _ -> redirect $ InventoryListingR :#: fsUpdateItem :: Handler Html | ||
| 27 | _ -> do | ||
| 28 | (sortOn entityVal -> stock) <- runDB $ selectList [] [] | ||
| 29 | defaultLayout $ inventoryListing InventoryState | ||
| 30 | { formState = Just UpdateForm{..} | ||
| 31 | , .. | ||
| 32 | } | ||
| 33 | provideJson () | ||
