Skip to content
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

Closed
paulcanning opened this issue Jul 25, 2016 · 5 comments
Closed
Labels

Comments

@paulcanning
Copy link

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 of do_not_delete = 1

nao-pon added a commit that referenced this issue Jul 26, 2016
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();
```
@nao-pon
Copy link
Member

nao-pon commented Jul 26, 2016

@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.

@nao-pon nao-pon added the howto label Jul 26, 2016
@paulcanning
Copy link
Author

  1. How are you specifically targeting the delete icon? How can I target other buttons?
  2. What do you mean by "In addition, you will not be able to control show/hide state for each item."?

@nao-pon
Copy link
Member

nao-pon commented Jul 26, 2016

  1. -> Please read js/commands source.
  2. -> It can enable/disable control but can not show/hide control of each items.

@paulcanning
Copy link
Author

You really need to put this kind of stuff in the wiki rather then people ask and refer them to the source code.

@nao-pon
Copy link
Member

nao-pon commented Jul 27, 2016

@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.

@nao-pon nao-pon closed this as completed Jul 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants