diff --git a/labotel/indico_labotel/client/js/components/BookRoomFormExtraFields.jsx b/labotel/indico_labotel/client/js/components/BookRoomFormExtraFields.jsx new file mode 100644 index 00000000..dd8e85d8 --- /dev/null +++ b/labotel/indico_labotel/client/js/components/BookRoomFormExtraFields.jsx @@ -0,0 +1,46 @@ +// This file is part of the CERN Indico plugins. +// Copyright (C) 2014 - 2024 CERN +// +// The CERN Indico plugins are free software; you can redistribute +// them and/or modify them under the terms of the MIT License; see +// the LICENSE file for more details. + +import PropTypes from 'prop-types'; +import React from 'react'; +import {Icon, Segment} from 'semantic-ui-react'; + +import {FinalCheckbox} from 'indico/react/forms'; +import {Markdown} from 'indico/react/util'; + +export default function BookRoomFormExtraFields({room: {confirmationPrompt}, booking, disabled}) { + if (!confirmationPrompt || booking) { + return null; + } + return ( + +

+ + Confirm requirements +

+ {confirmationPrompt} + +
+ ); +} + +BookRoomFormExtraFields.propTypes = { + room: PropTypes.shape({ + confirmationPrompt: PropTypes.string, + }).isRequired, + booking: PropTypes.object, + disabled: PropTypes.bool.isRequired, +}; + +BookRoomFormExtraFields.defaultProps = { + booking: null, +}; diff --git a/labotel/indico_labotel/client/js/index.js b/labotel/indico_labotel/client/js/index.js index e0c6697f..29001a8c 100644 --- a/labotel/indico_labotel/client/js/index.js +++ b/labotel/indico_labotel/client/js/index.js @@ -6,8 +6,13 @@ // the LICENSE file for more details. import setup from 'indico/modules/rb/setup'; +import {registerPluginComponent} from 'indico/utils/plugins'; +import BookRoomFormExtraFields from './components/BookRoomFormExtraFields.jsx'; import overrides from './overrides'; import parametrized from './parametrized'; +const PLUGIN_NAME = 'labotel'; + setup({...parametrized, ...overrides}); +registerPluginComponent(PLUGIN_NAME, 'rb-booking-form-extra-fields', BookRoomFormExtraFields); diff --git a/labotel/indico_labotel/plugin.py b/labotel/indico_labotel/plugin.py index ef4e3b91..294575c4 100644 --- a/labotel/indico_labotel/plugin.py +++ b/labotel/indico_labotel/plugin.py @@ -14,6 +14,8 @@ from indico.core import signals from indico.core.auth import multipass from indico.core.plugins import IndicoPlugin +from indico.modules.rb.models.rooms import Room +from indico.modules.rb.schemas import RoomSchema from indico.web.flask.util import make_view_func from indico.web.forms.base import IndicoForm @@ -51,6 +53,7 @@ def init(self): current_app.before_request(self._before_request) self.connect(signals.plugin.cli, self._extend_indico_cli) self.connect(signals.plugin.get_template_customization_paths, self._override_templates) + self.connect(signals.plugin.schema_post_dump, self._inject_prompt_attribute, sender=RoomSchema) self.inject_bundle('labotel.js', WPLabotelBase) self.inject_bundle('labotel.css', WPLabotelBase) @@ -69,3 +72,8 @@ def _extend_indico_cli(self, sender, **kwargs): def _override_templates(self, sender, **kwargs): return os.path.join(self.root_path, 'template_overrides') + + def _inject_prompt_attribute(self, sender, data, **kwargs): + prompts = {room.id: value for room, value in Room.find_with_attribute('confirmation-prompt') if value} + for room in data: + room['confirmation_prompt'] = prompts.get(room['id'])