Édition de l'url du serveur Solr.
[Plinn.git] / skins / ajax_scripts / folder_contents_script.js
index 0351cde..066bfc0 100644 (file)
@@ -18,38 +18,40 @@ function getTargetRow(evt){
        return target;
 }
 
        return target;
 }
 
-FolderDDropControler = function(listing) {
+FolderDDropControler = function(listing, orderable, firstItemPos) {
        this.folderUrl = document.getElementById("FolderUrl").innerHTML;
        this.targetRow = null;
        this.lastOverPosition = null;
        this.prevDirUp = null;
        this.noOver = true;
        this.listing = listing;
        this.folderUrl = document.getElementById("FolderUrl").innerHTML;
        this.targetRow = null;
        this.lastOverPosition = null;
        this.prevDirUp = null;
        this.noOver = true;
        this.listing = listing;
-       this.checkboxes = undefined;
-       this._updateCBIndex();
+       this.firstItemPos = firstItemPos;
+       this._updatePositions();
+       this.lastCBChecked = undefined;
        var thisControler = this;
        var thisControler = this;
-       this.listing.onmousedown        = function(evt) {thisControler.drag(evt);};
-       this.listing.onmouseover        = function(evt) {thisControler.moveRow(evt);};
-       this.listing.onmouseup          = function(evt) {thisControler.drop(evt);};
-       addListener(this.listing, 'click', function(evt) {thisControler.disableClickAfterDrop(evt);});
+       if (orderable) {
+               this.listing.onmousedown        = function(evt) {thisControler.drag(evt);};
+               this.listing.onmouseover        = function(evt) {thisControler.moveRow(evt);};
+               this.listing.onmouseup          = function(evt) {thisControler.drop(evt);};
+               addListener(this.listing, 'click', function(evt) {thisControler.disableClickAfterDrop(evt);});
+       }
        addListener(this.listing, 'click', function(evt) {thisControler.selectCBRange(evt);});
        
        addListener(this.listing, 'click', function(evt) {thisControler.selectCBRange(evt);});
        
-       if (browser.isIE) {
+       if (browser.isIE10max) {
                this.listing.ondragstart = function() { window.event.returnValue = false;};
        }
 };
 
                this.listing.ondragstart = function() { window.event.returnValue = false;};
        }
 };
 
-FolderDDropControler.prototype._updateCBIndex = function() {
-       var cbs = this.listing.getElementsByTagName('INPUT');
-       var index = 0;
-       var cb, i;
-       this.checkboxes = [];
-       for (i=0 ; i < cbs.length ; i++) {
-               cb = cbs[i];
-               if (cb.type === 'checkbox') {
-                       cb.position = index++;
-                       this.checkboxes[cb.position] = cb;
-               }
+FolderDDropControler.prototype._updatePositions = function() {
+       var rows = this.listing.getElementsByTagName("TR");
+       var i, row;
+       for (i=0 ; i < rows.length ; i++ ) {
+               row = rows[i];
+               row.pos = i + this.firstItemPos;
+               if (i % 2 === 0) {
+                       row.className = "even"; }
+               else {
+                       row.className = "odd"; }
        }
 };
 
        }
 };
 
@@ -68,7 +70,7 @@ FolderDDropControler.prototype.moveRow =  function(evt){
        var targetRow = this.targetRow;
        if (targetRow !== null) {
                this.noOver = false;
        var targetRow = this.targetRow;
        if (targetRow !== null) {
                this.noOver = false;
-               if (browser.isIE) {document.selection.clear();}
+               if (browser.isIE10max) {document.selection.clear();}
                var overRow = getTargetRow(evt);
 
                if (overRow.pos === targetRow.pos) {return;}
                var overRow = getTargetRow(evt);
 
                if (overRow.pos === targetRow.pos) {return;}
@@ -121,16 +123,7 @@ FolderDDropControler.prototype.drop =  function(evt){
                                           String(this.lastOverPosition - 1 + trim);
 
                        // reinitialize positions
                                           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();
 
                        // send request                         
                        var req = new XMLHttpRequest();
@@ -152,8 +145,37 @@ FolderDDropControler.prototype.disableClickAfterDrop = function(evt) {
 };
 
 FolderDDropControler.prototype.selectCBRange = 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;
 
 FolderDDropControler.prototype.reset = function() {
        this.targetRow = null;
@@ -212,7 +234,7 @@ DropTarget.prototype.drop = function(evt) {
 };
 
 DropTarget.prototype.highlightTarget = function(evt){
 };
 
 DropTarget.prototype.highlightTarget = function(evt){
-       if (browser.isIE) {document.selection.clear();}
+       if (browser.isIE10max) {document.selection.clear();}
        var target = getTargetedObject(evt);
        if (this.folderDDControler.targetRow &&
                target.nodeName === "A" &&
        var target = getTargetedObject(evt);
        if (this.folderDDControler.targetRow &&
                target.nodeName === "A" &&
@@ -330,14 +352,25 @@ DDFolderUploader.prototype.beforeUpload = function(item) {
 DDFolderUploader.prototype.uploadCompleteHandlerCB = function(req) {
        var item = this.uploadedItem;
        var row = getCopyOfNode(req.responseXML.documentElement.firstChild);
 DDFolderUploader.prototype.uploadCompleteHandlerCB = function(req) {
        var item = this.uploadedItem;
        var row = getCopyOfNode(req.responseXML.documentElement.firstChild);
-       row.className = item.className;
 
        if (req.status === 200) {
                // update
 
        if (req.status === 200) {
                // update
-               console.log('todo');
+               this.listing.removeChild(item);
+               var itemUrl = row.getElementsByTagName('a')[0].href;
+               var links = this.listing.getElementsByTagName('a');
+               var i, existingRow;
+               for (i=0 ; i < links.length ; i++) {
+                       if (links[i].href === itemUrl) {
+                               existingRow = links[i].parentNode.parentNode;
+                               row.className = existingRow.className;
+                               this.listing.replaceChild(row, existingRow);
+                               break;
+                       }
+               }
        }
        else if(req.status === 201) {
                // creation
        }
        else if(req.status === 201) {
                // creation
+               row.className = item.className;
                this.listing.replaceChild(row, item);
                this.progressBarMaxSize = row.clientWidth;
        }
                this.listing.replaceChild(row, item);
                this.progressBarMaxSize = row.clientWidth;
        }