Improve basic mobile views for customers, people
This commit is contained in:
parent
eccce1cabb
commit
3cc8adba86
|
@ -136,6 +136,7 @@ class CustomersView(MasterView):
|
||||||
g.set_link('id')
|
g.set_link('id')
|
||||||
g.set_link('number')
|
g.set_link('number')
|
||||||
g.set_link('name')
|
g.set_link('name')
|
||||||
|
g.set_link('person')
|
||||||
|
|
||||||
def get_mobile_data(self, session=None):
|
def get_mobile_data(self, session=None):
|
||||||
# TODO: hacky!
|
# TODO: hacky!
|
||||||
|
@ -172,7 +173,9 @@ class CustomersView(MasterView):
|
||||||
raise HTTPNotFound
|
raise HTTPNotFound
|
||||||
|
|
||||||
def configure_form(self, f):
|
def configure_form(self, f):
|
||||||
super(CustomersView, self).configure_form(f)
|
if not self.mobile:
|
||||||
|
super(CustomersView, self).configure_form(f)
|
||||||
|
|
||||||
customer = f.model_instance
|
customer = f.model_instance
|
||||||
permission_prefix = self.get_permission_prefix()
|
permission_prefix = self.get_permission_prefix()
|
||||||
|
|
||||||
|
@ -196,6 +199,13 @@ class CustomersView(MasterView):
|
||||||
preferences.insert(0, ('', "(no preference)"))
|
preferences.insert(0, ('', "(no preference)"))
|
||||||
f.set_widget('email_preference', dfwidget.SelectWidget(values=preferences))
|
f.set_widget('email_preference', dfwidget.SelectWidget(values=preferences))
|
||||||
|
|
||||||
|
# person
|
||||||
|
if self.creating:
|
||||||
|
f.remove_field('person')
|
||||||
|
else:
|
||||||
|
f.set_readonly('person')
|
||||||
|
f.set_renderer('person', self.form_render_person)
|
||||||
|
|
||||||
# people
|
# people
|
||||||
if self.creating:
|
if self.creating:
|
||||||
f.remove_field('people')
|
f.remove_field('people')
|
||||||
|
@ -212,6 +222,10 @@ class CustomersView(MasterView):
|
||||||
f.set_renderer('groups', self.render_groups)
|
f.set_renderer('groups', self.render_groups)
|
||||||
f.set_readonly('groups')
|
f.set_readonly('groups')
|
||||||
|
|
||||||
|
def configure_mobile_form(self, f):
|
||||||
|
super(CustomersView, self).configure_mobile_form(f)
|
||||||
|
self.configure_form(f)
|
||||||
|
|
||||||
def objectify(self, form, data):
|
def objectify(self, form, data):
|
||||||
customer = super(CustomersView, self).objectify(form, data)
|
customer = super(CustomersView, self).objectify(form, data)
|
||||||
customer = self.objectify_contact(customer, data)
|
customer = self.objectify_contact(customer, data)
|
||||||
|
@ -230,6 +244,12 @@ class CustomersView(MasterView):
|
||||||
return six.text_type(customer.addresses[0])
|
return six.text_type(customer.addresses[0])
|
||||||
|
|
||||||
def grid_render_person(self, customer, field):
|
def grid_render_person(self, customer, field):
|
||||||
|
person = getattr(customer, field)
|
||||||
|
if not person:
|
||||||
|
return ""
|
||||||
|
return six.text_type(person)
|
||||||
|
|
||||||
|
def form_render_person(self, customer, field):
|
||||||
person = getattr(customer, field)
|
person = getattr(customer, field)
|
||||||
if not person:
|
if not person:
|
||||||
return ""
|
return ""
|
||||||
|
@ -245,9 +265,12 @@ class CustomersView(MasterView):
|
||||||
|
|
||||||
items = []
|
items = []
|
||||||
for person in people:
|
for person in people:
|
||||||
link = tags.link_to(person, self.request.route_url('people.view', uuid=person.uuid))
|
text = six.text_type(person)
|
||||||
items.append(HTML.tag('li', link))
|
route = '{}people.view'.format('mobile.' if self.mobile else '')
|
||||||
return HTML.tag('ul', HTML.literal('').join(items))
|
url = self.request.route_url(route, uuid=person.uuid)
|
||||||
|
link = tags.link_to(text, url)
|
||||||
|
items.append(HTML.tag('li', c=[link]))
|
||||||
|
return HTML.tag('ul', c=items)
|
||||||
|
|
||||||
def render_people_removable(self, customer, field):
|
def render_people_removable(self, customer, field):
|
||||||
people = customer.people
|
people = customer.people
|
||||||
|
|
|
@ -45,6 +45,7 @@ class PeopleView(MasterView):
|
||||||
model_title_plural = "People"
|
model_title_plural = "People"
|
||||||
route_prefix = 'people'
|
route_prefix = 'people'
|
||||||
has_versions = True
|
has_versions = True
|
||||||
|
supports_mobile = True
|
||||||
|
|
||||||
grid_columns = [
|
grid_columns = [
|
||||||
'display_name',
|
'display_name',
|
||||||
|
@ -67,6 +68,19 @@ class PeopleView(MasterView):
|
||||||
'users',
|
'users',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
mobile_form_fields = [
|
||||||
|
'first_name',
|
||||||
|
'middle_name',
|
||||||
|
'last_name',
|
||||||
|
'display_name',
|
||||||
|
'phone',
|
||||||
|
'email',
|
||||||
|
'address',
|
||||||
|
'employee',
|
||||||
|
'customers',
|
||||||
|
'users',
|
||||||
|
]
|
||||||
|
|
||||||
def configure_grid(self, g):
|
def configure_grid(self, g):
|
||||||
super(PeopleView, self).configure_grid(g)
|
super(PeopleView, self).configure_grid(g)
|
||||||
|
|
||||||
|
@ -126,7 +140,8 @@ class PeopleView(MasterView):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def configure_form(self, f):
|
def configure_form(self, f):
|
||||||
super(PeopleView, self).configure_form(f)
|
if not self.mobile:
|
||||||
|
super(PeopleView, self).configure_form(f)
|
||||||
|
|
||||||
f.set_label('display_name', "Full Name")
|
f.set_label('display_name', "Full Name")
|
||||||
|
|
||||||
|
@ -148,6 +163,10 @@ class PeopleView(MasterView):
|
||||||
f.set_readonly('users')
|
f.set_readonly('users')
|
||||||
f.set_renderer('users', self.render_users)
|
f.set_renderer('users', self.render_users)
|
||||||
|
|
||||||
|
def configure_mobile_form(self, f):
|
||||||
|
super(PeopleView, self).configure_mobile_form(f)
|
||||||
|
self.configure_form(f)
|
||||||
|
|
||||||
def render_employee(self, person, field):
|
def render_employee(self, person, field):
|
||||||
employee = person.employee
|
employee = person.employee
|
||||||
if not employee:
|
if not employee:
|
||||||
|
@ -168,7 +187,8 @@ class PeopleView(MasterView):
|
||||||
text = "({}) {}".format(customer.id, text)
|
text = "({}) {}".format(customer.id, text)
|
||||||
elif customer.number:
|
elif customer.number:
|
||||||
text = "({}) {}".format(customer.number, text)
|
text = "({}) {}".format(customer.number, text)
|
||||||
url = self.request.route_url('customers.view', uuid=customer.uuid)
|
route = '{}customers.view'.format('mobile.' if self.mobile else '')
|
||||||
|
url = self.request.route_url(route, uuid=customer.uuid)
|
||||||
items.append(HTML.tag('li', c=[tags.link_to(text, url)]))
|
items.append(HTML.tag('li', c=[tags.link_to(text, url)]))
|
||||||
return HTML.tag('ul', c=items)
|
return HTML.tag('ul', c=items)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue