Status form in book page

This commit is contained in:
Mouse Reeve 2020-09-29 11:48:03 -07:00
parent 61fa15a0c2
commit dbc6fb1d18
3 changed files with 52 additions and 39 deletions

View file

@ -32,18 +32,9 @@ function rate_stars(e) {
} }
function tabChange(e) { function tabChange(e) {
e.preventDefault(); var target = e.target.parentElement.parentElement;
var target = e.target.parentElement;
var identifier = target.getAttribute('data-id'); var identifier = target.getAttribute('data-id');
var options_class = target.getAttribute('data-category');
var options = document.getElementsByClassName(options_class);
for (var i = 0; i < options.length; i++) {
if (!options[i].className.includes('hidden')) {
options[i].className += ' hidden';
}
}
var tabs = target.parentElement.children; var tabs = target.parentElement.children;
for (i = 0; i < tabs.length; i++) { for (i = 0; i < tabs.length; i++) {
if (tabs[i].getAttribute('data-id') == identifier) { if (tabs[i].getAttribute('data-id') == identifier) {
@ -54,7 +45,6 @@ function tabChange(e) {
} }
var el = document.getElementById(identifier); var el = document.getElementById(identifier);
el.className = el.className.replace('hidden', '');
} }
function ajaxPost(form) { function ajaxPost(form) {

View file

@ -4,13 +4,13 @@
<div class="tabs is-boxed"> <div class="tabs is-boxed">
<ul> <ul>
<li class="is-active" data-id="tab-review-{{ book.id }}" data-category="tab-option-{{ book.id }}"> <li class="is-active" data-id="tab-review-{{ book.id }}" data-category="tab-option-{{ book.id }}">
<a href="/book/{{ book.id }}/review" onclick="tabChange(event)">Review</a> <label for="review-{{ book.id }}" onclick="tabChange(event)"><a>Review</a></label>
</li> </li>
<li data-id="tab-comment-{{ book.id }}" data-category="tab-option-{{ book.id }}"> <li data-id="tab-comment-{{ book.id }}" data-category="tab-option-{{ book.id }}">
<a href="/book/{{ book.id }}/comment" onclick="tabChange(event)">Comment</a> <label for="comment-{{ book.id}}" onclick="tabChange(event)"><a>Comment</a></label>
</li> </li>
<li data-id="tab-quotation-{{ book.id }}" data-category="tab-option-{{ book.id }}"> <li data-id="tab-quotation-{{ book.id }}" data-category="tab-option-{{ book.id }}">
<a href="/book/{{ book.id }}/quotation" onclick="tabChange(event)">Quote</a> <label for="quote-{{ book.id }}" onclick="tabChange(event)"><a>Quote</a></label>
</li> </li>
</ul> </ul>
</div> </div>
@ -22,32 +22,53 @@
</div> </div>
{% endif %} {% endif %}
<form class="tab-option-{{ book.id }} column" name="review" action="/review/" method="post" id="tab-review-{{ book.id }}"> <div class="column">
{% csrf_token %} <div>
<input type="hidden" name="book" value="{{ book.id }}"> <input class="toggle-control" type="radio" name="status-tabs" id="review-{{ book.id }}" checked>
<div class="control"> <form class="toggle-content hidden tab-option-{{ book.id }}" name="review" action="/review/" method="post" id="tab-review-{{ book.id }}">
<label class="label" for="id_name">Title:</label> {% csrf_token %}
{{ review_form.name }} <input type="hidden" name="book" value="{{ book.id }}">
<div class="control">
<label class="label" for="id_name">Title:</label>
{{ review_form.name }}
</div>
<div class="control">
<label class="label" for="id_content">Review:</label>
{% include 'snippets/rate_form.html' with book=book %}
{{ review_form.content }}
</div>
<button class="button is-primary" type="submit">post review</button>
</form>
</div> </div>
<div class="control">
<label class="label" for="id_content">Review:</label> <div>
{% include 'snippets/rate_form.html' with book=book %} <input class="toggle-control" type="radio" name="status-tabs" id="comment-{{ book.id }}">
{{ review_form.content }} <form class="toggle-content hidden tab-option-{{ book.id }}" name="comment" action="/comment/" method="post" id="tab-comment-{{ book.id }}">
{% csrf_token %}
<input type="hidden" name="book" value="{{ book.id }}">
<div class="control">
<label class="label" for="id_content">Comment:</label>
{{ comment_form.content }}
</div>
<button class="button is-primary" type="submit">post comment</button>
</form>
</div> </div>
<button class="button is-primary" type="submit">post review</button>
</form>
<form class="hidden tab-option-{{ book.id }} column" name="comment" action="/comment/" method="post" id="tab-comment-{{ book.id }}"> <div>
{% csrf_token %} <input class="toggle-control" type="radio" name="status-tabs" id="quote-{{ book.id }}">
<input type="hidden" name="book" value="{{ book.id }}"> <form class="toggle-content hidden tab-option-{{ book.id }}" name="quotation" action="/quotate/" method="post" id="tab-quotation-{{ book.id }}">
{{ comment_form.as_p }} {% csrf_token %}
<button class="button is-primary" type="submit">post comment</button> <input type="hidden" name="book" value="{{ book.id }}">
</form> <div class="control">
<label class="label" for="id_quote">Quote:</label>
<form class="hidden tab-option-{{ book.id }} column" name="quotation" action="/quotate/" method="post" id="tab-quotation-{{ book.id }}"> {{ quotation_form.quote }}
{% csrf_token %} </div>
<input type="hidden" name="book" value="{{ book.id }}"> <div class="control">
{{ quotation_form.as_p }} <label class="label" for="id_content">Comment:</label>
<button class="button is-primary" type="submit">post quote</button> {{ quotation_form.content }}
</form> </div>
<button class="button is-primary" type="submit">post quote</button>
</form>
</div>
</div>
</div> </div>

View file

@ -467,6 +467,8 @@ def book_page(request, book_id, tab='friends'):
'tags': tags, 'tags': tags,
'user_tags': user_tags, 'user_tags': user_tags,
'review_form': forms.ReviewForm(), 'review_form': forms.ReviewForm(),
'quotation_form': forms.QuotationForm(),
'comment_form': forms.CommentForm(),
'tag_form': forms.TagForm(), 'tag_form': forms.TagForm(),
'feed_tabs': [ 'feed_tabs': [
{'id': 'friends', 'display': 'Friends'}, {'id': 'friends', 'display': 'Friends'},