bugfix
This commit is contained in:
parent
c2b73a5a08
commit
7901d7018d
@ -127,7 +127,7 @@ bricks.buildEventBind = function(from_widget, widget, event, desc){
|
|||||||
}
|
}
|
||||||
|
|
||||||
bricks.universal_handler = function(from_widget, widget, desc, event){
|
bricks.universal_handler = function(from_widget, widget, desc, event){
|
||||||
var f = bricks.buildEventHandler(from_widget, desc);
|
var f = bricks.buildEventHandler(from_widget, desc, event);
|
||||||
if (f){
|
if (f){
|
||||||
return f(event);
|
return f(event);
|
||||||
}
|
}
|
||||||
@ -137,23 +137,27 @@ bricks.universal_handler = function(from_widget, widget, desc, event){
|
|||||||
'desc=', desc,
|
'desc=', desc,
|
||||||
event);
|
event);
|
||||||
}
|
}
|
||||||
bricks.buildEventHandler = function(w, desc){
|
bricks.buildEventHandler = function(w, desc, event){
|
||||||
var target = bricks.getWidgetById(desc.target, w);
|
var target = bricks.getWidgetById(desc.target, w);
|
||||||
if (! target){
|
if (! target){
|
||||||
bricks.debug('target miss desc=', desc, 'w=', w);
|
bricks.debug('target miss desc=', desc, 'w=', w);
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
var rtdata = null;
|
var rtdata = {};
|
||||||
|
|
||||||
if (desc.rtdata) rtdata = desc.rtdata;
|
if (desc.rtdata) rtdata = desc.rtdata;
|
||||||
else if (desc.datawidget){
|
else if (desc.datawidget){
|
||||||
var data_desc = {
|
var data_desc = {
|
||||||
widget:desc.datawidget,
|
widget:desc.datawidget,
|
||||||
method:desc.datamethod,
|
method:desc.datamethod || 'getValue',
|
||||||
params:desc.dataparams,
|
params:desc.dataparams,
|
||||||
script:desc.datascript
|
script:desc.datascript
|
||||||
}
|
}
|
||||||
rtdata = bricks.getRealtimeData(w, data_desc);
|
rtdata = bricks.getRealtimeData(w, data_desc);
|
||||||
}
|
}
|
||||||
|
if (typeof event.params == typeof {}){
|
||||||
|
rtdata = bricks.extend(rtdata, event.params);
|
||||||
|
}
|
||||||
switch (desc.actiontype){
|
switch (desc.actiontype){
|
||||||
case 'urlwidget':
|
case 'urlwidget':
|
||||||
return bricks.buildUrlwidgetHandler(w, target, rtdata, desc);
|
return bricks.buildUrlwidgetHandler(w, target, rtdata, desc);
|
||||||
@ -234,6 +238,7 @@ bricks.buildUrlwidgetHandler = function(w, target, rtdata, desc){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
var options = objcopy(desc.options||{});
|
var options = objcopy(desc.options||{});
|
||||||
|
options = bricks.apply_data(options, rtdata);
|
||||||
bricks.extend(options.params, rtdata);
|
bricks.extend(options.params, rtdata);
|
||||||
var opts = {
|
var opts = {
|
||||||
"widgettype":"urlwidget",
|
"widgettype":"urlwidget",
|
||||||
@ -255,7 +260,7 @@ bricks.buildBricksHandler = function(w, target, rtdata, desc){
|
|||||||
target.add_widget(w);
|
target.add_widget(w);
|
||||||
}
|
}
|
||||||
var options = objcopy(desc.options||{});
|
var options = objcopy(desc.options||{});
|
||||||
bricks.extend(options.options, rtdata);
|
options = bricks.apply_data(options, rtdata);
|
||||||
return _buildWidget.bind(w, target, target, desc.mode || 'replace', options);
|
return _buildWidget.bind(w, target, target, desc.mode || 'replace', options);
|
||||||
}
|
}
|
||||||
bricks.buildRegisterFunctionHandler = function(w, target, rtdata, desc){
|
bricks.buildRegisterFunctionHandler = function(w, target, rtdata, desc){
|
||||||
@ -271,6 +276,7 @@ bricks.buildRegisterFunctionHandler = function(w, target, rtdata, desc){
|
|||||||
if (rtdata){
|
if (rtdata){
|
||||||
bricks.extend(params, rtdata);
|
bricks.extend(params, rtdata);
|
||||||
}
|
}
|
||||||
|
params = bricks.apply_data(params, rtdata);
|
||||||
return f.bind(target, params);
|
return f.bind(target, params);
|
||||||
}
|
}
|
||||||
bricks.buildMethodHandler = function(w, target, rtdata, desc){
|
bricks.buildMethodHandler = function(w, target, rtdata, desc){
|
||||||
@ -282,12 +288,14 @@ bricks.buildMethodHandler = function(w, target, rtdata, desc){
|
|||||||
var params = {};
|
var params = {};
|
||||||
bricks.extend(params, desc.params)
|
bricks.extend(params, desc.params)
|
||||||
bricks.extend(params, rtdata);
|
bricks.extend(params, rtdata);
|
||||||
|
params = bricks.apply_data(params, rtdata);
|
||||||
return f.bind(target, params);
|
return f.bind(target, params);
|
||||||
}
|
}
|
||||||
bricks.buildScriptHandler = function(w, target, rtdata, desc){
|
bricks.buildScriptHandler = function(w, target, rtdata, desc){
|
||||||
var params = {};
|
var params = {};
|
||||||
bricks.extend(params, desc.params)
|
bricks.extend(params, desc.params)
|
||||||
bricks.extend(params, rtdata);
|
bricks.extend(params, rtdata);
|
||||||
|
params = bricks.apply_data(params, rtdata);
|
||||||
var f = new Function('target', 'params', 'event', desc.script);
|
var f = new Function('target', 'params', 'event', desc.script);
|
||||||
bricks.debug('params=', params, 'buildScriptHandler() ..........');
|
bricks.debug('params=', params, 'buildScriptHandler() ..........');
|
||||||
return f.bind(target, target, params);
|
return f.bind(target, target, params);
|
||||||
@ -296,6 +304,7 @@ bricks.buildDispatchEventHandler = function(w, target, rtdata, desc){
|
|||||||
var params = {};
|
var params = {};
|
||||||
bricks.extend(params, desc.params)
|
bricks.extend(params, desc.params)
|
||||||
bricks.extend(params, rtdata);
|
bricks.extend(params, rtdata);
|
||||||
|
params = bricks.apply_data(params, rtdata);
|
||||||
var f = function(target, event_name, params){
|
var f = function(target, event_name, params){
|
||||||
target.dispatch(event_name, params);
|
target.dispatch(event_name, params);
|
||||||
}
|
}
|
||||||
|
@ -131,9 +131,7 @@ bricks.DynamicAccordion = class extends bricks.VScrollPanel {
|
|||||||
var info = new bricks.AccordionInfo({});
|
var info = new bricks.AccordionInfo({});
|
||||||
info.data = record;
|
info.data = record;
|
||||||
item.add_widget(info);
|
item.add_widget(info);
|
||||||
if (this.editable){
|
|
||||||
tb = this.build_record_toolbar(info, record);
|
tb = this.build_record_toolbar(info, record);
|
||||||
}
|
|
||||||
if (! record){
|
if (! record){
|
||||||
record = {};
|
record = {};
|
||||||
for (var i=0;i<this.fields.length;i++){
|
for (var i=0;i<this.fields.length;i++){
|
||||||
@ -308,10 +306,26 @@ bricks.DynamicAccordion = class extends bricks.VScrollPanel {
|
|||||||
build_record_toolbar(info, record){
|
build_record_toolbar(info, record){
|
||||||
var c = new bricks.Layout({cwidth:2.5, height:'auto'})
|
var c = new bricks.Layout({cwidth:2.5, height:'auto'})
|
||||||
var desc;
|
var desc;
|
||||||
if (! record){
|
var edit_tools = [];
|
||||||
|
if (this.record_toolbar){
|
||||||
|
desc = bricks.extend({}, this.record_toolbar);
|
||||||
|
} else {
|
||||||
desc = {
|
desc = {
|
||||||
cwidth:2.5,
|
cwidth:2.5,
|
||||||
tools:[
|
tools:[]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var event_names = [];
|
||||||
|
for (var i=0;i<desc.tools.length;i++){
|
||||||
|
event_names.push(desc.tools[i].name);
|
||||||
|
}
|
||||||
|
if (! record){
|
||||||
|
var mytools = [];
|
||||||
|
for (var i=0;i<desc.tools.length;i++){
|
||||||
|
mytools.push({ name:'blankicon'});
|
||||||
|
}
|
||||||
|
if (this.editable){
|
||||||
|
edit_tools = [
|
||||||
{
|
{
|
||||||
name:'add',
|
name:'add',
|
||||||
tip:'add new record',
|
tip:'add new record',
|
||||||
@ -320,16 +334,20 @@ bricks.DynamicAccordion = class extends bricks.VScrollPanel {
|
|||||||
{
|
{
|
||||||
name:'blankicon'
|
name:'blankicon'
|
||||||
}
|
}
|
||||||
]
|
];
|
||||||
|
desc.tools = edit_tools.concat(mytools);
|
||||||
|
} else {
|
||||||
|
desc.tools = mytools;
|
||||||
}
|
}
|
||||||
var w = new bricks.IconBar(desc);
|
var w = new bricks.IconBar(desc);
|
||||||
|
if (this.editable){
|
||||||
w.bind('add', this.add_record.bind(this, info, record));
|
w.bind('add', this.add_record.bind(this, info, record));
|
||||||
|
}
|
||||||
c.add_widget(w);
|
c.add_widget(w);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
var desc = {
|
if (this.editable){
|
||||||
cwidth:2.5,
|
var edit_tools = [
|
||||||
tools:[
|
|
||||||
{
|
{
|
||||||
name:"update",
|
name:"update",
|
||||||
tip:"update record in this line",
|
tip:"update record in this line",
|
||||||
@ -341,13 +359,22 @@ bricks.DynamicAccordion = class extends bricks.VScrollPanel {
|
|||||||
icon:this.editable.delete_icon || bricks_resource('imgs/delete.png')
|
icon:this.editable.delete_icon || bricks_resource('imgs/delete.png')
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
desc.tools = edit_tools.concat(desc.tools);
|
||||||
}
|
}
|
||||||
var w = new bricks.IconBar(desc);
|
var w = new bricks.IconBar(desc);
|
||||||
|
if (this.editable){
|
||||||
w.bind('update', this.update_record.bind(this, info, record));
|
w.bind('update', this.update_record.bind(this, info, record));
|
||||||
w.bind('delete', this.delete_record.bind(this, info, record));
|
w.bind('delete', this.delete_record.bind(this, info, record));
|
||||||
|
}
|
||||||
|
for (var i=0;i<event_names.length;i++){
|
||||||
|
w.bind(event_names[i], this.fire_event.bind(this, event_names[i], record));
|
||||||
|
}
|
||||||
c.add_widget(w);
|
c.add_widget(w);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
fire_event(event_name, data){
|
||||||
|
this.dispatch(event_name, data);
|
||||||
|
}
|
||||||
async renderAccordionItems(data, page) {
|
async renderAccordionItems(data, page) {
|
||||||
var pos;
|
var pos;
|
||||||
for (var i=0;i<data.length;i++){
|
for (var i=0;i<data.length;i++){
|
||||||
|
@ -5,9 +5,10 @@ add following lines before 'bricks.js'
|
|||||||
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bricks.MdText = class extends bricks.JsWidget {
|
bricks.MdWidget = class extends bricks.JsWidget {
|
||||||
/* options
|
/* options
|
||||||
{
|
{
|
||||||
|
"mdtext":
|
||||||
"md_url":
|
"md_url":
|
||||||
"method":"GET"
|
"method":"GET"
|
||||||
"params":{}
|
"params":{}
|
||||||
@ -16,12 +17,17 @@ bricks.MdText = class extends bricks.JsWidget {
|
|||||||
|
|
||||||
constructor(options){
|
constructor(options){
|
||||||
super(options);
|
super(options);
|
||||||
|
if (this.mdtext){
|
||||||
|
this.md_content = this.mdtext;
|
||||||
|
this._build1();
|
||||||
|
} else {
|
||||||
var f = this.build.bind(this);
|
var f = this.build.bind(this);
|
||||||
this.load_event = new Event('loaded');
|
this.load_event = new Event('loaded');
|
||||||
this.dom_element.style.overFlow='auto';
|
this.dom_element.style.overFlow='auto';
|
||||||
window.addEventListener('scroll', this.show_scroll.bind(this));
|
window.addEventListener('scroll', this.show_scroll.bind(this));
|
||||||
schedule_once(f, 0.01);
|
schedule_once(f, 0.01);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
show_scroll(event){
|
show_scroll(event){
|
||||||
bricks.debug('scrollY=', window.scrollY);
|
bricks.debug('scrollY=', window.scrollY);
|
||||||
}
|
}
|
||||||
@ -30,8 +36,12 @@ bricks.MdText = class extends bricks.JsWidget {
|
|||||||
}
|
}
|
||||||
_build = async function(md_url){
|
_build = async function(md_url){
|
||||||
var md_content = await (bricks.tget(md_url));
|
var md_content = await (bricks.tget(md_url));
|
||||||
this.dom_element.innerHTML = marked.parse(md_content);
|
this.md_content = md_content;
|
||||||
|
this._build1();
|
||||||
|
this.dispatch('loaded', {'url':md_url});
|
||||||
|
}
|
||||||
|
_build1(){
|
||||||
|
this.dom_element.innerHTML = marked.parse(this.md_content);
|
||||||
/* change links in markdown to a bricks action */
|
/* change links in markdown to a bricks action */
|
||||||
var links = this.dom_element.getElementsByTagName('a');
|
var links = this.dom_element.getElementsByTagName('a');
|
||||||
for (var i=0; i<links.length; i ++){
|
for (var i=0; i<links.length; i ++){
|
||||||
@ -39,7 +49,15 @@ bricks.MdText = class extends bricks.JsWidget {
|
|||||||
links[i].href = '#';
|
links[i].href = '#';
|
||||||
links[i].onclick=this._build.bind(this, url);
|
links[i].onclick=this._build.bind(this, url);
|
||||||
}
|
}
|
||||||
this.dispatch('loaded', {'url':md_url});
|
}
|
||||||
|
getname(){
|
||||||
|
return this.name || 'mdtext';
|
||||||
|
}
|
||||||
|
getValue(){
|
||||||
|
return {this.getname():this.md_content};
|
||||||
|
}
|
||||||
|
setValue(v){
|
||||||
|
this.md_content = v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bricks.MarkdownViewer = class extends bricks.VBox {
|
bricks.MarkdownViewer = class extends bricks.VBox {
|
||||||
@ -48,6 +66,7 @@ bricks.MarkdownViewer = class extends bricks.VBox {
|
|||||||
navigator:true
|
navigator:true
|
||||||
recommentable:false
|
recommentable:false
|
||||||
md_url:
|
md_url:
|
||||||
|
mdtext:
|
||||||
method:"GET",
|
method:"GET",
|
||||||
params:{}
|
params:{}
|
||||||
}
|
}
|
||||||
@ -59,7 +78,10 @@ bricks.MarkdownViewer = class extends bricks.VBox {
|
|||||||
if (this.opts.navigator){
|
if (this.opts.navigator){
|
||||||
this.createBackButton();
|
this.createBackButton();
|
||||||
}
|
}
|
||||||
this.mdtext = new bricks.MdText({
|
this.mdtext = new bricks.MdWidget({
|
||||||
|
mdtext:this.mdtext,
|
||||||
|
method:this.method,
|
||||||
|
params:this.params,
|
||||||
md_url:this.md_url
|
md_url:this.md_url
|
||||||
});
|
});
|
||||||
this.add_widget(this.mdtext);
|
this.add_widget(this.mdtext);
|
||||||
@ -127,3 +149,4 @@ bricks.MarkdownViewer = class extends bricks.VBox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bricks.Factory.register('MarkdownViewer', bricks.MarkdownViewer);
|
bricks.Factory.register('MarkdownViewer', bricks.MarkdownViewer);
|
||||||
|
bricks.Factory.register('MdWidget', bricks.MdWidget);
|
||||||
|
Loading…
Reference in New Issue
Block a user