-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to hide/disable toolbar icons based on file attributes/properties #1549
Comments
for easy customization of the ui-command for each volume. rel. #1545, #1549. **Example to disable `rm` of not writable items in selected volume** - Front end - JavaScript ```javascript // command `rm2` extends `rm` (elFinder.prototype.commands.rm2 = function() { this.getstate = function(sel) { var fm = this.fm; sel = sel || fm.selected(); return !this._disabled && sel.length && // check `write` too $.map(sel, function(h) { var f = fm.file(h); return f && f.phash && !f.locked && f.write ? h : null }).length == sel.length ? 0 : -1; }; }).prototype = { extendsCmd : 'rm', // extends command name forceLoad : true // to force load }; var options = { url : 'php/connector.php', } $('#elfinder').elfinder(options); ``` - Back end - PHP connector ```php // customized volume driver class elFinderMyVolumeLocalFileSystem extends elFinderVolumeLocalFileSystem extends { protected function remove($path, $force = false) { if (! $force && ($stat = $this->stat($path)) && ! $stat['write']) { return $this->setError(elFinder::ERROR_PERM_DENIED, $this->path($stat['hash'])); } return parent::remove($path, $force); } } $opts = array( 'roots' => array( array( 'driver' => 'LocalFileSystem', 'path' => '/path/to/files/', 'URL' => 'http://localhost/to/files/', ), array( 'driver' => 'MyLocalFileSystem', 'path' => '/path/to/files2/', 'URL' => 'http://localhost/to/files2/', 'uiCmdMap' => 'array('rm' => 'rm2'), // use `rm2` instead `rm` ), ) ); // run elFinder $connector = new elFinderConnector(new elFinder($opts)); $connector->run(); ```
@paulcanning If you want the same behavior in all of the volume... var options = {
url : 'php/connector.php',
handlers : {
init : function(e, fm) {
fm._commands.rm.getstate = function(sel) {
this.fm;
sel = sel || fm.selected();
return !this._disabled && sel.length &&
// check `do_not_delete` too
$.map(sel, function(h) { var f = fm.file(h); return f && f.phash && !f.locked && !f.do_not_delete ? h : null }).length == sel.length
? 0 : -1;
}
}
}
}
$('#elfinder').elfinder(options); If you have control over roll operation for each volume, please refer to 0360abe commit log to reference. In addition, you will not be able to control show/hide state for each item. |
|
|
You really need to put this kind of stuff in the wiki rather then people ask and refer them to the source code. |
@paulcanning This project is issued under a 3-clauses BSD license. If you can not accept this license, you will not be able to use the elFinder. |
How can I hide or disable an icon in the toolbar e.g. the delete button, based on a selected files attributes.
E.g. I currently add custom properties to each file when they are loaded, using the
bind
options in my connector. I would like to hide (or disable) the delete icon if a selected file has a specific custom property ofdo_not_delete = 1
The text was updated successfully, but these errors were encountered: