Support enabling checkbox selection on list after intialization and existing records

pull/5578/merge
Aleksander Machniak 6 years ago
parent f0fc42b3c4
commit 66550f65ae

@ -407,34 +407,7 @@ insert_row: function(row, before)
}
if (this.checkbox_selection) {
var key, cell = document.createElement(this.col_tagname()),
chbox = document.createElement('input');
chbox.type = 'checkbox';
chbox.tabIndex = -1;
chbox.onchange = function(e) {
self.select_row(row.uid, key || CONTROL_KEY, true);
e.stopPropagation();
key = null;
};
chbox.onmousedown = function(e) {
key = rcube_event.get_modifier(e);
};
cell.className = 'selection';
// make the whole cell "touchable" for touch devices
cell.onclick = function(e) {
if (!$(e.target).is('input')) {
key = rcube_event.get_modifier(e);
$(chbox).prop('checked', !chbox.checked).change();
}
e.stopPropagation();
};
cell.appendChild(chbox);
row.insertBefore(cell, row.firstChild);
this.insert_checkbox(row);
}
if (before && tbody.childNodes.length)
@ -451,7 +424,7 @@ insert_row: function(row, before)
},
/**
*
* Update existing record
*/
update_row: function(id, cols, newid, select)
{
@ -477,6 +450,60 @@ update_row: function(id, cols, newid, select)
}
},
/**
* Add selection checkbox to the list record
*/
insert_checkbox: function(row)
{
var key, self = this,
cell = document.createElement(this.col_tagname()),
chbox = document.createElement('input');
chbox.type = 'checkbox';
chbox.tabIndex = -1;
chbox.onchange = function(e) {
self.select_row(row.uid, key || CONTROL_KEY, true);
e.stopPropagation();
key = null;
};
chbox.onmousedown = function(e) {
key = rcube_event.get_modifier(e);
};
cell.className = 'selection';
// make the whole cell "touchable" for touch devices
cell.onclick = function(e) {
if (!$(e.target).is('input')) {
key = rcube_event.get_modifier(e);
$(chbox).prop('checked', !chbox.checked).change();
}
e.stopPropagation();
};
cell.appendChild(chbox);
row.insertBefore(cell, row.firstChild);
},
/**
* Enable checkbox selection
*/
enable_checkbox_selection: function()
{
this.checkbox_selection = true;
// Add checkbox to existing records if any
var r, len, cell, row_tag = this.row_tagname().toUpperCase(),
rows = this.tbody.childNodes;
for (r=0, len=rows.length; r<len; r++) {
if (rows[r].nodeName == row_tag && (cell = rows[r].firstChild)) {
if (cell.className == 'selection')
break;
this.insert_checkbox(rows[r]);
}
}
},
/**
* Set focus to the list

@ -448,12 +448,12 @@ function rcube_elastic_ui()
var parent = table.parents('.sidebar,.list,.content'),
toolbar = parent.find('.pagenav');
if (!toolbar) {
if (!toolbar.length) {
toolbar = $('<div class="pagenav toolbar footer small">').appendTo(parent);
}
// Enable checkbox selection on list widgets
rcmail[list].checkbox_selection = true;
rcmail[list].enable_checkbox_selection();
// Add Select button to the list navigation bar
button = $('<a>').attr({'class': 'button icon toggleselect disabled', role: 'button'})

Loading…
Cancel
Save