<?python from mailarchive.util import *
?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude">
  <div id="mail_editor_${id}" class="mail_editor">
    <script type="text/javascript">
    jQuery(function(){
      $("#mail_send_${id}").click(function(){
        res = confirm("送信して良いですか？");
        if(res == true){
          from = $("#mail_field_from_${id}").text();
          subject = $("#mail_field_subject_${id}").val();
          to = $("#mail_field_to_${id}").val();
          cc = $("#mail_field_cc_${id}").val();
          related_tickets = $("#mail_field_related_tickets_${id}").val();
          addchange = $("#mail_field_addchange_box_${id}").attr('checked');
          comment = $("#mail_field_related_ticket_comment_${id}").val();
          
          body = $("#mail_field_body_${id}").val();

          $.ajax({
            type: "POST",
            url: "${req.href.ajaxmaileditor(mail.id)}",
            data: "__FORM_TOKEN=${req.form_token}&amp;action=send&amp;from=" + from + "&amp;to=" + to + "&amp;cc=" + cc + "&amp;subject="+ subject + "&amp;body=" + body + "&amp;related_tickets=" + related_tickets + "&amp;addchange=" + addchange + "&amp;comment=" + comment,
            dataType: "html",
            success: function (data) {
              $("#mail_send_msg_${id}").children().remove();
              $("#mail_send_msg_${id}").append(data).fadeIn(200);
              $("#mail_close_${id}").show();
              $("#mail_editor_body_${id}").fadeOut(200);
            },
            error: function (data) {
              $("#mail_send_msg_${id}").children().remove();
              $("#mail_send_msg_${id}").append("<div>メール送信に失敗しました。</div>").fadeIn(200);
              $("#mail_buttons_${id}").show();
            },
            beforeSend: function() {
              $("#mail_buttons_${id}").hide();
              $("#loading_${id}").show();
            },
            complete: function() {
              $("#loading_${id}").hide();
            }
          });
        }
      });
      $("#mail_drop_${id}").click(function(){
        res = confirm("破棄して良いですか？");
        if(res == true){
          $("#mail_editor_${id}").remove();
        }
      });
      $("#mail_close_${id}").click(function(){
        $("#mail_editor_${id}").remove();
      });
    });
    </script>
    <div>
      <div id="mail_send_msg_${id}" style="display:none; color:#550000; background:#FFFFAA none repeat scroll 0 0; border:2px solid #888866;"></div>
    </div>
    <div align="right">
      <input id="mail_close_${id}" type="button" class="thread_from" style="display:none;" value="閉じる" />
    </div>
    <fieldset id="mail_editor_body_${id}">
      <legend>メール作成</legend>
      <div>
        <div style="float:right; position:relative;">
          <div id="mail_buttons_${id}">
            <input id="mail_send_${id}" type="button" class="thread_from" value="送信" />
            <input id="mail_drop_${id}" type="button" class="thread_from" value="破棄" />
          </div>
          <div id="loading_${id}" class="mail_loading" style="display:none;">&nbsp;</div>
        </div>
        <table>
          <tbody>
            <tr>
              <td class="thread_from">差出人:</td>
              <td id="mail_field_from_${id}" class="thread_from">${from_email}</td>
            </tr>
            <tr>
              <td class="thread_from">送信先:</td>
              <td><input id="mail_field_to_${id}" type="text" size="70" value="${mail.fromaddr}" class="thread_from" /></td>
            </tr>
            <tr>
              <td class="thread_from">Cc:</td>
              <td><input id="mail_field_cc_${id}" type="text" size="70" value="${', '.join([x[1] for x in mail.get_reply_ccs()])}" class="thread_from" /></td>
            </tr>
            <tr>
              <td class="thread_from">件名:</td>
              <td>
                <py:choose>
                  <py:when test="mail.subject.startswith('﻿Re:')">
                    <input id="mail_field_subject_${id}" type="text" size="70" value="${mail.subject}" class="thread_from" />
                  </py:when>
                  <py:otherwise test="">
                    <input id="mail_field_subject_${id}" type="text" size="70" value="Re: ${mail.subject}" class="thread_from" />
                  </py:otherwise>
                </py:choose>
              </td>
            </tr>
            <tr>
              <td class="thread_from">関連チケット:</td>
              <td>
                <input id="mail_field_related_tickets_${id}" type="text" size="20" value="${', '.join(related_tickets)}" class="thread_from" />
                <input id="mail_field_addchange_box_${id}" type="checkbox" checked="checked" value="addchange"/><span class="thread_from">関連チケットにメール送信を記録する</span>
              </td>
            </tr>
            <tr>
              <td class="thread_from">コメント:</td>
              <td>
                <input id="mail_field_related_ticket_comment_${id}" type="text" size="70" value="" class="thread_from" />
              </td>
            </tr>
          </tbody>
        </table>
        <div py:if="len(template_mails) > 0">
          <span class="thread_from">テンプレート:</span>
          <input type="button" py:for="tm in template_mails" class="thread_from mail_template_button" value="${tm[0]}" onclick="insertReplyTemplate('#mail_field_body_${id}', '${tm[1]}', '#mail_field_related_ticket_comment_${id}', '${tm[2]}')" />
        </div>
        <textarea id="mail_field_body_${id}" class="mail_reply_body_${mail.id}" wrap="soft" rows="14" style="width: 100%;">
${template_mail}

${quote_mail}
        </textarea>
      </div>
    </fieldset>
  </div>
</html>
