Add support for toggling custorder item "flagged"

This commit is contained in:
Lance Edgar 2023-09-10 17:49:29 -05:00
parent e49e0edc57
commit ddb8e3656f
2 changed files with 64 additions and 4 deletions

View file

@ -324,6 +324,12 @@
this.$refs.changeStatusForm.submit()
}
${form.component_studly}Data.changeFlaggedSubmitting = false
${form.component_studly}.methods.changeFlaggedSubmit = function() {
this.changeFlaggedSubmitting = true
}
% endif
% if master.has_perm('add_note'):

View file

@ -34,7 +34,7 @@ from rattail.time import localtime
from webhelpers2.html import HTML, tags
from tailbone.views import MasterView
from tailbone.util import raw_datetime
from tailbone.util import raw_datetime, csrf_token
class CustomerOrderItemView(MasterView):
@ -231,9 +231,53 @@ class CustomerOrderItemView(MasterView):
# status_code
f.set_renderer('status_code', self.render_status_code)
# flagged
f.set_renderer('flagged', self.render_flagged)
# notes
f.set_renderer('notes', self.render_notes)
def render_flagged(self, item, field):
text = "Yes" if item.flagged else "No"
items = [HTML.tag('span', c=text)]
if self.has_perm('change_status'):
button_text = "Un-Flag This" if item.flagged else "Flag This"
form = [
tags.form(self.get_action_url('change_flagged', item),
**{'@submit': 'changeFlaggedSubmit'}),
csrf_token(self.request),
tags.hidden('new_flagged',
value='false' if item.flagged else 'true'),
HTML.tag('b-button',
type='is-warning' if item.flagged else 'is-primary',
c=f"{{{{ changeFlaggedSubmitting ? 'Working, please wait...' : '{button_text}' }}}}",
native_type='submit',
style='margin-left: 1rem;',
icon_pack='fas', icon_left='flag',
**{':disabled': 'changeFlaggedSubmitting'}),
tags.end_form(),
]
items.append(HTML.literal('').join(form))
left = HTML.tag('div', class_='level-left', c=items)
outer = HTML.tag('div', class_='level', c=[left])
return outer
def change_flagged(self):
"""
View for changing "flagged" status of one or more order products.
"""
item = self.get_instance()
redirect = self.redirect(self.get_action_url('view', item))
new_flagged = self.request.POST['new_flagged'] == 'true'
item.flagged = new_flagged
flagged = "FLAGGED" if new_flagged else "UN-FLAGGED"
self.request.session.flash(f"Order item has been {flagged}")
return redirect
def highlight_pending_field(self, item, field, value=None):
if value is None:
value = getattr(item, field)
@ -299,14 +343,16 @@ class CustomerOrderItemView(MasterView):
factory = self.get_grid_factory()
g = factory(
key='{}.notes'.format(route_prefix),
key=f'{route_prefix}.notes',
data=[],
columns=[
'text',
'created_by',
'created',
'created_by',
'text',
],
labels={
'created': "Date/Time",
'created_by': "Added by",
'text': "Note",
},
)
@ -555,6 +601,14 @@ class CustomerOrderItemView(MasterView):
route_name='{}.change_status'.format(route_prefix),
permission='{}.change_status'.format(permission_prefix))
# change flagged
config.add_route(f'{route_prefix}.change_flagged',
f'{instance_url_prefix}/change-flagged',
request_method='POST')
config.add_view(cls, attr='change_flagged',
route_name=f'{route_prefix}.change_flagged',
permission=f'{permission_prefix}.change_status')
# add note
config.add_tailbone_permission(permission_prefix,
'{}.add_note'.format(permission_prefix),