Add speed bump when leaving timesheet page w/ unsaved changes
Also add save/undo buttons to top as well as bottom of timesheet.
This commit is contained in:
parent
e153390c15
commit
9e7cb532c8
4 changed files with 127 additions and 57 deletions
|
@ -48,6 +48,11 @@ class ScheduleView(TimeSheetView):
|
|||
"""
|
||||
View for editing (full) schedule.
|
||||
"""
|
||||
# first process filters; will redirect if any were received
|
||||
form = Form(self.request, schema=ShiftFilter)
|
||||
self.process_filter_form(form)
|
||||
|
||||
# okay then, maybe process saved shift data
|
||||
if self.request.method == 'POST':
|
||||
|
||||
# organize form data by uuid / field
|
||||
|
@ -61,47 +66,42 @@ class ScheduleView(TimeSheetView):
|
|||
data[field][uuid] = self.request.POST[key]
|
||||
break
|
||||
|
||||
# if no fields, don't apply changes (filter form uses POST also)
|
||||
if any(data.itervalues()):
|
||||
# apply delete operations
|
||||
deleted = []
|
||||
for uuid, value in data['delete'].iteritems():
|
||||
assert value == 'delete'
|
||||
shift = Session.query(model.ScheduledShift).get(uuid)
|
||||
assert shift
|
||||
Session.delete(shift)
|
||||
deleted.append(uuid)
|
||||
|
||||
# apply delete operations
|
||||
deleted = []
|
||||
for uuid, value in data['delete'].iteritems():
|
||||
assert value == 'delete'
|
||||
# apply create / update operations
|
||||
created = {}
|
||||
updated = {}
|
||||
time_format = '%a %d %b %Y %I:%M %p'
|
||||
for uuid, employee_uuid in data['start_time'].iteritems():
|
||||
if uuid in deleted:
|
||||
continue
|
||||
if uuid.startswith('new-'):
|
||||
shift = model.ScheduledShift()
|
||||
shift.employee_uuid = data['employee_uuid'][uuid]
|
||||
shift.store_uuid = data['store_uuid'][uuid]
|
||||
Session.add(shift)
|
||||
created[uuid] = shift
|
||||
else:
|
||||
shift = Session.query(model.ScheduledShift).get(uuid)
|
||||
assert shift
|
||||
Session.delete(shift)
|
||||
deleted.append(uuid)
|
||||
updated[uuid] = shift
|
||||
start_time = datetime.datetime.strptime(data['start_time'][uuid], time_format)
|
||||
shift.start_time = make_utc(localtime(self.rattail_config, start_time))
|
||||
end_time = datetime.datetime.strptime(data['end_time'][uuid], time_format)
|
||||
shift.end_time = make_utc(localtime(self.rattail_config, end_time))
|
||||
|
||||
# apply create / update operations
|
||||
created = {}
|
||||
updated = {}
|
||||
time_format = '%a %d %b %Y %I:%M %p'
|
||||
for uuid, employee_uuid in data['start_time'].iteritems():
|
||||
if uuid in deleted:
|
||||
continue
|
||||
if uuid.startswith('new-'):
|
||||
shift = model.ScheduledShift()
|
||||
shift.employee_uuid = data['employee_uuid'][uuid]
|
||||
shift.store_uuid = data['store_uuid'][uuid]
|
||||
Session.add(shift)
|
||||
created[uuid] = shift
|
||||
else:
|
||||
shift = Session.query(model.ScheduledShift).get(uuid)
|
||||
assert shift
|
||||
updated[uuid] = shift
|
||||
start_time = datetime.datetime.strptime(data['start_time'][uuid], time_format)
|
||||
shift.start_time = make_utc(localtime(self.rattail_config, start_time))
|
||||
end_time = datetime.datetime.strptime(data['end_time'][uuid], time_format)
|
||||
shift.end_time = make_utc(localtime(self.rattail_config, end_time))
|
||||
self.request.session.flash("Changes were applied: created {}, updated {}, "
|
||||
"deleted {} Scheduled Shifts".format(
|
||||
len(created), len(updated), len(deleted)))
|
||||
return self.redirect(self.request.route_url('schedule.edit'))
|
||||
|
||||
self.request.session.flash("Changes were applied: created {}, updated {}, "
|
||||
"deleted {} Scheduled Shifts".format(
|
||||
len(created), len(updated), len(deleted)))
|
||||
return self.redirect(self.request.route_url('schedule.edit'))
|
||||
|
||||
form = Form(self.request, schema=ShiftFilter)
|
||||
self.process_filter_form(form)
|
||||
context = self.get_timesheet_context()
|
||||
context['form'] = form
|
||||
context['page_title'] = "Edit Schedule"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue