<%inherit file="/template.html" />
<%namespace name="components" file="/components.html"/>
<%def name="title()">${_("Send mass message")}</%def>

<%def name="massmessage_form()">
  <h3>${_('Send mass message')}</h3>

  ${_('Please note that users may not necessarily receive this message '
      'by email. The message will however show up in their dashboards.')}

  <form name="create_message" class="inplace" method="POST"
        action="${c.preview_url}">
      ${h.field_token()|n}

      <fieldset class="massmessage_filter">
        <legend>${_("Filter users ...")}</legend>
        <div>
        ${_('... by instance:')}<br/>
        <select name="filter_instances" multiple="multiple">
          %for instance in c.instances:
          <option value="${instance.id}">${instance.label}</option>
          %endfor
        </select>
        </div>
        %if c.userbadges:
        <div>
        ${_('... by badge:')}<br/>
        ${tiles.badge.badge_selector(c.userbadges, 'filter_badges')}
        </div>
        %endif
      </fieldset>

      <fieldset>
        <legend>${_("Subject")}</legend>
        <input name="subject" required="required" />
      </fieldset>

      <fieldset>
        <legend>${_("Body")}</legend>
        <textarea name="body" required="required"></textarea>
        <div>${_('Use {name} and {salutation} to address the user directly.')}</div>

        %if lib.auth.authorization.has('global.admin'):
          <label title="${_('Add a note about why the user got this message, and how to unsubscribe.') + u'\n' + _('Uncheck if user management is centralized.')}">
          <input type="checkbox" name="include_footer" /> ${_('Include footer')}
          </label>
        %else:
          ## Just for reference; this will be set to true anyways unless user gains
          ## global.admin privileges in between rendering this form and submission
          <input type="hidden" name="include_footer" checked="checked" />
        %endif
      </fieldset>

      <fieldset>
        <legend>${_('Sender identity')}</legend>
        <div class="input_wrapper">
          %for (key, value) in c.sender_options.iteritems():
          <label>
            <input type="radio" name="sender_email" value=${key} ${'checked="checked"' if value['checked'] else '' | n} ${'disabled="disabled"' if not value['enabled'] else '' | n} />${value['email']}
            %if not value['enabled']:
            <em>${value['reason']}</em>
            %endif
          </label>
          %endfor
        </div>

        %if lib.auth.authorization.has('global.message'):
          <label>
            ${_('Customize sender name: ')} <input type="text" name="sender_name" value="${c.user.name}" />
          </label>
        %endif

        <p class="help-block">${_("Please note that your e-mail address may be included in this message to give the recipient a method to reply to you.")}</p>
      </fieldset>

      <div class="mainbar">
          ${components.savebox(h.base_url("/"), save_text=_("Preview"))}
      </div>
  </form>
</%def>


<%block name="main_content">
  ${massmessage_form()}
</%block>
