From 0207ee43773ba9d8752a12cb8f052fdf7043878a Mon Sep 17 00:00:00 2001 From: Yoan Le Clanche Date: Fri, 22 Dec 2017 10:37:12 +0100 Subject: [PATCH] chronometer https://trackers.pilotsystems.net/probarreau/0262 --- teleforma/static/teleforma/js/application.js | 42 +++++++++++++------- teleforma/views/pro.py | 10 ++++- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/teleforma/static/teleforma/js/application.js b/teleforma/static/teleforma/js/application.js index 7127d3ff..c5f744bc 100644 --- a/teleforma/static/teleforma/js/application.js +++ b/teleforma/static/teleforma/js/application.js @@ -30,23 +30,35 @@ var rainbow = new Rainbow(); rainbow.setSpectrum('#bb0000', '#e65911', '#f3ad17', 'green'); +function pad(num) { + var s = num+""; + while (s.length < 2) s = "0" + s; + return s; +} + $(window).ready(function() { var pageHeight = $(window).height(); var navHeight = pageHeight - 125; $('#desk_center').css({"max-height": navHeight + 'px'}); - - // chronometer - $('.autotimer').each(function(){ - var timer = new Timer(); - $timerSpan = $(this); - var value = $timerSpan.text() - // convert text value of timer to seconds - var timeArray = value.split(':'); - var seconds = parseInt(timeArray[0], 10) * 3600 + parseInt(timeArray[1], 10) * 60 + parseInt(timeArray[2], 10); - timer.start({precision: 'seconds', startValues: {seconds: seconds}}); - $timerSpan.html(timer.getTimeValues().toString()); - timer.addEventListener('secondsUpdated', function (e) { - $timerSpan.html(timer.getTimeValues().toString()); - }); - }); + launchTimer(); }); + + +var launchTimer = function(){ + // chronometer + $('.autotimer').each(function(){ + window.timer = new Timer(); + $timerSpan = $(this); + var value = $timerSpan.text() + // convert text value of timer to seconds + var timeArray = value.split(':'); + var seconds = parseInt(timeArray[0], 10) * 3600 + parseInt(timeArray[1], 10) * 60 + parseInt(timeArray[2], 10); + window.timer.start({precision: 'seconds', startValues: {seconds: seconds}}); + window.timer.addEventListener('secondsUpdated', function (e) { + var timeValues = window.timer.getTimeValues(); + var hours = timeValues.days * 24 + timeValues.hours + $timerSpan.html(pad(hours) + ':' + pad(timeValues.minutes) + ':' + pad(timeValues.seconds)); + }); + }); +} + diff --git a/teleforma/views/pro.py b/teleforma/views/pro.py index da13bacd..9f40ceba 100644 --- a/teleforma/views/pro.py +++ b/teleforma/views/pro.py @@ -112,6 +112,9 @@ def get_seminar_delta(user, seminar): delta = timer - datetime.timedelta(seconds=seminar.duration.as_seconds()) return delta.total_seconds() +def export_seminar_revisions(): + pass + class SeminarAccessMixin(object): @@ -126,7 +129,11 @@ class SeminarAccessMixin(object): timer = get_seminar_timer(user, seminar) delta_sec = get_seminar_delta(user, seminar) context['delta_sec'] = delta_sec - context['timer'] = str(timer).split('.')[0] + totsec = timer.total_seconds() + h = totsec//3600 + m = (totsec%3600) // 60 + sec =(totsec%3600)%60 + context['timer'] = "%d:%d:%d" %(h,m,sec) return context def render_to_response(self, context): @@ -204,6 +211,7 @@ class SeminarView(SeminarAccessMixin, DetailView): context['seminar_progress'] = progress context['seminar_validated'] = validated delta_sec = context['delta_sec'] + if progress == 100 and not validated and self.template_name == 'teleforma/seminar_detail.html': messages.info(self.request, _("You have successfully terminated your e-learning seminar. A training testimonial will be available as soon as the pedagogical team validate all your answers (48h maximum).")) elif progress < 100 and validated and self.template_name == 'teleforma/seminar_detail.html' and missing_steps == set('5'): -- 2.39.5