Skip to content

Commit

Permalink
feat(customisation): update field value from custom actions
Browse files Browse the repository at this point in the history
  • Loading branch information
RitvikSardana committed Dec 11, 2024
1 parent a1336d2 commit 3795562
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 5 deletions.
5 changes: 5 additions & 0 deletions desk/src/pages/TicketAgent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,14 @@ const ticket = createResource({
onSuccess: (data) => {
setupCustomActions(data, {
doc: data,
updateField,
});
},
});
function updateField(name, value, callback = () => {}) {
updateTicket(name, value);
callback();
}
const breadcrumbs = computed(() => {
let items = [{ label: "Tickets", route: { name: "TicketsAgent" } }];
Expand Down
50 changes: 50 additions & 0 deletions desk/src/pages/TicketCustomer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<Breadcrumbs :items="breadcrumbs" />
</template>
<template #right-header>
<CustomActions
v-if="ticket.data._customActions"
:actions="ticket.data._customActions"
/>
<Button
v-if="ticket.data.status !== 'Closed'"
label="Close"
Expand Down Expand Up @@ -73,6 +77,7 @@ import TicketCustomerSidebar from "@/components/ticket/TicketCustomerSidebar.vue
import { useScreenSize } from "@/composables/screen";
import { useConfigStore } from "@/stores/config";
import { confirmDialog } from "frappe-ui";
import { setupCustomActions } from "@/utils";
interface P {
ticketId: string;
}
Expand All @@ -85,6 +90,7 @@ const ticket = createResource({
auto: true,
params: {
name: props.ticketId,
is_customer_portal: true,
},
onError: () => {
createToast({
Expand All @@ -94,6 +100,12 @@ const ticket = createResource({
});
router.replace("/my-tickets");
},
onSuccess: (data) => {
setupCustomActions(data, {
doc: data,
updateField,
});
},
});
provide(ITicket, ticket);
const editor = ref(null);
Expand Down Expand Up @@ -125,6 +137,44 @@ const send = createResource({
},
});
function updateField(name, value, callback = () => {}) {
updateTicket(name, value);
callback();
}
function updateTicket(fieldname: string, value: string) {
createResource({
url: "frappe.client.set_value",
params: {
doctype: "HD Ticket",
name: props.ticketId,
fieldname,
value,
},
auto: true,
onSuccess: () => {
ticket.reload();
createToast({
title: "Ticket updated",
icon: "check",
iconClasses: "text-green-600",
});
},
onError: (e) => {
const title =
e.messages && e.messages.length > 0
? e.messages[0]
: "Failed to update ticket";
createToast({
title,
icon: "x",
iconClasses: "text-red-600",
});
},
});
}
function handleClose() {
if (showFeedback.value) {
showFeedbackDialog.value = true;
Expand Down
9 changes: 8 additions & 1 deletion helpdesk/helpdesk/doctype/hd_form_script/hd_form_script.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"apply_to",
"column_break_lhfw",
"enabled",
"apply_to_customer_portal",
"section_break_qhfq",
"script"
],
Expand Down Expand Up @@ -49,11 +50,17 @@
"fieldtype": "Code",
"label": "Script",
"options": "JS"
},
{
"default": "0",
"fieldname": "apply_to_customer_portal",
"fieldtype": "Check",
"label": "Apply to customer portal"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-06-05 16:19:39.615245",
"modified": "2024-12-11 22:56:25.186577",
"modified_by": "Administrator",
"module": "Helpdesk",
"name": "HD Form Script",
Expand Down
5 changes: 3 additions & 2 deletions helpdesk/helpdesk/doctype/hd_form_script/hd_form_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class HDFormScript(Document):
pass


def get_form_script(dt, apply_to="Form"):
def get_form_script(dt, apply_to="Form",is_customer_portal=False):
"""Returns the form script for the given doctype"""
FormScript = frappe.qb.DocType("HD Form Script")
query = (
Expand All @@ -18,9 +18,10 @@ def get_form_script(dt, apply_to="Form"):
.where(FormScript.dt == dt)
.where(FormScript.apply_to == apply_to)
.where(FormScript.enabled == 1)
.where(FormScript.apply_to_customer_portal == is_customer_portal)
)

doc = query.run(as_dict=True)
doc = query.run(as_dict=True,debug=True)
if doc:
return [d.script for d in doc] if len(doc) > 1 else doc[0].script
else:
Expand Down
4 changes: 2 additions & 2 deletions helpdesk/helpdesk/doctype/hd_ticket/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def new(doc, attachments=[]):


@frappe.whitelist()
def get_one(name):
def get_one(name,is_customer_portal=False):
check_permissions("HD Ticket", None)
QBContact = frappe.qb.DocType("Contact")
QBTicket = frappe.qb.DocType("HD Ticket")
Expand Down Expand Up @@ -72,7 +72,7 @@ def get_one(name):
"tags": get_tags(name),
"template": get_template(ticket.template or DEFAULT_TICKET_TEMPLATE),
"views": get_views(name),
"_form_script": get_form_script("HD Ticket"),
"_form_script": get_form_script("HD Ticket",is_customer_portal=is_customer_portal),
}


Expand Down

0 comments on commit 3795562

Please sign in to comment.