X-Git-Url: https://git.hcoop.net/hcoop/zz_old/portal.git/blobdiff_plain/57c305c1681b8b819d90b3f5a4d8c77a03926a4e..45174231c9693be788280cc80acc5e28394e35bf:/poll.mlt diff --git a/poll.mlt b/poll.mlt index 19e1eba..505044f 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) %> @@ -16,23 +16,72 @@ if $"cmd" = "list" then
  • <% end +elseif $"vote" <> "" then + showNormal := false; + 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) %>
    + +

    Choices

    + +
    + +<% val choices = Poll.listChoicesWithMyVotes id; +if #votes poll = 1 then %> + +<% end +foreach (you, cho) in choices do %> + +<% end %>

    + +
    + +<% elseif $"vote2" <> "" then + val id = Web.stoi ($"vote2"); + val poll = Poll.lookupPoll id; + editingPoll := SOME id; + + val votes = case Web.getMultiParam "v" of + [""] => [] + | v => map Web.stoi v; + + if 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!

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

    Thanks for voting!

    +<% end + elseif $"cmd" = "add" then val title = $"title"; val starts = $"starts"; val ends = $"ends"; val votes = Web.stoi ($"votes"); if title = "" then - %>

    Your poll must have a title.

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

    That start date is in the past!

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

    The end date comes before the start date!

    <% + %>

    Your poll must have a title.

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

    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!

    <% 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); editingPoll := SOME id; - %>

    Poll added!

    <% + %>

    Poll added!

    <% end elseif $"mod" <> "" then @@ -40,16 +89,16 @@ 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:
    Start date:
    End date:
    Max votes/person:
    Description:
    @@ -64,41 +113,41 @@ elseif $"mod" <> "" then val ends = $"ends"; val votes = Web.stoi ($"votes"); if title = "" then - %>

    Your poll must have a title.

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

    That start date is in the past!

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

    The end date comes before the start date!

    <% + %>

    Your poll must have a title.

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

    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!

    <% 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}; 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) %>?

    +

    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.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.

    <% + %>

    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 @@ -108,11 +157,11 @@ elseif $"modChoice" <> "" then val poll = Poll.lookupPoll (#pol cho); Poll.requireCanModify poll %> -
    + - - - +
    Text:
    Sequence#:
    + +
    Text:
    Sequence#:
    @@ -125,10 +174,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 @@ -137,7 +186,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 @@ -147,7 +196,55 @@ 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; + val id = Web.stoi ($"report"); + + val poll = Poll.lookupPoll id; + val canModify = Poll.canModify poll %> + +

    Vote Report

    + +

    Voters: +<% ref first = true; + foreach user in Poll.listPollVoters id do + if first then + first := false + else + %>, <% + end + %><% #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) %>
    + +


    + + + +<% foreach (_, total, cho) in Poll.listChoicesWithVotes id do %> + <% +end %> +
    Votes Choice Voters
    <% total %> <% Web.html (#descr cho) %> +<% ref first = true; + foreach user in Poll.listVoters (#id cho) do + if first then + first := false + else + %>, <% + end + %><% #name user %><% + end + %>
    <% elseif $"id" <> "" then editingPoll := SOME (Web.stoi ($"id")) @@ -156,39 +253,60 @@ end %> <% switch editingPoll of SOME id => - val pol = Poll.lookupPoll id; - val canModify = Poll.canModify pol %> + val poll = Poll.lookupPoll id; + val canModify = Poll.canModify poll %> - +
    <% if canModify then %><% end %> - - - - - - + + + + + +
    Edit poll data
    Poll#: <% id %>
    Title: <% Web.html (#title pol) %>
    Start: <% Web.html (#starts pol) %>
    End: <% Web.html (#ends pol) %>
    Votes/person: <% #votes pol %>
    Description: <% Web.htmlNl (#descr pol) %>
    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) %>
    -

    Choices

    +

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

    + +

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

    + +<% if Poll.takingVotes poll then %> + + +<% foreach (you, total, cho) in Poll.listChoicesWithVotes id do %> + + + +<% if canModify then %> + +<% end %> +<% end %> +
    You Total
    <% if you then %>X<% end %><% total %><% Web.html (#descr cho) %>(<% #seq cho %>) +[Modify] +[Delete]
    -<% foreach cho in Poll.listChoices id do %> +<% else +foreach cho in Poll.listChoices id do %>
  • <% Web.html (#descr cho) %> <% if canModify then %> (<% #seq cho %>) [Modify] [Delete] <% end %>
  • -<% end %> +<% end +end %> + +Vote Report <% if canModify then %>


    -

    Add a new choice

    +

    Add a new choice

    -
    + - - - +
    Text:
    Sequence#:
    + +
    Text:
    Sequence#:
    @@ -199,16 +317,16 @@ if showNormal then %> Show all polls
    -

    Create a poll

    +

    Create a poll

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