Skip to content

Commit

Permalink
Add option to show custom booking prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
ThiefMaster committed Jul 16, 2024
1 parent ad95677 commit e9b833a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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 (
<Segment inverted color="orange">
<h3 style={{marginBottom: '0.5em'}}>
<Icon name="warning sign" />
Confirm requirements
</h3>
<Markdown targetBlank>{confirmationPrompt}</Markdown>
<FinalCheckbox
name="_requirements_confirmed"
required
disabled={disabled}
label="I confirm that I meet the requirements"
/>
</Segment>
);
}

BookRoomFormExtraFields.propTypes = {
room: PropTypes.shape({
confirmationPrompt: PropTypes.string,
}).isRequired,
booking: PropTypes.object,
disabled: PropTypes.bool.isRequired,
};

BookRoomFormExtraFields.defaultProps = {
booking: null,
};
5 changes: 5 additions & 0 deletions labotel/indico_labotel/client/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
8 changes: 8 additions & 0 deletions labotel/indico_labotel/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand All @@ -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'])

0 comments on commit e9b833a

Please sign in to comment.