2011-07-30 19:18:54 +00:00
|
|
|
OC.search.catagorizeResults=function(results){
|
|
|
|
var types={};
|
|
|
|
for(var i=0;i<results.length;i++){
|
|
|
|
var type=results[i].type;
|
|
|
|
if(!types[type]){
|
|
|
|
types[type]=[];
|
|
|
|
}
|
|
|
|
types[type].push(results[i]);
|
|
|
|
}
|
|
|
|
return types;
|
2013-07-31 20:24:52 +00:00
|
|
|
};
|
2011-07-30 19:18:54 +00:00
|
|
|
OC.search.hide=function(){
|
|
|
|
$('#searchresults').hide();
|
|
|
|
if($('#searchbox').val().length>2){
|
|
|
|
$('#searchbox').val('');
|
2013-07-31 20:24:52 +00:00
|
|
|
if (FileList && typeof FileList.unfilter === 'function') { //TODO add hook system
|
|
|
|
FileList.unfilter();
|
|
|
|
}
|
2011-07-30 19:18:54 +00:00
|
|
|
};
|
2013-07-31 20:24:52 +00:00
|
|
|
if ($('#searchbox').val().length === 0) {
|
|
|
|
if (FileList && typeof FileList.unfilter === 'function') { //TODO add hook system
|
|
|
|
FileList.unfilter();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2011-07-30 19:18:54 +00:00
|
|
|
OC.search.showResults=function(results){
|
2013-07-31 20:24:52 +00:00
|
|
|
if(results.length === 0){
|
2011-07-31 00:05:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-07-30 19:18:54 +00:00
|
|
|
if(!OC.search.showResults.loaded){
|
|
|
|
var parent=$('<div/>');
|
|
|
|
$('body').append(parent);
|
|
|
|
parent.load(OC.filePath('search','templates','part.results.php'),function(){
|
|
|
|
OC.search.showResults.loaded=true;
|
|
|
|
$('#searchresults').click(function(event){
|
2012-09-28 19:18:11 +00:00
|
|
|
OC.search.hide();
|
2011-07-30 19:18:54 +00:00
|
|
|
event.stopPropagation();
|
|
|
|
});
|
2013-02-21 16:38:25 +00:00
|
|
|
$(document).click(function(event){
|
2011-07-30 19:18:54 +00:00
|
|
|
OC.search.hide();
|
2013-07-31 20:24:52 +00:00
|
|
|
if (FileList && typeof FileList.unfilter === 'function') { //TODO add hook system
|
|
|
|
FileList.unfilter();
|
|
|
|
}
|
2011-07-30 19:18:54 +00:00
|
|
|
});
|
2011-07-31 02:03:48 +00:00
|
|
|
OC.search.lastResults=results;
|
2011-07-30 19:18:54 +00:00
|
|
|
OC.search.showResults(results);
|
|
|
|
});
|
|
|
|
}else{
|
|
|
|
var types=OC.search.catagorizeResults(results);
|
|
|
|
$('#searchresults').show();
|
|
|
|
$('#searchresults tr.result').remove();
|
2011-07-31 02:03:48 +00:00
|
|
|
var index=0;
|
2013-09-17 15:27:47 +00:00
|
|
|
for(var typeid in types){
|
|
|
|
var type=types[typeid];
|
2011-07-30 19:18:54 +00:00
|
|
|
if(type.length>0){
|
2012-06-22 15:43:57 +00:00
|
|
|
for(var i=0;i<type.length;i++){
|
2011-07-30 19:18:54 +00:00
|
|
|
var row=$('#searchresults tr.template').clone();
|
|
|
|
row.removeClass('template');
|
|
|
|
row.addClass('result');
|
2013-09-17 15:27:47 +00:00
|
|
|
row.data('type', typeid);
|
|
|
|
row.data('name', type[i].name);
|
|
|
|
row.data('text', type[i].text);
|
|
|
|
row.data('container', type[i].container);
|
2013-07-31 20:24:52 +00:00
|
|
|
if (i === 0){
|
2013-09-17 15:27:47 +00:00
|
|
|
row.children('td.type').text(typeid);
|
2012-06-22 15:43:57 +00:00
|
|
|
}
|
2011-07-30 19:18:54 +00:00
|
|
|
row.find('td.result div.name').text(type[i].name);
|
|
|
|
row.find('td.result div.text').text(type[i].text);
|
2013-07-31 20:24:52 +00:00
|
|
|
if (type[i].container) {
|
|
|
|
var containerName = OC.basename(type[i].container);
|
|
|
|
if (containerName === '') {
|
|
|
|
containerName = '/';
|
|
|
|
}
|
2013-09-17 15:27:47 +00:00
|
|
|
var containerLink = OC.linkTo('files', 'index.php')
|
|
|
|
+'?dir='+encodeURIComponent(type[i].container)
|
|
|
|
+'&scrollto='+encodeURIComponent(type[i].name);
|
|
|
|
row.find('td.result a')
|
|
|
|
.attr('href', containerLink)
|
|
|
|
.attr('title', t('core', 'Show in {folder}', {folder: containerName}));
|
|
|
|
} else {
|
|
|
|
row.find('td.result a').attr('href', type[i].link);
|
2013-07-31 20:24:52 +00:00
|
|
|
}
|
2011-07-31 02:03:48 +00:00
|
|
|
row.data('index',index);
|
|
|
|
index++;
|
2013-09-17 15:27:47 +00:00
|
|
|
if(OC.search.customResults[typeid]){//give plugins the ability to customize the entries in here
|
|
|
|
OC.search.customResults[typeid](row,type[i]);
|
2011-07-30 22:50:04 +00:00
|
|
|
}
|
2011-07-30 19:18:54 +00:00
|
|
|
$('#searchresults tbody').append(row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-09-17 15:27:47 +00:00
|
|
|
$('#searchresults').on('click', 'result', function () {
|
|
|
|
if ($(this).data('type') === 'Files') {
|
2013-09-17 16:45:38 +00:00
|
|
|
//FIXME use ajax to navigate to folder & highlight file
|
2013-09-17 15:27:47 +00:00
|
|
|
}
|
|
|
|
});
|
2011-07-30 19:18:54 +00:00
|
|
|
}
|
2013-07-31 20:24:52 +00:00
|
|
|
};
|
2011-07-30 19:18:54 +00:00
|
|
|
OC.search.showResults.loaded=false;
|
2011-07-31 02:03:48 +00:00
|
|
|
|
|
|
|
OC.search.renderCurrent=function(){
|
|
|
|
if($('#searchresults tr.result')[OC.search.currentResult]){
|
|
|
|
var result=$('#searchresults tr.result')[OC.search.currentResult];
|
|
|
|
$('#searchresults tr.result').removeClass('current');
|
|
|
|
$(result).addClass('current');
|
|
|
|
}
|
2013-07-31 20:24:52 +00:00
|
|
|
};
|
2013-09-17 15:29:22 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// customize search results, currently replaces a technical type with a more human friendly version
|
|
|
|
// TODO implement search result renderers instead of changing results after adding them to the DOM
|
|
|
|
//
|
|
|
|
OC.search.customResults.file = function (row, item) {
|
|
|
|
if(row.children('td.type').text() === 'file') {
|
|
|
|
row.children('td.type').text(t('lib','Files'));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
OC.search.customResults.folder = function (row, item) {
|
|
|
|
if(row.children('td.type').text() === 'folder') {
|
|
|
|
row.children('td.type').text(t('lib','Folders'));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
OC.search.customResults.image = function (row, item) {
|
|
|
|
if(row.children('td.type').text() === 'image') {
|
|
|
|
row.children('td.type').text(t('lib','Images'));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
OC.search.customResults.audio = function (row, item) {
|
|
|
|
if(row.children('td.type').text() === 'audio') {
|
|
|
|
row.children('td.type').text(t('lib','Audio'));
|
|
|
|
};
|
|
|
|
}
|