1 """GNUmed staff management widgets."""
2
3 __author__ = "K. Hilbert <Karsten.Hilbert@gmx.net>"
4 __license__ = "GPL v2 or later (details at http://www.gnu.org)"
5
6 import logging
7
8 import wx
9
10 from Gnumed.pycommon import gmTools, gmI18N
11 from Gnumed.business import gmPerson
12 from Gnumed.business import gmStaff
13 from Gnumed.wxpython import gmGuiHelpers, gmAuthWidgets
14 from Gnumed.wxGladeWidgets import wxgAddPatientAsStaffDlg, wxgEditStaffListDlg
15
16 _log = logging.getLogger('gm.ui')
17
19
21 wxgEditStaffListDlg.wxgEditStaffListDlg.__init__(self, *args, **kwds)
22
23 self._LCTRL_staff.InsertColumn(0, _('Alias'))
24 self._LCTRL_staff.InsertColumn(1, _('DB account'))
25 self._LCTRL_staff.InsertColumn(2, _('Role'))
26 self._LCTRL_staff.InsertColumn(3, _('Name'))
27 self._LCTRL_staff.InsertColumn(4, _('Comment'))
28 self._LCTRL_staff.InsertColumn(5, _('Status'))
29
30 self.__init_ui_data()
31
32
33
35 lbl_active = {True: _('active'), False: _('inactive')}
36 lbl_login = {True: _('can login'), False: _('can not login')}
37
38 self._LCTRL_staff.DeleteAllItems()
39 staff_list = gmStaff.get_staff_list()
40 pos = len(staff_list) + 1
41 for staff in staff_list:
42 row_num = self._LCTRL_staff.InsertStringItem(pos, label=staff['short_alias'])
43 self._LCTRL_staff.SetStringItem(index = row_num, col = 1, label = staff['db_user'])
44 self._LCTRL_staff.SetStringItem(index = row_num, col = 2, label = staff['l10n_role'])
45 title = gmTools.coalesce(staff['title'], '')
46 self._LCTRL_staff.SetStringItem(index = row_num, col = 3, label = '%s %s, %s' % (title, staff['lastnames'], staff['firstnames']))
47 self._LCTRL_staff.SetStringItem(index = row_num, col = 4, label = gmTools.coalesce(staff['comment'], ''))
48 self._LCTRL_staff.SetStringItem(index = row_num, col = 5, label = '%s / %s' % (lbl_active[bool(staff['is_active'])], lbl_login[bool(staff['can_login'])]))
49
50 if staff['is_active'] and staff['can_login']:
51
52 pass
53 elif not staff['is_active'] and not staff['can_login']:
54 self._LCTRL_staff.SetItemTextColour(row_num, col=wx.LIGHT_GREY)
55 else:
56 self._LCTRL_staff.SetItemTextColour(row_num, col=wx.NamedColour('RED'))
57
58 self._LCTRL_staff.SetItemData(item = row_num, data = staff['pk_staff'])
59
60 if len(staff_list) > 0:
61 self._LCTRL_staff.SetColumnWidth(col=0, width=wx.LIST_AUTOSIZE)
62 self._LCTRL_staff.SetColumnWidth(col=1, width=wx.LIST_AUTOSIZE_USEHEADER)
63 self._LCTRL_staff.SetColumnWidth(col=2, width=wx.LIST_AUTOSIZE)
64 self._LCTRL_staff.SetColumnWidth(col=3, width=wx.LIST_AUTOSIZE)
65 self._LCTRL_staff.SetColumnWidth(col=4, width=wx.LIST_AUTOSIZE)
66 self._LCTRL_staff.SetColumnWidth(col=5, width=wx.LIST_AUTOSIZE)
67
68
69 self._btn_save.Enable(False)
70 self._btn_delete.Enable(False)
71 self._btn_deactivate.Enable(False)
72 self._btn_activate.Enable(False)
73
74 self._TCTRL_name.SetValue('')
75 self._TCTRL_alias.SetValue('')
76 self._TCTRL_account.SetValue('')
77 self._TCTRL_comment.SetValue('')
78
79
80
82 self._btn_save.Enable(True)
83 self._btn_delete.Enable(True)
84 self._btn_deactivate.Enable(True)
85 self._btn_activate.Enable(True)
86
87 pk_staff = self._LCTRL_staff.GetItemData(self._LCTRL_staff.GetFirstSelected())
88 staff = gmStaff.cStaff(aPK_obj=pk_staff)
89 self._TCTRL_name.SetValue('%s.%s %s' % (staff['title'], staff['firstnames'], staff['lastnames']))
90 self._TCTRL_alias.SetValue(staff['short_alias'])
91 self._TCTRL_account.SetValue(staff['db_user'])
92 self._TCTRL_comment.SetValue(gmTools.coalesce(staff['comment'], ''))
93
95 self._btn_save.Enable(False)
96 self._btn_delete.Enable(False)
97 self._btn_deactivate.Enable(False)
98 self._btn_activate.Enable(False)
99
100 self._TCTRL_name.SetValue('')
101 self._TCTRL_alias.SetValue('')
102 self._TCTRL_account.SetValue('')
103 self._TCTRL_comment.SetValue('')
104
114
124
137
160
162
166
167
168
179
180
181
184
234
235