## The contents of this file are subject to the Common Public Attribution
## License Version 1.0. (the "License"); you may not use this file except in
## compliance with the License. You may obtain a copy of the License at
## http://code.reddit.com/LICENSE. The License is based on the Mozilla Public
## License Version 1.1, but Sections 14 and 15 have been added to cover use of
## software over a computer network and provide for limited attribution for the
## Original Developer. In addition, Exhibit A has been modified to be
## consistent with Exhibit B.
##
## Software distributed under the License is distributed on an "AS IS" basis,
## WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
## the specific language governing rights and limitations under the License.
##
## The Original Code is reddit.
##
## The Original Developer is the Initial Developer.  The Initial Developer of
## the Original Code is reddit Inc.
##
## All portions of the code written by reddit are Copyright (c) 2006-2013
## reddit Inc. All Rights Reserved.
###############################################################################

<%inherit file="reddit.html"/>

<%!
  from r2.lib.template_helpers import static
  from r2.lib import js
 %>

<%namespace name="pr" file="promotelinkform.html" />
<%namespace name="utils" file="utils.html"/>

<%def name="javascript()">
  ${parent.javascript()}
  ${unsafe(js.use('sponsored'))}
</%def>

<%def name="bodyHTML()">
    <form id="promotion-history" method="get" action="/admin/promoted">
        <div class="promo-admin-form">
           <div class="promo-admin-row" onclick="$('#qstarted_on').attr('checked', true);">
               <input type="hidden" id="date-min" name="date-min" value="6/30/2012" />
               <input type="radio" name="q" id="qstarted_on" value="started_on" checked=1>
                   see ads that started on:
               </input>
               <%pr:datepicker name="ondate" value="${thing.start.strftime('%m/%d/%Y')}"
                              minDateSrc="date-min" initfuncname="init_ondate" min_date_offset="86400000">
                 function(elem) { return elem; }
               </%pr:datepicker>
           </div>
           <div class="promo-admin-row" onclick="$('#qbetween').attr('checked', true);">
               <input type="radio" name="q" id="qbetween" value="between" ${"checked=1" if thing.query_type=="between" else ""}>
                   see ads that were running any day between:
               </input>
               <%pr:datepicker name="startdate" value="${thing.launch.strftime('%m/%d/%Y')}"
                              minDateSrc="date-min" initfuncname="init_startdate" min_date_offset="86400000">
                 function(elem) { return elem; }
               </%pr:datepicker>
               and 
               <%pr:datepicker name="enddate" value="${thing.end.strftime('%m/%d/%Y')}"
                              minDateSrc="date-min" initfuncname="init_enddate" min_date_offset="86400000">
                 function(elem) { return elem; }
               </%pr:datepicker>
               (inclusive)
           </div>
           <div>
               <button class="fancybutton">show</button>
           </div>
        <div> 
    </form>

    ## init date pickers
    <script type="text/javascript">
    $(function() {
      init_ondate();
      init_startdate();
      init_enddate();
    })
    </script>

    <div>
      <table class='promo-admin-data'>
        <tr>
          <th>campaign</th>
          <th>username</th>
          <th>user email</th>
          <th>campaign start</th>
          <th>campaign end</th>
          <th>bid per day</th>
          <th>edit link</th>
          <th>link title</th>
        </tr>

        %for p in thing.promos:
          <tr>
            <td>${p['campaign_id']}</td>
            <td>${p['username']}</td>
            <td><a href="mailto:${p['user_email']}" target="_blank">${p['user_email']}</a></td>
            <td>${p['campaign_start']}</td>
            <td>${p['campaign_end']}</td>
            <td class="right">$${"%0.2f" % p['bid_per_day']}</td>
            <td><a href="${p['edit_link']}" target="_blank">${p['edit_link']}</a></td>
            <td>${p['link_title']}</td>
        </tr>
        %endfor

      </table>
    </div>
</%def>
