diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2017-03-15 14:47:31 +0100 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2017-03-15 14:47:31 +0100 |
commit | fe5cd6ad6c61eb13ca99acd1b69cd09b84051404 (patch) | |
tree | 4afc8cb5ae4171047d6af17082fb74d49c726abe /Handler/UpdateItem.hs | |
parent | 668961c90368b55a3409ae93b96e288f8ebe33a4 (diff) | |
download | bar-fe5cd6ad6c61eb13ca99acd1b69cd09b84051404.tar bar-fe5cd6ad6c61eb13ca99acd1b69cd09b84051404.tar.gz bar-fe5cd6ad6c61eb13ca99acd1b69cd09b84051404.tar.bz2 bar-fe5cd6ad6c61eb13ca99acd1b69cd09b84051404.tar.xz bar-fe5cd6ad6c61eb13ca99acd1b69cd09b84051404.zip |
Support types
Diffstat (limited to 'Handler/UpdateItem.hs')
-rw-r--r-- | Handler/UpdateItem.hs | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/Handler/UpdateItem.hs b/Handler/UpdateItem.hs index a4a29c2..befbe99 100644 --- a/Handler/UpdateItem.hs +++ b/Handler/UpdateItem.hs | |||
@@ -11,21 +11,24 @@ postUpdateItemR fsUpdateId = do | |||
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 | case updateResult of |
15 | FormSuccess Item{..} -> [] <$ runDB (update fsUpdateId [ ItemKind =. itemKind | 15 | FormSuccess (Item{..} `WithType` t) -> runDB $ do |
16 | , ItemNormKind =. normalizeKind itemKind | 16 | upsertBy (UniqueKind itemNormKind) (Kind itemNormKind t) [ KindType =. t ] |
17 | , ItemBought =. itemBought | 17 | update fsUpdateId [ ItemKind =. itemKind |
18 | , ItemExpires =. itemExpires | 18 | , ItemNormKind =. itemNormKind |
19 | , ItemOpened =. itemOpened | 19 | , ItemBought =. itemBought |
20 | ]) | 20 | , ItemExpires =. itemExpires |
21 | FormFailure errors -> return errors | 21 | , ItemOpened =. itemOpened |
22 | _ -> return [] | 22 | ] |
23 | return () | ||
24 | FormFailure errors -> mapM_ (addMessage "formError" . toHtml) errors | ||
25 | _ -> return () | ||
23 | 26 | ||
24 | selectRep $ do | 27 | selectRep $ do |
25 | provideRep $ case updateResult of | 28 | provideRep $ case updateResult of |
26 | FormSuccess _ -> redirect $ InventoryListingR :#: fsUpdateId :: Handler Html | 29 | FormSuccess _ -> redirect $ InventoryListingR :#: fsUpdateId :: Handler Html |
27 | _ -> do | 30 | _ -> do |
28 | (sortOn entityVal -> stock) <- runDB $ selectList [] [] | 31 | (sortOn (entityVal . typedVal) -> stock) <- runDB $ mapM withType =<< selectList [] [] |
29 | defaultLayout $ inventoryListing InventoryState | 32 | defaultLayout $ inventoryListing InventoryState |
30 | { invFormState = Just UpdateForm{..} | 33 | { invFormState = Just UpdateForm{..} |
31 | , .. | 34 | , .. |