From 2d7a49dab1e5060d12c8179cf876a10c5a37a3bd Mon Sep 17 00:00:00 2001 From: Adrien Schoffeniels Date: Mon, 21 Aug 2023 17:15:53 +0200 Subject: [PATCH] [IMP] web: move properties field's "add a property" btn in the cog menu Purpose: -------- When the property field is added into a form view, the "add a property" button is shown by default. However, most of the time the users won't add properties when opening a form view, making this button take up space for nothing. To alleviate this issue, commit [1] added an option that allows to hide this button, and added actions to allow adding properties from the cog menu instead. Now that properties are being added into several views, one would like this "add properties" button to be hidden by default, and show an entry in the cogmenu allowing add properties by default, without needing to create an action for every view using a property field. Therefore, a new static action "Add Properties" has been added in the form controller that is available if a properties field has been encountered during the parsing of the form view's arch. The "hideAddButton" has been changed into "showAddButton" and now allows to show the "Add a Property" by default. Task-3458627 [1]: https://github.com/odoo/odoo/commit/1f80810e39f811122a65e11cd8cac99aa39a7960 Part-of: odoo/odoo#137589 --- addons/crm/__manifest__.py | 1 - addons/crm/data/ir_actions_client_data.xml | 10 --- addons/crm/views/crm_lead_views.xml | 3 +- addons/fleet/data/fleet_data.xml | 8 -- addons/fleet/views/fleet_vehicle_views.xml | 3 +- addons/project/__manifest__.py | 1 - .../project/data/ir_actions_client_data.xml | 10 --- addons/project/views/project_task_views.xml | 3 +- .../fields/properties/properties_field.js | 36 +++----- .../fields/properties/properties_field.xml | 6 +- .../static/src/views/form/form_arch_parser.js | 3 + .../static/src/views/form/form_controller.js | 7 ++ .../views/fields/properties_field_tests.js | 90 ++++++++++++++++--- 13 files changed, 107 insertions(+), 74 deletions(-) delete mode 100644 addons/crm/data/ir_actions_client_data.xml delete mode 100644 addons/project/data/ir_actions_client_data.xml diff --git a/addons/crm/__manifest__.py b/addons/crm/__manifest__.py index 6d1a527bb4c..b688d53a110 100644 --- a/addons/crm/__manifest__.py +++ b/addons/crm/__manifest__.py @@ -32,7 +32,6 @@ 'data/crm_team_data.xml', 'data/digest_data.xml', 'data/ir_action_data.xml', - 'data/ir_actions_client_data.xml', 'data/ir_cron_data.xml', 'data/mail_message_subtype_data.xml', 'data/crm_recurring_plan_data.xml', diff --git a/addons/crm/data/ir_actions_client_data.xml b/addons/crm/data/ir_actions_client_data.xml deleted file mode 100644 index 49c1ca38d02..00000000000 --- a/addons/crm/data/ir_actions_client_data.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - Add Properties - crm.lead - action_configure_properties_field - - form - - diff --git a/addons/crm/views/crm_lead_views.xml b/addons/crm/views/crm_lead_views.xml index 807238547d7..bca2e13778b 100644 --- a/addons/crm/views/crm_lead_views.xml +++ b/addons/crm/views/crm_lead_views.xml @@ -252,8 +252,7 @@
- +
diff --git a/addons/fleet/data/fleet_data.xml b/addons/fleet/data/fleet_data.xml index 395c8cd65c4..3f87f150199 100644 --- a/addons/fleet/data/fleet_data.xml +++ b/addons/fleet/data/fleet_data.xml @@ -13,14 +13,6 @@ - - Add Properties - fleet.vehicle - action_configure_properties_field - - form - - New Request 4 diff --git a/addons/fleet/views/fleet_vehicle_views.xml b/addons/fleet/views/fleet_vehicle_views.xml index 474f300d826..84d94c60811 100644 --- a/addons/fleet/views/fleet_vehicle_views.xml +++ b/addons/fleet/views/fleet_vehicle_views.xml @@ -112,8 +112,7 @@
- +
diff --git a/addons/project/__manifest__.py b/addons/project/__manifest__.py index aa37bcfd017..dd2db436234 100644 --- a/addons/project/__manifest__.py +++ b/addons/project/__manifest__.py @@ -24,7 +24,6 @@ 'security/ir.model.access.csv', 'security/ir.model.access.xml', 'data/digest_data.xml', - 'data/ir_actions_client_data.xml', 'report/project_task_burndown_chart_report_views.xml', 'views/account_analytic_account_views.xml', 'views/digest_digest_views.xml', diff --git a/addons/project/data/ir_actions_client_data.xml b/addons/project/data/ir_actions_client_data.xml deleted file mode 100644 index 3cd1414f935..00000000000 --- a/addons/project/data/ir_actions_client_data.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - Add Properties - project.task - action_configure_properties_field - - form - - diff --git a/addons/project/views/project_task_views.xml b/addons/project/views/project_task_views.xml index 168c2ebb2dd..a9cf8f9a7fc 100644 --- a/addons/project/views/project_task_views.xml +++ b/addons/project/views/project_task_views.xml @@ -372,8 +372,7 @@
- +
diff --git a/addons/web/static/src/views/fields/properties/properties_field.js b/addons/web/static/src/views/fields/properties/properties_field.js index 7c6c910c8c5..e0e829f3475 100644 --- a/addons/web/static/src/views/fields/properties/properties_field.js +++ b/addons/web/static/src/views/fields/properties/properties_field.js @@ -8,7 +8,7 @@ import { PropertyDefinition } from "./property_definition"; import { Dropdown } from "@web/core/dropdown/dropdown"; import { DropdownItem } from "@web/core/dropdown/dropdown_item"; import { PropertyValue } from "./property_value"; -import { useService } from "@web/core/utils/hooks"; +import { useBus, useService } from "@web/core/utils/hooks"; import { usePopover } from "@web/core/popover/popover_hook"; import { ConfirmationDialog } from "@web/core/confirmation_dialog/confirmation_dialog"; import { reposition } from "@web/core/position_hook"; @@ -30,7 +30,7 @@ export class PropertiesField extends Component { ...standardFieldProps, context: { type: Object, optional: true }, columns: { type: Number, optional: true }, - hideAddButton: { type: Boolean, optional: true }, + showAddButton: { type: Boolean, optional: true }, hideKanbanOption: { type: Boolean, optional: true }, }; @@ -56,10 +56,17 @@ export class PropertiesField extends Component { this.state = useState({ canChangeDefinition: true, movedPropertyName: null, - hideAddButton: this.props.hideAddButton, + showAddButton: this.props.showAddButton, unfoldedSeparators: this._getUnfoldedSeparators(), }); + // Properties can be added from the cogmenu of the form controller + if (this.env.config?.viewType === "form") { + useBus(this.env.model.bus, "PROPERTY_FIELD:ADD_PROPERTY_VALUE", () => { + this.onPropertyCreate(); + }); + } + onWillStart(async () => { await this._checkDefinitionAccess(); }); @@ -609,7 +616,7 @@ export class PropertiesField extends Component { definition_changed: true, }); this.openPropertyDefinition = newName; - this.state.hideAddButton = false; + this.state.showAddButton = true; this.props.record.update({ [this.props.name]: propertiesDefinitions }); } @@ -939,29 +946,10 @@ export const propertiesField = { return { context: dynamicInfo.context, columns: parseInt(attrs.columns || "1"), - hideAddButton: archParseBoolean(attrs.hideAddButton), + showAddButton: archParseBoolean(attrs.showAddButton), hideKanbanOption: archParseBoolean(attrs.hideKanbanOption), }; }, }; registry.category("fields").add("properties", propertiesField); - -/** - * This action is meant to be called from a form client action - * and will let the user create properties, typically used along - * with the "hideAddButton" option of the properties field. - * - * @param {object} env - */ -async function actionAddProperty(env) { - const addProperty = document.querySelector(".o_field_property_add button"); - if (addProperty) { - addProperty.click(); - } else { - const message = _t("You can not create a new property."); - env.services.notification.add(message, { type: "danger" }); - } -} - -registry.category("actions").add("action_configure_properties_field", actionAddProperty); diff --git a/addons/web/static/src/views/fields/properties/properties_field.xml b/addons/web/static/src/views/fields/properties/properties_field.xml index cf48f2ea65c..911b973edf8 100644 --- a/addons/web/static/src/views/fields/properties/properties_field.xml +++ b/addons/web/static/src/views/fields/properties/properties_field.xml @@ -2,7 +2,7 @@
@@ -76,9 +76,9 @@
+ t-att-class="{'g-col-2': props.columns !== 1}">