add: ProfileStyle products
This commit is contained in:
parent
077e9252e3
commit
95cb889080
19 changed files with 525 additions and 54 deletions
|
@ -150,35 +150,60 @@
|
|||
(icon (text "package-check"))
|
||||
(b
|
||||
(str (text "economy:label.fulfillment_style"))))
|
||||
(form
|
||||
(div
|
||||
("class" "card flex flex_col gap_2")
|
||||
("onsubmit" "update_method_from_form(event)")
|
||||
(p (text "If you choose to send an automated mail letter upon purchase, users will automatically receive the message you supply below."))
|
||||
(p (text "If you disable automail, you'll be required to manually mail users who have purchased your product before the transfer is finalized."))
|
||||
(select
|
||||
("id" "fulfillment_style_select")
|
||||
("onchange" "mirror_fulfillment_style_select(true)")
|
||||
(option ("value" "mail") (text "Mail") ("selected" "{{ not product.method == \"ProfileStyle\" }}"))
|
||||
(option ("value" "snippet") (text "CSS Snippet") ("selected" "{{ product.method == \"ProfileStyle\" }}")))
|
||||
(form
|
||||
("class" "flex flex_col gap_2 hidden")
|
||||
("id" "mail_fulfillment")
|
||||
("onsubmit" "update_method_from_form(event)")
|
||||
(p (text "If you choose to send an automated mail letter upon purchase, users will automatically receive the message you supply below."))
|
||||
(p (text "If you disable automail, you'll be required to manually mail users who have purchased your product before the transfer is finalized."))
|
||||
(text "{% set is_automail = product.method != \"ManualMail\" and product.method != \"ProfileStyle\" %}")
|
||||
|
||||
(label
|
||||
("for" "use_automail")
|
||||
("class" "flex items_center gap_2")
|
||||
(input
|
||||
("type" "checkbox")
|
||||
("id" "use_automail")
|
||||
("name" "use_automail")
|
||||
("class" "w_content")
|
||||
("oninput" "mirror_use_automail()")
|
||||
("checked" "{% if product.method != \"ManualMail\" -%} true {%- else -%} false {%- endif %}"))
|
||||
(span
|
||||
(str (text "economy:label.use_automail"))))
|
||||
(div
|
||||
("class" "flex flex_col gap_1")
|
||||
(label
|
||||
("for" "automail_message")
|
||||
(str (text "economy:label.automail_message")))
|
||||
(textarea
|
||||
("name" "automail_message")
|
||||
("id" "automail_message")
|
||||
("placeholder" "automail_message")
|
||||
(text "{% if product.method != \"ManualMail\" -%} {{ product.method.AutoMail }} {%- endif %}")))
|
||||
(button (str (text "general:action.save")))))
|
||||
("for" "use_automail")
|
||||
("class" "flex items_center gap_2")
|
||||
(input
|
||||
("type" "checkbox")
|
||||
("id" "use_automail")
|
||||
("name" "use_automail")
|
||||
("class" "w_content")
|
||||
("oninput" "mirror_use_automail()")
|
||||
("checked" "{% if is_automail -%} true {%- else -%} false {%- endif %}"))
|
||||
(span
|
||||
(str (text "economy:label.use_automail"))))
|
||||
(div
|
||||
("class" "flex flex_col gap_1")
|
||||
(label
|
||||
("for" "automail_message")
|
||||
(str (text "economy:label.automail_message")))
|
||||
(textarea
|
||||
("name" "automail_message")
|
||||
("id" "automail_message")
|
||||
("placeholder" "automail_message")
|
||||
(text "{% if is_automail -%} {{ product.method.AutoMail }} {%- endif %}")))
|
||||
(button (str (text "general:action.save"))))
|
||||
(form
|
||||
("class" "flex flex_col gap_2 hidden")
|
||||
("id" "snippet_fulfillment")
|
||||
("onsubmit" "update_data_from_form(event)")
|
||||
(text "{{ components::supporter_ad(body=\"Become a supporter to create snippets!\") }}")
|
||||
(div
|
||||
("class" "flex flex_col gap_1")
|
||||
(label
|
||||
("for" "data")
|
||||
(str (text "economy:label.snippet_data")))
|
||||
(textarea
|
||||
("name" "data")
|
||||
("id" "data")
|
||||
("placeholder" "data")
|
||||
(text "{{ product.data }}")))
|
||||
(button (str (text "general:action.save"))))))
|
||||
|
||||
(div
|
||||
("class" "flex gap_2")
|
||||
|
@ -347,6 +372,28 @@
|
|||
});
|
||||
}
|
||||
|
||||
async function update_data_from_form(e) {
|
||||
e.preventDefault();
|
||||
await trigger(\"atto::debounce\", [\"products::update\"]);
|
||||
|
||||
fetch(\"/api/v1/products/{{ product.id }}/data\", {
|
||||
method: \"POST\",
|
||||
headers: {
|
||||
\"Content-Type\": \"application/json\",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
data: e.target.data.value,
|
||||
}),
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
trigger(\"atto::toast\", [
|
||||
res.ok ? \"success\" : \"error\",
|
||||
res.message,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
async function delete_product() {
|
||||
if (
|
||||
!(await trigger(\"atto::confirm\", [
|
||||
|
@ -378,7 +425,46 @@
|
|||
}
|
||||
}
|
||||
|
||||
globalThis.mirror_fulfillment_style_select = (send = false) => {
|
||||
const selected = document.getElementById(\"fulfillment_style_select\").selectedOptions[0].value;
|
||||
|
||||
if (selected === \"mail\") {
|
||||
document.getElementById(\"mail_fulfillment\").classList.remove(\"hidden\");
|
||||
document.getElementById(\"snippet_fulfillment\").classList.add(\"hidden\");
|
||||
|
||||
if (send) {
|
||||
update_method_from_form({
|
||||
preventDefault: () => {},
|
||||
target: document.getElementById(\"mail_fulfillment\"),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
document.getElementById(\"mail_fulfillment\").classList.add(\"hidden\");
|
||||
document.getElementById(\"snippet_fulfillment\").classList.remove(\"hidden\");
|
||||
|
||||
if (send) {
|
||||
fetch(\"/api/v1/products/{{ product.id }}/method\", {
|
||||
method: \"POST\",
|
||||
headers: {
|
||||
\"Content-Type\": \"application/json\",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
method: \"ProfileStyle\",
|
||||
}),
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
trigger(\"atto::toast\", [
|
||||
res.ok ? \"success\" : \"error\",
|
||||
res.message,
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
mirror_use_automail();
|
||||
mirror_fulfillment_style_select();
|
||||
}, 150);"))
|
||||
(text "{% endblock %}")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue