[REV] web: kanban: bottom quickCreate button

This commit is the revert of #98703.

closes odoo/odoo#102116

X-original-commit: 64c0ed09f058cff9b3cebfe5480a7efd0caa7be6
Signed-off-by: Simon Genin (ges@odoo) <ges@odoo.com>
Signed-off-by: Dardenne Florent (dafl) <dafl@odoo.com>
This commit is contained in:
Dardenne Florent (dafl)
2022-10-04 19:04:25 +02:00
parent f0fc3ee7eb
commit fc4df3c0b2
6 changed files with 17 additions and 71 deletions
@@ -507,12 +507,6 @@
box-shadow: -1px 0px 0px 0px var(--KanbanColumn__highlight-border) inset,
1px 0px 0px 0px var(--KanbanColumn__highlight-border) inset;
}
.o_kanban_quick_add_bottom {
font-size: 0.94791667rem;
font-weight: $font-weight-bold;
@include o-hover-opacity(.7);
@include o-hover-text-color($text-muted, $body-color);
}
}
.o_group_draggable .o_column_title {
@@ -145,13 +145,13 @@ class KanbanGroup extends Group {
/**
* @override
*/
quickCreate(activeFields, context, atFirstPosition) {
quickCreate(activeFields, context) {
const ctx = { ...context };
if (this.hasActiveProgressValue && this.progressValue.active !== FALSE) {
const { fieldName } = this.model.progressAttributes;
ctx[`default_${fieldName}`] = this.progressValue.active;
}
return super.quickCreate(activeFields, ctx, atFirstPosition);
return super.quickCreate(activeFields, ctx);
}
async load() {
@@ -281,12 +281,12 @@ class KanbanGroup extends Group {
* @param {number} index
* @returns {Promise<Record | false>}
*/
async validateQuickCreate(index) {
async validateQuickCreate() {
const record = this.list.quickCreateRecord;
if (record) {
const saved = await record.save();
if (saved) {
this.addRecord(this.removeRecord(record), index);
this.addRecord(this.removeRecord(record), 0);
this.count++;
this.list.count++;
return record;
@@ -347,16 +347,15 @@ export class KanbanRenderer extends Component {
// Edition methods
// ------------------------------------------------------------------------
quickCreate(group, atFirstPosition = true) {
return this.props.list.quickCreate(group, atFirstPosition);
quickCreate(group) {
return this.props.list.quickCreate(group);
}
async validateQuickCreate(mode, group) {
const values = group.list.quickCreateRecord.data;
const quickCreateRecordIndex = group.list.quickCreateRecordIndex;
let record;
try {
record = await group.validateQuickCreate(quickCreateRecordIndex);
record = await group.validateQuickCreate();
} catch (e) {
// TODO: filter RPC errors more specifically (eg, for access denied, there is no point in opening a dialog)
if (!(e instanceof RPCError)) {
@@ -389,7 +388,7 @@ export class KanbanRenderer extends Component {
if (mode === "edit") {
await this.props.openRecord(record, "edit");
} else {
await this.quickCreate(group, quickCreateRecordIndex === 0);
await this.quickCreate(group);
}
}
}
@@ -47,7 +47,7 @@
</DropdownItem>
</t>
</Dropdown>
<button t-if="canQuickCreate()" class="o_kanban_quick_add btn p-0 border-0 fs-6 shadow-none" t-on-click="() => this.quickCreate(group, true)">
<button t-if="canQuickCreate()" class="o_kanban_quick_add btn p-0 border-0 fs-6 shadow-none" t-on-click="() => this.quickCreate(group)">
<i class="fa fa-plus fa-stack d-block small text-end text-700 opacity-50 opacity-100-hover cursor-pointer" role="img" aria-label="Quick add" title="Quick add" />
</button>
</t>
@@ -112,18 +112,12 @@
<div t-if="unloadedCount > 0" class="o_kanban_load_more">
<button class="btn btn-outline-primary w-100 mt-4" t-on-click="() => this.loadMore(group)">Load more... (<t t-out="unloadedCount"/> remaining)</button>
</div>
<span t-elif="canQuickCreate()" class="o_kanban_quick_add_bottom d-block m-2 cursor-pointer" t-on-click="() => this.quickCreate(group, false)">
<i class="fa fa-plus" role="img" aria-label="Quick add" title="Quick add" /> New
</span>
</t>
<t t-elif="env.isSmall">
<t t-set="unloadedCount" t-value="getGroupUnloadedCount(group)" />
<div t-if="unloadedCount > 0" class="o_kanban_load_more">
<button class="btn btn-outline-primary w-100 mt-4" t-on-click="() => this.toggleGroup(group)">Load more... (<t t-out="unloadedCount"/> remaining)</button>
</div>
<span t-elif="canQuickCreate()" class="o_kanban_quick_add_bottom d-block m-2 cursor-pointer" t-on-click="() => this.quickCreate(group, false)">
<i class="fa fa-plus" role="img" aria-label="Quick add" title="Quick add" /> New
</span>
</t>
</div>
</t>
@@ -1789,10 +1789,6 @@ export class DynamicRecordList extends DynamicList {
return this.records.find((r) => r.isInQuickCreation);
}
get quickCreateRecordIndex() {
return this.records.findIndex((r) => r.isInQuickCreation);
}
// -------------------------------------------------------------------------
// Public
// -------------------------------------------------------------------------
@@ -1943,7 +1939,7 @@ export class DynamicRecordList extends DynamicList {
}
}
async quickCreate(activeFields, context, atFirstPosition = true) {
async quickCreate(activeFields, context) {
await this.model.mutex.getUnlockedDef();
const record = this.quickCreateRecord;
if (record) {
@@ -1953,10 +1949,7 @@ export class DynamicRecordList extends DynamicList {
parent: this.rawContext,
make: () => makeContext([context, {}]),
};
return this.createRecord(
{ activeFields, rawContext, isInQuickCreation: true },
atFirstPosition
);
return this.createRecord({ activeFields, rawContext, isInQuickCreation: true }, true);
}
/**
@@ -2245,7 +2238,7 @@ export class DynamicGroupList extends DynamicList {
return this.groups.reduce((acc, group) => acc + group.count, 0);
}
async quickCreate(group, atFirstPosition = true) {
async quickCreate(group) {
group = group || this.groups[0];
if (this.model.useSampleModel) {
// Empty the groups because they contain sample data
@@ -2261,7 +2254,7 @@ export class DynamicGroupList extends DynamicList {
if (isFolded) {
await group.toggle();
}
await group.quickCreate(this.quickCreateInfo.activeFields, this.context, atFirstPosition);
await group.quickCreate(this.quickCreateInfo.activeFields, this.context);
}
/**
@@ -2656,12 +2649,12 @@ export class Group extends DataPoint {
});
}
quickCreate(activeFields, context, atFirstPosition = false) {
quickCreate(activeFields, context) {
const ctx = {
...context,
[`default_${this.groupByField.name}`]: this.getServerValue(),
};
return this.list.quickCreate(activeFields, ctx, atFirstPosition);
return this.list.quickCreate(activeFields, ctx);
}
/**
@@ -104,12 +104,8 @@ async function createRecord() {
await click(target, "button.o-kanban-button-new");
}
async function quickCreateRecord(groupIndex, position = "top") {
if (position === "top") {
await click(getColumn(groupIndex), ".o_kanban_quick_add");
} else if (position === "bottom") {
await click(getColumn(groupIndex), ".o_kanban_quick_add_bottom");
}
async function quickCreateRecord(groupIndex) {
await click(getColumn(groupIndex), ".o_kanban_quick_add");
}
async function editQuickCreateInput(field, value) {
@@ -11289,36 +11285,6 @@ QUnit.module("Views", (hooks) => {
}
);
QUnit.test("quick create record with bottom quick create button", async (assert) => {
await makeView({
type: "kanban",
resModel: "product",
serverData,
groupBy: ["name"],
arch: /* xml */ `
<kanban on_create="quick_create">
<templates>
<t t-name="kanban-box">
<div>
<field name="display_name"/>
</div>
</t>
</templates>
</kanban>
`,
});
// quick create at the bottom and verify the order
await quickCreateRecord(1, "bottom");
await editQuickCreateInput("display_name", "new product");
await validateRecord();
assert.deepEqual(getCardTexts(1), ["xmo", "new product"]);
// directly re-create another records at the bottom
await editQuickCreateInput("display_name", "new product 2");
await validateRecord();
assert.deepEqual(getCardTexts(1), ["xmo", "new product", "new product 2"]);
});
QUnit.test("no leak of TransactionInProgress (grouped case)", async (assert) => {
let def;
await makeView({