From d6880c3081538942cdb2fe80f5efbab750532097 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 21 Mar 2024 18:12:24 +0800 Subject: [PATCH] bugfix --- bricks/audio.js | 14 +++++++++-- bricks/dynamicaccordion.js | 4 +++ bricks/form.js | 12 ++++++--- bricks/input.js | 51 +++++++++++++++++++++++++++++++++++++- bricks/running.js | 47 +++++++++++++++++++++++++++++++++++ examples/form.ui | 9 ++++++- examples/running.ui | 4 +++ 7 files changed, 134 insertions(+), 7 deletions(-) create mode 100644 bricks/running.js create mode 100644 examples/running.ui diff --git a/bricks/audio.js b/bricks/audio.js index db050f5..c47a113 100755 --- a/bricks/audio.js +++ b/bricks/audio.js @@ -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; diff --git a/bricks/dynamicaccordion.js b/bricks/dynamicaccordion.js index 22ab266..ed0cb57 100644 --- a/bricks/dynamicaccordion.js +++ b/bricks/dynamicaccordion.js @@ -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'); } } diff --git a/bricks/form.js b/bricks/form.js index 26dbb1b..348d051 100644 --- a/bricks/form.js +++ b/bricks/form.js @@ -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); diff --git a/bricks/input.js b/bricks/input.js index c394092..8d57b65 100755 --- a/bricks/input.js +++ b/bricks/input.js @@ -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); diff --git a/bricks/running.js b/bricks/running.js new file mode 100644 index 0000000..b9caae4 --- /dev/null +++ b/bricks/running.js @@ -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); diff --git a/examples/form.ui b/examples/form.ui index cc3ab73..3cf45a9 100644 --- a/examples/form.ui +++ b/examples/form.ui @@ -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 } ] } diff --git a/examples/running.ui b/examples/running.ui new file mode 100644 index 0000000..ae5c41c --- /dev/null +++ b/examples/running.ui @@ -0,0 +1,4 @@ +{ + "widgettype":"Running", + "options":{} +}