## 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-2015
## reddit Inc. All Rights Reserved.
###############################################################################

<%!
  from r2.lib.pages import SubredditSelector
  from r2.lib.template_helpers import static
  from r2.lib import js
 %>
<%namespace name="utils" file="utils.html"/>
<%namespace file="promotelinkbase.html" name="p" />
<%namespace file="utils.html" 
            import="error_field, checkbox, image_upload" />

${unsafe(js.use('sponsored'))}

<div class="sponsored-page">
  <div class="dashboard roadblock-dashboard campaign">
    <header>
      <h2>create a roadblock</h2>
    </header>
    <div class="dashboard-content">
      <div class="editor">
        <div class="editor-group">
          ${p.timing_field()}
          ${p.subreddit_targeting_field(SubredditSelector())}
        </div>
        <footer class="buttons">
          <span class="status error"></span>
          <button name="create"
                  onclick="return post_pseudo_form('.campaign', 'add_roadblock')">
             create
           </button>
        </footer>
      </div>
    </div>
  </div>
  <div class='existing-campaigns'>
    <table>
      <thead>
        <tr>
          <th>subreddit</th>
          <th>Start Date</th>
          <th>End Date</th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        %if thing.roadblocks:
          %for reddit, startdate, enddate in thing.roadblocks:
            <tr>
              <td>${reddit}</td>
              <td>${startdate.strftime("%Y-%m-%d")}</td>
              <td>${enddate.strftime("%Y-%m-%d")}</td>
              <td class="campaign-buttons">
                <form method="post" action="/post/rm_roadblock" onsubmit="return post_form(this, 'rm_roadblock')">
                  <input type="hidden" name="sr" value="${reddit}"/>
                  <input type="hidden" name="startdate" value='${startdate.strftime("%m/%d/%Y")}'/>
                  <input type="hidden" name="enddate" value='${enddate.strftime("%m/%d/%Y")}'/>
                  <button type="submit">remove</button>
                </form>
              </td>
            </tr>
          %endfor
        %endif
    </table>
  </div>
</div>

<script type="text/javascript">
  r.sponsored.set_form_render_fnc(r.sponsored.fill_roadblock_form);
  $(function() {
    r.sponsored.render();
    init_startdate();
    init_enddate();
  })
</script>
