diff options
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 () |
