2
0
mirror of https://github.com/frappe/books.git synced 2025-02-02 12:08:27 +00:00

incr: open quick edit on edit click

This commit is contained in:
18alantom 2022-07-11 14:15:37 +05:30
parent 2f33f24db9
commit a8e8649112
9 changed files with 85 additions and 12 deletions

View File

@ -53,7 +53,8 @@
"label": "Items", "label": "Items",
"fieldtype": "Table", "fieldtype": "Table",
"target": "PurchaseInvoiceItem", "target": "PurchaseInvoiceItem",
"required": true "required": true,
"edit": true
}, },
{ {
"fieldname": "netTotal", "fieldname": "netTotal",

View File

@ -85,5 +85,15 @@
} }
], ],
"tableFields": ["item", "tax", "quantity", "rate", "amount"], "tableFields": ["item", "tax", "quantity", "rate", "amount"],
"keywordFields": ["item", "tax"] "keywordFields": ["item", "tax"],
"quickEditFields": [
"item",
"description",
"hsnCode",
"tax",
"quantity",
"rate",
"itemDiscountAmount",
"itemDiscountPercent"
]
} }

View File

@ -52,7 +52,8 @@
"label": "Items", "label": "Items",
"fieldtype": "Table", "fieldtype": "Table",
"target": "SalesInvoiceItem", "target": "SalesInvoiceItem",
"required": true "required": true,
"edit": true
}, },
{ {
"fieldname": "netTotal", "fieldname": "netTotal",

View File

@ -86,5 +86,15 @@
} }
], ],
"tableFields": ["item", "tax", "quantity", "rate", "amount"], "tableFields": ["item", "tax", "quantity", "rate", "amount"],
"keywordFields": ["item", "tax"] "keywordFields": ["item", "tax"],
"quickEditFields": [
"item",
"description",
"hsnCode",
"tax",
"quantity",
"rate",
"itemDiscountAmount",
"itemDiscountPercent"
]
} }

View File

