Commit 5c1d0076 authored by Stephane Glondu's avatar Stephane Glondu
Browse files

Add the possibility to (un)feature an election from its admin page

parent 1bd922a9
......@@ -318,7 +318,27 @@ module Make (D : ELECTION_DATA) (P : WEB_PARAMS) : REGISTRATION = struct
let () = Html5.register ~service:W.S.admin
(fun () () ->
match_lwt S.get_user () with
| Some u when W.metadata.e_owner = Some u -> T.admin ()
| Some u when W.metadata.e_owner = Some u ->
let post_params = Eliom_parameter.(
bool "featured"
) in
let set_featured = Eliom_service.post_coservice
~csrf_safe:true
~csrf_scope:scope
~fallback:W.S.admin
~post_params
()
in
let () = Any.register ~scope ~service:set_featured
(fun () featured ->
lwt () = if featured then (
S.add_featured_election uuid
) else (
S.remove_featured_election uuid
) in Redirection.send W.S.admin
)
in
T.admin ~set_featured ()
| _ -> forbidden ()
)
......
......@@ -223,6 +223,11 @@ module type ELECTION_TEMPLATES = sig
unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val admin :
set_featured:(unit, 'a, [< Eliom_service.post_service_kind ],
[< Eliom_service.suff ], 'b,
[ `One of bool ] Eliom_parameter.param_name,
[< Eliom_service.registrable ], 'c)
Eliom_service.service ->
unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val update_credential :
......
......@@ -381,8 +381,14 @@ module Make (S : SITE_SERVICES) : TEMPLATES = struct
lwt login_box = election_login_box () in
base ~title:params.e_name ~login_box ~content
let admin () =
let admin ~set_featured () =
let title = W.election.e_params.e_name ^ " — Administration" in
let feature_form = post_form ~service:set_featured
(fun featured -> [
bool_checkbox ~name:featured ();
string_input ~input_type:`Submit ~value:"(Un)feature" ();
]) ()
in
let content = [
h1 [pcdata title];
div [
......@@ -393,6 +399,7 @@ module Make (S : SITE_SERVICES) : TEMPLATES = struct
let service = W.S.election_update_credential in
a ~service [pcdata "Update a credential"] ();
];
div [feature_form];
] in
lwt login_box = site_login_box () in
base ~title ~login_box ~content
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment