X-Git-Url: https://scm.cri.ensmp.fr/git/Plinn.git/blobdiff_plain/3e0a2c257d49fb162da9c70d2f70194036235166..a23495c46f185990eddd43e372d6b83fad403af4:/skins/ajax_scripts/folder_contents_script.js?ds=inline diff --git a/skins/ajax_scripts/folder_contents_script.js b/skins/ajax_scripts/folder_contents_script.js index b896cb7..6480f9d 100644 --- a/skins/ajax_scripts/folder_contents_script.js +++ b/skins/ajax_scripts/folder_contents_script.js @@ -1,40 +1,66 @@ // (c) Benoît PIN 2006-2007 // http://plinn.org // Licence GPL -// $Id: folder_contents_script.js 1375 2008-09-12 12:29:12Z pin $ -// $URL: http://svn.cri.ensmp.fr/svn/Plinn/branches/CMF-2.1/skins/ajax_scripts/folder_contents_script.js $ +// +// + +var FolderDDropControler; +var DropTarget; +var loadListing; +var DDFolderUploader; + +(function(){ function getTargetRow(evt){ var target = getTargetedObject(evt); - while (target.nodeName != "TR") - target = target.parentNode; + while (target.nodeName !== "TR") { + target = target.parentNode; } return target; } -function FolderDDropControler(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.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);}; - this.listing.onmouseup = function(evt) {thisControler.drop(evt);}; - this.listing.onclick = 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);}); - if (browser.isIE) { + if (browser.isIE10max) { this.listing.ondragstart = function() { window.event.returnValue = false;}; } -} +}; + +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"; } + } +}; FolderDDropControler.prototype.drag = function(evt){ var target = getTargetedObject(evt); - if (target.nodeName == "INPUT") return true; + if (target.nodeName === "INPUT") { return true; } disableDefault(evt); var targetRow = getTargetRow(evt); - targetRow.style.backgroundColor = base_properties["highLightColor"]; + targetRow.style.backgroundColor = base_properties.highLightColor; this.listing.style.cursor = "move"; this.targetRow = targetRow; this.lastOverPosition = targetRow.pos; @@ -42,13 +68,13 @@ FolderDDropControler.prototype.drag = function(evt){ FolderDDropControler.prototype.moveRow = function(evt){ var targetRow = this.targetRow; - if (targetRow != null) { + 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; - + if (overRow.pos === targetRow.pos) {return;} + if (this.lastOverPosition < overRow.pos) { // move up this.listing.insertBefore(targetRow, overRow.nextSibling); this.prevDirUp = true; @@ -74,45 +100,36 @@ FolderDDropControler.prototype.moveRow = function(evt){ FolderDDropControler.prototype.drop = function(evt){ var targetRow = this.targetRow; - if (targetRow != null) { + if (targetRow !== null) { targetRow.style.backgroundColor=""; this.listing.style.cursor = ""; + var thisControler = this; if (this.noOver) { - var thisControler = this; setTimeout(function(){thisControler.reset();}, 50); return; } - if (this.lastOverPosition != null) { + if (this.lastOverPosition !== null) { // get new object position. var trim = 0; - if (targetRow.pos < this.lastOverPosition && !this.prevDirUp) - trim = -1; - else if (targetRow.pos > this.lastOverPosition && this.prevDirUp) - trim = 1; + if (targetRow.pos < this.lastOverPosition && !this.prevDirUp) { + trim = -1; } + else if (targetRow.pos > this.lastOverPosition && this.prevDirUp) { + trim = 1; } // construct url - var object_id = targetRow.getElementsByTagName("INPUT")[0].getAttribute("value"); - var url = this.folderUrl + "/moveObjectIdToPosition"; - var form ="object_id=" + object_id + "&position:int=" + - String(this.lastOverPosition - 1 + trim); + var object_id = targetRow.getElementsByTagName("INPUT")[0].getAttribute("value"); + var url = this.folderUrl + "/moveObjectIdToPosition"; + var form ="object_id=" + object_id + "&position:int=" + + String(this.lastOverPosition - 1 + trim); // reinitialize positions - var rows = this.listing.getElementsByTagName("TR"), row; - for (var i = 0 ; i < rows.length ; i++) { - row = rows[i]; - row.pos = i+1; - if (i % 2 == 0) - row.className = "even"; - else - row.className = "odd"; - } - - // send request + this._updatePositions(); + + // send request var req = new XMLHttpRequest(); req.open("POST", url, true); req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); req.send(form); - var thisControler = this; setTimeout(function(){thisControler.reset();}, 50); } } @@ -127,47 +144,80 @@ FolderDDropControler.prototype.disableClickAfterDrop = function(evt) { this.reset(); }; +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