<%page args="section_data" expression_filter="h"/>
<%!
from django.utils.translation import ugettext as _
from openedx.core.djangolib.markup import HTML
%>

<div class="vert-left send-email" id="section-send-email">
    <div class="request-response msg msg-confirm copy" id="request-response"></div>
    <ul class="list-fields">
        <li class="field">
            <div class="send_to_list">${_("Send to:")}</div>
        </li>
        <li class="field">
        <fieldset>
            <legend class="sr">${_("Send to:")}</legend>
            <ul role="group" class="email-targets-primary">
                <li>
                    <input type="checkbox" name="send_to" value="myself" id="target_myself">
                    <label for="target_myself">${_("Myself")}</label>
                </li>
                <li>
                    <input type="checkbox" name="send_to" value="staff" id="target_staff">
                    <label for="target_staff">${_("Staff and Administrators")}</label>
                </li>
                <li>
                    <input type="checkbox" name="send_to" value="learners" id="target_learners">
                    <label for="target_learners">${_("All Learners")}</label>
                </li>
            </ul>
            %if len(section_data['cohorts']) > 0:
            <ul role="group" class="email-targets-secondary">
                %for cohort in section_data['cohorts']:
                <li>
                    <input type="checkbox" name="send_to" value="cohort:${cohort.name}" id="target_cohort_${cohort.id}">
                    <label for="target_cohort_${cohort.id}">
                        ${_("Cohort: ") + cohort.name}
                        %if cohort.name == section_data['default_cohort_name']:
                        <br/>
                        <div class="subheading">
                            ${_("(Learners not explicitly assigned to a cohort)")}
                        </div>
                        %endif
                    </label>
                </li>
                %endfor
            </ul>
            %endif
        </fieldset>
        </li>
        <li class="field">
            <label>
                ${_("Subject: ")}
                <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">${_("(Maximum 128 characters)")}</span>
            </label>
        </li>
        <li>
            <label>
                ${_("Message:")}
                <div class="email-editor">
                    ${ HTML(section_data['editor']) }
                </div>
                <input type="hidden" name="message" value="">
            </label>
        </li>
    </ul>
    <div class="submit-email-action">
        <p class="copy">${_("We recommend sending learners no more than one email message per week. Before you send your email, review the text carefully and send it to yourself first, so that you can preview the formatting and make sure embedded images and links work correctly.")}</p>
    </div>
    <div class="submit-email-warning">
        <p class="copy"><span style="color: red;"><b>${_("CAUTION!")}</b></span>
        ${_("When you select Send Email, your email message is added to the queue for sending, and cannot be cancelled.")}
        </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>
        <h3 class="hd hd-3">${_("Pending Tasks")}</h3>
        <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">
        <h3 class="hd hd-3">${_("Email Task History")}</h3>
        <div>
            <p>${_("To see the content of previously sent emails, click this button:")}</p>
            <br/>
            <input type="button" name="task-history-email-content" value="${_("Show 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 a sent email message, 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 email tasks submitted for this course, click 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 -->
