Project

General

Profile

0001-workflows-use-everybody-as-empty-label-for-message-c.patch

Frédéric Péters, 06 Jul 2021 03:16 PM

Download (5.05 KB)

View differences:

Subject: [PATCH] workflows: use "everybody" as empty label for message/comment
 actions (#55410)

 wcs/qommon/form.py                  | 26 ++++++++++++++++++++++++++
 wcs/qommon/static/js/widget_list.js |  6 ++++++
 wcs/wf/register_comment.py          | 11 ++++-------
 wcs/workflows.py                    | 10 ++++------
 4 files changed, 40 insertions(+), 13 deletions(-)
wcs/qommon/form.py
1759 1759
        return r.getvalue()
1760 1760

  
1761 1761

  
1762
class WidgetListOfRoles(WidgetList):
1763
    def __init__(self, name, value=None, roles=None, **kwargs):
1764
        self.first_element_empty_label = kwargs.pop('first_element_empty_label', '---')
1765
        super().__init__(
1766
            name,
1767
            value=value,
1768
            element_type=SingleSelectWidget,
1769
            element_kwargs={
1770
                'render_br': False,
1771
                'options': [(None, '---', None)] + roles or [],
1772
            },
1773
            **kwargs,
1774
        )
1775

  
1776
    def get_widgets(self):
1777
        seen = False
1778
        for widget in super().get_widgets():
1779
            # change first option (empty value) of first element to use a specific label
1780
            if not seen and isinstance(widget, SingleSelectWidget):
1781
                widget.full_options = widget.full_options[:]
1782
                widget.full_options[0] = list(widget.full_options[0])
1783
                widget.full_options[0][1] = self.first_element_empty_label
1784
                seen = True
1785
            yield widget
1786

  
1787

  
1762 1788
class WidgetDict(quixote.form.widget.WidgetDict):
1763 1789
    # Fix the title and hint setting
1764 1790
    # FIXME: to be fixed in Quixote upstream : title and hint parameters should be removed
wcs/qommon/static/js/widget_list.js
50 50
                        }
51 51
                    }
52 52
                );
53
                if (name_attr == 'to$add_element') {
54
                  /* replace 1st list element by an empty label, as it's used
55
                   * to remove an actual selection */
56
                  $(new_row).find('option[value="None"]').first().text('----');
57
                }
58

  
53 59
                /* add new row after the last row */
54 60
                $(row).after($(new_row));
55 61

  
wcs/wf/register_comment.py
28 28
)
29 29

  
30 30
from ..qommon import _, ezt, get_logger
31
from ..qommon.form import SingleSelectWidget, TextWidget, WidgetList
31
from ..qommon.form import TextWidget, WidgetListOfRoles
32 32
from ..qommon.template import TemplateError
33 33

  
34 34

  
......
97 97
            )
98 98
        if 'to' in parameters:
99 99
            form.add(
100
                WidgetList,
100
                WidgetListOfRoles,
101 101
                '%sto' % prefix,
102 102
                title=_('To'),
103
                element_type=SingleSelectWidget,
104 103
                value=self.to or [],
105 104
                add_element_label=self.get_add_role_label(),
106
                element_kwargs={
107
                    'render_br': False,
108
                    'options': [(None, '---', None)] + self.get_list_of_roles(include_logged_in_users=False),
109
                },
105
                first_element_empty_label=_('Everybody'),
106
                roles=self.get_list_of_roles(include_logged_in_users=False),
110 107
            )
111 108

  
112 109
    def get_parameters(self):
wcs/workflows.py
49 49
    ValidatedStringWidget,
50 50
    VarnameWidget,
51 51
    WidgetList,
52
    WidgetListOfRoles,
52 53
    WysiwygTextWidget,
53 54
)
54 55
from .qommon.humantime import seconds2humanduration
......
3246 3247
            )
3247 3248
        if 'to' in parameters:
3248 3249
            form.add(
3249
                WidgetList,
3250
                WidgetListOfRoles,
3250 3251
                '%sto' % prefix,
3251 3252
                title=_('To'),
3252
                element_type=SingleSelectWidget,
3253 3253
                value=self.to or [],
3254 3254
                add_element_label=self.get_add_role_label(),
3255
                element_kwargs={
3256
                    'render_br': False,
3257
                    'options': [(None, '---', None)] + self.get_list_of_roles(include_logged_in_users=False),
3258
                },
3255
                first_element_empty_label=_('Everybody'),
3256
                roles=self.get_list_of_roles(include_logged_in_users=False),
3259 3257
            )
3260 3258

  
3261 3259
    def get_parameters(self):
3262
-