X-Git-Url: https://svn.cri.ensmp.fr/git/Plinn.git/blobdiff_plain/99afe0ce8700bf835ff7bbedf77bb46e58f996d8..2e2304b15d0fd71d6ce99a009f30231f605295ec:/skins/ajax_scripts/folder_contents_script.js?ds=sidebyside diff --git a/skins/ajax_scripts/folder_contents_script.js b/skins/ajax_scripts/folder_contents_script.js index 379c2c3..5033108 100644 --- a/skins/ajax_scripts/folder_contents_script.js +++ b/skins/ajax_scripts/folder_contents_script.js @@ -4,6 +4,13 @@ // // +var FolderDDropControler; +var DropTarget; +var loadListing; +var DDFolderUploader; + +(function(){ + function getTargetRow(evt){ var target = getTargetedObject(evt); while (target.nodeName != "TR") @@ -11,24 +18,41 @@ function getTargetRow(evt){ return target; } -function FolderDDropControler(listing) { +FolderDDropControler = function(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; 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);}; + addListener(this.listing, 'click', function(evt) {thisControler.disableClickAfterDrop(evt);}); + addListener(this.listing, 'click', function(evt) {thisControler.selectCBRange(evt);}); if (browser.isIE) { this.listing.ondragstart = function() { window.event.returnValue = false;}; } } +FolderDDropControler.prototype._updateCBIndex = function() { + var cbs = this.listing.getElementsByTagName('INPUT'); + var index = 0; + var cb; + this.checkboxes = []; + for (var i=0 ; i < cbs.length ; i++) { + cb = cbs[i]; + if (cb.type === 'checkbox') { + cb.position = index++; + this.checkboxes[cb.position] = cb; + } + } +}; + FolderDDropControler.prototype.drag = function(evt){ var target = getTargetedObject(evt); if (target.nodeName == "INPUT") return true; @@ -127,6 +151,10 @@ FolderDDropControler.prototype.disableClickAfterDrop = function(evt) { this.reset(); }; +FolderDDropControler.prototype.selectCBRange = function(evt) { +}; + + FolderDDropControler.prototype.reset = function() { this.targetRow = null; this.lastOverPosition = null; @@ -136,7 +164,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 +224,7 @@ DropTarget.prototype.highlightTarget = function(evt){ -function loadListing(evt) { +loadListing = function(evt) { var target = getTargetedObject(evt); disableDefault(evt); disablePropagation(evt); @@ -233,3 +261,92 @@ function loadListing(evt) { } return false; } + +DDFolderUploader = function(dropbox, uploadUrl, listing) { + DDFileUploaderBase.apply(this, [dropbox, uploadUrl]); + this.listing = listing; + this.progressBarMaxSize = listing.clientWidth; + 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); + var relSpan = document.createElement('span'); + relSpan.style.position = 'relative'; + td.appendChild(relSpan); + var progressBar = document.createElement('span'); + progressBar.className = 'upload-progress'; + row.progressBar = progressBar; + relSpan.appendChild(progressBar); + var fileNameSpan = document.createElement('span'); + fileNameSpan.innerHTML = file.name; + td.appendChild(fileNameSpan); + row.appendChild(td); + this.listing.appendChild(row); + this.progressBarMaxSize = row.clientWidth; + 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; + this.progressBar = item.progressBar; +}; + +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); + this.progressBarMaxSize = row.clientWidth; + } +}; + +DDFolderUploader.prototype.progressHandlerCB = function(progress) { + // 0 <= progress <= 1 + var size = this.progressBarMaxSize * progress; + size = Math.round(size); + this.progressBar.style.width = size + 'px'; +}; + +}()); \ No newline at end of file