<%! from django.utils.translation import ugettext as _ %>
<%page args="section_data"/>

<div class="vert-left send-email" id="section-send-email">
  <h2> ${_("Send Email")} </h2>
  <div class="request-response msg msg-confirm copy" id="request-response"></div>
  <ul class="list-fields">
    <li class="field">
      <label for="id_to">${_("Send to:")}</label><br/>
      <select id="id_to" name="send_to">
        <option value="myself">${_("Myself")}</option>
        %if to_option == "staff":
        <option value="staff" selected="selected">${_("Staff and instructors")}</option>
        %else:
        <option value="staff">${_("Staff and instructors")}</option>
          %endif
          %if to_option == "all":
            <option value="all" selected="selected">${_("All (students, staff and instructors)")}</option>
          %else:
      <option value="all">${_("All (students, staff and instructors)")}</option>
      %endif
      </select>
    </li>
  <br/>
  <li class="field">
    <label for="id_subject">${_("Subject: ")}</label><br/>
     %if subject:
      <input type="text" id="id_subject" name="subject" maxlength="128" size="75" value="${subject}">
     %else:
      <input type="text" id="id_subject" name="subject" maxlength="128" size="75">
     %endif
     <span class="tip">${_("(Max 128 characters)")}</span>
  </li>
  <li class="field">
    <label>${_("Message:")}</label>
      <div class="email-editor">
      ${ section_data['editor'] }
      </div>
    <input type="hidden" name="message" value="">
  </li>
  </ul>
 <div class="submit-email-action">
  <p class="copy">${_("Please try not to email students more than once per week. Before sending your email, consider:")}</p>
  <ul class="list-advice">
   <li class="item">${_("Have you read over the email to make sure it says everything you want to say?")}</li>
   <li class="item">${_("Have you sent the email to yourself first to make sure you're happy with how it's displayed, and that embedded links and images work properly?")}</li>
  </ul>
 </div>
 <div class="submit-email-warning">
   <p class="copy"><span style="color: red;"><b>${_("CAUTION!")}</b></span>
     ${_("Once the 'Send Email' button is clicked, your email will be queued for sending.")}
   <b>${_("A queued email CANNOT be cancelled.")}</b></p>
</div>
 <br />
  <input type="button" name="send" value="${_("Send Email")}" data-endpoint="${ section_data['send_email'] }" >
  <div class="request-response-error"></div>

%if settings.FEATURES.get('ENABLE_INSTRUCTOR_BACKGROUND_TASKS'):
  <div class="running-tasks-container action-type-container">
    <hr>
    <h2> ${_("Pending Instructor Tasks")} </h2>
    <div class="running-tasks-section">
      <p>${_("Email actions run in the background. The status for any active tasks - including email tasks - appears in a table below.")} </p>
      <br />

      <div class="running-tasks-table" data-endpoint="${ section_data['list_instructor_tasks_url'] }"></div>
    </div>
    <div class="no-pending-tasks-message"></div>
  </div>


<hr>

<div class="vert-left email-background" id="section-task-history">
  <h2> ${_("Email Task History")} </h2>
  <div>
    <p>${_("To see the content of all previously sent emails, click this button:")}</p>
    <br/>
    <input type="button" name="task-history-email-content" value="${_("Sent Email History")}" data-endpoint="${ section_data['email_content_history_url'] }" >
    <div class="content-request-response-error msg msg-warning copy"></div>
    <p>
    <div class="content-history-email-table">
      <p><em>${_("To read an email, click its subject.")}</em></p>
      <br/>
      <div class="content-history-table-inner"></div>
    </div>
    <div class="email-messages-wrapper"></div>
  </div>
  <div>
    <p>${_("To see the status for all bulk email tasks ever submitted for this course, click on this button:")}</p>
    <br/>
    <input type="button" name="task-history-email" value="${_("Show Email Task History")}" data-endpoint="${ section_data['email_background_tasks_url'] }" >
    <div class="history-request-response-error msg msg-warning copy"></div>
    <div class="task-history-email-table"></div>
  </div>
</div>
%endif

</div> <!-- end section send-email -->
