Add week navigation to time sheet view
This commit is contained in:
parent
7e0e1f6659
commit
25ec005764
|
@ -6,6 +6,14 @@
|
|||
<%def name="head_tags()">
|
||||
${parent.head_tags()}
|
||||
<style type="text/css">
|
||||
.timesheet-header {
|
||||
position: relative;
|
||||
}
|
||||
.timesheet-header .week-picker {
|
||||
bottom: 0.5em;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
}
|
||||
.timesheet {
|
||||
border-bottom: 1px solid black;
|
||||
border-right: 1px solid black;
|
||||
|
@ -27,21 +35,55 @@
|
|||
display: block;
|
||||
}
|
||||
</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>
|
||||
|
||||
<div class="field-wrapper employee">
|
||||
<label>Employee</label>
|
||||
<div class="field">
|
||||
${employee}
|
||||
</div>
|
||||
</div>
|
||||
<div class="timesheet-header">
|
||||
|
||||
<div class="field-wrapper week">
|
||||
<label>Week of</label>
|
||||
<div class="field">
|
||||
${week_of}
|
||||
<div class="field-wrapper employee">
|
||||
<label>Employee</label>
|
||||
<div class="field">
|
||||
${employee}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field-wrapper week">
|
||||
<label>Week of</label>
|
||||
<div class="field">
|
||||
${week_of}
|
||||
</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">
|
||||
<thead>
|
||||
|
|
|
@ -41,10 +41,20 @@ class TimeSheetView(View):
|
|||
"""
|
||||
|
||||
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
|
||||
assert employee
|
||||
today = localtime(self.rattail_config).date()
|
||||
sunday = get_sunday(today)
|
||||
sunday = get_sunday(date)
|
||||
|
||||
weekdays = [sunday]
|
||||
for i in range(1, 7):
|
||||
|
@ -103,9 +113,9 @@ class TimeSheetView(View):
|
|||
|
||||
def includeme(config):
|
||||
|
||||
config.add_tailbone_permission('timesheet', 'timesheet.view', "View Time Sheet")
|
||||
|
||||
# current user's time sheet
|
||||
config.add_route('timesheet', '/timesheet/')
|
||||
config.add_view(TimeSheetView, route_name='timesheet',
|
||||
renderer='/timesheet/index.mako',
|
||||
permission='timesheet.view')
|
||||
config.add_tailbone_permission('timesheet', 'timesheet.view', "View Time Sheet")
|
||||
renderer='/timesheet/index.mako', permission='timesheet.view')
|
||||
|
|
Loading…
Reference in a new issue