X-Git-Url: https://svn.cri.ensmp.fr/git/Plinn.git/blobdiff_plain/3e0a2c257d49fb162da9c70d2f70194036235166..326a6677709320dc5149de76f6ae2bdea31fe4fa:/skins/ajax_scripts/folder_contents_script.js diff --git a/skins/ajax_scripts/folder_contents_script.js b/skins/ajax_scripts/folder_contents_script.js index b896cb7..7204a4e 100644 --- a/skins/ajax_scripts/folder_contents_script.js +++ b/skins/ajax_scripts/folder_contents_script.js @@ -1,8 +1,15 @@ // (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); @@ -11,7 +18,7 @@ function getTargetRow(evt){ return target; } -function FolderDDropControler(listing) { +FolderDDropControler = function(listing) { this.folderUrl = document.getElementById("FolderUrl").innerHTML; this.targetRow = null; this.lastOverPosition = null; @@ -136,7 +143,7 @@ FolderDDropControler.prototype.reset = function() { -function DropTarget(node, folderDDControler) { +DropTarget = function(node, folderDDControler) { this.folderDDControler = folderDDControler; this.batchSize = parseInt(document.getElementById("BatchNavigationSize").innerHTML); var thisControler = this; @@ -196,7 +203,7 @@ DropTarget.prototype.highlightTarget = function(evt){ -function loadListing(evt) { +loadListing = function(evt) { var target = getTargetedObject(evt); disableDefault(evt); disablePropagation(evt); @@ -233,3 +240,78 @@ function loadListing(evt) { } return false; } + +DDFolderUploader = function(dropbox, uploadUrl, listing) { + DDFileUploaderBase.apply(this, [dropbox, uploadUrl]); + this.listing = listing; + var thead = listing; + do { + thead = thead.previousSibling; + } while (thead.tagName !== 'THEAD') + + var cells = thead.getElementsByTagName('th'); + var cell; + this.tableSpan = 0; + for (var i = 0 ; i < cells.length ; i++) { + cell = cells[i]; + this.tableSpan += cell.getAttribute('colspan') ? Number(cell.getAttribute('colspan')) : 1; + } + var lastRow = listing.lastChild; + while(lastRow && lastRow.tagName !== 'TR') { + lastRow = lastRow.previousSibling; + } + this.lastRowClassName = lastRow ? lastRow.className : 'even'; +}; + +copyPrototype(DDFolderUploader, DDFileUploaderBase); + + +DDFolderUploader.prototype.createRow = function(file) { + var row = document.createElement('tr'); + row.file = file; + row.className = this.lastRowClassName === 'even' ? 'odd' : 'even'; + this.lastRowClassName = row.className; + var td = document.createElement('td'); + td.setAttribute('colspan', this.tableSpan); + td.innerHTML = file.name; + row.appendChild(td); + this.listing.appendChild(row); + return row; +}; + +// Methods about upload +DDFolderUploader.prototype.handleFiles = function(files) { + var file, i, row; + for (i = 0; i < files.length; i++) { + file = files[i]; + row = this.createRow(file); + this.uploadQueuePush(row); + } +}; + +DDFolderUploader.prototype.beforeUpload = function(item) { + this.uploadedItem = item; + // To be implemented by decendant. +}; + +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 + console.log('todo'); + } + else if(req.status === 201) { + // creation + this.listing.replaceChild(row, item); + } +}; + +DDFolderUploader.prototype.progressHandlerCB = function(progress) { + // To be implemented by descendant. + // 0 <= progress <= 1 +}; + +}()); \ No newline at end of file