Use radio for single mode selection
As the selection mode may be changed after the construction of the view, the selection column is always constructed but its visibility and the input type are set on the display call. issue6795 review39711002
This commit is contained in:
1 parent
dfb48edd1d
commit
c92a529391
2 files changed
+50
-28
No files matched your search
+43
-28
@@ -54,7 +54,7 @@
|
||||
Sao.View.Tree._super.init.call(this, screen, xml);
|
||||
this.view_type = 'tree';
|
||||
this.selection_mode = (screen.attributes.selection_mode ||
|
||||
Sao.common.SELECTION_SINGLE);
|
||||
Sao.common.SELECTION_MULTIPLE);
|
||||
this.el = jQuery('<div/>', {
|
||||
'class': 'treeview responsive'
|
||||
});
|
||||
@@ -78,17 +78,15 @@
|
||||
this.el.append(this.table);
|
||||
this.thead = jQuery('<thead/>').appendTo(this.table);
|
||||
var tr = jQuery('<tr/>');
|
||||
if (this.selection_mode != Sao.common.SELECTION_NONE) {
|
||||
var th = jQuery('<th/>', {
|
||||
'class': 'selection'
|
||||
});
|
||||
this.selection = jQuery('<input/>', {
|
||||
'type': 'checkbox',
|
||||
});
|
||||
this.selection.change(this.selection_changed.bind(this));
|
||||
th.append(this.selection);
|
||||
tr.append(th);
|
||||
}
|
||||
var th = jQuery('<th/>', {
|
||||
'class': 'selection'
|
||||
});
|
||||
this.selection = jQuery('<input/>', {
|
||||
'type': 'checkbox',
|
||||
});
|
||||
this.selection.change(this.selection_changed.bind(this));
|
||||
th.append(this.selection);
|
||||
tr.append(th);
|
||||
this.thead.append(tr);
|
||||
this.columns.forEach(function(column) {
|
||||
th = jQuery('<th/>', {
|
||||
@@ -289,6 +287,12 @@
|
||||
}
|
||||
expanded = expanded || [];
|
||||
|
||||
if (this.selection_mode == Sao.common.SELECTION_MULTIPLE) {
|
||||
this.selection.show();
|
||||
} else {
|
||||
this.selection.hide();
|
||||
}
|
||||
|
||||
var row_records = function() {
|
||||
return this.rows.map(function(row) {
|
||||
return row.record;
|
||||
@@ -647,17 +651,17 @@
|
||||
}
|
||||
|
||||
var td;
|
||||
if (this.tree.selection_mode != Sao.common.SELECTION_NONE) {
|
||||
td = jQuery('<td/>', {
|
||||
'class': 'selection',
|
||||
});
|
||||
this.el.append(td);
|
||||
this.selection = jQuery('<input/>', {
|
||||
'type': 'checkbox',
|
||||
});
|
||||
this.selection.change(this.selection_changed.bind(this));
|
||||
td.append(this.selection);
|
||||
}
|
||||
this.tree.el.uniqueId();
|
||||
td = jQuery('<td/>', {
|
||||
'class': 'selection',
|
||||
});
|
||||
this.el.append(td);
|
||||
this.selection = jQuery('<input/>', {
|
||||
'type': 'checkbox',
|
||||
'name': 'tree-selection-' + this.tree.el.attr('id'),
|
||||
});
|
||||
this.selection.change(this.selection_changed.bind(this));
|
||||
td.append(this.selection);
|
||||
|
||||
var depth = this.path.split('.').length;
|
||||
for (var i = 0; i < this.tree.columns.length; i++) {
|
||||
@@ -743,11 +747,7 @@
|
||||
},
|
||||
_get_column_td: function(column_index, row) {
|
||||
row = row || this.el;
|
||||
var child_offset = 0;
|
||||
if (this.tree.selection_mode != Sao.common.SELECTION_NONE) {
|
||||
child_offset += 1;
|
||||
}
|
||||
return jQuery(row.children()[column_index + child_offset]);
|
||||
return jQuery(row.children()[column_index + 1]);
|
||||
},
|
||||
redraw: function(selected, expanded) {
|
||||
selected = selected || [];
|
||||
@@ -760,6 +760,21 @@
|
||||
};
|
||||
var thead_visible = this.tree.thead.is(':visible');
|
||||
|
||||
switch(this.tree.selection_mode) {
|
||||
case Sao.common.SELECTION_NONE:
|
||||
this.selection.hide();
|
||||
break;
|
||||
case Sao.common.SELECTION_SINGLE:
|
||||
this.selection.attr('type', 'radio');
|
||||
this.selection.show();
|
||||
break;
|
||||
case Sao.common.SELECTION_MULTIPLE:
|
||||
this.selection.attr('type', 'checkbox');
|
||||
this.selection.show();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
for (var i = 0; i < this.tree.columns.length; i++) {
|
||||
if ((i === 0) && this.children_field) {
|
||||
this.record.load(this.children_field).done(
|
||||
|
||||
@@ -519,6 +519,13 @@
|
||||
});
|
||||
this.screen.load_next_view().done(function() {
|
||||
this.screen.switch_view().done(function() {
|
||||
if (!this.sel_multi) {
|
||||
this.screen.current_view.selection_mode = (
|
||||
Sao.common.SELECTION_SINGLE);
|
||||
} else {
|
||||
this.screen.current_view.selection_mode = (
|
||||
Sao.common.SELECTION_MULTIPLE);
|
||||
}
|
||||
dialog.body.append(this.screen.screen_container.el);
|
||||
this.el.modal('show');
|
||||
this.screen.display();
|
||||
|
||||
Reference in new issue
Block a user