fix: prefill doctype dialog with 'Is Child Table'

This commit is contained in:
RitvikSardana 2024-01-16 09:22:01 +05:30
parent 34ff893f14
commit 35a8a64879
4 changed files with 23 additions and 17 deletions

View file

@ -3,8 +3,9 @@ frappe.listview_settings["DocType"] = {
this.new_doctype_dialog();
},
new_doctype_dialog() {
new_doctype_dialog(args) {
let non_developer = frappe.session.user !== "Administrator" || !frappe.boot.developer_mode;
let prefill_child = args?.is_child || 0;
let fields = [
{
label: __("DocType Name"),
@ -36,6 +37,7 @@ frappe.listview_settings["DocType"] = {
fieldtype: "Check",
description: __("Child Tables are shown as a Grid in other DocTypes"),
depends_on: "eval:!doc.is_submittable && !doc.issingle",
default: prefill_child,
},
{
label: __("Editable Grid"),

View file

@ -4,6 +4,7 @@ import { useStore } from "../store";
import { move_children_to_parent, clone_field } from "../utils";
import { ref, computed, onMounted } from "vue";
import AddFieldButton from "./AddFieldButton.vue";
import NavigateIcon from "./icons/NavigateIcon.vue";
import { useMagicKeys, whenever } from "@vueuse/core";
const props = defineProps(["column", "field"]);
@ -237,17 +238,17 @@ onMounted(() => selected.value && label_input.value.focus_on_label());
>
<div v-html="frappe.utils.icon('filter', 'sm')"></div>
</button>
<AddFieldButton ref="add_field_ref" :column="column" :field="field">
<div v-html="frappe.utils.icon('add', 'sm')" />
</AddFieldButton>
<button
v-if="field.df.fieldtype === 'Table'"
class="btn btn-xs btn-icon"
@click="open_child_doctype"
:title="__(`Edit ${field.df.options} Doctype`)"
>
<div v-html="frappe.utils.icon('arrow-up-right', 'sm')"></div>
<NavigateIcon />
</button>
<AddFieldButton ref="add_field_ref" :column="column" :field="field">
<div v-html="frappe.utils.icon('add', 'sm')" />
</AddFieldButton>
<button
v-if="column.fields.indexOf(field)"
class="btn btn-xs btn-icon"
@ -255,9 +256,7 @@ onMounted(() => selected.value && label_input.value.focus_on_label());
__('Move the current field and the following fields to a new column')
"
@click="move_fields_to_column"
>
<div v-html="frappe.utils.icon('move', 'sm')"></div>
</button>
></button>
<button
class="btn btn-xs btn-icon"
:title="__('Duplicate field')"

View file

@ -14,13 +14,8 @@ let table_columns = computedAsync(async () => {
return get_table_columns(props.df, child_doctype);
}, []);
function open_new_doctype_dialog() {
let new_doctype = window.open("/app/doctype", "_blank");
//window.open returns a window object of the newly opened tab,
setTimeout(() => {
// to perform any action on the new tab, we need to wait for the tab to load hence the setTimeout
new_doctype.document.querySelector("[data-label='Add DocType']").click();
}, 100);
function open_new_child_doctype_dialog() {
frappe.listview_settings["DocType"].new_doctype_dialog({ is_child: 1 });
}
</script>
@ -58,10 +53,10 @@ function open_new_doctype_dialog() {
<!-- render this button when there are no columns, which means that options is not added for the table -->
<button
class="btn btn-xs btn-secondary"
@click="open_new_doctype_dialog"
@click="open_new_child_doctype_dialog"
v-if="!table_columns.length"
>
{{ __("Create New Doctype") }}
{{ __("Create a New Child Doctype") }}
</button>
<p v-else>{{ __("No Data") }}</p>
</div>

View file

@ -0,0 +1,10 @@
<template>
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M5.86813 10.1317C5.67286 9.93647 5.67286 9.61988 5.86813 9.42462L12.7926 2.5001L9 2.5001C8.72386 2.5001 8.5 2.27624 8.5 2.0001C8.5 1.72396 8.72386 1.5001 9 1.5001L13.9899 1.5001C14.1076 1.49777 14.2261 1.53678 14.3215 1.61714C14.4306 1.70886 14.5 1.84638 14.5 2.0001V7.0001C14.5 7.27624 14.2761 7.5001 14 7.5001C13.7239 7.5001 13.5 7.27624 13.5 7.0001V3.20696L6.57523 10.1317C6.37997 10.327 6.06339 10.327 5.86813 10.1317ZM2.5 4.0001C2.5 3.17167 3.17157 2.5001 4 2.5001H5.8C6.07614 2.5001 6.3 2.27624 6.3 2.0001C6.3 1.72396 6.07614 1.5001 5.8 1.5001H4C2.61929 1.5001 1.5 2.61939 1.5 4.0001V12.0001C1.5 13.3808 2.61929 14.5001 4 14.5001H12C13.3807 14.5001 14.5 13.3808 14.5 12.0001V10.2001C14.5 9.92396 14.2761 9.7001 14 9.7001C13.7239 9.7001 13.5 9.92396 13.5 10.2001V12.0001C13.5 12.8285 12.8284 13.5001 12 13.5001H4C3.17157 13.5001 2.5 12.8285 2.5 12.0001V4.0001Z"
fill="#525252"
/>
</svg>
</template>