diff options
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 | , .. |