<% #listItem %>
<tr>
   <td class='uk-text-right'><% poll.votes %></td>
   <td class='uk-width-1-2 av-overflow'>
      <% poll.question | stripTags | poll.link %>
   </td>
   <td class='uk-text-truncate'><% poll.creator %></td>
   <td class='uk-text-truncate' title='<% poll.modified short %>' data-uk-tooltip="{pos: 'top-left'}">
      <% poll.modified text %>
   </td>
   <td class='uk-text-right'>
      <% poll.link status <% if <% poll.status %> is open then "<i class='uk-icon-unlock'></i>" else "<i class='uk-icon-lock'></i>" %> %>
   </td>
   <td class='uk-text-right uk-text-nowrap'>
      <a href='javascript:' class='av-clipboard-copy' data-text='<% gettext 'Press CTRL & C to copy to clipboard.' %>' data-value="<% poll.macro %>"><i class='uk-icon-clipboard'></i></a>
      <% poll.link delete "<i class='uk-icon-trash-o'></i>" %>
      <% poll.link edit "<i class='uk-icon-pencil'></i>" %>
   </td>
</tr>

<% #header %>
<h1><% poll.question | stripTags %></h1>
<div class='uk-article-meta uk-margin-bottom'>
   <% gettext "Posted by {0} on {1}" <% poll.creator %> <% poll.created short %> %>
</div>

<% #footer %>
<div class='uk-margin-top'>
   <% poll.link edit <% gettext Edit %> class='uk-button' %>
</div>

<% #main %>
<% poll.skin #header %>
<% poll.skin #open %>
<% poll.skin #footer %>

<% #results %>
<% poll.skin #header %>
<% poll.skin #closed %>
<% poll.skin #footer %>

<% #embed %>
<div class='uk-margin-bottom'>
   <% if <% poll.status %> is open then
      <% poll.skin $Poll#open title=<% poll.question %> %>
   else
      <% poll.skin $Poll#closed title=<% poll.question %> %>
   %>
   <% poll.source %>
</div>

<% #open %>
<form class='uk-panel uk-panel-box uk-form uk-form-stacked' method="post" action="<% poll.href %>">
   <% param.title prefix="<h1 class='uk-panel-title'>" suffix=</h1> %>
   <% poll.loop skin="$Choice#main" %>
   <div class='uk-margin-top'>
      <button class='uk-button uk-button-primary' type="submit" id="submit" name="submit" value="1">
         <% gettext Vote %>
      </button>
      <% poll.link result <% gettext "Results" %> class='uk-button uk-button-link' %>
   </div>
</form>

<% #closed %>
<div class='uk-panel uk-panel-box'>
   <% param.title prefix="<h1 class='uk-panel-title'>" suffix=</h1> %>
   <% poll.loop skin="$Choice#result" %>
   <div class='uk-float-left'>
      <strong><% gettext Total suffix=: %></strong>
      <% ngettext "{0} vote" "{0} votes" <% poll.votes %> %>
   </div>
   <div class='uk-text-right'>
      <% if <% poll.status %> is open then
         <% poll.link main <% gettext 'Add Your Vote' %> %>
      else <% if <% poll.closed %> is null then '' else
         <% gettext "This poll was closed {0} by {1}" <% poll.closed text %> <% poll.modifier %> prefix="<span class='uk-text-muted'>" suffix='</span>' %>
      %> %>
   </div>
</div>

<% #edit %>
<h1>
   <% response.title %>
   <% poll.link . ' ' class='uk-icon-button uk-icon-link uk-text-middle' %>
</h1>
<div class='uk-article-meta'><% poll.skin $HopObject#meta %></div>
<form class='uk-margin-top uk-form uk-form-stacked' method="post" action="<% response.action %>">
   <div class='uk-form-row'>
      <div class='uk-form-label'><% gettext Question %></div>
      <div class='uk-form-controls'>
         <% poll.input question class=uk-width-1-1 %>
      </div>
   </div>
   <fieldset class='uk-margin-top'>
      <legend><% gettext Choices %></legend>
      <% poll.input choices %>
      <div class='uk-text-small uk-form-row uk-hidden' id='av-add-choice'>
         <a href='javascript:'>
            <i class='uk-icon-plus'></i>
            <% gettext "Add Choice" %>
         </a>
      </div>
   </fieldset>
   <fieldset class='uk-margin-top'>
     <legend><% gettext Information %></legend>
      <div class='uk-form-row'>
         <% poll.macro | link <% poll.href %> data-value=<% poll.macro %> data-text=<% gettext "Press CTRL & C to copy to clipboard." %> class='av-clipboard-copy' %>
      </div>
   </fieldset>
   <div class='uk-margin-top'>
      <button class='uk-button uk-button-primary' type="submit" name="save" value="<% poll.status default=closed %>">
         <% gettext Save %>
      </button>
      <% if <% poll.status %> is open then
         <% poll.link status <% gettext Stop %> class='uk-button uk-button-danger' %>
      else
         <% gettext "Save and Run" prefix="<button class='uk-button uk-button-success' type='submit' name='save' value='open'>" suffix=</button> %>
      %>
      <% poll.link delete <% gettext Delete %> class='uk-button' %>
      <a href='.' class='uk-button uk-button-link'><% gettext Cancel %></a>
   </div>
</form>
<script type="text/javascript">
   var index = $(".av-choice").length + 1;
   $("#av-add-choice").removeClass('uk-hidden').find('a').on('click', function (event) {
      event.preventDefault();
      var choice = $(".av-choice:last").clone();
      choice.find(".uk-form-label").text('#' + index);
      choice.find("input").attr("value", '');
      $(".av-choice:last").after(choice);
      $(".av-choice:last").find("input").focus();
      index += 1;
   });
</script>
