-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Description
I had a requirement to limit the cut command to files only, not directories. I knew that I needed to override the getstate function of that command as shown below:
Lines 16 to 21 in bc6a08b
| this.getstate = function(select) { | |
| var sel = this.files(select), | |
| cnt = sel.length; | |
| return cnt && $.grep(sel, function(f) { return f.read && ! f.locked && ! fm.isRoot(f) ? true : false; }).length == cnt ? 0 : -1; | |
| }; |
I struggled how to achieve this without replacing the entire command as shown in Overriding the “Open” Menu Item in elFinder.
Then I came across the question How to change function inside constructor in JavaScript? which allowed me to achieve what I wanted. The solution below can be added to bootCallback function in the configuration options.
(function (old) {
fm.commands.cut = function () {
old.apply(this);
this.getstate = function (select) {
var sel = this.files(select),
cnt = sel.length;
return cnt && $.grep(sel, function (f) {
return f.mime !== 'directory' && f.read && !f.locked && !fm.isRoot(f) ? true : false;
}).length == cnt ? 0 : -1;
};
};
var fn = function () { };
fn.prototype = old.prototype;
fm.commands.cut.prototype = new fn();
}(fm.commands.cut));I hope this helps others as it took me a while to figure out. If anyone has a more elegant way to achieve the same result please share!
Reactions are currently unavailable