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