aboutsummaryrefslogtreecommitdiff
path: root/webgui
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-02-25 01:44:56 +0000
committerGregor Kleen <gkleen@yggdrasil.li>2016-02-25 01:44:56 +0000
commited1df9173bdddbcaa677f8cc05134bca5d117a35 (patch)
tree30a30e1b9f6a0c7980bc50999a3a52ac1c0e9ddd /webgui
parentda0aef961fef08e2690f0dff272b57340dc1d151 (diff)
downloadthermoprint-ed1df9173bdddbcaa677f8cc05134bca5d117a35.tar
thermoprint-ed1df9173bdddbcaa677f8cc05134bca5d117a35.tar.gz
thermoprint-ed1df9173bdddbcaa677f8cc05134bca5d117a35.tar.bz2
thermoprint-ed1df9173bdddbcaa677f8cc05134bca5d117a35.tar.xz
thermoprint-ed1df9173bdddbcaa677f8cc05134bca5d117a35.zip
Fixed draft loading
Diffstat (limited to 'webgui')
-rw-r--r--webgui/src/Main.hs34
1 files changed, 21 insertions, 13 deletions
diff --git a/webgui/src/Main.hs b/webgui/src/Main.hs
index be2a0a1..4f2c83c 100644
--- a/webgui/src/Main.hs
+++ b/webgui/src/Main.hs
@@ -195,7 +195,7 @@ setup Config{..} window (split -> (socketErr, dataUpdate)) = void $ do
195 on UI.click printButton $ const printAction 195 on UI.click printButton $ const printAction
196 on UI.click discardButton $ const discardAction 196 on UI.click discardButton $ const discardAction
197 197
198 return changeEditorStatus 198 return modifyStatus
199 199
200 saveable s@EditorState{..} = isRight ePrintout && discardable s 200 saveable s@EditorState{..} = isRight ePrintout && discardable s
201 printable EditorState{..} = isRight ePrintout && not (null eText) 201 printable EditorState{..} = isRight ePrintout && not (null eText)
@@ -208,7 +208,7 @@ setup Config{..} window (split -> (socketErr, dataUpdate)) = void $ do
208 deletion <- stepper deletion' $ UI.checkedChange allowDeletion 208 deletion <- stepper deletion' $ UI.checkedChange allowDeletion
209 let 209 let
210 toTable :: Map DraftId (Maybe DraftTitle) -> UI [Element] 210 toTable :: Map DraftId (Maybe DraftTitle) -> UI [Element]
211 toTable = mapM toLine . Map.toList 211 toTable = mapM toLine . Map.toList
212 212
213 toLine (id@(DraftId (show -> tId)), fromMaybe "" . fmap T.unpack -> title) = do 213 toLine (id@(DraftId (show -> tId)), fromMaybe "" . fmap T.unpack -> title) = do
214 id' <- UI.td # set TP.text tId 214 id' <- UI.td # set TP.text tId
@@ -216,7 +216,7 @@ setup Config{..} window (split -> (socketErr, dataUpdate)) = void $ do
216 delete <- UI.button 216 delete <- UI.button
217 # set TP.text "Delete" 217 # set TP.text "Delete"
218 # sink UI.enabled deletion 218 # sink UI.enabled deletion
219 on UI.click delete . const $ draftDelete id 219 on UI.click delete . const $ draftDelete id >> changeEditorState (\s@(EditorState{..}) -> if associatedDraft == Just id then def else s)
220 load <- UI.button 220 load <- UI.button
221 # set TP.text "Load" 221 # set TP.text "Load"
222 on UI.click load . const $ loadDraft id 222 on UI.click load . const $ loadDraft id
@@ -224,15 +224,21 @@ setup Config{..} window (split -> (socketErr, dataUpdate)) = void $ do
224 UI.tr # set children [id', title', actions] 224 UI.tr # set children [id', title', actions]
225 loadDraft id = do 225 loadDraft id = do
226 (title, po) <- draft id 226 (title, po) <- draft id
227 time <- liftIO $ getCurrentTime 227 let
228 let newState = def 228 t = cobbcode po
229 { eTitle = fmap T.unpack title 229 case t of
230 , eText = "unimplemented" -- TODO: implement -- drops data as it is 230 Left (show -> errStr) -> emitError $ "Could not load draft: " ++ errStr
231 , ePrintout = Right po 231 Right text -> do
232 , associatedDraft = Just id 232 time <- liftIO $ getCurrentTime
233 , lastSaved = Just (time, newState) 233 let newState = def
234 } 234 { eTitle = fmap T.unpack title
235 changeEditorState newState 235 , eText = T.unpack text
236 , ePrintout = Right po
237 , associatedDraft = Just id
238 , lastSaved = Just (time, newState)
239 }
240 changeEditorState (const newState)
241 runFunction $ switchTab "editor"
236 table <- fatal' "Could not find draft table" =<< getElementById window "draftListBody" 242 table <- fatal' "Could not find draft table" =<< getElementById window "draftListBody"
237 initialContent <- toTable =<< drafts 243 initialContent <- toTable =<< drafts
238 return table # set children initialContent 244 return table # set children initialContent
@@ -248,7 +254,9 @@ setup Config{..} window (split -> (socketErr, dataUpdate)) = void $ do
248 | p == "drafts" = True 254 | p == "drafts" = True
249 | "draft/" `isPrefixOf` p = True 255 | "draft/" `isPrefixOf` p = True
250 | otherwise = False 256 | otherwise = False
251 257
258switchTab :: String -> JSFunction ()
259switchTab = ffi "$(%1).first().trigger(\"click\")" . (\p -> "a[href='#" ++ p ++ "']")
252 260
253data EditorState = EditorState 261data EditorState = EditorState
254 { eTitle :: Maybe String 262 { eTitle :: Maybe String