Add week navigation to time sheet view

This commit is contained in:
Lance Edgar 2016-05-02 19:15:51 -05:00
parent 7e0e1f6659
commit 25ec005764
2 changed files with 68 additions and 16 deletions

View file

@ -6,6 +6,14 @@
<%def name="head_tags()"> <%def name="head_tags()">
${parent.head_tags()} ${parent.head_tags()}
<style type="text/css"> <style type="text/css">
.timesheet-header {
position: relative;
}
.timesheet-header .week-picker {
bottom: 0.5em;
position: absolute;
right: 0;
}
.timesheet { .timesheet {
border-bottom: 1px solid black; border-bottom: 1px solid black;
border-right: 1px solid black; border-right: 1px solid black;
@ -27,8 +35,32 @@
display: block; display: block;
} }
</style> </style>
<script type="text/javascript">
$(function() {
$('.week-picker #date').datepicker({
dateFormat: 'yy-mm-dd',
changeYear: true,
changeMonth: true,
showButtonPanel: true,
onSelect: function(dateText, inst) {
$(this).focus().select();
}
});
$('.week-picker form').submit(function() {
location.href = '${url('timesheet')}?date=' + $('.week-picker #date').val();
return false;
});
});
</script>
</%def> </%def>
<div class="timesheet-header">
<div class="field-wrapper employee"> <div class="field-wrapper employee">
<label>Employee</label> <label>Employee</label>
<div class="field"> <div class="field">
@ -43,6 +75,16 @@
</div> </div>
</div> </div>
<div class="week-picker">
${h.form(url('timesheet'))}
<label>Jump to week:</label>
${h.text('date', value=sunday.strftime('%Y-%m-%d'))}
${h.submit('go', "Go")}
${h.end_form()}
</div>
</div><!-- timesheet-header -->
<table class="timesheet"> <table class="timesheet">
<thead> <thead>
<tr> <tr>

View file

@ -41,10 +41,20 @@ class TimeSheetView(View):
""" """
def __call__(self): def __call__(self):
date = None
if 'date' in self.request.GET:
try:
date = datetime.datetime.strptime(self.request.GET['date'], '%Y-%m-%d').date()
except ValueError:
self.request.session.flash("The specified date is not valid: {}".format(self.request.GET['date']), 'error')
if not date:
date = localtime(self.rattail_config).date()
return self.render(date)
def render(self, date):
employee = self.request.user.employee employee = self.request.user.employee
assert employee assert employee
today = localtime(self.rattail_config).date() sunday = get_sunday(date)
sunday = get_sunday(today)
weekdays = [sunday] weekdays = [sunday]
for i in range(1, 7): for i in range(1, 7):
@ -103,9 +113,9 @@ class TimeSheetView(View):
def includeme(config): def includeme(config):
config.add_tailbone_permission('timesheet', 'timesheet.view', "View Time Sheet")
# current user's time sheet # current user's time sheet
config.add_route('timesheet', '/timesheet/') config.add_route('timesheet', '/timesheet/')
config.add_view(TimeSheetView, route_name='timesheet', config.add_view(TimeSheetView, route_name='timesheet',
renderer='/timesheet/index.mako', renderer='/timesheet/index.mako', permission='timesheet.view')
permission='timesheet.view')
config.add_tailbone_permission('timesheet', 'timesheet.view', "View Time Sheet")