diff options
| -rw-r--r-- | webgui/data/index.html | 1 | ||||
| -rw-r--r-- | webgui/src/Main.hs | 21 |
2 files changed, 16 insertions, 6 deletions
diff --git a/webgui/data/index.html b/webgui/data/index.html index d368fa5..3bdd047 100644 --- a/webgui/data/index.html +++ b/webgui/data/index.html | |||
| @@ -25,6 +25,7 @@ | |||
| 25 | <div class="tab-content"> | 25 | <div class="tab-content"> |
| 26 | <div class="tab active" id="editor"> | 26 | <div class="tab active" id="editor"> |
| 27 | <!-- <label id="titleLabel" for="editorTitle">Title</label> --> | 27 | <!-- <label id="titleLabel" for="editorTitle">Title</label> --> |
| 28 | <input id="saveDraft" type="checkbox" checked="checked" /><label for="saveDraft">Save as Draft</label> | ||
| 28 | <input id="editorTitle" /> | 29 | <input id="editorTitle" /> |
| 29 | <textarea id="editorText"></textarea> | 30 | <textarea id="editorText"></textarea> |
| 30 | <span id="bbcodeStatus"></span> | 31 | <span id="bbcodeStatus"></span> |
diff --git a/webgui/src/Main.hs b/webgui/src/Main.hs index dde6eb1..cbb1a75 100644 --- a/webgui/src/Main.hs +++ b/webgui/src/Main.hs | |||
| @@ -45,6 +45,7 @@ import Data.Monoid | |||
| 45 | import Text.Read hiding (get) | 45 | import Text.Read hiding (get) |
| 46 | import Data.Either | 46 | import Data.Either |
| 47 | import Data.List (isPrefixOf) | 47 | import Data.List (isPrefixOf) |
| 48 | import Data.Bool | ||
| 48 | 49 | ||
| 49 | import Paths_thermoprint_webgui | 50 | import Paths_thermoprint_webgui |
| 50 | 51 | ||
| @@ -147,6 +148,10 @@ setup Config{..} window (split -> (socketErr, dataUpdate)) = void $ do | |||
| 147 | 148 | ||
| 148 | (editorStatus, fmap liftIO -> changeEditorStatus) <- stepper' def | 149 | (editorStatus, fmap liftIO -> changeEditorStatus) <- stepper' def |
| 149 | 150 | ||
| 151 | saveDraft <- do | ||
| 152 | saveDraft <- fatal' "Could not find save switch" =<< getElementById window "saveDraft" | ||
| 153 | flip stepper (UI.checkedChange saveDraft) =<< saveDraft # get UI.checked | ||
| 154 | |||
| 150 | let | 155 | let |
| 151 | modifyStatus f = changeEditorStatus . f =<< currentValue editorStatus | 156 | modifyStatus f = changeEditorStatus . f =<< currentValue editorStatus |
| 152 | 157 | ||
| @@ -186,10 +191,11 @@ setup Config{..} window (split -> (socketErr, dataUpdate)) = void $ do | |||
| 186 | when' :: Applicative m => Bool -> m a -> m (Maybe a) | 191 | when' :: Applicative m => Bool -> m a -> m (Maybe a) |
| 187 | when' True = fmap Just | 192 | when' True = fmap Just |
| 188 | when' False = const $ pure Nothing | 193 | when' False = const $ pure Nothing |
| 189 | discardAction = do | 194 | clearAction = do |
| 190 | -- maybe (return ()) draftDelete . associatedDraft =<< currentValue editorStatus | 195 | -- maybe (return ()) draftDelete . associatedDraft =<< currentValue editorStatus |
| 191 | saved <- saveAction False | 196 | saved <- saveAction False |
| 192 | when saved $ modifyStatus $ const def | 197 | when saved $ discardAction |
| 198 | discardAction = modifyStatus $ const def | ||
| 193 | printAction = do | 199 | printAction = do |
| 194 | EditorState{..} <- currentValue editorStatus | 200 | EditorState{..} <- currentValue editorStatus |
| 195 | case ePrintout of | 201 | case ePrintout of |
| @@ -201,15 +207,18 @@ setup Config{..} window (split -> (socketErr, dataUpdate)) = void $ do | |||
| 201 | runFunction . focusJob =<< jobCreate Nothing po -- FIXME | 207 | runFunction . focusJob =<< jobCreate Nothing po -- FIXME |
| 202 | Left err -> emitError $ "Could not print draft due to error parsing bbcode: " ++ show err | 208 | Left err -> emitError $ "Could not print draft due to error parsing bbcode: " ++ show err |
| 203 | 209 | ||
| 204 | onEvent (tick autoSaveTimer) (const . void $ saveAction True) | 210 | onEvent (whenE saveDraft $ tick autoSaveTimer) (const . void $ saveAction True) |
| 205 | 211 | ||
| 206 | return saveButton # sink UI.enabled (saveable <$> editorStatus) | 212 | return saveButton # sink UI.enabled ((&&) <$> (saveable <$> editorStatus) <*> saveDraft) |
| 207 | return printButton # sink UI.enabled (printable <$> editorStatus) | 213 | return printButton # sink UI.enabled (printable <$> editorStatus) |
| 208 | return discardButton # sink UI.enabled (discardable <$> editorStatus) | 214 | return discardButton # sink UI.enabled (discardable <$> editorStatus) |
| 209 | 215 | ||
| 210 | on UI.click saveButton . const . void $ saveAction False | 216 | return discardButton # sink UI.text (bool "Discard" "Save & Clear" <$> saveDraft) |
| 217 | |||
| 218 | on (whenE saveDraft . UI.click) saveButton . const . void $ saveAction False | ||
| 211 | on UI.click printButton $ const printAction | 219 | on UI.click printButton $ const printAction |
| 212 | on UI.click discardButton $ const discardAction | 220 | on (whenE (not <$> saveDraft) . UI.click) discardButton $ const discardAction |
| 221 | on (whenE saveDraft . UI.click) discardButton $ const clearAction | ||
| 213 | 222 | ||
| 214 | return modifyStatus | 223 | return modifyStatus |
| 215 | 224 | ||