@ -50,6 +50,7 @@ export interface TargetField extends BaseField {
fieldtype: FieldTypeEnum.Table | FieldTypeEnum.Link; fieldtype: FieldTypeEnum.Table | FieldTypeEnum.Link;
target: string; // Name of the table or group of tables to fetch values target: string; // Name of the table or group of tables to fetch values
create?: boolean; // Whether to show Create in the dropdown create?: boolean; // Whether to show Create in the dropdown
edit?: boolean; // Whether the Table has quick editable columns
} }
export interface DynamicLinkField extends BaseField { export interface DynamicLinkField extends BaseField {

View File

@ -6,7 +6,6 @@
flex flex
justify-center justify-center
items-center items-center
h-8
text-sm text-sm
" "
:class="_class" :class="_class"
@ -35,15 +34,20 @@ export default {
type: Boolean, type: Boolean,
default: true, default: true,
}, },
background: {
type: Boolean,
default: true,
},
}, },
computed: { computed: {
_class() { _class() {
return { return {
'opacity-50 cursor-not-allowed pointer-events-none': this.disabled, 'opacity-50 cursor-not-allowed pointer-events-none': this.disabled,
'text-white': this.type === 'primary', 'text-white': this.type === 'primary',
'bg-blue-500': this.type === 'primary', 'bg-blue-500': this.type === 'primary' && this.background,
'text-gray-700': this.type !== 'primary', 'text-gray-700': this.type !== 'primary',
'bg-gray-200': this.type !== 'primary', 'bg-gray-200': this.type !== 'primary' && this.background,
'h-8': this.background,
'px-3': this.padding && this.icon, 'px-3': this.padding && this.icon,
'px-6': this.padding && !this.icon, 'px-6': this.padding && !this.icon,
}; };

View File

@ -38,6 +38,7 @@
v-bind="{ row, tableFields, size, ratio, isNumeric }" v-bind="{ row, tableFields, size, ratio, isNumeric }"
:read-only="isReadOnly" :read-only="isReadOnly"
@remove="removeRow(row)" @remove="removeRow(row)"
:can-edit-row="canEditRow"
/> />
</div> </div>
@ -169,8 +170,17 @@ export default {
} }
return 2; return 2;
}, },
canEditRow() {
return !this.doc?.isSubmitted && this.df.edit;
},
ratio() { ratio() {
return [0.3].concat(this.tableFields.map(() => 1)); const ratio = [0.3].concat(this.tableFields.map(() => 1));
if (this.canEditRow) {
return ratio.concat(0.3);
}
return ratio;
}, },
tableFields() { tableFields() {
const fields = fyo.schemaMap[this.df.target].tableFields ?? []; const fields = fyo.schemaMap[this.df.target].tableFields ?? [];

View File

@ -19,6 +19,7 @@
<feather-icon <feather-icon
name="x" name="x"
class="w-4 h-4 -ml-1 cursor-pointer" class="w-4 h-4 -ml-1 cursor-pointer"
:button="true"
@click="$emit('remove')" @click="$emit('remove')"
/> />
</span> </span>
@ -39,6 +40,18 @@
@change="(value) => onChange(df, value)" @change="(value) => onChange(df, value)"
@new-doc="(doc) => row.set(df.fieldname, doc.name)" @new-doc="(doc) => row.set(df.fieldname, doc.name)"
/> />
<Button
:icon="true"
:padding="false"
:background="false"
@click="openRowQuickEdit"
>
<feather-icon
name="edit"
class="w-4 h-4 text-gray-600"
v-if="canEditRow"
/>
</Button>
<!-- Error Display --> <!-- Error Display -->
<div <div
@ -53,6 +66,8 @@
import { Doc } from 'fyo/model/doc'; import { Doc } from 'fyo/model/doc';
import Row from 'src/components/Row.vue'; import Row from 'src/components/Row.vue';
import { getErrorMessage } from 'src/utils'; import { getErrorMessage } from 'src/utils';
import { openQuickEdit } from 'src/utils/ui';
import Button from '../Button.vue';
import FormControl from './FormControl.vue'; import FormControl from './FormControl.vue';
export default { export default {
@ -64,11 +79,16 @@ export default {
ratio: Array, ratio: Array,
isNumeric: Function, isNumeric: Function,
readOnly: Boolean, readOnly: Boolean,
canEditRow: {
type: Boolean,
default: false,
},
}, },
emits: ['remove'], emits: ['remove'],
components: { components: {
Row, Row,
FormControl, FormControl,
Button,
}, },
data: () => ({ hovering: false, errors: {} }), data: () => ({ hovering: false, errors: {} }),
beforeCreate() { beforeCreate() {
@ -95,6 +115,16 @@ export default {
getErrorString() { getErrorString() {
return Object.values(this.errors).filter(Boolean).join(' '); return Object.values(this.errors).filter(Boolean).join(' ');
}, },
openRowQuickEdit() {
if (!this.row) {
return;
}
openQuickEdit({
schemaName: this.row.schemaName,
name: this.row.name,
});
},
}, },
}; };
</script> </script>

View File

@ -4,7 +4,10 @@
:class="white ? 'bg-white' : 'bg-gray-25'" :class="white ? 'bg-white' : 'bg-gray-25'"
> >
<!-- Quick edit Tool bar --> <!-- Quick edit Tool bar -->
<div class="flex items-center justify-between px-4 border-b h-row-largest"> <div
class="flex items-center justify-between px-4 h-row-largest"
:class="{ 'border-b': !isChild }"
>
<!-- Close Button and Status Text --> <!-- Close Button and Status Text -->
<div class="flex items-center"> <div class="flex items-center">
<Button :icon="true" @click="routeToPrevious"> <Button :icon="true" @click="routeToPrevious">
@ -17,8 +20,8 @@
<!-- Actions, Badge and Status Change Buttons --> <!-- Actions, Badge and Status Change Buttons -->
<div class="flex items-stretch gap-2"> <div class="flex items-stretch gap-2">
<StatusBadge :status="status" /> <StatusBadge :status="status" v-if="!isChild" />
<DropdownWithActions :actions="actions" /> <DropdownWithActions :actions="actions" v-if="!isChild" />
<Button <Button
:icon="true" :icon="true"
@click="sync" @click="sync"
@ -49,7 +52,7 @@
<div <div
class="px-4 flex-center flex flex-col items-center gap-1.5" class="px-4 flex-center flex flex-col items-center gap-1.5"
style="height: calc(var(--h-row-mid) * 2 + 1px)" style="height: calc(var(--h-row-mid) * 2 + 1px)"
v-if="doc" v-if="doc && !isChild"
> >
<FormControl <FormControl
v-if="imageField" v-if="imageField"
@ -145,6 +148,9 @@ export default {
await this.fetchFieldsAndDoc(); await this.fetchFieldsAndDoc();
}, },
computed: { computed: {
isChild() {
return !!this?.doc?.schema?.isChild;
},
schema() { schema() {
return fyo.schemaMap[this.schemaName] ?? null; return fyo.schemaMap[this.schemaName] ?? null;
}, },