/
InputfieldFileFilter.module
39 lines (31 loc) · 1.39 KB
/
InputfieldFileFilter.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
/**
* Add live filter to the head of file input fields
*/
class InputfieldFileFilter extends Wire implements Module {
public static function getModuleInfo() {
return array(
"title" => __('File Filter', __FILE__),
"summary" => __('Add live filtering capability to InputfieldFile', __FILE__),
"version" => "0.0.5",
"autoload" => true,
);
}
public function init() {
$qstring = "?v=" . filemtime("./InputfieldFileFilter.js");
$this->config->scripts->add($this->config->urls->{$this->className()} . "InputfieldFileFilter.js" . $qstring);
$this->addHookAfter("InputfieldFile::renderList", $this, "addFilterInput");
}
public function addFilterInput(HookEvent $event) {
$field = $event->object;
if($field->className() != "InputfieldFile") return;
$out = $event->return;
$val = $event->arguments(0);
$status = $this->_("[displaying {0} of {1} files]");
$cur = str_replace(array('{0}', '{1}'), count($val), $status);
$inject = "<div class='InputfieldContent filefilter'><span class='fa fa-search'> </span> <input type='text' data-for='{$field->id}' size='50' onkeyup='updateFileFilter(this);' /> <span class='filefilterinfo' data-tpl='{$status}'>{$cur}</span>\n" .
"<p class='description'>" . $this->_("Start typing in the text field above to filter the list of files, clear to show all.") . "</p>\n" .
"</div>\n";
$event->return = $inject . $out;
}
}