This commit is contained in:
yumoqing 2024-03-21 18:12:24 +08:00
parent 849751feb4
commit d6880c3081
7 changed files with 134 additions and 7 deletions

View File

@ -72,9 +72,19 @@ bricks.AudioRecorder = class extends bricks.HBox {
super(opts);
this.start_icon = opts.start_icon || bricks_resource('imgs/start_recording.png');
this.stop_icon = opts.stop_icon || bricks_resource('imgs/stop_recording.png');
this.rec_btn = new bricks.Icon({url:this.start_icon, rate:this.icon_rate });
this.rec_btn = new bricks.Icon({
dynsize:true,
url:this.start_icon,
rate:this.icon_rate
});
// this.player = new bricks.AudioPlayer({url:"",width:'80px'});
this.rec_time = new bricks.Text({text:" record time", i18n:false, wrap:false, width:'120px'});
this.rec_time = new bricks.Text({
text:" record time",
i18n:false,
dynsize:true,
wrap:false,
width:'120px'
});
this.upload_url = opts.upload_url;
this.rec_btn.bind('click', this.rec_btn_pressed.bind(this))
this.URL = window.URL||webkitURL;

View File

@ -403,6 +403,7 @@ bricks.DynamicAccordion = class extends bricks.VScrollPanel {
bricks.debug('this.loading is set, do not thing');
return;
}
var running = new bricks.Running({target:this});
this.loading = true;
try {
var d = await this.loader.loadPreviousPage();
@ -417,12 +418,14 @@ bricks.DynamicAccordion = class extends bricks.VScrollPanel {
bricks.debug('e=', e);
}
this.loading = false;
running.dismiss();
}
async load_next_page(){
if (this.loading){
bricks.debug('this.loading is set, do not thing');
return;
}
var running = new bricks.Running({target:this});
this.loading = true;
try {
var d = await this.loader.loadNextPage();
@ -437,6 +440,7 @@ bricks.DynamicAccordion = class extends bricks.VScrollPanel {
bricks.debug('error happened', e);
}
this.loading = false;
running.dismiss();
bricks.debug('load_next_page() finished');
}
}

View File

@ -24,7 +24,9 @@ bricks.FieldGroup = class extends bricks.VBox {
box = new bricks.HBox({height:'auto',overflow:'none'});
}
box.set_css('inputbox');
dc.add_widget(box);
if (fields[i].uitype !== 'hide'){
dc.add_widget(box);
}
var txt = new bricks.Text({
otext:fields[i].label||fields[i].name,
dynsize:true,
@ -190,6 +192,8 @@ bricks.Form = class extends bricks.VBox {
return data;
}
async validation(){
var running = new bricks.Running({target:this});
try {
var data = this.getValue();
this.dispatch('submit', data);
if (this.submit_url){
@ -201,9 +205,11 @@ bricks.Form = class extends bricks.VBox {
});
this.dispatch('submited', resp);
}
} catch (e){
bricks.debug('form submit error', e);
}
running.dismiss();
}
}
bricks.Factory.register('Form', bricks.Form);

View File

@ -5,7 +5,7 @@ bricks.UiType =class extends bricks.Layout {
this.name = this.opts.name;
this.required = opts.required || false;
this.ctype = 'text';
this.value = '';
this.value = opts.value || opts.defaultvalue||'';
}
getValue(){
@ -13,6 +13,9 @@ bricks.UiType =class extends bricks.Layout {
o[this.name] = this.resultValue();
return o;
}
resultValue(){
return this.value;
}
focus(){
this.dom_element.focus();
}
@ -39,6 +42,50 @@ bricks.UiType =class extends bricks.Layout {
}
}
bricks.UiAudioText = class extends bricks.UiType {
/*
{
"upload_url"
}
*/
static uitype = 'audiotext';
constructor(opts){
super(opts);
this.recorder = new bricks.AudioRecorder({
icon_rate:2,
upload_url:opts.upload_url
});
this.recorder.bind('record_started', this.clear_text.bind(this));
this.add_widget(this.recorder);
var opts1 = bricks.extend({}, opts);
opts1.width = "97%";
this.text_w = new bricks.UiText(opts1);
this.add_widget(this.text_w);
this.recorder.bind('uploaded', this.set_result_text.bind(this));
}
clear_text(){
this.text_w.setValue('');
}
getValue(){
return this.text_w.getValue();
}
setValue(v){
this.text_w.setValue(v);
}
set_result_text(event){
var txt = event.params.text;
this.text_w.setValue(txt);
}
}
bricks.UiHide = class extends bricks.UiType {
static uitype = 'hide';
constructor(opts){
super(opts);
this.set_style('display', 'none');
}
}
bricks.UiStr =class extends bricks.UiType {
static uitype='str';
/*
@ -722,6 +769,7 @@ bricks.UiVideo =class extends bricks.UiStr {
}
var Input = new bricks._Input();
Input.register('UiStr', bricks.UiStr);
Input.register('UiHide', bricks.UiHide);
Input.register('UiTel', bricks.UiTel);
Input.register('UiDate', bricks.UiDate);
Input.register('UiInt', bricks.UiInt);
@ -735,3 +783,4 @@ Input.register('UiText', bricks.UiText);
Input.register('UiPassword', bricks.UiPassword);
Input.register('UiAudio', bricks.UiAudio);
Input.register('UiVideo', bricks.UiVideo);
Input.register('UiAudioText', bricks.UiAudioText);

47
bricks/running.js Normal file
View File

@ -0,0 +1,47 @@
var bricks = window.bricks || {};
bricks.Running = class extends bricks.BaseModal {
/*
{
target:
icon:
}
*/
constructor(opts){
opts.auto_open = true;
opts.archor = 'cc';
opts.width='96px';
super(opts);
this.icon_w = new bricks.Icon({
url:opts.icon || bricks_resource('imgs/running.gif')
});
this.time_w = new bricks.Text({
text:'test123',
color:'#222',
wrap:false,
width:'50px',
i18n:false
});
this.time_start = new Date().getTime();
var box = new bricks.FHBox({width:'auto'});
box.add_widget(this.icon_w);
box.add_widget(this.time_w);
this.add_widget(box);
this.showtime_task = schedule_once(this.show_timepass.bind(this), 0.05);
}
show_timepass(){
var t = new Date().getTime() - this.time_start;
var txt = bricks.formatMs(t, 1);
this.time_w.set_text(txt);
this.showtime_task = schedule_once(this.show_timepass.bind(this), 0.05);
}
dismiss(){
if (this.showtime_task){
this.showtime_task.cancel();
this.showtime_task = null;
}
bricks.BaseModal.prototype.dismiss.bind(this)();
}
}
bricks.Factory.register('Running', bricks.Running);

View File

@ -1,4 +1,3 @@
{
"widgettype":"VBox",
"options":{"height":"100%", "width":"100%"},
@ -147,6 +146,14 @@
"value":"This is a test",
"label":"Text",
'required':true
},
{
"uitype":"audiotext",
"upload_url":"https://sage.opencomputing.cn/stt/generate",
"name":"atext",
"value":"This is a test",
"label":"Text",
'required':true
}
]
}

4
examples/running.ui Normal file
View File

@ -0,0 +1,4 @@
{
"widgettype":"Running",
"options":{}
}