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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
/*
* Copyright (c) 2014
*
* This file is licensed under the Affero General Public License version 3
* or later.
*
* See the COPYING-README file.
*
*/
(function() {
if (!OCA.Files) {
OCA.Files = {};
}
OCA.Files.Search = {
attach: function(search) {
search.setFilter('files', function (query) {
if (OCA.Files.Search.fileAppLoaded()) {
if (query) {
OCA.Files.App.fileList.setFilter(query);
} else {
OCA.Files.App.fileList.unfilter();
}
}
});
search.setRenderer('folder', OCA.Files.Search.renderFolderResult);
search.setRenderer('file', OCA.Files.Search.renderFileResult);
search.setRenderer('audio', OCA.Files.Search.renderAudioResult);
search.setRenderer('image', OCA.Files.Search.renderImageResult);
search.setHandler('folder', OCA.Files.Search.handleFolderClick);
search.setHandler(['file', 'audio', 'image'], OCA.Files.Search.handleFileClick);
},
renderFolderResult: function($row, result) {
if (OCA.Files.Search.inFileList($row, result)) {
return null;
}
/*render folder icon, show path beneath filename,
show size and last modified date on the right */
// backward compatibility:
if (typeof result.mime !== 'undefined') {
result.mime_type = result.mime;
} else if (typeof result.mime_type !== 'undefined') {
result.mime = result.mime_type;
}
var $pathDiv = $('<div class="path"></div>').text(result.path);
$row.find('td.info div.name').after($pathDiv).text(result.name);
$row.find('td.result a').attr('href', result.link);
$row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/folder') + ')');
return $row;
},
renderFileResult: function($row, result) {
if (OCA.Files.Search.inFileList($row, result)) {
return null;
}
/*render preview icon, show path beneath filename,
show size and last modified date on the right */
// backward compatibility:
if (typeof result.mime !== 'undefined') {
result.mime_type = result.mime;
} else if (typeof result.mime_type !== 'undefined') {
result.mime = result.mime_type;
}
$pathDiv = $('<div class="path"></div>').text(result.path);
$row.find('td.info div.name').after($pathDiv).text(result.name);
$row.find('td.result a').attr('href', result.link);
if (OCA.Files.Search.fileAppLoaded()) {
OCA.Files.App.fileList.lazyLoadPreview({
path: result.path,
mime: result.mime,
callback: function (url) {
$row.find('td.icon').css('background-image', 'url(' + url + ')');
}
});
} else {
// FIXME how to get mime icon if not in files app
var mimeicon = result.mime.replace('/', '-');
$row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/' + mimeicon) + ')');
var dir = OC.dirname(result.path);
if (dir === '') {
dir = '/';
}
$row.find('td.info a').attr('href',
OC.generateUrl('/apps/files/?dir={dir}&scrollto={scrollto}', {dir: dir, scrollto: result.name})
);
}
return $row;
},
renderAudioResult: function($row, result) {
if (OCA.Files.Search.inFileList($row, result)) {
return null;
}
/*render preview icon, show path beneath filename,
show size and last modified date on the right
show Artist and Album */
return $row;
},
renderImageResult: function($row, result) {
if (OCA.Files.Search.inFileList($row, result)) {
return null;
}
/*render preview icon, show path beneath filename,
show size and last modified date on the right
show width and height */
return $row;
},
inFileList: function($row, result){
if (OCA.Files.Search.fileAppLoaded() && OCA.Files.App.fileList.inList(result.name)) {
return true;
} else {
return false;
}
},
handleFolderClick: function($row, result, event) {
// open folder
if (OCA.Files.Search.fileAppLoaded()) {
OCA.Files.App.fileList.changeDirectory(result.path);
return false;
} else {
return true;
}
},
handleFileClick: function($row, result, event) {
if (OCA.Files.Search.fileAppLoaded()) {
OCA.Files.App.fileList.changeDirectory(OC.dirname(result.path));
OCA.Files.App.fileList.scrollTo(result.name);
return false;
} else {
return true;
}
},
fileAppLoaded: function() {
return OCA.Files && OCA.Files.App;
}
};
})();
OC.Plugins.register('OCA.Search', OCA.Files.Search);
|