Implémentation de la sélection par range des cases à cocher.
[Plinn.git] / skins / ajax_scripts / folder_contents_script.js
index 89cca56..7edda7d 100644 (file)
@@ -27,6 +27,7 @@ FolderDDropControler = function(listing, firstItemPos) {
        this.listing = listing;
        this.firstItemPos = firstItemPos;
        this._updatePositions();
+       this.lastCBChecked = undefined;
        var thisControler = this;
        this.listing.onmousedown        = function(evt) {thisControler.drag(evt);};
        this.listing.onmouseover        = function(evt) {thisControler.moveRow(evt);};
@@ -41,10 +42,15 @@ FolderDDropControler = function(listing, firstItemPos) {
 
 FolderDDropControler.prototype._updatePositions = function() {
        var rows = this.listing.getElementsByTagName("TR");
-       var i;
+       var i, row;
        for (i=0 ; i < rows.length ; i++ ) {
-               rows[i].pos = i + this.firstItemPos; }
-
+               row = rows[i];
+               row.pos = i + this.firstItemPos;
+               if (i % 2 === 0) {
+                       row.className = "even"; }
+               else {
+                       row.className = "odd"; }
+       }
 };
 
 FolderDDropControler.prototype.drag =  function(evt){
@@ -115,16 +121,7 @@ FolderDDropControler.prototype.drop =  function(evt){
                                           String(this.lastOverPosition - 1 + trim);
 
                        // reinitialize positions
-                       var rows = this.listing.getElementsByTagName("TR"), row;
-                       var i;
-                       for (i = 0 ; i < rows.length ; i++) {
-                               row = rows[i];
-                               row.pos = i+1;
-                               if (i % 2 === 0){
-                                       row.className = "even";}
-                               else{
-                                       row.className = "odd";}
-                       }
+                       this._updatePositions();
 
                        // send request                         
                        var req = new XMLHttpRequest();
@@ -146,8 +143,37 @@ FolderDDropControler.prototype.disableClickAfterDrop = function(evt) {
 };
 
 FolderDDropControler.prototype.selectCBRange = function(evt) {
+       var target = getTargetedObject(evt);
+       if (target.tagName === 'INPUT' && target.type === 'checkbox') {
+               evt = getEventObject(evt);
+               var shift = evt.shiftKey;
+               if (shift && this.lastCBChecked) {
+                       var from = this.getCBIndex(this.lastCBChecked);
+                       var to = this.getCBIndex(target);
+                       var rows = this.listing.getElementsByTagName('TR');
+                       var start = Math.min(from, to);
+                       var stop = Math.max(from, to);
+                       var i;
+                       for (i=start ; i<stop ; i++ ) {
+                               rows[i].getElementsByTagName('INPUT')[0].checked = true;
+                       }
+               }
+               else if (target.checked) {
+                       this.lastCBChecked = target;
+               }
+               else {
+                       this.lastCBChecked = undefined;
+               }
+       }
 };
 
+FolderDDropControler.prototype.getCBIndex = function(cb) {
+       var row = cb.parentNode;
+       while(row.tagName !== 'TR') {
+               row = row.parentNode;
+       }
+       return row.pos - this.firstItemPos;
+};
 
 FolderDDropControler.prototype.reset = function() {
        this.targetRow = null;