Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
add 403 to app dashboard, bug fixes to thread create
Browse files Browse the repository at this point in the history
  • Loading branch information
ngokevin committed Feb 25, 2014
1 parent 108c601 commit 53a70ba
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/media/css/comm.styl
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ tick() {
}
a.selected {
border-radius: 3px;
box-shadow: 0px 4px 5px darken($faint-gray, 10%) inset;
box-shadow: 0 0 2px 1px darken($faint-gray, 10%);
color: #666;
}
li {
Expand Down
29 changes: 18 additions & 11 deletions src/media/js/views/comm.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,22 @@ define('views/comm',

// Send attachment with XHR2.
var formData = new FormData();
var hasInput;
$attachments.each(function(i, attachment) {
var $attachment = $(attachment);
if ($('[type="file"]', $attachment).val() != '') {
hasInput = true;
}
formData.append('form-' + i + '-attachment', $attachment.find('.realfileinput').get(0).files[0]);
formData.append('form-' + i + '-description', $attachment.find('.attach-description input').val());
});
if (!hasInput) {
return;
}

var xhr = new XMLHttpRequest();
xhr.onload = function() {
// Add attachment response to note.
var data = JSON.parse(this.responseText);
var $attachmentList = $('.note-detail[data-note-id="' + note_id + '"] .note-attachments');

Expand All @@ -99,6 +107,10 @@ define('views/comm',
};
xhr.open('POST', attachUrl);
xhr.send(formData);

// Clear input.
$thread.find('.attachment-field:first-child input').val('');
$thread.find('.attachment-field:not(:first-child)').remove();
};

z.page.on('click', '.reply.button.open-reply', function(e) {
Expand Down Expand Up @@ -126,33 +138,28 @@ define('views/comm',
var $this = $(this);
$this.siblings('button.post').toggleClass('disabled', !$this.val().length);

}).on('click', 'button.post:not(.create-thread)', function(e) {
}).on('click', 'button.post', function(e) {
// Post the note.
var $this = $(this);
var replyBox = $this.closest('.thread-header').find('.reply-box').addClass('hidden');
if (postNoteEnabled) {
postNote($this.siblings('.reply-text')).done(function(note) {
postNote($this.siblings('.reply-text'), $this.hasClass('create-thread')).done(function(note) {
replyBox.val('');
postAttachments($this.closest('.thread-item'), note.id);
});
}

}).on('click', 'button.post.create-thread', function(e) {
// Create thread (i.e. posting to a thread with 0 notes.).
var replyBox = $(this).closest('.thread-header').find('.reply-box').addClass('hidden');
if (postNoteEnabled) {
postNote($(this).siblings('.reply-text'), true).done(function() {
replyBox.val('');
});
}

}).on('click', '.notes-filter', function(e) {
var $this = $(this);
var $threadItem = $this.closest('.thread-item');
var threadId = $threadItem.data('thread-id');
var filterMode = $this.data('filter-mode');
var params = {ordering: '-created', limit: 5};

if (!threadId) {
return;
}

$threadItem.data('notes-filter', filterMode);
$threadItem.data('notes-page', 1);

Expand Down
8 changes: 5 additions & 3 deletions src/templates/_macros/thread_header.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ <h3 class="note-count" data-count="{{ thread.notes_count }}">
{% if thread %}
<li><a href="#show-unread-{{ thread.id }}" class="notes-filter filter-unread" data-filter-mode="unread">{{ _('Unread') }}</a></li>
<li><a href="#show-read-{{ thread.id }}" class="notes-filter filter-read" data-filter-mode="read">{{ _('Read') }}</a></li>
{% if user and user.get_permission('reviewer') %}
<li><a class="review-link" href="{{ thread.addon_meta.review_url }}">{{ _('Review') }}</a></li>
{% endif %}
{% endif %}
{% if user and user.get_permission('reviewer') %}
<li><a class="review-link" href="{{ thread.addon_meta.review_url }}">{{ _('Review') }}</a></li>
{% endif %}
{% if thread %}
<li><b title="{{ _('Mark All Read') }}" class="mark-thread-read tick"></b></li>
{% endif %}
</ul>
Expand Down
12 changes: 10 additions & 2 deletions src/templates/comm/app_dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,21 @@ <h1>{{ _('App Not Found') }}</h1>
{% else %}
{% defer (url=app_endpoint) %}
{# Show create thread widget for most recent version. #}
{{ create_thread(this, max.apply(Math, this.versions.keys())) }}
{% for version in this.versions.keys() %}
{{ create_thread(this, version) }}
{% endfor %}
{% end %}
{% endif %}

{% placeholder %}
<div class="spinner alt"></div>
{% except %}
<p>{{ _('Error loading threads') }}</p>
{% if error == 403 %}
<p>{{ _("You are not allowed to access this app's threads.") }}</p>
{% else %}
<p>{{ _('Error loading threads') }}</p>
{% endif %}
{% end %}

{% include '_includes/attachment_field.html' %}
</section>

0 comments on commit 53a70ba

Please sign in to comment.