Skip to content

Instantly share code, notes, and snippets.

@orthagh
Last active April 21, 2016 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orthagh/8d95efbb25d2526dd9902f034499dd10 to your computer and use it in GitHub Desktop.
Save orthagh/8d95efbb25d2526dd9902f034499dd10 to your computer and use it in GitHub Desktop.
shift select for glpi list
diff --git a/css/styles.css b/css/styles.css
index 47f7ed9..5e8fca0 100644
--- a/css/styles.css
+++ b/css/styles.css
@@ -50,6 +50,15 @@ body.iframed {
background: inherit;
}
+.unselectable {
+ -moz-user-select: none;
+ -o-user-select: none;
+ -khtml-user-select: none;
+ -webkit-user-select: none;
+ -ms-user-select: none;
+ user-select: none;
+}
+
ul, li, dt, dl, dd, form, img, input {
margin: 0;
padding: 0;
diff --git a/inc/search.class.php b/inc/search.class.php
index 044e559..6fb5a42 100644
--- a/inc/search.class.php
+++ b/inc/search.class.php
@@ -1470,6 +1470,10 @@ class Search {
Html::showMassiveActions($massiveactionparams);
// End form for delete item
Html::closeForm();
+
+ // permit to shift select checkboxes
+ echo Html::scriptBlock("
+ \$('#$massformid input[type=\"checkbox\"]').shiftSelectable();");
} else {
echo "<br>";
}
diff --git a/script.js b/script.js
index e54ffa8..e3b6816 100644
--- a/script.js
+++ b/script.js
@@ -470,19 +470,48 @@ function displayOtherSelectOptions(select_object, other_option_name) {
**/
function checkAsCheckboxes( reference_id, container_id ) {
- var ref = document.getElementById(reference_id);
- var checkboxes = document.getElementById(container_id).getElementsByTagName('input');
+ $('#' + container_id + ' input[type="checkbox"]:enabled')
+ .prop('checked', $('#' + reference_id).is(':checked'));
- for (var j=0 ; j<checkboxes.length ; j++ ) {
- checkbox = checkboxes[j];
- if (checkbox && (checkbox.type == 'checkbox')) {
- if (checkbox.disabled == false) {
- checkbox.checked = ref.checked;
+ return true;
+}
+
+
+// Usage: $form.find('input[type="checkbox"]').shiftSelectable();
+// replace input[type="checkbox"] with the selector to match your list of checkboxes
+$.fn.shiftSelectable = function() {
+ var lastChecked,
+ $boxes = this;
+
+ // prevent html selection
+ document.onkeydown = function(e) {
+ var keyPressed = e.keyCode;
+ if (keyPressed == 16) { // shift key
+ $('html').addClass('unselectable');
+ document.onkeyup = function() {
+ $('html').removeClass('unselectable');
}
}
}
- return true;
-}
+
+ $boxes.click(function(evt) {
+ if(!lastChecked) {
+ lastChecked = this;
+ return;
+ }
+
+ if(evt.shiftKey) {
+ var start = $boxes.index(this),
+ end = $boxes.index(lastChecked);
+ $boxes.slice(Math.min(start, end), Math.max(start, end) + 1)
+ .prop('checked', $(lastChecked).is(':checked'))
+ .trigger('change');
+ }
+
+ lastChecked = this;
+ console.log(lastChecked)
+ });
+};
/**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment