]> git.parisson.com Git - teleforma.git/commitdiff
First version of JS chrono
authorGael Le Mignot <gael@pilotsystems.net>
Tue, 5 Dec 2017 16:47:21 +0000 (17:47 +0100)
committerGael Le Mignot <gael@pilotsystems.net>
Tue, 5 Dec 2017 16:47:21 +0000 (17:47 +0100)
teleforma/static/teleforma/js/application.js
teleforma/static/teleforma/js/easytimer.js [new file with mode: 0644]
teleforma/templates/quiz/question.html
teleforma/templates/teleforma/answer_form.html
teleforma/templates/teleforma/inc/seminar_description.html
teleforma/templates/teleforma/seminar_detail.html
teleforma/templates/telemeta/base.html
teleforma/views/pro.py

index a43febbd8d4e1a3d6d5b327baba8d9d1ba7a5597..7127d3ffdc1e3021fd0822e580f6a5974476df07 100644 (file)
@@ -35,13 +35,18 @@ $(window).ready(function() {
        var navHeight = pageHeight - 125;
        $('#desk_center').css({"max-height": navHeight + 'px'});
 
+       // chronometer
        $('.autotimer').each(function(){
                var timer = new Timer();
-               $timer = $(this);
-               timer.start({precision: 'seconds', startValues: {seconds: 90}, target: {seconds: 120}});
-               $(this).html(timer.getTimeValues().toString());
+               $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) {
-                       $(this).html(timer.getTimeValues().toString());
+                       $timerSpan.html(timer.getTimeValues().toString());
                });
        });
 });
diff --git a/teleforma/static/teleforma/js/easytimer.js b/teleforma/static/teleforma/js/easytimer.js
new file mode 100644 (file)
index 0000000..3b41264
--- /dev/null
@@ -0,0 +1 @@
+!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):n.Timer=t()}(this,function(){"use strict";function n(n,t,e){var o=void 0,i="";for(o=0;o<t;o+=1)i+=String(e);return(i+n).slice(-i.length)}function t(){this.secondTenths=0,this.seconds=0,this.minutes=0,this.hours=0,this.days=0,this.toString=function(t,e,o){t=t||["hours","minutes","seconds"],e=e||":",o=o||2;var i=[],r=void 0;for(r=0;r<t.length;r+=1)void 0!==this[t[r]]&&i.push(n(this[t[r]],o,"0"));return i.join(e)}}function e(){return"undefined"!=typeof document}function o(){return S}function i(n,t){return(n%t+t)%t}var r="undefined"!=typeof window?window.CustomEvent:void 0;"undefined"!=typeof window&&"function"!=typeof r&&((r=function(n,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var e=document.createEvent("CustomEvent");return e.initCustomEvent(n,t.bubbles,t.cancelable,t.detail),e}).prototype=window.Event.prototype,window.CustomEvent=r);var s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},u=10,d=60,c=60,f=24,a=0,v=1,h=2,l=3,p=4,m="secondTenths",y="seconds",b="minutes",w="hours",g="days",E={secondTenths:100,seconds:1e3,minutes:6e4,hours:36e5,days:864e5},T={secondTenths:u,seconds:d,minutes:c,hours:f},S="undefined"!=typeof module&&module.exports&&"function"==typeof require?require("events"):void 0;return function(){function n(n,t){var e=Math.floor(t);X[n]=e,W[n]=n!==g?i(e,T[n]):e}function r(n){return U(n,g)}function j(n){return U(n,w)}function C(n){return U(n,b)}function M(n){return U(n,y)}function L(n){return U(n,m)}function U(t,e){var o=X[e];return n(e,t/E[e]),X[e]!==o}function V(){A(),z()}function A(){clearInterval(Y),Y=void 0,$=!1,_=!1}function k(n){Q()?(cn=D(),sn=F(rn.target)):R(n),x()}function x(){var n=E[nn];O(q(Date.now()))||(Y=setInterval(P,n),$=!0,_=!1)}function D(){return q(Date.now())-X.secondTenths*E[m]*tn}function P(){var n=q(Date.now()),t=tn>0?n-cn:cn-n,e={};e[m]=L(t),e[y]=M(t),e[b]=C(t),e[w]=j(t),e[g]=r(t),I(e),en(an.detail.timer),O(n)&&(K("targetAchieved",an),J())}function q(n){return Math.floor(n/E[nn])*E[nn]}function I(n){n[m]&&K("secondTenthsUpdated",an),n[y]&&K("secondsUpdated",an),n[b]&&K("minutesUpdated",an),n[w]&&K("hoursUpdated",an),n[g]&&K("daysUpdated",an)}function O(n){return sn instanceof Array&&n>=fn}function z(){for(var n in W)W.hasOwnProperty(n)&&"number"==typeof W[n]&&(W[n]=0);for(var t in X)X.hasOwnProperty(t)&&"number"==typeof X[t]&&(X[t]=0)}function R(n){nn="string"==typeof(n=n||{}).precision?n.precision:y,en="function"==typeof n.callback?n.callback:function(){},dn=!0===n.countdown,tn=!0===dn?-1:1,"object"===s(n.startValues)&&G(n.startValues),cn=D(),"object"===s(n.target)?sn=F(n.target):dn&&(n.target={seconds:0},sn=F(n.target)),on={precision:nn,callback:en,countdown:"object"===(void 0===n?"undefined":s(n))&&!0===n.countdown,target:sn,startValues:un},rn=n}function B(n){var t=void 0,e=void 0,o=void 0,i=void 0,r=void 0,m=void 0;if("object"===(void 0===n?"undefined":s(n)))if(n instanceof Array){if(5!==n.length)throw new Error("Array size not valid");m=n}else m=[n.secondTenths||0,n.seconds||0,n.minutes||0,n.hours||0,n.days||0];for(var y=0;y<n.length;y+=1)n[y]<0&&(n[y]=0);return t=m[a],e=m[v]+Math.floor(t/u),o=m[h]+Math.floor(e/d),i=m[l]+Math.floor(o/c),r=m[p]+Math.floor(i/f),m[a]=t%u,m[v]=e%d,m[h]=o%c,m[l]=i%f,m[p]=r,m}function F(n){if(n){var t=H(sn=B(n));return fn=cn+t.secondTenths*E[m]*tn,sn}}function G(n){un=B(n),W.secondTenths=un[a],W.seconds=un[v],W.minutes=un[h],W.hours=un[l],W.days=un[p],X=H(un,X)}function H(n,t){var e=t||{};return e.days=n[p],e.hours=e.days*f+n[l],e.minutes=e.hours*c+n[h],e.seconds=e.minutes*d+n[v],e.secondTenths=e.seconds*u+n[[a]],e}function J(){V(),K("stopped",an)}function K(n,t){e()?Z.dispatchEvent(new CustomEvent(n,t)):o()&&Z.emit(n,t)}function N(){return $}function Q(){return _}var W=new t,X=new t,Y=void 0,Z=e()?document.createElement("span"):o()?new S.EventEmitter:void 0,$=!1,_=!1,nn=void 0,tn=void 0,en=void 0,on={},rn=void 0,sn=void 0,un=void 0,dn=void 0,cn=void 0,fn=void 0,an={detail:{timer:this}};void 0!==this&&(this.start=function(n){N()||(k(n),K("started",an))},this.pause=function(){A(),_=!0,K("paused",an)},this.stop=J,this.reset=function(){V(),k(rn),K("reset",an)},this.isRunning=N,this.isPaused=Q,this.getTimeValues=function(){return W},this.getTotalTimeValues=function(){return X},this.getConfig=function(){return on},this.addEventListener=function(n,t){e()?Z.addEventListener(n,t):o()&&Z.on(n,t)},this.removeEventListener=function(n,t){e()?Z.removeEventListener(n,t):o()&&Z.removeListener(n,t)})}});
\ No newline at end of file
index b65eea530a07952fdb3a1cf1a4a2cc70837341b7..89215db4a81deda88980c08763dcf9acd59bd169 100644 (file)
     <li>{% trans "Quiz" %} : {{ progress|quiz_progress }}%
      <div id="progressbar-answer"></div>
     </li>
-
+    {% if timer %}
+    <li>
+      Votre temps de connexion : <span class="autotimer">{{ timer }}</span> sur {{ seminar.duration }}
+    </li>
+    {% endif %}
   </ul>
 
  </div>
index c23f72cc950997f544872d2d3dd8073a14db434e..c1b8e1a47d47c69f36d54ee10cb5a6ef753d3873 100644 (file)
@@ -115,7 +115,7 @@ $(document).ready(function(){
     </li>
     {% if timer %}
     <li>
-      {% trans "chronometer" %} : <span class="autotimer">{{ timer }}</span> sur {{ seminar.duration }}
+      Votre temps de connexion : <span class="autotimer">{{ timer }}</span> sur {{ seminar.duration }}
     </li>
     {% endif %}
   </ul>
index bc92c28ce56dee48d5687d541b1e8dd76d21505a..3ace5a4e08ff66237909599cb2cf517afa1576ff 100644 (file)
@@ -10,9 +10,6 @@
 {% endif %}
 <dt>{% trans "level" %}</dt><dd>{{ seminar.level }}</dd>
 <dt>{% trans "duration" %}</dt><dd>{{ seminar.duration|hours }} {% trans "hours" %}</dd>
-{% if timer %}
-<dt>{% trans "chronometer" %}</dt><dd>{{ timer }}</dd>
-{% endif %}
 <dt>{% trans "expiry date" %}</dt><dd>{{ seminar.expiry_date }}</dd>
 <dt>{% trans "last modification date" %}</dt><dd>{% if seminar.date_forced %}{{ seminar.date_forced }}{% else %}{{ seminar.date_modified }}{% endif %}</dd>
 {% if user.is_superuser %}
index be059fad2e79cce5227d3d99d83d7b70f038463c..b35cb683af144648f8851bd9461eba7b5ef8ddb9 100644 (file)
@@ -239,7 +239,7 @@ $(window).ready(function( ){
     </li>
     {% if timer %}
     <li>
-      {% trans "chronometer" %} : <span class="autotimer">{{ timer }}</span> sur {{ seminar.duration }}
+      Votre temps de connexion : <span class="autotimer">{{ timer }}</span> sur {{ seminar.duration }}
     </li>
     {% endif %}
   </ul>
index 29a28d2ef1261d618fa02ebc2bad217ed496b5cf..cb444c644dbb84189cc2925724ba4b3d7515e0a2 100644 (file)
@@ -48,7 +48,7 @@
 <script src="{{ STATIC_URL }}teleforma/js/messi.min.js" type="text/javascript"></script>
 <script src="{{ STATIC_URL }}teleforma/js/rainbowvis.js" type="text/javascript"></script>
 <script src="{{ STATIC_URL }}jqchat/jqchat.js" type="text/javascript" ></script>
-<script src="{{ STATIC_URL }}teleforma/easytimer.min.js" type="text/javascript" ></script>
+<script src="{{ STATIC_URL }}teleforma/js/easytimer.js" type="text/javascript" ></script>
 <script src="{{ STATIC_URL }}telemeta/js/locale.js" type="text/javascript"></script>
 <script src="{{ STATIC_URL }}telemeta/js/application.js" type="text/javascript"></script>
 <script src="{{ STATIC_URL }}teleforma/js/application.js" type="text/javascript"></script>
index 7757736eb5e7a794e366c237720ba99e6897864f..f5eaef8722dee8d2a888abfb9fe5fcc3a26fbfb2 100644 (file)
@@ -119,7 +119,7 @@ class SeminarAccessMixin(object):
         context = super(SeminarAccessMixin, self).get_context_data(**kwargs)
         seminar = context.get('seminar')
         if not seminar:
-            seminar = Seminar.objects.get(pk=self.kwargs.get('id', 'pk'))
+            seminar = Seminar.objects.get(pk=self.kwargs.get('id', self.kwargs.get('pk')))
         context['seminar'] = seminar
         user = self.request.user