diff --git a/HISTORY.rst b/HISTORY.rst index a8fc5237be..b70f6e3789 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -131,6 +131,8 @@ The storage.backends.filebasedstorage.FileBasedStorage has been remove, instead Django's default storage is used and each app is responsible of specifying their default path. +- Unify checkbox selection code for list items and table items. +- Add smart checkbox manager. 2.7.3 (2017-09-11) diff --git a/docs/releases/3.0.rst b/docs/releases/3.0.rst index 23e8790f07..6c512f39be 100644 --- a/docs/releases/3.0.rst +++ b/docs/releases/3.0.rst @@ -294,6 +294,13 @@ If no path is specified the backend will default to 'mayan/media/document_storag Finally, to standardize the way app use storage, the .storages modules is now used instead of the .runtime module. +Smart checkbox selection +------------------------ +A faster way to select multiple item has been added. Click the checkbox of the first, +hold the Shift key, and then click the checkbox of the last item of the selection. +This will select the first, the last and all items in between. To deselect multiple +items the same procedure is used. This code was donated by the Paperattor +project (www.paperattor.com). Other changes worth mentioning ------------------------------ diff --git a/mayan/apps/appearance/static/appearance/js/base.js b/mayan/apps/appearance/static/appearance/js/base.js index 21bb1705c8..72f0978ecc 100644 --- a/mayan/apps/appearance/static/appearance/js/base.js +++ b/mayan/apps/appearance/static/appearance/js/base.js @@ -8,8 +8,11 @@ var partialNavigation = new PartialNavigation({ }); jQuery(document).ready(function() { + app.setupAutoSubmit(); app.setupFullHeightResizing(); + app.setupItemsSelector(); app.setupNavbarCollapse(); + app.setupNewWindowAnchor(); app.setupAJAXperiodicWorkers(); partialNavigation.initialize(); }); @@ -17,10 +20,6 @@ jQuery(document).ready(function() { var afterBaseLoad = function () { MayanImage.intialize(); app.doToastrMessages(); - app.setupAutoSubmit(); - app.setupItemsSelector(); - app.setupNewWindowAnchor(); - app.setupTableSelector(); app.resizeFullHeight(); app.setupSelect2(); app.setupScrollView(); diff --git a/mayan/apps/appearance/static/appearance/js/mayan_app.js b/mayan/apps/appearance/static/appearance/js/mayan_app.js index 94e2045d30..7748ed6558 100644 --- a/mayan/apps/appearance/static/appearance/js/mayan_app.js +++ b/mayan/apps/appearance/static/appearance/js/mayan_app.js @@ -187,7 +187,7 @@ App.prototype.setupAJAXperiodicWorkers = function () { } App.prototype.setupAutoSubmit = function () { - $('.select-auto-submit').change(function () { + $('body').on('change', '.select-auto-submit', function () { if ($(this).val()) { $(this.form).trigger('submit'); } @@ -209,7 +209,7 @@ App.prototype.setupNavbarCollapse = function () { } App.prototype.setupNewWindowAnchor = function () { - $('a.new_window').click(function (event) { + $('body').on('click', 'a.new_window', function (event) { event.preventDefault(); var newWindow = window.open($(this).attr('href'), '_blank'); newWindow.focus(); @@ -220,20 +220,35 @@ App.prototype.setupScrollView = function () { $('.scrollable').scrollview(); } -App.prototype.setupTableSelector = function () { - $('th input:checkbox').click(function(e) { - var table = $(e.target).closest('table'); - var checked = $(e.target).prop('checked'); - $('td input:checkbox', table).prop('checked', checked); - }); -} - App.prototype.setupItemsSelector = function () { - $('.check-all').click(function(e) { - var parent = $(e.target).closest('.well'); - var checked = $(e.target).prop('checked'); - $('.panel-item input:checkbox', parent).prop('checked', checked); + var app = this; + app.lastChecked = null; + + $('body').on('click', '.check-all', function (event) { + var checked = $(event.target).prop('checked'); + var $checkBoxes = $('.check-all-slave'); + + $checkBoxes.prop('checked', checked); + $checkBoxes.trigger('change'); }); + + $('body').on('click', '.check-all-slave', function(e) { + if(!app.lastChecked) { + app.lastChecked = this; + return; + } + if(e.shiftKey) { + var $checkBoxes = $('.check-all-slave'); + + var start = $checkBoxes.index(this); + var end = $checkBoxes.index(app.lastChecked); + + $checkBoxes.slice( + Math.min(start,end), Math.max(start,end) + 1 + ).prop('checked', app.lastChecked.checked).trigger('change'); + } + app.lastChecked = this; + }) } App.prototype.setupSelect2 = function () { diff --git a/mayan/apps/appearance/templates/appearance/generic_list_items_subtemplate.html b/mayan/apps/appearance/templates/appearance/generic_list_items_subtemplate.html index e22f3b5883..fa4a4bf7b3 100644 --- a/mayan/apps/appearance/templates/appearance/generic_list_items_subtemplate.html +++ b/mayan/apps/appearance/templates/appearance/generic_list_items_subtemplate.html @@ -64,9 +64,9 @@