X-Git-Url: https://git.hcoop.net/hcoop/portal.git/blobdiff_plain/b90b0980f97ea3c9623f99db83abeb7419b916b2..34bc3b831fe9636352043dbc15e9078c319f3fb8:/poll.mlt diff --git a/poll.mlt b/poll.mlt index b216a4f..200c96a 100644 --- a/poll.mlt +++ b/poll.mlt @@ -8,7 +8,7 @@ ref showNormal = true; if $"cmd" = "list" then showNormal := false %> -

All polls

+

All polls

<% foreach pol in Poll.listPolls () do %>
  • <% Web.html (#title pol) %> @@ -21,18 +21,22 @@ elseif $"vote" <> "" then val id = Web.stoi ($"vote"); val poll = Poll.lookupPoll id %> - - - - - - - +
    Poll#: <% id %>
    Title: <% Web.html (#title poll) %>
    Start: <% Web.html (#starts poll) %>
    End: <% Web.html (#ends poll) %>
    Votes/person: <% #votes poll %>
    Description: <% Web.htmlNl (#descr poll) %>
    + + + + + + +
    Poll#: <% id %>
    Title: <% Web.html (#title poll) %>
    Start: <% Web.html (#starts poll) %>
    End: <% Web.html (#ends poll) %>
    Votes/person: <% #votes poll %>
    Official: <% if #official poll then "yes" else "no" end %>
    Description: <% Web.htmlNl (#descr poll) %>
    -

    Choices

    +<% if #official poll and Poll.membershipLength (Init.getUserId ()) < Poll.votingMembershipRequirement then %> +

    You haven't been a member long enough to vote in an official poll.

    +<% else %> +

    Choices

    -
    + <% val choices = Poll.listChoicesWithMyVotes id; if #votes poll = 1 then %> @@ -47,7 +51,8 @@ foreach (you, cho) in choices do %>
    -<% elseif $"vote2" <> "" then +<% end +elseif $"vote2" <> "" then val id = Web.stoi ($"vote2"); val poll = Poll.lookupPoll id; editingPoll := SOME id; @@ -56,13 +61,15 @@ foreach (you, cho) in choices do %> [""] => [] | v => map Web.stoi v; - if length votes > #votes poll then - %>

    You can't vote for that many different choices!

    <% + if #official poll and Poll.membershipLength (Init.getUserId ()) < Poll.votingMembershipRequirement then + %>

    You haven't been a member long enough to vote in an official poll.

    <% + elseif length votes > #votes poll then + %>

    You can't vote for that many different choices!

    <% elseif not (Poll.noDupes votes) then - %>

    You can't vote multiple times for the same choice!

    <% + %>

    You can't vote multiple times for the same choice!

    <% else Poll.vote (Init.getUserId (), id, votes) - %>

    Thanks for voting!

    + %>

    Thanks for voting!

    <% end elseif $"cmd" = "add" then @@ -70,18 +77,19 @@ elseif $"cmd" = "add" then val starts = $"starts"; val ends = $"ends"; val votes = Web.stoi ($"votes"); + val official = $"official" = "on"; if title = "" then - %>

    Your poll must have a title.

    <% + %>

    Your poll must have a title.

    <% elseif not pollAdmin and not (Poll.dateGeNow starts) then - %>

    That start date is in the past!

    <% + %>

    That start date is in the past!

    <% elseif not pollAdmin and not (Poll.dateLe (starts, ends)) then - %>

    The end date comes before the start date!

    <% + %>

    The end date comes before the start date!

    <% elseif votes <= 0 then - %>

    You must specify a positive number of votes per person.

    <% + %>

    You must specify a positive number of votes per person.

    <% else - val id = Poll.addPoll (Init.getUserId(), title, $"descr", starts, ends, votes); + val id = Poll.addPoll (Init.getUserId(), title, $"descr", starts, ends, votes, official, false); editingPoll := SOME id; - %>

    Poll added!

    <% + %>

    Poll added!

    <% end elseif $"mod" <> "" then @@ -89,16 +97,18 @@ elseif $"mod" <> "" then val poll = Poll.lookupPoll (Web.stoi ($"mod")); Poll.requireCanModify poll %> -

    Modify poll

    +

    Modify poll

    -
    + "> - - - - - - +
    Title:
    Start date:
    End date:
    Max votes/person:
    Description:
    + + + + + + +
    Title:
    Ready? >
    Start date:
    End date:
    Max votes/person:
    Official: >
    Description:
    @@ -112,42 +122,50 @@ elseif $"mod" <> "" then val starts = $"starts"; val ends = $"ends"; val votes = Web.stoi ($"votes"); - if title = "" then - %>

    Your poll must have a title.

    <% + val official = $"official" = "on"; + val ready = $"ready" = "on"; + if not (Poll.canModify poll) then + %>

    You can't modify this poll anymore, because voting is already open.

    <% + elseif title = "" then + %>

    Your poll must have a title.

    <% elseif not pollAdmin and not (Poll.dateGeNow starts) then - %>

    That start date is in the past!

    <% + %>

    That start date is in the past!

    <% elseif not pollAdmin and not (Poll.dateLe (starts, ends)) then - %>

    The end date comes before the start date!

    <% + %>

    The end date comes before the start date!

    <% elseif votes <= 0 then - %>

    You must specify a positive number of votes per person.

    <% + %>

    You must specify a positive number of votes per person.

    <% else - Poll.modPoll {poll with title = title, descr = $"descr", starts = starts, ends = ends, votes = votes}; + Poll.modPoll {poll with title = title, descr = $"descr", starts = starts, ends = ends, votes = votes, official = official, + ready = ready}; editingPoll := SOME (#id poll); - %>

    Poll record saved.

    <% + %>

    Poll record saved.

    <% end elseif $"del" <> "" then - Group.requireGroupName "poll"; showNormal := false; - val poll = Poll.lookupPoll (Web.stoi ($"del")) %> -

    Are you sure you want to delete poll <% Web.html (#title poll) %>?

    + val poll = Poll.lookupPoll (Web.stoi ($"del")); + Poll.requireCanModify poll %> +

    Are you sure you want to delete poll <% Web.html (#title poll) %>?

    ">Yes, delete <% Web.html (#title poll) %>! <% elseif $"del2" <> "" then - Group.requireGroupName "poll"; val poll = Poll.lookupPoll (Web.stoi ($"del2")); + Poll.requireCanModify poll; Poll.deletePoll (Web.stoi ($"del2")) %> -

    <% Web.html (#title poll) %> deleted!

    +

    <% Web.html (#title poll) %> deleted!

    <% elseif $"addChoice" <> "" then val id = Web.stoi ($"addChoice"); editingPoll := SOME id; val descr = $"descr"; - if descr = "" then - %>

    Your poll choice must have a description.

    <% + val poll = Poll.lookupPoll id; + if not (Poll.canModify poll) then + %>

    You can't modify this poll anymore, because voting is already open.

    <% + elseif descr = "" then + %>

    Your poll choice must have a description.

    <% else val id = Poll.addChoice (id, Web.stor ($"seq"), descr); - %>

    Choice added!

    <% + %>

    Choice added!

    <% end elseif $"modChoice" <> "" then @@ -157,11 +175,11 @@ elseif $"modChoice" <> "" then val poll = Poll.lookupPoll (#pol cho); Poll.requireCanModify poll %> -
    + - - - +
    Text:
    Sequence#:
    + +
    Text:
    Sequence#:
    @@ -174,10 +192,10 @@ elseif $"modChoice" <> "" then editingPoll := SOME (#id poll); val descr = $"descr"; if descr = "" then - %>

    Your poll choice must have a description.

    <% + %>

    Your poll choice must have a description.

    <% else Poll.modChoice {cho with seq = Web.stor ($"seq"), descr = descr}; - %>

    Choice saved!

    <% + %>

    Choice saved!

    <% end elseif $"delChoice" <> "" then @@ -186,7 +204,7 @@ elseif $"delChoice" <> "" then val poll = Poll.lookupPoll (#pol cho); Poll.requireCanModify poll; showNormal := false %> -

    Are you sure you want to delete choice "<% Web.html (#descr cho) %>"?

    +

    Are you sure you want to delete choice "<% Web.html (#descr cho) %>"?

    ">Yes, delete "<% Web.html (#descr cho) %>"! <% elseif $"delChoice2" <> "" then @@ -196,7 +214,7 @@ elseif $"delChoice" <> "" then Poll.requireCanModify poll; Poll.deleteChoice id; editingPoll := SOME (#id poll) %> -

    "<% Web.html (#descr cho) %>" deleted!

    +

    "<% Web.html (#descr cho) %>" deleted!

    <% elseif $"report" <> "" then showNormal := false; @@ -205,7 +223,7 @@ elseif $"delChoice" <> "" then val poll = Poll.lookupPoll id; val canModify = Poll.canModify poll %> -

    Vote Report

    +

    Vote Report

    Voters: <% ref first = true; @@ -218,13 +236,14 @@ elseif $"delChoice" <> "" then %><% #name user %><% end %>

    - - - - - - - +
    Poll#: <% id %>
    Title: <% Web.html (#title poll) %>
    Start: <% Web.html (#starts poll) %>
    End: <% Web.html (#ends poll) %>
    Votes/person: <% #votes poll %>
    Description: <% Web.htmlNl (#descr poll) %>
    + + + + + + +
    Poll#: <% id %>
    Title: <% Web.html (#title poll) %>
    Start: <% Web.html (#starts poll) %>
    End: <% Web.html (#ends poll) %>
    Votes/person: <% #votes poll %>
    Official: <% if #official poll then "yes" else "no" end %>
    Description: <% Web.htmlNl (#descr poll) %>



    @@ -256,17 +275,18 @@ end %> val poll = Poll.lookupPoll id; val canModify = Poll.canModify poll %> - +
    <% if canModify then %><% end %> - - - - - - + + + + + + +
    Edit poll data
    Poll#: <% id %>
    Title: <% Web.html (#title poll) %>
    Start: <% Web.html (#starts poll) %>
    End: <% Web.html (#ends poll) %>
    Votes/person: <% #votes poll %>
    Description: <% Web.htmlNl (#descr poll) %>
    Poll#: <% id %>
    Title: <% Web.html (#title poll) %>
    Start: <% Web.html (#starts poll) %>
    End: <% Web.html (#ends poll) %>
    Votes/person: <% #votes poll %>
    Official: <% if #official poll then "yes" else "no" end %>
    Description: <% Web.htmlNl (#descr poll) %>
    -

    Choices<% if Poll.takingVotes poll then %>(Vote!)<% end %>

    +

    Choices<% if Poll.takingVotes poll then %>(Vote!)<% end %>

    <% Poll.countVoters (#id poll) %> people have voted.

    @@ -300,33 +320,52 @@ end %> <% if canModify then %>


    -

    Add a new choice

    +

    Delete this poll

    + +

    Add a new choice

    -
    + - - - +
    Text:
    Sequence#:
    + +
    Text:
    Sequence#:
    <% end %> <% | NONE => -if showNormal then %> +if showNormal then -Show all polls
    +val mlen = Poll.membershipLength (Init.getUserId ()) %> -

    Create a poll

    +

    You have been an HCoop member for <% mlen %> days, so you are<% if mlen < Poll.votingMembershipRequirement then %> not<% end %> eligible to vote in official polls.

    -
    +<% val polls = Poll.listCurrentPolls (); +switch polls of + _::_ => %> +

    Current polls

    + +<% foreach pol in polls do %> +
  • <% Web.html (#title pol) %> +<% if Poll.takingVotes pol then %>[VOTE]<% end %> +(<% Web.html (#starts pol) %> to <% Web.html (#ends pol) %>)
  • +<% end +end %> + +

    Show all polls

    + +

    Create a poll

    + + - - - - - - +
    Title:
    Start date:
    End date:
    Max votes/person:
    Description:
    + + + + + +
    Title:
    Start date:
    End date:
    Max votes/person:
    Official:
    Description: