Permalink
Browse files

Check if file/directory exists (option)

  • Loading branch information...
jcubic committed Sep 10, 2017
1 parent b6587b0 commit 94dd721bef5de0c9424eabeb3511e90893e9cbff
View
@@ -1,5 +1,6 @@
0.8.0 context menu
allow to create new file/directory
exists option executed before creating new file/directory
markdown icon
few bug fixes
0.7.3 prevent opening file on enter when focus in adress bar
View
@@ -70,6 +70,7 @@ If you want context menu (enabled using contextmenu option) you'll need jQuery U
* name - used to distinguish different filesystem for copying nad moving files (rename)
* dir - function that should return a promise that resolve to object `{files: <ARRAY>, dirs: <ARRAY>}` or return that object
* exists - function that will return true/false or a promise that resolve to true/false that indicate if file or directory exists (used when create new file/directory)
* separator - path separator (a string) usualy `/` or `\` (to use `\` you need to put `'\\'`) default /
* root - root of the filesystem, it can be any path like `/home/<user>`, default `/`
* change - callback function that's called on refresh of the directory
View
@@ -70,6 +70,7 @@ If you want context menu (enabled using contextmenu option) you'll need jQuery U
* name - used to distinguish different filesystem for copying nad moving files (rename)
* dir - function that should return a promise that resolve to object `{files: <ARRAY>, dirs: <ARRAY>}` or return that object
* exists - function that will return true/false or a promise that resolve to true/false that indicate if file or directory exists (used when create new file/directory)
* separator - path separator (a string) usualy `/` or `\` (to use `\` you need to put `'\\'`) default /
* root - root of the filesystem, it can be any path like `/home/<user>`, default `/`
* change - callback function that's called on refresh of the directory
View
@@ -81,7 +81,7 @@
if (type == 'li') {
return {
'alert': function($li) {
alert('alert for item ' + $li.text());
alert('alert for item "' + $li.text() + '"');
}
}
} else {
@@ -115,6 +115,9 @@
}
});
},
exists: function(path) {
return typeof get(path) != 'undefined';
},
error: function(message) {
alert(message);
},
@@ -115,6 +115,9 @@
}
return $.when(result); // resolved promise
},
exists: function(path) {
return typeof get(path) != 'undefined';
},
upload: function(file, path) {
return upload(file, path);
},
@@ -5,7 +5,7 @@
* Copyright (c) 2016-2017 Jakub Jankiewicz <http://jcubic.pl/me>
* Released under the MIT license
*
* Date: Wed, 06 Sep 2017 19:48:00 +0000
* Date: Sun, 10 Sep 2017 08:12:03 +0000
*/
/* global setTimeout jQuery File Directory */
(function($, undefined) {
@@ -135,6 +135,7 @@
create: $.noop,
remove: $.noop,
copy: $.noop,
exists: $.noop,
upload: $.noop,
name: 'default',
error: $.noop,
@@ -622,7 +623,7 @@
} else {
if (self.name() !== drag.context.name()) {
var msg = "You can't drag across different filesystems";
throw new Error(msg);
settings.error(msg);
}
var promise;
if (drag.selection) {
@@ -697,17 +698,30 @@
_create: function(type, path) {
return $.when(settings.create(type, path));
},
_exists: function(path) {
return $.when(settings.exists(path));
},
create: function(type, path) {
var _class = class_name(type);
if (path == undefined) {
var $li = $(['<li class="new ' + class_name(type) + '" draggable="true">',
var $li = $(['<li class="new ' + _class + '" draggable="true">',
' <span></span>',
' <textarea/>',
'</li>'].join('')).appendTo($ul);
scroll_to_bottom();
$li.find('textarea').val('New ' + type).focus().select();
return $.when();
}
return self._create(type, path).then(refresh_same);
return self._exists(path).then(function(exists) {
if (exists == true) {
$content.find('li.new').remove();
setTimeout(function() {
settings.error(type + ' already exists');
}, 10);
} else {
return self._create(type, path).then(refresh_same);
}
});
},
_copy: function(src, dest) {
if (!same_root(src, dest)) {
@@ -742,7 +756,7 @@
}
if (copy && copy.contents && copy.contents.length) {
if (self.name() !== copy.source.name()) {
throw new Error("You can't paste across different filesystems");
settings.error("You can't paste across different filesystems");
} else {
var promise;
if (cut) {

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -135,6 +135,7 @@
create: $.noop,
remove: $.noop,
copy: $.noop,
exists: $.noop,
upload: $.noop,
name: 'default',
error: $.noop,
@@ -622,7 +623,7 @@
} else {
if (self.name() !== drag.context.name()) {
var msg = "You can't drag across different filesystems";
throw new Error(msg);
settings.error(msg);
}
var promise;
if (drag.selection) {
@@ -697,17 +698,30 @@
_create: function(type, path) {
return $.when(settings.create(type, path));
},
_exists: function(path) {
return $.when(settings.exists(path));
},
create: function(type, path) {
var _class = class_name(type);
if (path == undefined) {
var $li = $(['<li class="new ' + class_name(type) + '" draggable="true">',
var $li = $(['<li class="new ' + _class + '" draggable="true">',
' <span></span>',
' <textarea/>',
'</li>'].join('')).appendTo($ul);
scroll_to_bottom();
$li.find('textarea').val('New ' + type).focus().select();
return $.when();
}
return self._create(type, path).then(refresh_same);
return self._exists(path).then(function(exists) {
if (exists == true) {
$content.find('li.new').remove();
setTimeout(function() {
settings.error(type + ' already exists');
}, 10);
} else {
return self._create(type, path).then(refresh_same);
}
});
},
_copy: function(src, dest) {
if (!same_root(src, dest)) {
@@ -742,7 +756,7 @@
}
if (copy && copy.contents && copy.contents.length) {
if (self.name() !== copy.source.name()) {
throw new Error("You can't paste across different filesystems");
settings.error("You can't paste across different filesystems");
} else {
var promise;
if (cut) {
View
@@ -5,7 +5,7 @@
* Copyright (c) 2016-2017 Jakub Jankiewicz <http://jcubic.pl/me>
* Released under the MIT license
*
* Date: Wed, 06 Sep 2017 19:48:00 +0000
* Date: Sun, 10 Sep 2017 08:12:03 +0000
*/
/* global setTimeout jQuery File Directory */
(function($, undefined) {
@@ -135,6 +135,7 @@
create: $.noop,
remove: $.noop,
copy: $.noop,
exists: $.noop,
upload: $.noop,
name: 'default',
error: $.noop,
@@ -622,7 +623,7 @@
} else {
if (self.name() !== drag.context.name()) {
var msg = "You can't drag across different filesystems";
throw new Error(msg);
settings.error(msg);
}
var promise;
if (drag.selection) {
@@ -697,17 +698,30 @@
_create: function(type, path) {
return $.when(settings.create(type, path));
},
_exists: function(path) {
return $.when(settings.exists(path));
},
create: function(type, path) {
var _class = class_name(type);
if (path == undefined) {
var $li = $(['<li class="new ' + class_name(type) + '" draggable="true">',
var $li = $(['<li class="new ' + _class + '" draggable="true">',
' <span></span>',
' <textarea/>',
'</li>'].join('')).appendTo($ul);
scroll_to_bottom();
$li.find('textarea').val('New ' + type).focus().select();
return $.when();
}
return self._create(type, path).then(refresh_same);
return self._exists(path).then(function(exists) {
if (exists == true) {
$content.find('li.new').remove();
setTimeout(function() {
settings.error(type + ' already exists');
}, 10);
} else {
return self._create(type, path).then(refresh_same);
}
});
},
_copy: function(src, dest) {
if (!same_root(src, dest)) {
@@ -742,7 +756,7 @@
}
if (copy && copy.contents && copy.contents.length) {
if (self.name() !== copy.source.name()) {
throw new Error("You can't paste across different filesystems");
settings.error("You can't paste across different filesystems");
} else {
var promise;
if (cut) {
Oops, something went wrong.

0 comments on commit 94dd721

Please sign in to comment.