jump right to document/folder in typeahead list

This commit is contained in:
Uwe Steinmann 2021-03-26 07:48:36 +01:00
parent 2e21c7c6a0
commit b18128fef2

View File

@ -130,10 +130,22 @@ $(document).ready( function() {
/* updater is called when the item in the list is clicked. It is
* actually provided to update the input field, but here we use
* it to set the document location. The passed value is the string
* set in data-value of the list items. */
* set in data-value of the list items.
* This method relies on some changes in bootstrap-typeahead.js
* Originally, update was passed only the data-value of the li item
* which is set in the render fuction below,
* but the modified version passes all data fields. which also
* contain the 'id' and 'type' (also set in render function).
**/
updater: function (item) {
document.location = "../out/out.Search.php?query=" + encodeURIComponent(item);
return item;
if(item.id) {
if(item.type == 'D')
document.location = "../out/out.ViewDocument.php?documentid=" + item.id;
else
document.location = "../out/out.ViewFolder.php?folderid=" + item.id;
} else
document.location = "../out/out.Search.php?query=" + encodeURIComponent(item.value);
return item.value;
},
sorter: function(items) {
return items;
@ -144,6 +156,10 @@ $(document).ready( function() {
matcher : function (item) {
return true;
},
/* highlighter is for modifying the 'a' tag text. It places an icon
* in front of the name and replaces a '<' within the name with an
* entity.
**/
highlighter : function (item) {
if(item.type.charAt(0) == 'D')
return '<i class="fa fa-file"></i> ' + item.name.replace(/</g, '&lt;');
@ -164,7 +180,7 @@ $(document).ready( function() {
var that = this
items = $(items).map(function (i, item) {
i = $(that.options.item).attr('data-value', item.name)
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]
})