bricks/bricks/datarow.js

133 lines
2.9 KiB
JavaScript
Raw Normal View History

2024-04-29 17:36:36 +08:00
var bricks = window.bricks || {};
bricks.DataRow = class extends bricks.HBox {
/*
{
toolbar:[
]
fields:[]
css
2024-05-07 18:15:06 +08:00
browserfields{
2024-05-08 18:11:59 +08:00
exclouded:[],
2024-05-07 18:15:06 +08:00
cwidth:{
field:10,
field2:11
}
}
2024-05-08 18:11:59 +08:00
editexclouded:[],
2024-04-29 17:36:36 +08:00
header_css
}
*/
constructor(opts){
super(opts);
2024-07-08 21:19:09 +08:00
this.set_style('width', 'auto');
2024-05-08 16:01:23 +08:00
this.record_w = null;
2024-04-29 17:36:36 +08:00
}
2024-05-30 16:06:46 +08:00
render_header(){
this.render(true);
2024-04-29 17:36:36 +08:00
}
2024-05-30 16:06:46 +08:00
render_data(){
this.render(false);
2024-04-29 17:36:36 +08:00
}
2024-05-30 16:06:46 +08:00
render(header){
this.build_toolbar(header);
2024-05-24 16:07:34 +08:00
if (this.checkField){
var w;
if (header){
w = new bricks.BlankIcon({});
} else {
w = new bricks.UiCheck({name:this.checkField,value:this.user_data[this.checkField]});
2024-06-03 19:04:30 +08:00
w.bind('changed', this.get_check_state.bind(this));
2024-05-24 16:07:34 +08:00
}
2024-04-29 17:36:36 +08:00
this.add_widget(w);
}
this.build_fields(header);
}
2024-05-08 16:01:23 +08:00
renew(record){
this.user_data = record;
this.record_w.clear_widgets();
this._build_fields(false, this.record_w);
}
2024-04-29 17:36:36 +08:00
get_check_state(e){
2024-06-03 19:04:30 +08:00
var d = e.target.bricks_widget.getValue()
2024-05-24 16:07:34 +08:00
this.user_data[this.checkField] = d[this.checkField];
this.dispatch('check_changed', this);
2024-04-29 17:36:36 +08:00
}
2024-05-30 16:06:46 +08:00
build_toolbar(header){
2024-04-29 17:36:36 +08:00
var tools = [];
if (header){
if (this.toolbar){
2024-05-06 11:19:10 +08:00
this.toolbar.tools.forEach(t => {
2024-05-30 16:06:46 +08:00
tools.push({name:'blankicon'});
2024-05-06 11:19:10 +08:00
});
2024-04-29 17:36:36 +08:00
}
} else {
if (this.toolbar){
2024-05-06 11:19:10 +08:00
this.toolbar.tools.forEach(t => {
2024-05-30 16:06:46 +08:00
tools.push(t);
2024-05-06 11:19:10 +08:00
});
2024-04-29 17:36:36 +08:00
}
}
var toolbar = bricks.extend({cwidth:2.5}, this.toolbar || {});
toolbar.tools = tools;
2024-05-06 11:19:10 +08:00
var w = new bricks.IconBar(toolbar);
2024-04-29 17:36:36 +08:00
this.add_widget(w);
2024-05-07 16:53:57 +08:00
this.toolbar_w = w;
2024-04-29 17:36:36 +08:00
this.event_names = []
for(var i=0;i<tools.length;i++){
2024-05-06 18:26:21 +08:00
if (tools[i].name != 'blankicon'){
this.event_names.push(tools[i].name);
w.bind(tools[i].name, this.my_dispatch(tools[i].name));
}
2024-04-29 17:36:36 +08:00
}
}
2024-05-06 11:19:10 +08:00
2024-05-06 18:26:21 +08:00
my_dispatch(e){
this.dispatch(e);
}
2024-05-08 16:01:23 +08:00
build_fields(header, cw){
this.record_w = new bricks.HBox({height:'auto'});
this.add_widget(this.record_w);
this._build_fields(header, this.record_w);
}
_build_fields(header, cw){
2024-05-07 18:15:06 +08:00
var exclouded = [];
var cwidths = {};
if (this.browserfields && this.browserfields.exclouded){
exclouded = this.browserfields.exclouded;
}
2024-05-08 11:15:05 +08:00
if (this.browserfields && this.browserfields.cwidths){
2024-05-07 18:15:06 +08:00
cwidths = this.browserfields.cwidths;
}
2024-06-03 19:04:30 +08:00
if (this.checkField){
exclouded.push(this.checkField);
}
2024-04-29 17:36:36 +08:00
for (var i=0;i<this.fields.length;i++){
var f = this.fields[i]
2024-05-08 16:01:23 +08:00
if (exclouded.includes(f.name)){
2024-05-07 18:15:06 +08:00
continue;
}
2024-05-06 11:19:10 +08:00
var opts = bricks.extend({
margin:'3px'
}, f);
2024-05-14 17:14:30 +08:00
if (header || ! this.user_data){
2024-05-06 11:19:10 +08:00
opts.value = f.label || f.name;
2024-05-08 16:01:23 +08:00
} else {
2024-05-24 16:07:34 +08:00
opts.user_data = this.user_data;
2024-07-07 01:05:31 +08:00
opts.value = opts.tip = this.user_data[f.name];
2024-05-08 16:01:23 +08:00
}
2024-05-07 18:15:06 +08:00
var cwidth = cwidths[f.name];
if (cwidth){
opts.cwidth = cwidth;
}
2024-05-06 11:19:10 +08:00
var f = bricks.get_ViewBuilder(f.uitype);
if (!f) f = bricks.get_ViewBuilder('str');
var w = f(opts);
2024-07-07 01:05:31 +08:00
w.set_css('tabular-cell');
2024-05-08 16:01:23 +08:00
cw.add_widget(w)
2024-04-29 17:36:36 +08:00
}
}
}
bricks.Factory.register('DataRow', bricks.DataRow);