Commit 64fd8eac authored by Konrad Mohrfeldt's avatar Konrad Mohrfeldt

add support for in-reply-to field, when answering to contributions in frontend. refs #489

parent ad760e06
Pipeline #1208 failed with stage
in 3 seconds
......@@ -16,6 +16,8 @@ class Text(forms.ModelForm):
contributions = kwargs.pop('contributions')
super().__init__(*args, **kwargs)
self.fields['in_reply_to'].queryset = contributions
self.fields['in_reply_to'].widget = forms.HiddenInput(
{'data-component': 'cite cite-in-reply-to'})
def save(self, commit=True):
contribution = super().save(False)
......
......@@ -77,7 +77,7 @@
{% if contribution.contribution.text %}
<span class="media-footer-separator"></span>
<a class="js" data-component="cite" href="#{% ref contribution %}">
Zitieren
Antworten
</a>
{% endif %}
</div>
......
......@@ -4,7 +4,9 @@
{% block media_content %}
<div class="media-body"
{% block media_content_attrs %}
data-author="{{ contribution.author }}" data-permalink="{{ permalink_url }}#{% ref contribution %}"
data-author="{{ contribution.author }}"
data-permalink="{{ permalink_url }}#{% ref contribution %}"
data-id="{{ contribution.id }}"
{% endblock %}>
{% block media_body %}
{% markdown contribution.contribution.text heading_baselevel=3 %}
......
......@@ -3,7 +3,7 @@
{% block media_body %}
<form method="post">
{% csrf_token %}
{{ form.in_reply_to.as_hidden }}
{{ form.in_reply_to }}
{% field form.text hide_label=True %}
<button class="btn btn-primary">{{ submit_label }}</button>
</form>
......
......@@ -18,11 +18,12 @@ function citeSource (el, opts) {
event.preventDefault()
const target = $(`${event.target.getAttribute('href')} .media-body`)
const id = getAttr(target, 'data-id')
const author = getAttr(target, 'data-author')
const permalink = getAttr(target, 'data-permalink')
const text = decode(JSON.parse($('[data-original-content]', target).textContent))
const formattedText = (text + (author ? `\n — [${author}](${permalink})` : '')).replace(/^/gm, '> ')
const data = { author, permalink, text, formattedText }
const data = { id, author, permalink, text, formattedText }
bus.emit(EVENT_CITE, data)
})
......@@ -53,8 +54,24 @@ function citeSink (el, opts) {
}
}
function citeInReplyTo (el, opts) {
const { bus } = opts.conf
const citeListener = bus.on(EVENT_CITE, data => {
el.value = data.id
})
return {
remove () {
citeListener.destroy()
}
}
}
export default (el, opts) => {
return includes(opts.types, 'sink')
? citeSink(el, opts)
: includes(opts.types, 'in-reply-to')
? citeInReplyTo(el, opts)
: citeSource(el, opts)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment