diff --git a/bricks/audio.js b/bricks/audio.js index 2f06e57..a93774c 100644 --- a/bricks/audio.js +++ b/bricks/audio.js @@ -105,7 +105,9 @@ bricks.AudioRecorder = class extends bricks.HBox { this.add_widget(this.rec_btn); this.add_widget(this.rec_time); this.recordData = null; - this.bind('record_ended', this.upload.bind(this)); + if (this.upload_url){ + this.bind('record_ended', this.upload.bind(this)); + } } rec_btn_pressed(){ bricks.debug(this.rec_btn.url, ':url:', this.start_icon, this.stop_icon); diff --git a/bricks/bricks.js b/bricks/bricks.js index 7751e74..798dc0d 100644 --- a/bricks/bricks.js +++ b/bricks/bricks.js @@ -214,7 +214,7 @@ bricks.buildEventHandler = async function(w, desc, event){ return null } var rtdata = {}; - + desc.event_params = event.params || {} ; if (desc.rtdata) rtdata = desc.rtdata; else if (desc.datawidget){ var data_desc = { @@ -225,9 +225,15 @@ bricks.buildEventHandler = async function(w, desc, event){ } rtdata = await bricks.getRealtimeData(w, data_desc); } + /* if (typeof event.params == typeof {}){ rtdata = bricks.extend(rtdata, event.params); + } else if (event.params instanceof FormData){ + for ( const [key, value] of Object.entries(rtdata)){ + params.append(key, value); + } } + */ switch (desc.actiontype){ case 'urlwidget': return bricks.buildUrlwidgetHandler(w, target, rtdata, desc); @@ -312,8 +318,21 @@ bricks.buildUrlwidgetHandler = function(w, target, rtdata, desc){ } var options = objcopy(desc.options||{}); var params = options.params || {}; - options = bricks.apply_data(options, rtdata); - options.params = bricks.extend(params, rtdata); + if (desc.event_params instanceof FormData){ + var params = desc.event_params; + for ( const [key, value] of Object.entries(rtdata)){ + params.append(key, value); + } + options = bricks.apply_data(options, rtdata); + for ( const [key, value] of Object.entries(options.params||{})){ + params.append(key, value); + } + options.params = params; + } else { + rtdata = bricks.extend(rtdata, desc.event_params); + options = bricks.apply_data(options, rtdata); + options.params = bricks.extend(params, rtdata); + } var opts = { "widgettype":"urlwidget", diff --git a/bricks/build.sh b/bricks/build.sh index 81a9310..84bc196 100755 --- a/bricks/build.sh +++ b/bricks/build.sh @@ -8,7 +8,7 @@ SOURCES=" page_data_loader.js factory.js uitypesdef.js utils.js uitype.js \ floaticonbar.js miniform.js wterm.js dynamicaccordion.js \ binstreaming.js streaming_audio.js vadtext.js rtc.js docxviewer.js \ llm_dialog.js llm.js websocket.js datarow.js tabular.js \ - line.js pie.js bar.js gobang.js period.js " + line.js pie.js bar.js gobang.js period.js pdfviewer.js" echo ${SOURCES} cat ${SOURCES} > ../dist/bricks.js # uglifyjs --compress --mangle -- ../dist/bricks.js > ../dist/bricks.min.js diff --git a/bricks/form.js b/bricks/form.js index d245c94..f8782d4 100644 --- a/bricks/form.js +++ b/bricks/form.js @@ -177,6 +177,12 @@ bricks.FormBase = class extends bricks.Layout { } } getValue(){ + if (this.data) { + var ret = this.data; + this.data = null; + return ret; + } + return this.get_formdata(); var data = {}; for (var name in this.name_inputs){ if (! this.name_inputs.hasOwnProperty(name)){ @@ -204,11 +210,12 @@ bricks.FormBase = class extends bricks.Layout { var w = this.name_inputs[name]; var d = w.getValue(); if (w.required && ( d[name] == '' || d[name] === null)){ - bricks.debug('data=', data, 'd=', d); new bricks.Error({title:'Requirement', message:'required field must input"' + w.label + '"'}) w.focus(); return; } + w.set_formdata(data); + /* if (bricks.need_formdata_fields.includes(w.uitype)){ var files = w.get_files(); for (var i=0;i --> - + + + diff --git a/bricks/input.js b/bricks/input.js index 1dd4fe9..ff5fbc0 100644 --- a/bricks/input.js +++ b/bricks/input.js @@ -17,6 +17,9 @@ bricks.UiType =class extends bricks.Layout { } return o; } + set_formdata(formdata){ + formdata.append(this.name, this.resultValue()); + } resultValue(){ return this.value; } @@ -71,7 +74,8 @@ bricks.UiAudioText = class extends bricks.UiType { this.text_w.setValue(''); } getValue(){ - return this.text_w.getValue(); + this.value = this.text_w.getValue(); + return this.value; } setValue(v){ this.text_w.setValue(v); @@ -265,6 +269,7 @@ bricks.UiFloat =class extends bricks.UiInt { this.dom_element.step = step; } resultValue(){ + super.resultValue(); return parseFloat(this.value); } setValue(v){ @@ -403,6 +408,9 @@ bricks.UiImage =class extends bricks.VBox { }; reader.readAsDataURL(file); } + set_formdata(formdata){ + formdata.append(this.name, this.value); + } getValue(){ var ret = {} if (this.imgw){ diff --git a/bricks/jsoncall.js b/bricks/jsoncall.js index 21fc3ac..ac27bc3 100644 --- a/bricks/jsoncall.js +++ b/bricks/jsoncall.js @@ -77,8 +77,6 @@ bricks.HttpText = class { return await resp.text(); } add_own_params(params){ - if (! params) - params = {}; var session = bricks.app.get_session(); if (params instanceof FormData){ for ( const [key, value] of Object.entries(this.params)){ @@ -89,6 +87,8 @@ bricks.HttpText = class { } return params; } + if (! params) + params = {}; var p = bricks.extend({}, this.params); p = bricks.extend(p, params); if (session){ @@ -109,13 +109,13 @@ bricks.HttpText = class { var _params = { method:method } - // _params.headers = headers; - if (method == 'GET' || method == 'HEAD') { - let pstr = url_params(data); - url = url + '?' + pstr; + if (data instanceof FormData){ + method = 'POST'; + _params.body = data; } else { - if (data instanceof FormData){ - _params.body = data; + if (method == 'GET' || method == 'HEAD') { + let pstr = url_params(data); + url = url + '?' + pstr; } else { _params.body = JSON.stringify(data); } diff --git a/bricks/pdfviewer.js b/bricks/pdfviewer.js index b7b80d0..d4268c1 100644 --- a/bricks/pdfviewer.js +++ b/bricks/pdfviewer.js @@ -15,7 +15,7 @@ bricks.PDFviewer = class extends bricks.VBox { this.curpage = null; this.pdf = null; bricks.app.bind('keydown', this.key_action.bind(this)); - schedule_once(this.renderPage(1), 0.2); + schedule_once(this.renderPage(1), 1); } key_action(e){ if (!this.curpage) return;