updated folder chooser

This commit is contained in:
Uwe Steinmann 2024-03-30 12:12:47 +01:00
parent f06267dd0b
commit 245bfe640a
2 changed files with 34 additions and 9 deletions

View File

@ -144,8 +144,8 @@ switch($command) {
$result = array();
foreach($hits['folders'] as $hit) {
if($hit->getAccessMode($user, 'search') >= M_READ)
//$result[] = $hit->getID().'#'.$basefolder->getName().'/'.$hit->getName();
$result[] = $hit->getID().'#'.$hit->getFolderPathPlain(true, '/');
// $result[] = $hit->getID().'#'.$hit->getFolderPathPlain(true, '/');
$result[] = array('type'=>'F', 'id'=>$hit->getId(), 'name'=>htmlspecialchars($hit->getFolderPathPlain(true, '/')), 'path'=>htmlspecialchars($hit->getParent()->getFolderPathPlain(true, '/')));
}
header('Content-Type: application/json');
echo json_encode($result);
@ -157,7 +157,8 @@ switch($command) {
$result = array();
foreach($subfolders as $subfolder) {
//$result[] = $subfolder->getID().'#'.$basefolder->getName().'/'.$subfolder->getName();
$result[] = $subfolder->getID().'#'.$subfolder->getFolderPathPlain(true, '/');
// $result[] = $subfolder->getID().'#'.$subfolder->getFolderPathPlain(true, '/');
$result[] = array('type'=>'F', 'id'=>$subfolder->getId(), 'name'=>htmlspecialchars($subfolder->getFolderPathPlain(true, '/')), 'path'=>htmlspecialchars($subfolder->getParent()->getFolderPathPlain(true, '/')));
}
header('Content-Type: application/json');
echo json_encode($result);
@ -172,7 +173,8 @@ switch($command) {
$result = array();
foreach($hits['folders'] as $hit) {
if($hit->getAccessMode($user, 'search') >= M_READ)
$result[] = $hit->getID().'#'.$hit->getFolderPathPlain(true, '/');
// $result[] = $hit->getID().'#'.$hit->getFolderPathPlain(true, '/');
$result[] = array('type'=>'F', 'id'=>$hit->getId(), 'name'=>htmlspecialchars($hit->getFolderPathPlain(true, '/')), 'path'=>htmlspecialchars($hit->getParent()->getFolderPathPlain(true, '/')));
}
header('Content-Type: application/json');
echo json_encode($result);

View File

@ -236,7 +236,7 @@ function initMost() {
/* Folder chooser */
$("[id^=choosefoldersearch]").typeahead({ /* {{{ */
menu: '<div class="typeahead dropdown-menu"></div>',
item: '<li><a class="dropdown-item" href="#"></a></li>',
item: '<a class="dropdown-item" href="#"></a>',
minLength: 3,
source: function(query, process) {
// console.log(this.options);
@ -248,19 +248,42 @@ function initMost() {
* actually provided to update the input field, but here we use
* it to set the document location. */
updater: function (item) {
strarr = item.value.split("#");
//console.log(this.$element.data('target'));
target = this.$element.data('target');
$('#'+target).attr('value', strarr[0]);
return strarr[1];
$('#'+target).attr('value', item.id);
return item.value;
},
sorter: function(items) {
return items;
},
/* Set a matcher that allows any returned value */
matcher : function (item) {
return true;
},
highlighter : function (item) {
return '<i class="fa fa-folder-o"></i> ' + item.name.replace(/</g, '&lt;') + (typeof(item.path) != 'undefined' ? '<br /><span class="path">' + item.path + '</span>' : '');
strarr = item.split("#");
return '<i class="fa fa-folder-o"></i> ' + strarr[1].replace(/</g, '&lt;');
},
/* This only works with a modified version of bootstrap typeahead located
* in boostrap-typeahead.js Search for 'render'
* The line
* this.render = this.options.render || this.render
* was added to bootstrap-typeahead.js
* The following function is a copy of the original render function but
* access item.name instead of item
*/
render : function (items) {
var that = this
items = $(items).map(function (i, item) {
i = $(that.options.item).attr('data-value', item.name).attr('data-id', item.id).attr('data-type', item.type);
i./*find('a').*/html(that.highlighter(item))
return i[0]
})
items.first().addClass('active')
this.$menu.html(items)
return this
}
}); /* }}} */
}