diff --git a/bricks/datarow.js b/bricks/datarow.js new file mode 100644 index 0000000..9edf000 --- /dev/null +++ b/bricks/datarow.js @@ -0,0 +1,100 @@ +var bricks = window.bricks || {}; + +bricks.DataRow = class extends bricks.HBox { + /* + { + toolbar:[ + ] + fields:[] + css + header_css + } + */ + constructor(opts){ + super(opts); + } + render_header(editable, checkable){ + this.render(editable, checkable, true); + } + render_data(editable, checkable){ + this.render(editable, checkable, false); + } + render(editable, checkable, header){ + if (checkable){ + var w = new bricks.UiCheck({name:'c',value:false}) + this.add_widget(w); + w.bind(changed, this.get_check_state.bind(this)); + } + this.build_toolbar(editable, header); + this.build_fields(header); + } + get_check_state(e){ + d = e.target.getValue() + this.dispatch('checked', d.c) + } + build_toolbar(editable, header){ + var tools = []; + const reserved = ['add', 'update', 'delete']; + + if (editable){ + if (header){ + tools.push({ + name:'add', + tip:'add new record', + icon:this.editable.add_icon || bricks_resource('imgs/add.png') + }); + tools.push({ + name:'blankicon' + }); + } else { + tools.push({ + }); + tools.push({ + }); + } + } + if (header){ + if (this.toolbar){ + this.toolbar.tools.foreach(t => if (not reserved.includes(t.name)) tools.push({name:'blankicon'})); + } + } else { + if (this.toolbar){ + this.toolbar.tools.foreach(t => if (not reserved.includes(t.name)) tools.push(t)); + } + } + var toolbar = bricks.extend({cwidth:2.5}, this.toolbar || {}); + toolbar.tools = tools; + var w = new bricks.IconBar(desc); + this.add_widget(w); + this.event_names = [] + for(var i=0;i