2024-04-29 17:36:36 +08:00
|
|
|
var bricks = window.bricks || {};
|
2024-07-07 01:05:31 +08:00
|
|
|
bricks.Tabular = class extends bricks.DataViewer {
|
2024-04-29 17:36:36 +08:00
|
|
|
constructor(opts){
|
|
|
|
super(opts);
|
2024-06-03 19:04:30 +08:00
|
|
|
this.bind('row_check_changed', this.show_check_event_data.bind(this));
|
|
|
|
}
|
2024-07-07 01:05:31 +08:00
|
|
|
async build_other(){
|
|
|
|
this.get_edit_fields();
|
2024-04-29 17:36:36 +08:00
|
|
|
}
|
2024-07-07 01:05:31 +08:00
|
|
|
async before_data_handle(){
|
|
|
|
await this.build_header_row();
|
2024-07-08 21:19:09 +08:00
|
|
|
this.data_offset = 1;
|
2024-05-30 16:06:46 +08:00
|
|
|
}
|
2024-07-07 01:05:31 +08:00
|
|
|
async build_header_row(){
|
|
|
|
var options = bricks.extend({cheight:this.cheight}, this.row_options);
|
|
|
|
var dr = new bricks.DataRow(options);
|
|
|
|
dr.render(false);
|
|
|
|
dr.set_css('tabular-header-row');
|
|
|
|
this.scrollpanel.add_widget(dr);
|
|
|
|
}
|
2024-07-08 21:19:09 +08:00
|
|
|
async build_record_view(record){
|
2024-07-07 01:05:31 +08:00
|
|
|
var r = await this.build_info(record);
|
2024-07-08 21:19:09 +08:00
|
|
|
if (!this.content_view){
|
|
|
|
r.user_data = record;
|
|
|
|
r.bind('click', this.record_clicked.bind(this, r, record));
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
var row = new bricks.VBox({
|
|
|
|
css:'tabular-row'
|
|
|
|
});
|
2024-07-07 01:05:31 +08:00
|
|
|
row.add_widget(r);
|
|
|
|
var content = new bricks.VBox({
|
|
|
|
height:'auto',
|
|
|
|
display:'none'
|
|
|
|
});
|
|
|
|
row.add_widget(content);
|
2024-07-08 21:19:09 +08:00
|
|
|
r.bind('click', this.record_clicked.bind(this, row, record));
|
|
|
|
row.rec_widget = r;
|
|
|
|
row.content_widget = content;
|
|
|
|
row.user_data = record;
|
|
|
|
return row
|
|
|
|
}
|
|
|
|
async record_clicked(row, record, event){
|
|
|
|
var r = event.target.bricks_widget;
|
|
|
|
var old_select_row = this.select_row;
|
|
|
|
if (old_select_row){
|
|
|
|
this.select_row = null;
|
|
|
|
if (this.content_view){
|
|
|
|
await this.toggle_content(old_select_row, false);
|
|
|
|
old_select_row.rec_widget.set_css('tabular-row-selected', true);
|
|
|
|
} else {
|
|
|
|
old_select_row.set_css('tabular-row-selected', true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (old_select_row != row){
|
|
|
|
this.select_row = row;
|
|
|
|
if (this.content_view){
|
|
|
|
row.rec_widget.set_css('tabular-row-selected');
|
|
|
|
await this.toggle_content(row, true);
|
|
|
|
} else {
|
|
|
|
row.set_css('tabular-row-selected');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
async toggle_content(row, flag){
|
|
|
|
if (flag){
|
|
|
|
row.content_widget.show();
|
|
|
|
row.content_widget.clear_widgets();
|
|
|
|
var w = await bricks.widgetBuild(this.content_view, row.content_widget, row.user_data);
|
|
|
|
if (w){
|
|
|
|
row.content_widget.add_widget(w);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
row.content_widget.hide();
|
|
|
|
row.content_widget.clear_widgets();
|
|
|
|
}
|
2024-05-30 16:06:46 +08:00
|
|
|
}
|
2024-05-08 11:15:05 +08:00
|
|
|
get_edit_fields(){
|
2024-05-14 17:14:30 +08:00
|
|
|
var fs = this.row_options.fields;
|
2024-05-07 18:15:06 +08:00
|
|
|
this.fields = [];
|
|
|
|
var exclouded = [];
|
2024-05-14 17:14:30 +08:00
|
|
|
if (this.row_options.editexclouded){
|
|
|
|
exclouded = this.row_options.editexclouded;
|
2024-05-07 18:15:06 +08:00
|
|
|
}
|
|
|
|
fs.forEach(f => {
|
2024-05-08 11:15:05 +08:00
|
|
|
if (!exclouded.includes(f.name)){
|
2024-05-07 18:15:06 +08:00
|
|
|
this.fields.push(f);
|
|
|
|
}
|
2024-05-08 11:15:05 +08:00
|
|
|
});
|
2024-05-07 18:15:06 +08:00
|
|
|
}
|
|
|
|
|
2024-07-07 01:05:31 +08:00
|
|
|
async build_info(record){
|
2024-05-14 17:14:30 +08:00
|
|
|
var header = true;
|
|
|
|
var options = bricks.extend({cheight:this.cheight}, this.row_options);
|
2024-04-29 17:36:36 +08:00
|
|
|
if (record){
|
2024-05-07 16:53:57 +08:00
|
|
|
options.user_data = record;
|
2024-05-14 17:14:30 +08:00
|
|
|
header = false;
|
2024-04-29 17:36:36 +08:00
|
|
|
}
|
2024-05-14 17:14:30 +08:00
|
|
|
var dr = new bricks.DataRow(options);
|
2024-05-30 16:06:46 +08:00
|
|
|
dr.render(header);
|
2024-05-14 17:14:30 +08:00
|
|
|
dr.event_names.forEach(e => {
|
2024-07-07 01:05:31 +08:00
|
|
|
dr.toolbar_w.bind(e, this.record_event_handle.bind(this, e, record, dr));
|
2024-05-14 17:14:30 +08:00
|
|
|
});
|
2024-05-24 16:07:34 +08:00
|
|
|
dr.bind('check_changed', this.record_check_changed.bind(this));
|
2024-05-06 11:19:10 +08:00
|
|
|
return dr;
|
2024-04-29 17:47:29 +08:00
|
|
|
}
|
2024-05-24 16:07:34 +08:00
|
|
|
record_check_changed(event){
|
2024-06-03 19:04:30 +08:00
|
|
|
this.check_changed_row = event.params;
|
|
|
|
this.dispatch('row_check_changed', event.params.user_data);
|
2024-05-24 16:07:34 +08:00
|
|
|
}
|
2024-07-08 21:19:09 +08:00
|
|
|
async renew_record_view(form, row){
|
2024-05-08 16:01:23 +08:00
|
|
|
var d = form.getValue();
|
2024-07-08 21:19:09 +08:00
|
|
|
var record = bricks.extend(row.user_data, d);
|
|
|
|
if (this.content_view){
|
|
|
|
row.rec_widget.renew(record);
|
|
|
|
} else {
|
|
|
|
row.renew(record);
|
|
|
|
}
|
2024-05-08 16:01:23 +08:00
|
|
|
}
|
2024-05-06 11:19:10 +08:00
|
|
|
record_event_handle(event_name, record, row, item){
|
2024-05-06 18:26:21 +08:00
|
|
|
console.log('event_name=', event_name, 'record=', record);
|
2024-05-30 16:06:46 +08:00
|
|
|
this.dispatch(event_name, record);
|
|
|
|
}
|
2024-07-03 18:04:19 +08:00
|
|
|
get_hidefields(){
|
|
|
|
var fs = [];
|
|
|
|
var params = this.data_params || {};
|
|
|
|
for (var k in params){
|
|
|
|
fs.push({name:k, value:params[k], uitype:'hide'});
|
|
|
|
}
|
|
|
|
return fs;
|
|
|
|
}
|
2024-04-29 17:36:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bricks.Factory.register('Tabular', bricks.Tabular);
|