diff options
Diffstat (limited to 'elm/Discussions/Edit.elm')
-rw-r--r-- | elm/Discussions/Edit.elm | 136 |
1 files changed, 73 insertions, 63 deletions
diff --git a/elm/Discussions/Edit.elm b/elm/Discussions/Edit.elm index 6008cdef..f4899e95 100644 --- a/elm/Discussions/Edit.elm +++ b/elm/Discussions/Edit.elm @@ -24,43 +24,45 @@ main = Browser.element type alias Model = - { state : Api.State - , tid : Maybe String - , can_mod : Bool - , can_private : Bool - , locked : Bool - , hidden : Bool - , private : Bool - , nolastmod : Bool - , delete : Bool - , title : Maybe String - , boards : Maybe (List GDE.SendBoards) - , boardAdd : A.Model GApi.ApiBoardResult - , msg : TP.Model - , poll : Maybe GDE.SendPoll - , pollEnabled : Bool - , pollEdit : Bool + { state : Api.State + , tid : Maybe String + , can_mod : Bool + , can_private : Bool + , locked : Bool + , hidden : Bool + , private : Bool + , nolastmod : Bool + , delete : Bool + , title : Maybe String + , boards : Maybe (List GDE.SendBoards) + , boardAdd : A.Model GApi.ApiBoardResult + , boardsLocked : Bool + , msg : TP.Model + , poll : Maybe GDE.SendPoll + , pollEnabled : Bool + , pollEdit : Bool } init : GDE.Recv -> Model init d = - { state = Api.Normal - , can_mod = d.can_mod - , can_private = d.can_private - , tid = d.tid - , locked = d.locked - , hidden = d.hidden - , private = d.private - , nolastmod = False - , delete = False - , title = d.title - , boards = d.boards - , boardAdd = A.init "" - , msg = TP.bbcode d.msg - , poll = d.poll - , pollEnabled = isJust d.poll - , pollEdit = isJust d.poll + { state = Api.Normal + , can_mod = d.can_mod + , can_private = d.can_private + , tid = d.tid + , locked = d.locked + , hidden = d.hidden + , private = d.private + , nolastmod = False + , delete = False + , title = d.title + , boards = d.boards + , boardAdd = A.init "" + , boardsLocked = d.boards_locked + , msg = TP.bbcode d.msg + , poll = d.poll + , pollEnabled = isJust d.poll + , pollEdit = isJust d.poll } @@ -70,16 +72,17 @@ searchConfig = { wrap = BoardSearch, id = "boardadd", source = A.boardSource } encode : Model -> GDE.Send encode m = - { tid = m.tid - , locked = m.locked - , hidden = m.hidden - , private = m.private - , nolastmod = m.nolastmod - , delete = m.delete - , boards = m.boards - , poll = if m.pollEnabled then m.poll else Nothing - , title = m.title - , msg = m.msg.data + { tid = m.tid + , locked = m.locked + , hidden = m.hidden + , private = m.private + , nolastmod = m.nolastmod + , delete = m.delete + , boards = m.boards + , boards_locked = m.boardsLocked + , poll = if m.pollEnabled then m.poll else Nothing + , title = m.title + , msg = m.msg.data } @@ -87,7 +90,7 @@ numPollOptions : Model -> Int numPollOptions model = Maybe.withDefault 0 (Maybe.map (\o -> List.length o.options) model.poll) dupBoards : Model -> Bool -dupBoards model = hasDuplicates (List.map (\b -> (b.btype, b.iid)) (Maybe.withDefault [] model.boards)) +dupBoards model = hasDuplicates (List.map (\b -> (b.btype, Maybe.withDefault "" b.iid)) (Maybe.withDefault [] model.boards)) isValid : Model -> Bool isValid model = not (model.boards == Just [] || dupBoards model || Maybe.map (\p -> p.max_options < 1 || p.max_options > numPollOptions model) model.poll == Just True) @@ -101,6 +104,7 @@ type Msg | Delete Bool | Content TP.Msg | Title String + | BoardsLocked Bool | BoardDel Int | BoardSearch (A.Msg GApi.ApiBoardResult) | PollEnabled Bool @@ -130,6 +134,7 @@ update msg model = PollRem n -> ({ model | poll = Maybe.map (\p -> { p | options = delidx n p.options }) model.poll }, Cmd.none) PollAdd -> ({ model | poll = Maybe.map (\p -> { p | options = p.options ++ [""] }) model.poll }, Cmd.none) + BoardsLocked b-> ({ model | boardsLocked = b }, Cmd.none) BoardDel i -> ({ model | boards = Maybe.map (\b -> delidx i b) model.boards }, Cmd.none) BoardSearch m -> let (nm, c, res) = A.update searchConfig m model.boardAdd @@ -147,28 +152,34 @@ view model = let board n bd = li [] <| - [ text "[" - , a [ href "#", onClickD (BoardDel n), tabindex 10 ] [ text "remove" ] - , text "] " + [ if model.boardsLocked then text "" else span [] + [ text "[" + , a [ href "#", onClickD (BoardDel n), tabindex 10 ] [ text "remove" ] + , text "] " + ] , text (Maybe.withDefault "" (lookup bd.btype boardTypes)) - ] ++ case (bd.btype, bd.title) of - (_, Just title) -> - [ b [ class "grayedout" ] [ text " > " ] - , a [ href <| "/" ++ bd.btype ++ String.fromInt bd.iid ] [ text title ] + ] ++ case (bd.btype, bd.iid, bd.title) of + (_, Just iid, Just title) -> + [ small [] [ text " > " ] + , a [ href <| "/" ++ iid ] [ text title ] ] - ("u", _) -> [ b [ class "grayedout" ] [ text " > " ], text <| bd.btype ++ String.fromInt bd.iid ++ " (deleted)" ] - (_, _) -> [] + ("u", Just iid, _) -> [ small [] [ text " > " ], text <| iid ++ " (deleted)" ] + _ -> [] boards () = - [ text "You can link this thread to multiple boards. Every visual novel, producer and user in the database has its own board," + [ if not model.can_mod then text "" + else label [] [ inputCheck "" model.boardsLocked BoardsLocked, text " Lock boards.", br [] [] ] + , text "You can link this thread to multiple boards. Every visual novel, producer and user in the database has its own board," , text " but you can also use the \"General Discussions\" and \"VNDB Discussions\" boards for threads that do not fit at a particular database entry." , ul [ style "list-style-type" "none", style "margin" "10px" ] <| List.indexedMap board (Maybe.withDefault [] model.boards) - , A.view searchConfig model.boardAdd [placeholder "Add boards..."] + , if model.boardsLocked + then text "Boards are locked, only a moderator can move this thread." + else A.view searchConfig model.boardAdd [placeholder "Add boards..."] ] ++ if model.boards == Just [] - then [ b [ class "standout" ] [ text "Please add at least one board." ] ] + then [ b [] [ text "Please add at least one board." ] ] else if dupBoards model - then [ b [ class "standout" ] [ text "List contains duplicates." ] ] + then [ b [] [ text "List contains duplicates." ] ] else [] pollOpt n p = @@ -186,7 +197,7 @@ view model = case (model.pollEnabled, model.poll) of (True, Just p) -> [ if model.pollEdit - then formField "" [ b [ class "standout" ] [ text "Votes will be reset if any changes are made to these options!" ] ] + then formField "" [ b [] [ text "Votes will be reset if any changes are made to these options!" ] ] else text "" , formField "pollq::Poll question" [ inputText "pollq" p.question PollQ (style "width" "400px" :: GDE.valPollQuestion) ] , formField "Options" @@ -204,8 +215,8 @@ view model = in - form_ Submit (model.state == Api.Loading) - [ div [ class "mainbox" ] + form_ "" Submit (model.state == Api.Loading) + [ article [] [ h1 [] [ text <| if model.tid == Nothing then "Create new thread" else "Edit thread" ] , table [ class "formtable" ] <| [ formField "title::Thread title" [ inputText "title" (Maybe.withDefault "" model.title) Title (style "width" "400px" :: required True :: GDE.valTitle) ] @@ -225,8 +236,8 @@ view model = , tr [ class "newpart" ] [ td [ colspan 2 ] [ text "" ] ] , formField "msg::Message" [ TP.view "msg" model.msg Content 700 ([rows 12, cols 50] ++ GDE.valMsg) - [ b [ class "standout" ] [ text " (English please!) " ] - , a [ href "/d9#3" ] [ text "Formatting" ] + [ b [] [ text " (English please!) " ] + , a [ href "/d9#4" ] [ text "Formatting" ] ] ] ] @@ -236,6 +247,5 @@ view model = , formField "" [ inputCheck "" model.delete Delete, text " Permanently delete this thread and all replies. This action can not be reverted, only do this with obvious spam!" ] ]) ] - , div [ class "mainbox" ] - [ fieldset [ class "submit" ] [ submitButton "Submit" model.state (isValid model) ] ] + , article [ class "submit" ] [ submitButton "Submit" model.state (isValid model) ] ] |