summaryrefslogtreecommitdiff
path: root/elm/Discussions/Edit.elm
diff options
context:
space:
mode:
Diffstat (limited to 'elm/Discussions/Edit.elm')
-rw-r--r--elm/Discussions/Edit.elm168
1 files changed, 82 insertions, 86 deletions
diff --git a/elm/Discussions/Edit.elm b/elm/Discussions/Edit.elm
index f8873fa7..f4899e95 100644
--- a/elm/Discussions/Edit.elm
+++ b/elm/Discussions/Edit.elm
@@ -24,45 +24,45 @@ main = Browser.element
type alias Model =
- { state : Api.State
- , tid : Maybe Int
- , num : Maybe Int
- , 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
- , num = d.num
- , 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
}
@@ -72,17 +72,17 @@ searchConfig = { wrap = BoardSearch, id = "boardadd", source = A.boardSource }
encode : Model -> GDE.Send
encode m =
- { tid = m.tid
- , num = m.num
- , 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
}
@@ -90,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)
@@ -104,6 +104,7 @@ type Msg
| Delete Bool
| Content TP.Msg
| Title String
+ | BoardsLocked Bool
| BoardDel Int
| BoardSearch (A.Msg GApi.ApiBoardResult)
| PollEnabled Bool
@@ -133,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
@@ -148,32 +150,36 @@ update msg model =
view : Model -> Html Msg
view model =
let
- thread = model.tid == Nothing || model.num == Just 1
-
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 =
@@ -184,14 +190,14 @@ view model =
else text ""
]
- poll () =
+ poll =
[ tr [ class "newpart" ] [ td [ colspan 2 ] [ text "" ] ]
, formField "" [ label [] [ inputCheck "" model.pollEnabled PollEnabled, text " Add poll" ] ]
] ++
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"
@@ -209,47 +215,37 @@ view model =
in
- form_ Submit (model.state == Api.Loading)
- [ div [ class "mainbox" ]
- [ h1 [] [ text <| if model.tid == Nothing then "Create new thread" else "Edit post" ]
+ form_ "" Submit (model.state == Api.Loading)
+ [ article []
+ [ h1 [] [ text <| if model.tid == Nothing then "Create new thread" else "Edit thread" ]
, table [ class "formtable" ] <|
- [ if thread
- then formField "title::Thread title" [ inputText "title" (Maybe.withDefault "" model.title) Title (style "width" "400px" :: required True :: GDE.valTitle) ]
- else formField "Topic" [ a [ href <| "/t" ++ String.fromInt (Maybe.withDefault 0 model.tid) ] [ text (Maybe.withDefault "" model.title) ] ]
- , if thread && model.can_mod
+ [ formField "title::Thread title" [ inputText "title" (Maybe.withDefault "" model.title) Title (style "width" "400px" :: required True :: GDE.valTitle) ]
+ , if model.can_mod
then formField "" [ label [] [ inputCheck "" model.locked Locked, text " Locked" ] ]
else text ""
, if model.can_mod
then formField "" [ label [] [ inputCheck "" model.hidden Hidden, text " Hidden" ] ]
else text ""
- , if thread && model.can_private
+ , if model.can_private
then formField "" [ label [] [ inputCheck "" model.private Private, text " Private" ] ]
else text ""
, if model.tid /= Nothing && model.can_mod
then formField "" [ label [] [ inputCheck "" model.nolastmod Nolastmod, text " Don't update last modification timestamp" ] ]
else text ""
- , if thread
- then formField "boardadd::Boards" (boards ())
- else text ""
+ , formField "boardadd::Boards" (boards ())
, 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" ]
]
]
]
- ++ (if thread then poll () else [])
- ++ (if not model.can_mod then [] else
+ ++ poll
+ ++ (if not model.can_mod || model.tid == Nothing then [] else
[ tr [ class "newpart" ] [ td [ colspan 2 ] [ text "DANGER ZONE" ] ]
- , formField ""
- [ inputCheck "" model.delete Delete
- , text <| " Permanently delete this " ++ if thread then "thread and all replies." else "post."
- , text <| if thread then "" else " This causes all replies after this one to be renumbered."
- , text <| " This action can not be reverted, only do this with obvious spam!"
- ]
+ , 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) ]
]