Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions alinka/constants/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

RPSO_SUPPORT_CENTER_TYPE_ID = 48
INVALID_FORM_MESSAGE = "Popraw błędy w formularzu."
CHOOSE_FROM_LIST_MESSAGE = "Wybierz z listy..."


class DocumentsTypes(Enum):
Expand Down
17 changes: 16 additions & 1 deletion alinka/widget/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
)

from alinka import rspo_client
from alinka.constants.common import CHOOSE_FROM_LIST_MESSAGE


class ValidationMixin:
Expand Down Expand Up @@ -129,12 +130,15 @@ def __init__(
min_length: int | None = None,
required: bool = False,
static: bool = False,
unselectable: bool = False,
):
self.label = text
self.is_required = required
# If static, options won't change dynamically, e.g. school types
# clear means in this case remove selection only
self.is_static = static
# If unselectable, user is able to remove selection (set to no selection)
self.is_unselectable = unselectable
super().__init__(parent)
layout = QVBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
Expand All @@ -143,7 +147,9 @@ def __init__(
self.combobox = QComboBox(self)
if min_length:
self.combobox.setMinimumWidth(min_length)

if self.is_unselectable:
self.combobox.insertItem(0, CHOOSE_FROM_LIST_MESSAGE)
self.combobox.currentIndexChanged.connect(self._clear_if_unselected)
self.combobox.currentIndexChanged.connect(self.clear_validation_state)
layout.addWidget(label)
layout.addWidget(self.combobox)
Expand All @@ -158,11 +164,20 @@ def text(self, text):
if index >= 0:
self.combobox.setCurrentIndex(index)

def _clear_if_unselected(self) -> None:
if self.is_unselectable and self.combobox.currentIndex() == 0:
self.remove_selection()

def remove_selection(self) -> None:
self.combobox.setCurrentIndex(-1)

def _insert_invitation_item(self) -> None:
self.combobox.insertItem(0, CHOOSE_FROM_LIST_MESSAGE)

def clear_options(self) -> None:
self.combobox.clear()
if self.is_unselectable:
self._insert_invitation_item()

def clear(self) -> None:
self.remove_selection()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, parent: QWidget):
self.application_reason = LabeledComboBoxComponent("Z uwagi na", self)
self.application_reason.combobox.setPlaceholderText("Wybierz z listy...")
self.application_reason.combobox.currentTextChanged.connect(self.change_application_reason)
self.application_reason_2 = LabeledComboBoxComponent("Z uwagi na", self)
self.application_reason_2 = LabeledComboBoxComponent("Z uwagi na", self, unselectable=True)
self.application_reason_2.combobox.setPlaceholderText("Wybierz z listy...")
self.application_reason_2.setFixedHeight(0)

Expand Down Expand Up @@ -67,8 +67,8 @@ def change_application_subject(self):
self.application_reason.combobox.addItem(reason_description, reason)

def change_application_reason(self):
self.application_reason_2.combobox.clear()
self.application_period.combobox.clear()
self.application_reason_2.clear()
self.application_period.clear()
primary_reason = self.application_reason.combobox.currentData()
if primary_reason == Reason.GLEBOKIE:
self._activity_form.setFixedHeight(45)
Expand Down Expand Up @@ -154,11 +154,11 @@ def activity_form(self) -> ActivityForm | None:

def clear(self):
self.application_date.date_input.clear()
self.application_subject.combobox.setCurrentIndex(-1)
self.application_reason.combobox.setCurrentIndex(-1)
self.application_reason_2.combobox.setCurrentIndex(-1)
self.application_subject.remove_selection()
self.application_reason.remove_selection()
self.application_reason_2.remove_selection()
self.application_reason_2.setFixedHeight(0)
self._activity_form.combobox.setCurrentIndex(-1)
self._activity_form.remove_selection()
self._activity_form.setFixedHeight(0)
self._activity_form.combobox.setEnabled(False)
self.application_period.combobox.setCurrentIndex(-1)
self.application_period.clear()