var bricks = window.bricks || {}; var tooltip = null; bricks.app = null; /* all type of bind action's desc has the following attributes: actiontype:'bricks', wid: event: target: datawidget: datascript: datamethod: datakwargs: rtdata: conform: and each type of binds specified attributes list following urlwidget action: mode:, options:{ method: params:{}, url: } bricks action: mode:, options:{ "widgettype":"gg", ... } method action: method: params: for methods kwargs script action: script: params: registerfunction action: rfname: params: event action: dispatch_event: params: */ bricks.str2data = function(s, d){ /* fmt like 'my name is ${name}, ${age:type}' type can be: int, str, json */ funcs = { 'json':JSON.stringify } var regex = /\${(\w+)(?::(int|str|json))?}/; var match = s.match(regex) if (match){ var key = match[1]; var typ = match[2]; var ss = '${' + key; if (typ != ''){ ss += ':' + typ; } ss += '}'; if (s == ss){ if (!d.hasOwnProperty(key)){ return null; } if (typ == ''){ return d[key]; } var f = funcs[typ]; if (f){ return f(d[key]); } return d[key]; } return s.replace(regex, (k, key, typ) => { if (d.hasOwnProperty(key)){ var f = funcs[typ]; if (f){ return f(d[key]); } return d[key]; } return ''; }); } return s; } bricks.apply_data = function(desc, data){ var tmpl = JSON.stringify(desc); var s = bricks.obj_fmtstr(data, tmpl); return JSON.parse(s); } bricks.widgetBuild = async function(desc, widget, data){ if (! widget){ widget = bricks.Body; } var klassname = desc.widgettype; var base_url = widget.baseURI; while (klassname == 'urlwidget'){ let url = absurl(desc.options.url, widget); base_url = url; let method = desc.options.method || 'GET'; let opts = desc.options.params || {}; var jcall = bricks.jcall; var desc1 = await jcall(url, { "method":method, "params":opts}); desc = desc1; klassname = desc.widgettype; } if (data){ desc = bricks.apply_data(desc, data); } let klass = bricks.Factory.get(desc.widgettype); if (! klass){ bricks.debug('widgetBuild():',desc.widgettype, 'not registered', bricks.Factory.widgets_kw); return null; } var options = desc.options || {}; options.baseURI = base_url; let w = new klass(options); if (desc.id){ w.set_id(desc.id); } if (w.is_container() && desc.subwidgets){ for (let i=0; i