Improve "employees" list when viewing a department, for buefy themes
This commit is contained in:
parent
3b6b1aa5b6
commit
ec5ff8a788
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
<%def name="page_content()">
|
<%def name="page_content()">
|
||||||
${parent.page_content()}
|
${parent.page_content()}
|
||||||
|
% if not use_buefy:
|
||||||
<h2>Employees</h2>
|
<h2>Employees</h2>
|
||||||
|
|
||||||
% if employees:
|
% if employees:
|
||||||
|
@ -12,7 +12,16 @@
|
||||||
% else:
|
% else:
|
||||||
<p>No employees are assigned to this department.</p>
|
<p>No employees are assigned to this department.</p>
|
||||||
% endif
|
% endif
|
||||||
|
% endif
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
|
<%def name="modify_this_page_vars()">
|
||||||
|
${parent.modify_this_page_vars()}
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
${form.component_studly}Data.employeesData = ${json.dumps(employees_data)|n}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</%def>
|
||||||
|
|
||||||
${parent.body()}
|
${parent.body()}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import six
|
||||||
from rattail.db import model
|
from rattail.db import model
|
||||||
|
|
||||||
from deform import widget as dfwidget
|
from deform import widget as dfwidget
|
||||||
|
from webhelpers2.html import HTML
|
||||||
|
|
||||||
from tailbone import grids
|
from tailbone import grids
|
||||||
from tailbone.views import MasterView, AutocompleteView
|
from tailbone.views import MasterView, AutocompleteView
|
||||||
|
@ -59,6 +60,7 @@ class DepartmentView(MasterView):
|
||||||
'personnel',
|
'personnel',
|
||||||
'exempt_from_gross_sales',
|
'exempt_from_gross_sales',
|
||||||
'allow_product_deletions',
|
'allow_product_deletions',
|
||||||
|
'employees',
|
||||||
]
|
]
|
||||||
|
|
||||||
def configure_grid(self, g):
|
def configure_grid(self, g):
|
||||||
|
@ -73,23 +75,72 @@ class DepartmentView(MasterView):
|
||||||
|
|
||||||
def configure_form(self, f):
|
def configure_form(self, f):
|
||||||
super(DepartmentView, self).configure_form(f)
|
super(DepartmentView, self).configure_form(f)
|
||||||
|
use_buefy = self.get_use_buefy()
|
||||||
|
|
||||||
f.remove_field('subdepartments')
|
f.remove_field('subdepartments')
|
||||||
f.remove_field('employees')
|
|
||||||
|
if not use_buefy or self.creating or self.editing:
|
||||||
|
f.remove('employees')
|
||||||
|
else:
|
||||||
|
f.set_renderer('employees', self.render_employees)
|
||||||
|
|
||||||
f.set_type('product', 'boolean')
|
f.set_type('product', 'boolean')
|
||||||
f.set_type('personnel', 'boolean')
|
f.set_type('personnel', 'boolean')
|
||||||
|
|
||||||
|
def render_employees(self, department, field):
|
||||||
|
route_prefix = self.get_route_prefix()
|
||||||
|
permission_prefix = self.get_permission_prefix()
|
||||||
|
|
||||||
|
factory = self.get_grid_factory()
|
||||||
|
g = factory(
|
||||||
|
key='{}.employees'.format(route_prefix),
|
||||||
|
data=[],
|
||||||
|
columns=[
|
||||||
|
'first_name',
|
||||||
|
'last_name',
|
||||||
|
],
|
||||||
|
sortable=True,
|
||||||
|
sorters={'first_name': True, 'last_name': True},
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.request.has_perm('employees.view'):
|
||||||
|
g.main_actions.append(self.make_action('view', icon='eye'))
|
||||||
|
if self.request.has_perm('employees.edit'):
|
||||||
|
g.main_actions.append(self.make_action('edit', icon='edit'))
|
||||||
|
|
||||||
|
return HTML.literal(
|
||||||
|
g.render_buefy_table_element(data_prop='employeesData'))
|
||||||
|
|
||||||
def template_kwargs_view(self, **kwargs):
|
def template_kwargs_view(self, **kwargs):
|
||||||
|
kwargs = super(DepartmentView, self).template_kwargs_view(**kwargs)
|
||||||
|
use_buefy = self.get_use_buefy()
|
||||||
department = kwargs['instance']
|
department = kwargs['instance']
|
||||||
if department.employees:
|
department_employees = sorted(department.employees, key=six.text_type)
|
||||||
employees = sorted(department.employees, key=six.text_type)
|
|
||||||
actions = [
|
if use_buefy:
|
||||||
grids.GridAction('view', icon='zoomin',
|
employees = []
|
||||||
url=lambda r, i: self.request.route_url('employees.view', uuid=r.uuid))
|
for employee in department_employees:
|
||||||
]
|
person = employee.person
|
||||||
kwargs['employees'] = grids.Grid(None, employees, ['display_name'], request=self.request,
|
employees.append({
|
||||||
model_class=model.Employee, main_actions=actions)
|
'uuid': employee.uuid,
|
||||||
else:
|
'first_name': person.first_name,
|
||||||
kwargs['employees'] = None
|
'last_name': person.last_name,
|
||||||
|
'_action_url_view': self.request.route_url('employees.view', uuid=employee.uuid),
|
||||||
|
'_action_url_edit': self.request.route_url('employees.edit', uuid=employee.uuid),
|
||||||
|
})
|
||||||
|
kwargs['employees_data'] = employees
|
||||||
|
|
||||||
|
else: # not buefy
|
||||||
|
if department.employees:
|
||||||
|
actions = [
|
||||||
|
grids.GridAction('view', icon='zoomin',
|
||||||
|
url=lambda r, i: self.request.route_url('employees.view', uuid=r.uuid))
|
||||||
|
]
|
||||||
|
kwargs['employees'] = grids.Grid(None, department_employees, ['display_name'], request=self.request,
|
||||||
|
model_class=model.Employee, main_actions=actions)
|
||||||
|
else:
|
||||||
|
kwargs['employees'] = None
|
||||||
|
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
def before_delete(self, department):
|
def before_delete(self, department):
|
||||||
|
|
Loading…
Reference in a new issue