{% import 'allura:templates/jinja_master/lib.html' as lib with context %}

<div>
  <div id="{{value.slug}}" class="discussion-post">
    <div class="row">
      <div class="grid-2 tcenter">
       <p class="gravatar">
        {% set size = value.parent and 32 or 48 %}
        {{lib.gravatar(value.author(), size=size)}}<br>
        <small><a href="{{value.author().url()}}">{{value.author().display_name}}</a></small>
        <br>
        <small>{{lib.abbr_date(value.timestamp)}}</small>
       </p>
      </div>

      <div class="grid-14" style="width: {{indent == 0 and 525 or (indent <= 40 and 515-indent*10 or 65)}}px">
        <div class="display_post">
          {% if show_subject %}
            <b>{{value.subject or '(no subject)'}}<br/></b>
          {% endif %}
          {{g.markdown.convert(value.text)|safe}}&nbsp;
          {{lib.related_artifacts(value)}}
          {% if value.edit_count %}
            <br><small>Last edit: {{value.last_edit_by().display_name}} {{h.ago(value.last_edit_date)}}</small>
          {% endif %}
        </div>
        {% if h.has_access(value.thread, 'post')() %}
        <div class="edit_post_form reply" style="display:none">
            {{widgets.edit_post.display(value=value, submit_text='Save', action=value.url())}}
        </div>
        {% endif %}
        {% if h.has_access(value, 'moderate')() %}
        <div class="add_attachment_form" style="display:none; clear: both; overflow: auto;">
            {{widgets.attach_post.display(value=value, action=value.url() + 'attach')}}
        </div>
        {% endif %}
        {% if value.attachments %}
        <div>
          <strong>Attachments</strong>
          <div class="clear"></div>
          {% for att in value.attachments %}
            <div class="attachment_thumb" style="min-height: 130px;">
              {% if att.is_image() %}
                <a href="{{att.url()}}"><img src="{{att.url()}}/thumb"/></a>
                <br/>
                <a href="{{att.url()}}">{{att.filename}}</a>
              {% else %}
                <a href="{{att.url()}}">{{att.filename}}</a>
              {% endif %}
              {% if c.user._id and value.author_id==c.user._id %}
              <br>
              <form method="POST" action="{{att.url()}}">
                <input class="submit delete_attachment" type="submit" name="delete" value="X"/>
              </form>
              {% endif %}
            </div>
          {% endfor %}
        </div>
        {% endif %}
        </div>
        
        <div class="options grid-3">
        <a href="" class="reply_post btn"><b data-icon="{{g.icons['reply'].char}}" class="ico {{g.icons['reply'].css}}"></b>Reply</a>
        <div style="clear:both">
          <a href="{{tg.url(url.current(),dict(page=page,limit=limit))}}#{{value.slug}}" class="little_link shortlink"><span>Link</span></a><br/>
          {% if c.user != c.user.anonymous() %}<a href="" class="edit_post little_link"><span>Edit</span></a><br/>{% endif %}
          {% if h.has_access(value, 'moderate')() %}
            {{widgets.moderate_post.display(value=value, action=value.url()+'moderate')}}
          {% endif %}
          {% if h.has_access(value.thread, 'post')() %}
            <a href="#" class="add_attachment little_link"><span>Attach</span></a>
          {% endif %}
        </div>
      </div>
      <div class="shortlink_popup modal" style="display: none">
        <b data-icon="{{g.icons['close'].char}}" class="ico {{g.icons['close'].css}} close"></b>
        If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
        <input type="text" style="width:100%"
          value='{% filter forceescape %}<a href="{{tg.url(url.current(),dict(page=page,limit=limit))}}#{{value.slug}}">{{value.subject or "comment"}}</a>{% endfilter %}'>
      </div>
    </div>
    <ul>
      <li>
        {% if h.has_access(value.thread, 'post')() %}
        <div class="row reply_post_form" style="display:none">
          <div class="reply">
            <div class="grid-2 tcenter">
              <p class="gravatar">
                {{lib.gravatar(c.user, size=32)}}<br>
                <small><a href="{{c.user.url()}}">{{c.user.display_name}}</a></small>
              </p>
            </div>
            <div class="grid-14" style="width: {{indent <= 40 and 625-indent*10 or 225}}px">
              {{widgets.edit_post.display(
                submit_text='Post Reply',
                action=value.url()+'reply',
                value=dict(
                text='',
                subject=value.reply_subject()),
              )}}
            </div>
          </div>
        </div>
        {% endif %}
      </li>
    </ul>
  </div>

  {% if h.has_access(value.thread, 'moderate')() and 'promote_to_thread' in widgets and not supress_promote %}
  <div class="promote_to_thread_form push-{{3+indent}} span-{{16-indent}} last clear" style="display:none">
    {{widgets.promote_to_thread.display(value=value, action=value.url()+'moderate')}}
  </div>
  {% endif %}
</div>
