2022-12-23 00:08:42 -05:00
{% load static %}
{% load i18n %}
{% load l10n %}
{% load humanize %}
{% load mastodon %}
{% load thumb %}
2023-06-09 02:45:27 -04:00
{% load duration %}
< dialog open
2024-01-20 22:52:08 -05:00
class="mark-editor"
2023-06-09 02:45:27 -04:00
_="on close_dialog add .closing then wait for animationend then remove me">
< article >
< header >
< link to = "#"
aria-label="Close"
class="close"
_="on click trigger close_dialog" />
2024-05-20 23:17:47 -04:00
< strong > {% trans "Mark" %} - {{ item.title }}< / strong >
2023-06-09 02:45:27 -04:00
< / header >
2024-01-20 22:52:08 -05:00
< div >
2023-06-09 02:45:27 -04:00
< form method = "post" action = "{% url 'journal:mark' item.uuid %}" >
2023-05-20 11:01:18 -04:00
{% csrf_token %}
2024-05-29 10:50:41 -04:00
{% if shelf_statuses %}
< input type = "hidden" id = "mark-status" name = "status" value = "{{ shelf_type }}" >
2023-06-16 17:47:22 -04:00
< div class = "grid mark-line" >
< div >
2024-05-29 10:50:41 -04:00
< div role = "group" >
{% for k, v in shelf_statuses %}
2023-06-16 17:47:22 -04:00
{% if v %}
2024-05-29 10:50:41 -04:00
< button data-value = "{{ k }}"
id="id_status_{{ k }}"
style="padding-left:0.1em;
padding-right:0.1em;
width:25%;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden"
2024-06-10 17:28:20 -04:00
{% if k == "wishlist" %} _="on click add .outline to .status-selector then remove .outline from me then set value of #mark-status to '{{ k }}' then add .hidden to .rating-editor then halt" {% else %} _="on click add .outline to .status-selector then remove .outline from me then set value of #mark-status to '{{ k }}' then remove .hidden from .rating-editor then halt" {% endif %}
2024-05-29 10:50:41 -04:00
{% if shelf_type == k %}class="status-selector"{% else %}class="status-selector outline"{% endif %}>
{{ v }}
< / button >
2023-06-16 17:47:22 -04:00
{% endif %}
{% endfor %}
2024-05-29 10:50:41 -04:00
< / div >
2023-06-16 17:47:22 -04:00
< / div >
< div >
2023-07-25 16:55:15 -04:00
< span class = "rating-editor {% if shelf_type == 'wishlist' %}hidden{% endif %}" _ = "on mousemove ( currentTarget , offsetX ) set current_value to Math . round ( ( 10 * offsetX ) / currentTarget . offsetWidth ) if current_value < = 10 then set star_div to the
2023-06-16 17:47:22 -04:00
< div / >
2024-05-20 23:17:47 -04:00
in me set star_div.style.width to (current_value * 10) + '%' set @data-tooltip to current_value or '{% trans "not rated" %}' add .yellow to star_div end on click(currentTarget, offsetX) set current_value to Math.round((10 * offsetX) / currentTarget.offsetWidth) if current_value < =10 then set star_div to the
2023-06-16 17:47:22 -04:00
< div / >
in me set star_input to the
< input / >
2024-05-20 23:17:47 -04:00
in me set star_div.style.width to (current_value * 10) + '%' set @data-tooltip to current_value or '{% trans "not rated" %}' set star_input.value to current_value end on mouseleave(currentTarget) set star_div to the
2023-06-16 17:47:22 -04:00
< div / >
in me set star_input to the
< input / >
2024-05-20 23:17:47 -04:00
in me set current_value to star_input.value set star_div.style.width to (current_value * 10) + '%' set @data-tooltip to current_value or '{% trans "not rated" %}' end">
2023-06-16 17:47:22 -04:00
{{ mark.rating_grade|rating_star }}
< input type = "hidden"
name="rating_grade"
id="id_rating"
value="{{ mark.rating_grade | default:0 }}">
< / span >
< / div >
2023-06-09 02:45:27 -04:00
< / div >
2023-06-16 17:47:22 -04:00
{% endif %}
2023-06-09 02:45:27 -04:00
< div >
< fieldset >
< textarea name = "text"
rows="5"
autofocus
2024-05-20 23:17:47 -04:00
placeholder="{% trans "Tips: use > !text!< for spoilers; some instances may not be able to show posts longer than 360 charactors." %}"
2023-06-09 02:45:27 -04:00
id="id_text">{{ mark.comment_text|default:"" }}< / textarea >
< / fieldset >
2022-12-23 00:08:42 -05:00
< / div >
2024-01-20 22:52:08 -05:00
< div >
2023-05-20 11:01:18 -04:00
< div class = "tag-input" >
2023-06-09 14:47:12 -04:00
< input name = "tags"
type="text"
2024-05-20 23:17:47 -04:00
placeholder="{% trans "add a tag and press Enter" %}"
2023-06-09 14:47:12 -04:00
id="tags_input"
data-initial-value="{{ tags }}">
2023-05-20 11:01:18 -04:00
< / div >
2022-12-23 00:08:42 -05:00
< / div >
2024-05-29 10:50:41 -04:00
< div class = "grid" style = "overflow-x:scroll;" >
2023-06-09 02:45:27 -04:00
< div >
< fieldset >
< input type = "radio"
name="visibility"
value="0"
required
id="id_visibility_0"
{% if mark.visibility == 0 %}checked{% endif %}>
2024-05-20 23:17:47 -04:00
< label for = "id_visibility_0" > {% trans "Public" %}< / label >
2023-06-09 02:45:27 -04:00
< input type = "radio"
name="visibility"
value="1"
required
id="id_visibility_1"
{% if mark.visibility == 1 %}checked{% endif %}>
2024-05-20 23:17:47 -04:00
< label for = "id_visibility_1" > {% trans "Followers Only" %}< / label >
2023-06-09 02:45:27 -04:00
< input type = "radio"
name="visibility"
value="2"
required
id="id_visibility_2"
{% if mark.visibility == 2 %}checked{% endif %}>
2024-05-20 23:17:47 -04:00
< label for = "id_visibility_2" > {% trans "Mentioned Only" %}< / label >
2023-06-09 02:45:27 -04:00
< / fieldset >
2023-05-20 11:01:18 -04:00
< / div >
2023-06-09 02:45:27 -04:00
< div >
< fieldset >
2023-12-10 19:14:32 -05:00
{% if request.user.mastodon_acct %}
< label for = "id_share_to_mastodon" >
< input role = "switch"
type="checkbox"
name="share_to_mastodon"
id="id_share_to_mastodon"
value="1"
{% if request.user.preference.mastodon_default_repost %}checked{% endif %}>
2024-06-16 21:54:20 -04:00
{% trans "Crosspost to timeline" %}
2023-12-10 19:14:32 -05:00
< / label >
{% endif %}
2023-06-09 02:45:27 -04:00
< / fieldset >
< / div >
< / div >
< div class = "grid" >
< div >
< div >
< input role = "switch"
_="on click toggle .invisible on #mark_date "
type="checkbox"
name="mark_anotherday"
value="1"
id="mark_anotherday">
2024-05-20 23:17:47 -04:00
< label for = "mark_anotherday" > {% trans "change mark date" %}< / label >
2023-06-09 02:45:27 -04:00
< input class = "invisible"
type="date"
2023-05-20 11:01:18 -04:00
name="mark_date"
id="mark_date"
min="1900-01-01"
max="{{ date_today }}"
2023-06-09 02:45:27 -04:00
value="{{ date_today }}">
< / div >
< / div >
< div >
< fieldset >
2024-05-20 23:17:47 -04:00
< input type = "submit" value = "{% trans " Save " % } " >
2023-06-09 02:45:27 -04:00
< / fieldset >
2023-05-20 11:01:18 -04:00
< / div >
< / div >
< / form >
2023-06-09 02:45:27 -04:00
< div >
{% if mark.id %}
< form id = "mark_delete"
action="{% url 'journal:mark' mark.item.uuid %}"
method="post">
{% csrf_token %}
< input type = "hidden" name = "delete" value = "1" >
< a >
2024-05-20 23:17:47 -04:00
< button class = "secondary"
onclick="return confirm('{% trans "Sure to delete mark, comment and tags for this item?" %}')">
{% trans "Delete" %}
< / button >
2023-06-09 02:45:27 -04:00
< / a >
< / form >
{% endif %}
< / div >
2023-05-20 11:01:18 -04:00
< / div >
2023-06-09 02:45:27 -04:00
< / article >
< / dialog >
2023-05-20 11:01:18 -04:00
< script >
2023-06-09 02:45:27 -04:00
function inputTags(configs) {
2023-05-21 09:41:51 -04:00
2023-06-09 02:45:27 -04:00
let tagsContainer = configs.container,
input = configs.container.querySelector('input')
2023-05-21 09:41:51 -04:00
2023-06-09 02:45:27 -04:00
let _privateMethods = {
2023-05-21 09:41:51 -04:00
2023-06-09 02:45:27 -04:00
init: function (configs) {
2023-05-21 09:41:51 -04:00
2023-06-09 02:45:27 -04:00
// this.inspectConfigProperties(configs);
2023-05-21 09:41:51 -04:00
2023-06-09 02:45:27 -04:00
let self = this,
input_hidden = document.createElement('input');
let name = input.getAttribute('name'),
id = input.getAttribute('id');
input.removeAttribute('name');
// input.removeAttribute('id');
input_hidden.setAttribute('type', 'hidden');
// input_hidden.setAttribute('id', id);
input_hidden.setAttribute('name', name);
input.parentNode.insertBefore(input_hidden, input);
this.input_hidden = input_hidden
tagsContainer.addEventListener('click', function () {
input.focus();
});
2023-05-21 09:41:51 -04:00
2023-06-09 02:45:27 -04:00
if (configs.tags) {
for (let i = 0; i < configs.tags.length ; i + + ) {
if (configs.tags[i]) {
this.create(configs.tags[i]);
}
2023-05-21 09:41:51 -04:00
}
}
2023-06-09 02:45:27 -04:00
input.addEventListener("focusout", function () {
2023-05-21 09:41:51 -04:00
2023-06-09 02:45:27 -04:00
let tag_txt = this.value.trim(),
tag_exists = false;
2023-05-21 09:41:51 -04:00
2023-06-09 02:45:27 -04:00
if (self.tags_array) {
tag_exists = Boolean(self.tags_array.indexOf(tag_txt) + 1);
}
2023-05-21 09:41:51 -04:00
2023-06-09 02:45:27 -04:00
if (tag_txt & & tag_exists & & !configs.allowDuplicateTags) {
self.showDuplicate(tag_txt);
}
else if (tag_txt & & tag_exists & & configs.allowDuplicateTags) {
self.create(tag_txt);
}
else if (tag_txt & & !tag_exists) {
self.create(tag_txt);
}
this.value = "";
2023-05-21 09:41:51 -04:00
2023-06-09 02:45:27 -04:00
});
2023-05-21 09:41:51 -04:00
2023-06-09 02:45:27 -04:00
input.addEventListener('keydown', function (ev) {
2023-05-21 09:41:51 -04:00
2023-06-09 02:45:27 -04:00
if (ev.keyCode === 13 || ev.keyCode === 188 ||
(ev.keyCode === 32 & & configs.allowDuplicateTags)) { // enter || comma || space
let event = new Event('focusout');
input.dispatchEvent(event);
ev.preventDefault();
2023-05-21 09:41:51 -04:00
}
2023-06-09 02:45:27 -04:00
else if (event.which === 8 & & !input.value) { // backspace
let tag_nodes = document.querySelectorAll('.tag-input__tag');
if (tag_nodes.length > 0) {
input.addEventListener('keyup', function (event) {
if (event.which === 8) {
let node_to_del = tag_nodes[tag_nodes.length - 1];
node_to_del.remove();
self.update();
}
});
}
ev.preventDefault();
}
});
},
2023-05-21 09:41:51 -04:00
2023-06-09 02:45:27 -04:00
create: function (tag_txt) {
2023-05-21 09:41:51 -04:00
2023-06-09 02:45:27 -04:00
let tag_nodes = document.querySelectorAll('.tag-input__tag');
2023-05-21 09:41:51 -04:00
2023-06-09 02:45:27 -04:00
if (!configs.maxTags || tag_nodes.length < configs.maxTags ) {
let self = this,
span_tag = document.createElement('span'),
input_hidden_field = self.input_hidden;
2023-05-21 09:41:51 -04:00
2023-06-09 02:45:27 -04:00
span_tag.setAttribute('class', 'tag-input__tag');
span_tag.innerText = tag_txt;
2023-05-21 09:41:51 -04:00
2023-06-09 02:45:27 -04:00
let span_tag_close = document.createElement('span');
span_tag_close.setAttribute('class', 'tag-input__close');
span_tag.appendChild(span_tag_close);
2023-05-21 09:41:51 -04:00
2023-06-09 02:45:27 -04:00
tagsContainer.insertBefore(span_tag, input_hidden_field);
2023-05-21 09:41:51 -04:00
2023-06-09 02:45:27 -04:00
span_tag.childNodes[1].addEventListener('click', function () {
self.remove(this);
});
2023-05-21 09:41:51 -04:00
2023-06-09 02:45:27 -04:00
this.update();
2023-05-21 09:41:51 -04:00
2023-06-09 02:45:27 -04:00
}
},
2023-05-21 09:41:51 -04:00
2023-06-09 02:45:27 -04:00
update: function () {
2023-05-21 09:41:51 -04:00
2023-06-09 02:45:27 -04:00
let tags = document.getElementsByClassName('tag-input__tag'),
tags_arr = [];
2023-05-21 09:41:51 -04:00
2023-06-09 02:45:27 -04:00
for (let i = 0; i < tags.length ; i + + ) {
2023-11-22 09:44:19 -05:00
tags_arr.push(tags[i].textContent);
2023-05-21 09:41:51 -04:00
}
2023-06-09 02:45:27 -04:00
this.tags_array = tags_arr;
2023-05-21 09:41:51 -04:00
2023-06-09 02:45:27 -04:00
this.input_hidden.setAttribute('value', tags_arr.join());
2023-05-20 11:01:18 -04:00
},
2023-06-09 02:45:27 -04:00
remove: function (tag) {
configs.onTagRemove(tag.parentNode.textContent);
tag.parentNode.remove();
this.update();
},
showDuplicate: function (tag_value) {
let tags = document.getElementsByClassName('tag-input__tag');
for (let i = 0; i < tags.length ; i + + ) {
if (tags[i].textContent === tag_value) {
tags[i].classList.add("tag-input__tag--highlight");
window.setTimeout(function () {
tags[i].classList.remove("tag-input__tag--highlight");
}, configs.duplicateTime);
}
}
2023-05-20 11:01:18 -04:00
}
}
2023-01-10 22:36:13 -05:00
2023-06-09 02:45:27 -04:00
_privateMethods.init(configs);
// return false;
2023-05-20 11:01:18 -04:00
}
2023-06-09 02:45:27 -04:00
(function () {
new inputTags({
container: document.getElementsByClassName("tag-input")[0],
2023-06-09 14:47:12 -04:00
tags: $("#tags_input").data("initial-value").split(","),
2023-06-09 02:45:27 -04:00
allowDuplicateTags: false,
duplicateTime: 300,
onTagRemove: function (tag) { },
});
})();
2023-05-20 11:01:18 -04:00
< / script >