<%doc>
USAGE DOCUMENTATION :: PLEASE LEAVE THIS AT THE TOP OF THIS FILE

For Mako templating syntax documentation please visit: http://docs.makotemplates.org/en/latest/

Filename:           newsletters_table.html
Version:            0.1

DOCUMENTATION :: END
</%doc>

<% from plexpy.newsletter_handler import NEWSLETTER_SCHED %>
<ul class="stacked-configs list-unstyled">
    % for newsletter in sorted(newsletters_list, key=lambda k: (k['agent_label'], k['friendly_name'], k['id'])):
    <li class="newsletter-agent" data-id="${newsletter['id']}">
        <span>
            <span class="toggle-left trigger-tooltip ${'active' if newsletter['active'] else ''}" data-toggle="tooltip" data-placement="top" title="Newsletter ${'active' if newsletter['active'] else 'inactive'}"><i class="fa fa-lg fa-newspaper-o"></i></span>
            % if newsletter['friendly_name']:
            ${newsletter['agent_label']} &nbsp;<span class="friendly_name">(${newsletter['id']} - ${newsletter['friendly_name']})</span>
            % else:
            ${newsletter['agent_label']} &nbsp;<span class="friendly_name">(${newsletter['id']})</span>
            % endif
            <span class="toggle-right"><i class="fa fa-lg fa-cog"></i></span>
            <span class="toggle-right friendly_name" id="newsletter-next_run-${newsletter['id']}">
                % if NEWSLETTER_SCHED.get_job('newsletter-{}'.format(newsletter['id'])):
                <% job = NEWSLETTER_SCHED.get_job('newsletter-{}'.format(newsletter['id'])) %>
                <script>
                    $("#newsletter-next_run-${newsletter['id']}").text(moment("${job.next_run_time}", "YYYY-MM-DD HH:mm:ssZ").fromNow())
                </script>
                % endif
            </span>
        </span>
    </li>
    % endfor
    <li class="add-newsletter-agent" id="add-newsletter-agent" data-target="#add-newsletter-modal" data-toggle="modal">
        <span>
            <span class="toggle-left"><i class="fa fa-lg fa-newspaper-o"></i></span> Add a new newsletter agent
            <span class="toggle-right"><i class="fa fa-lg fa-plus"></i></span>
        </span>
    </li>
</ul>

<script>
    // Load newsletter config modal
    $(".newsletter-agent").click(function () {
        var newsletter_id = $(this).data('id');
        loadNewsletterConfig(newsletter_id);
    });

    $('.trigger-tooltip').tooltip();
</script>