Commit dd8c8aa1 by Roman Shevchuk

"Check All" checkboxes added. Closed #3

parent 8a555cce
/*
* showLineNumbersInTables
*/
html.salesforceuiimprover-enabledScript-showLineNumbersInTables #bodyCell table.list > * > tr > th:first-child::before,
html.salesforceuiimprover-enabledScript-showLineNumbersInTables #bodyCell table.list > * > tr > td:first-child::before {
content: attr(line-number);
......@@ -12,4 +15,48 @@ html.salesforceuiimprover-enabledScript-showLineNumbersInTables #bodyCell table.
html.salesforceuiimprover-enabledScript-showLineNumbersInTables #bodyCell table.list > * > tr > th:first-child,
html.salesforceuiimprover-enabledScript-showLineNumbersInTables #bodyCell table.list > * > tr > td:first-child {
padding-left: 2.8em;
}
\ No newline at end of file
}
/*
* checkAllCheckboxes
*/
html.salesforceuiimprover-enabledScript-checkAllCheckboxes #bodyCell .addcheckboxes-container {
padding: 0 3px 0 0;
position: relative;
margin-left: -1px;
}
html.salesforceuiimprover-enabledScript-checkAllCheckboxes #bodyCell .addcheckboxes-container input {
vertical-align: top;
}
html.salesforceuiimprover-enabledScript-checkAllCheckboxes #bodyCell .addcheckboxes-container:hover .addcheckboxes-reset {
display: block;
}
html.salesforceuiimprover-enabledScript-checkAllCheckboxes #bodyCell .addcheckboxes-container.addcheckboxes-container-disabled .addcheckboxes-reset {
display: none;
}
html.salesforceuiimprover-enabledScript-checkAllCheckboxes #bodyCell .addcheckboxes-container .addcheckboxes-reset {
display: none;
position: absolute;
top: 0;
left: 100%;
border-radius: 3px;
margin-left: -1px;
margin-top: -3px;
opacity: 0.2;
background-color: #222;
}
html.salesforceuiimprover-enabledScript-checkAllCheckboxes #bodyCell .addcheckboxes-container .addcheckboxes-reset:hover {
opacity: 1;
}
html.salesforceuiimprover-enabledScript-checkAllCheckboxes #bodyCell .addcheckboxes-container .addcheckboxes-reset a {
color: #fff;
display: inline-block;
padding: 3px 6px;
}
......@@ -48,6 +48,9 @@
<div>
<label><input type="checkbox" name="showLineNumbersInTables"> Show line numbers in tables</label>
</div>
<div>
<label><input type="checkbox" name="checkAllCheckboxes"> Show checkbox in header to check all</label>
</div>
<div id="status"></div>
<div class="footer">
<a href="http://salesforceuiimprover.com" target="_blank">salesforceuiimprover.com</a>
......
......@@ -11,12 +11,14 @@ $(function() {
// Saves options to chrome.storage
function save_options() {
var show1000PerPage = ($('input[name="show1000PerPage"]:checked').length > 0) ? true : false;
var showLineNumbersInTables = ($('input[name="showLineNumbersInTables"]:checked').length > 0) ? true : false;
var show1000PerPage = ($('input[name="show1000PerPage"]:checked').length > 0);
var showLineNumbersInTables = ($('input[name="showLineNumbersInTables"]:checked').length > 0);
var checkAllCheckboxes = ($('input[name="checkAllCheckboxes"]:checked').length > 0);
chrome.storage.sync.set({
show1000PerPage: show1000PerPage,
showLineNumbersInTables: showLineNumbersInTables
showLineNumbersInTables: showLineNumbersInTables,
checkAllCheckboxes: checkAllCheckboxes
}, function() {
optionsSaved();
});
......@@ -26,10 +28,12 @@ function save_options() {
function restore_options() {
chrome.storage.sync.get({
show1000PerPage: true,
showLineNumbersInTables: true
showLineNumbersInTables: true,
checkAllCheckboxes: true
}, function(items) {
$('input[name="show1000PerPage"]').attr('checked', items.show1000PerPage);
$('input[name="showLineNumbersInTables"]').attr('checked', items.showLineNumbersInTables);
$('input[name="checkAllCheckboxes"]').attr('checked', items.checkAllCheckboxes);
});
}
......
......@@ -14,6 +14,10 @@
document.documentElement.classList.add('salesforceuiimprover-enabledScript-' + 'showLineNumbersInTables');
salesforceuiimprover_scripts.showLineNumbersInTables();
}
if (true === options.checkAllCheckboxes) {
document.documentElement.classList.add('salesforceuiimprover-enabledScript-' + 'checkAllCheckboxes');
salesforceuiimprover_scripts.checkAllCheckboxes();
}
}
}
......@@ -21,7 +25,8 @@
chrome.storage.sync.get({
show1000PerPage: true,
showLineNumbersInTables: true
showLineNumbersInTables: true,
checkAllCheckboxes: true
}, function(items) {
var options = $.extend(options, items);
exec_scripts(options);
......
......@@ -153,5 +153,191 @@ var salesforceuiimprover_scripts = {
$bodyCell.find('table.list > thead, table.list > tbody').children('tr.headerRow').children('th:first-child').each(function () {
$(this).attr('line-number', '#');
});
},
checkAllCheckboxes : function () {
function recheckHeaderCheckbox(index) {
index = +index;
var $checkboxes = $('.addcheckboxes-container input[type=checkbox][addcheckboxes-colindex=' + index + ']');
$checkboxes.each(function(){
var $this = $(this);
var checkedCount = 0;
var uncheckedCount = 0;
$this
.closest('table')
.find('input.addcheckboxes-target[type=checkbox][addcheckboxes-colindex=' + index + ']')
.not('[disabled]')
.not('[disabled="*"]')
.each(function(){
var $this = $(this);
var isChecked = $this.is(':checked');
if (true === isChecked) {
checkedCount++;
} else {
uncheckedCount++;
}
});
if (1 <= checkedCount && 0 === uncheckedCount) {
$this.prop('checked', true);
} else {
$this.prop('checked', false);
}
});
}
function generateHeaderCheckbox(index, disabled) {
var $container = $('<span/>').addClass('addcheckboxes-container');
if (true === disabled) {
$container.addClass('addcheckboxes-container-disabled', true);
}
var $checkbox = $('<input/>');
$checkbox.attr('type', 'checkbox');
$checkbox.attr('addcheckboxes-colindex', index);
$checkbox.attr('title', 'Check/Uncheck All Checkboxes');
if (true === disabled) {
$checkbox.prop('disabled', true);
}
$checkbox.change(function(){
var $this = $(this);
var index = +$this.attr('addcheckboxes-colindex');
var needChecked = $this.is(':checked');
$this
.closest('table')
.find('input.addcheckboxes-target[type=checkbox][addcheckboxes-colindex=' + index + ']')
.not('[disabled]')
.not('[disabled="*"]')
.each(function(){
var $this = $(this);
var isChecked = $this.is(':checked');
if ((needChecked && !isChecked) || (!needChecked && isChecked)) {
$this.click();
}
});
});
var $tip = $('<span/>').addClass('addcheckboxes-reset');
var $tip_link = $('<a/>');
$tip_link.text('Reset');
$tip_link.attr('href', 'javascript:void(0)');
$tip_link.attr('title', 'Restore the initial values');
$tip_link.click(function(){
var $this = $(this);
var $container = $this.closest('.addcheckboxes-container');
var $checkbox = $container.find('input[type=checkbox]');
var index = +$checkbox.attr('addcheckboxes-colindex');
$this
.closest('table')
.find('input.addcheckboxes-target[type=checkbox][addcheckboxes-colindex=' + index + ']')
.not('[disabled]')
.not('[disabled="*"]')
.each(function(){
$this = $(this);
var needChecked = true;
var resetvalue = $this.attr('addcheckboxes-resetvalue');
if (!resetvalue || resetvalue == 'false') {
needChecked = false;
}
var isChecked = $this.is(':checked');
if ((needChecked && !isChecked) || (!needChecked && isChecked)) {
$this.click();
}
});
});
$tip.append($tip_link);
$container.append($checkbox);
$container.append($tip);
return $container;
}
$('#bodyCell').find('table').has('td > input[type=checkbox]').each(function(){
var $table = $(this);
var $trHeader;
var cols = {};
var disabledCount = {};
var $tds;
if (0 !== $table.children('tbody').length) {
$tds = $table.children('tbody').children('tr').children('td');
} else {
$tds = $table.children('tr').children('td');
}
$tds.children('input[type=checkbox]').each(function(){
var $this = $(this);
var $td = $this.parent();
var index = $td.index();
var checked = $this.is(':checked');
$this.addClass('addcheckboxes-target');
$this.attr('addcheckboxes-resetvalue', checked);
$this.attr('addcheckboxes-colindex', index);
$this.on('change', function (){
recheckHeaderCheckbox(index);
});
if (undefined === cols[index]) {
cols[index] = 0;
}
if (undefined === disabledCount[index]) {
disabledCount[index] = 0;
}
if ($this.is(':disabled')) {
disabledCount[index]++;
}
cols[index]++;
});
if ($table.children('thead')) {
$trHeader = $table.children('thead').children('tr:first');
} else {
var $firtTrInTbody;
if ($table.children('tbody')) {
$firtTrInTbody = $table.children('tbody').children('tr:first');
} else {
$firtTrInTbody = $table.children('tr:first');
}
if (0 === $firtTrInTbody.children('td').length) {
$trHeader = $firtTrInTbody;
}
}
if (undefined !== $trHeader && 0 !== $trHeader.length) {
$.each(cols, function( key, value ) {
var index = key;
var $th = $($trHeader.children().get(index));
var disabled = false;
if (value == disabledCount[index]) {
disabled = true;
}
var $deepestElem = $th;
while ($deepestElem.children(':first').length > 0) {
$deepestElem = $deepestElem.children(':first');
}
$deepestElem.prepend(generateHeaderCheckbox(index, disabled));
recheckHeaderCheckbox(index);
});
}
});
}
};
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment