diff --git a/program/js/list.js b/program/js/list.js index edfb19065..a4b800131 100644 --- a/program/js/list.js +++ b/program/js/list.js @@ -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').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 = $('').attr({'class': 'button icon toggleselect disabled', role: 'button'})