add: drawings in questions
This commit is contained in:
parent
6be729de50
commit
16843a6ab8
28 changed files with 1181 additions and 32 deletions
|
@ -405,7 +405,7 @@
|
|||
(text "{%- endif %}"))))
|
||||
(text "{% if community and show_community and community.id != config.town_square or question %}"))
|
||||
|
||||
(text "{%- endif %} {%- endmacro %} {% macro post_media(upload_ids) -%} {% if upload_ids|length > 0%}")
|
||||
(text "{%- endif %} {%- endmacro %} {% macro post_media(upload_ids) -%} {% if upload_ids|length > 0 -%}")
|
||||
(div
|
||||
("class" "media_gallery gap-2")
|
||||
(text "{% for upload in upload_ids %}")
|
||||
|
@ -677,6 +677,8 @@
|
|||
("class" "no_p_margin")
|
||||
("style" "font-weight: 500")
|
||||
(text "{{ question.content|markdown|safe }}"))
|
||||
; question drawings
|
||||
(text "{{ self::post_media(upload_ids=question.drawings) }}")
|
||||
; anonymous user ip thing
|
||||
; this is only shown if the post author is anonymous AND we are a helper
|
||||
(text "{% if is_helper and owner.id == 0 %}")
|
||||
|
@ -693,7 +695,7 @@
|
|||
(div
|
||||
("class" "flex gap-2 items-center justify-between"))))
|
||||
|
||||
(text "{%- endmacro %} {% macro create_question_form(receiver=\"0\", community=\"\", header=\"\", is_global=false) -%}")
|
||||
(text "{%- endmacro %} {% macro create_question_form(receiver=\"0\", community=\"\", header=\"\", is_global=false, drawing_enabled=false) -%}")
|
||||
(div
|
||||
("class" "card-nest")
|
||||
(div
|
||||
|
@ -707,6 +709,12 @@
|
|||
("onsubmit" "create_question_from_form(event)")
|
||||
(div
|
||||
("class" "flex flex-col gap-1")
|
||||
; carp canvas
|
||||
(text "{% if drawing_enabled -%}")
|
||||
(div ("ui_ident" "carp_canvas_field"))
|
||||
(text "{%- endif %}")
|
||||
|
||||
; form
|
||||
(label
|
||||
("for" "content")
|
||||
(text "{{ text \"communities:label.content\" }}"))
|
||||
|
@ -718,25 +726,83 @@
|
|||
("required" "")
|
||||
("minlength" "2")
|
||||
("maxlength" "4096")))
|
||||
(button
|
||||
("class" "primary")
|
||||
(text "{{ text \"communities:action.create\" }}"))))
|
||||
(div
|
||||
("class" "flex gap-2")
|
||||
(button
|
||||
("class" "primary")
|
||||
(text "{{ text \"communities:action.create\" }}"))
|
||||
|
||||
(text "{% if drawing_enabled -%}")
|
||||
(button
|
||||
("class" "lowered")
|
||||
("ui_ident" "add_drawing")
|
||||
("onclick" "attach_drawing()")
|
||||
("type" "button")
|
||||
(text "{{ text \"communities:action.draw\" }}"))
|
||||
|
||||
(button
|
||||
("class" "lowered red hidden")
|
||||
("ui_ident" "remove_drawing")
|
||||
("onclick" "remove_drawing()")
|
||||
("type" "button")
|
||||
(text "{{ text \"communities:action.remove_drawing\" }}"))
|
||||
|
||||
(script
|
||||
(text "globalThis.attach_drawing = () => {
|
||||
globalThis.gerald = trigger(\"carp::new\", [document.querySelector(\"[ui_ident=carp_canvas_field]\")]);
|
||||
globalThis.gerald.create_canvas();
|
||||
|
||||
document.querySelector(\"[ui_ident=add_drawing]\").classList.add(\"hidden\");
|
||||
document.querySelector(\"[ui_ident=remove_drawing]\").classList.remove(\"hidden\");
|
||||
}
|
||||
|
||||
globalThis.remove_drawing = async () => {
|
||||
if (
|
||||
!(await trigger(\"atto::confirm\", [
|
||||
\"Are you sure you would like to do this?\",
|
||||
]))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
document.querySelector(\"[ui_ident=carp_canvas_field]\").innerHTML = \"\";
|
||||
globalThis.gerald = null;
|
||||
|
||||
document.querySelector(\"[ui_ident=add_drawing]\").classList.remove(\"hidden\");
|
||||
document.querySelector(\"[ui_ident=remove_drawing]\").classList.add(\"hidden\");
|
||||
}"))
|
||||
(text "{%- endif %}"))))
|
||||
|
||||
(script
|
||||
(text "async function create_question_from_form(e) {
|
||||
(text "globalThis.gerald = null;
|
||||
async function create_question_from_form(e) {
|
||||
e.preventDefault();
|
||||
await trigger(\"atto::debounce\", [\"questions::create\"]);
|
||||
fetch(\"/api/v1/questions\", {
|
||||
method: \"POST\",
|
||||
headers: {
|
||||
\"Content-Type\": \"application/json\",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
|
||||
// create body
|
||||
const body = new FormData();
|
||||
|
||||
if (globalThis.gerald) {
|
||||
body.append(\"drawing.carpgraph\", new Blob([new Uint8Array(globalThis.gerald.as_carp2())], {
|
||||
type: \"application/octet-stream\"
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
body.append(
|
||||
\"body\",
|
||||
JSON.stringify({
|
||||
content: e.target.content.value,
|
||||
receiver: \"{{ receiver }}\",
|
||||
community: \"{{ community }}\",
|
||||
is_global: \"{{ is_global }}\" == \"true\",
|
||||
}),
|
||||
);
|
||||
|
||||
// ...
|
||||
fetch(\"/api/v1/questions\", {
|
||||
method: \"POST\",
|
||||
body,
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
|
@ -747,6 +813,10 @@
|
|||
|
||||
if (res.ok) {
|
||||
e.target.reset();
|
||||
|
||||
if (globalThis.gerald) {
|
||||
globalThis.gerald.clear();
|
||||
}
|
||||
}
|
||||
});
|
||||
}"))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue