bugfix
This commit is contained in:
parent
1f5a545e8e
commit
530315d6e0
@ -1,5 +1,42 @@
|
||||
var bricks = window.bricks || {};
|
||||
|
||||
bricks.formatTime = function(seconds) {
|
||||
let hrs = Math.floor(seconds / 3600);
|
||||
let mins = Math.floor((seconds % 3600) / 60);
|
||||
let secs = seconds % 60;
|
||||
|
||||
return [
|
||||
hrs.toString().padStart(2, '0'),
|
||||
mins.toString().padStart(2, '0'),
|
||||
secs.toString().padStart(2, '0')
|
||||
].join(':');
|
||||
}
|
||||
bricks.TimePassed = class extends bricks.VBox {
|
||||
constructor(opts){
|
||||
super(opts);
|
||||
this.seconds = 0;
|
||||
var t = bricks.formatTime(this.seconds);
|
||||
this.text_w = new bricks.Text({
|
||||
text:this.t,
|
||||
rate:this.text_rate
|
||||
});
|
||||
this.add_widget(this.text_w);
|
||||
}
|
||||
start(){
|
||||
this.task = schedule_once(this.add_one_second.bind(this));
|
||||
}
|
||||
|
||||
add_one_second(){
|
||||
this.seconds += 1;
|
||||
var t = bricks.formatTime(this.seconds);
|
||||
this.text_w.set_text(t);
|
||||
this.task = schedule_once(this.add_one_second.bind(this));
|
||||
}
|
||||
stop(){
|
||||
this.task.cancel();
|
||||
this.task = null;
|
||||
}
|
||||
}
|
||||
bricks.Countdown = class extends bricks.VBox {
|
||||
/*
|
||||
options:
|
||||
@ -49,17 +86,6 @@ bricks.Countdown = class extends bricks.VBox {
|
||||
start(){
|
||||
schedule_once(this.time_down_second.bind(this), 1)
|
||||
}
|
||||
formatTime(seconds) {
|
||||
let hrs = Math.floor(seconds / 3600);
|
||||
let mins = Math.floor((seconds % 3600) / 60);
|
||||
let secs = seconds % 60;
|
||||
|
||||
return [
|
||||
hrs.toString().padStart(2, '0'),
|
||||
mins.toString().padStart(2, '0'),
|
||||
secs.toString().padStart(2, '0')
|
||||
].join(':');
|
||||
}
|
||||
time_down_second(){
|
||||
if (this.seconds < 1){
|
||||
this.dispatch('timeout');
|
||||
@ -67,10 +93,11 @@ bricks.Countdown = class extends bricks.VBox {
|
||||
}
|
||||
var h, m, s;
|
||||
this.seconds -= 1;
|
||||
var ts = formatTime(this.seconds);
|
||||
var ts = bricks.formatTime(this.seconds);
|
||||
this.text_w.set_text(ts);
|
||||
schedule_once(this.time_down_second.bind(this), 1)
|
||||
}
|
||||
}
|
||||
|
||||
bricks.Factory.register('Countdown', bricks.Countdown);
|
||||
bricks.Factory.register('TimePassed', bricks.TimePassed);
|
||||
|
@ -4,6 +4,7 @@ bricks.QAFrame = class extends bricks.PopupWindow {
|
||||
/*
|
||||
{
|
||||
ws_url:
|
||||
ws_opts:
|
||||
title:
|
||||
description:
|
||||
courseware:{
|
||||
@ -27,13 +28,25 @@ bricks.QAFrame = class extends bricks.PopupWindow {
|
||||
this.add_widget(this.top_w);
|
||||
this.add_widget(this.main_w);
|
||||
this.add_widget(this.bottom_w);
|
||||
this.ws = new bricks.WebSocket(this.ws_url);
|
||||
var url = this.ws_url;
|
||||
if (this.ws_params){
|
||||
url += '?' + URLSearchParams(this.ws_params).toString();
|
||||
}
|
||||
this.ws = new bricks.WebSocket(url);
|
||||
if (this.courseware){
|
||||
this.play_course();
|
||||
} else {
|
||||
this.show_conform();
|
||||
}
|
||||
}
|
||||
show_conform(){
|
||||
var btn = new bricks.Button({
|
||||
label: 'Start ?'
|
||||
});
|
||||
btn.bind('click', this.start_question_answer.bind(this));
|
||||
this.main_w.clear_widgets();
|
||||
this.main_w.add_widget(btn);
|
||||
}
|
||||
build_startbtn(){
|
||||
var btn = new bricks.Button({
|
||||
label:'press to start'
|
||||
@ -41,7 +54,8 @@ bricks.QAFrame = class extends bricks.PopupWindow {
|
||||
btn.bind('click', this.start_answer_question.bind(this));
|
||||
this.bottom_w.add_widget(btn);
|
||||
}
|
||||
start_answer_question(){
|
||||
start_question_answer(){
|
||||
this.main_w.clear_widgets();
|
||||
var d = {
|
||||
'type': 'qa_start',
|
||||
'data': null
|
||||
|
Loading…
Reference in New Issue
Block a user