Commit b457655e authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Check if file exists (in js) before uploading

parent 802c80a4
......@@ -39,8 +39,7 @@ foreach ($strings as $string) {
$javascript = <<<JAVASCRIPT
var browser = new FileBrowser('filelist');
var uploader = new FileUploader('uploader');
uploader.uploadcallback = browser.refresh;
var uploader = new FileUploader('uploader', null, null, browser.refresh, browser.fileexists);
browser.changedircallback = uploader.updatedestination;
JAVASCRIPT;
......
......@@ -6,6 +6,7 @@ function FileBrowser(element, changedircallback) {
this.pathids = {'/':null};
this.cwd = '/';
this.changedircallback = changedircallback;
this.filenames = {};
this.init = function() {
self.filelist = new TableRenderer(
......@@ -106,6 +107,7 @@ function FileBrowser(element, changedircallback) {
}
this.formatname = function(r) {
self.filenames[r.title] = true;
if (r.artefacttype == 'file') {
return TD(null, r.title);
}
......@@ -118,10 +120,15 @@ function FileBrowser(element, changedircallback) {
}
}
this.fileexists = function (filename) {
return self.filenames[filename] == true;
}
this.changedir = function(path) {
self.cwd = path;
self.linked_path();
self.changedircallback(self.pathids[path], path);
self.filenames = {};
var args = path == '/' ? null : {'folder':self.pathids[path]};
self.filelist.doupdate(args);
return false;
......
function FileUploader(element, foldername, folderid, uploadcallback) {
function FileUploader(element, foldername, folderid, uploadcallback, fileexists) {
var self = this;
this.element = element;
this.foldername = foldername ? foldername : get_string('home');
this.folderid = folderid;
this.uploadcallback = uploadcallback;
if (typeof(fileexists) == 'function') {
this.fileexists = fileexists;
}
else {
this.fileexists = function (filename) { alert(filename); };
}
this.init = function() {
self.nextupload = 1;
......@@ -70,10 +77,6 @@ function FileUploader(element, foldername, folderid, uploadcallback) {
}
}
this.fileexists = function (filename) {
return true;
}
this.sendform = function (replace) {
var localname = self.form.userfile.value;
if (isEmpty(localname)) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment