1<template>
2 <Dialog v-model:open="open" :title="__('Assign')">
3 <template #default>
4 <AssignTo v-model="assignees" hide-label />
5 </template>
6 <template #actions>
7 <div class="flex items-center justify-end gap-2">
8 <Button :label="__('Cancel')" @click="open = false" />
9 <Button
10 variant="solid"
11 :loading="loading"
12 :disabled="!assignees.length"
13 :label="__('Assign {0} tickets', selections.size)"
14 @click="submit"
15 />
16 </div>
17 </template>
18 </Dialog>
19</template>
20
21<script setup lang="ts">
22import AssignTo from "@/components/ticket-agent/AssignTo.vue";
23import { __ } from "@/translation";
24import { Button, call, Dialog, toast } from "frappe-ui";
25import { ref, watch } from "vue";
26
27const ASSIGN_METHOD = "frappe.desk.form.assign_to.add_multiple";
28
29const open = defineModel<boolean>();
30
31const props = defineProps<{
32 selections: Set<string>;
33}>();
34const emit = defineEmits<{
35 (e: "success"): void;
36}>();
37
38const assignees = ref<string[]>([]);
39const loading = ref(false);
40
41async function submit() {
42 if (!assignees.value.length) return;
43 const ticketIds = Array.from(props.selections);
44 loading.value = true;
45 try {
46 // `add_multiple` reads the raw form_dict, so the lists go as JSON strings.
47 await call(ASSIGN_METHOD, {
48 doctype: "OD Ticket",
49 name: JSON.stringify(ticketIds),
50 assign_to: JSON.stringify(assignees.value),
51 });
52 open.value = false;
53 toast.success(__("Assigned {0} ticket(s)", ticketIds.length));
54 emit("success");
55 } finally {
56 loading.value = false;
57 }
58}
59
60watch(open, (isOpen) => {
61 if (isOpen) assignees.value = [];
62});
63</script>
64