2014-10-24 10:50:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3
|
|
|
|
* or later.
|
|
|
|
*
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*
|
|
|
|
*/
|
2014-12-17 17:49:39 +00:00
|
|
|
(function() {
|
2014-12-30 23:14:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct a new FileActions instance
|
|
|
|
* @constructs Files
|
|
|
|
*/
|
|
|
|
var Files = function() {
|
|
|
|
this.initialize();
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* @memberof OCA.Search
|
|
|
|
*/
|
|
|
|
Files.prototype = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the file search
|
|
|
|
*/
|
|
|
|
initialize: function() {
|
|
|
|
OC.Plugins.register('OCA.Search', this);
|
|
|
|
},
|
2014-12-17 17:49:39 +00:00
|
|
|
attach: function(search) {
|
2014-12-31 13:28:01 +00:00
|
|
|
var self = this;
|
2014-12-17 17:49:39 +00:00
|
|
|
search.setFilter('files', function (query) {
|
2014-12-31 13:28:01 +00:00
|
|
|
if (self.fileAppLoaded()) {
|
2014-12-18 22:11:42 +00:00
|
|
|
OCA.Files.App.fileList.setFilter(query);
|
|
|
|
|
2014-12-17 17:49:39 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-12-31 13:28:01 +00:00
|
|
|
search.setRenderer('folder', this.renderFolderResult);
|
|
|
|
search.setRenderer('file', this.renderFileResult);
|
|
|
|
search.setRenderer('audio', this.renderAudioResult);
|
|
|
|
search.setRenderer('image', this.renderImageResult);
|
2014-12-17 17:49:39 +00:00
|
|
|
|
2014-12-31 13:28:01 +00:00
|
|
|
search.setHandler('folder', this.handleFolderClick);
|
|
|
|
search.setHandler(['file', 'audio', 'image'], this.handleFileClick);
|
2014-12-17 17:49:39 +00:00
|
|
|
},
|
|
|
|
renderFolderResult: function($row, result) {
|
2014-12-31 13:28:01 +00:00
|
|
|
if (this.inFileList($row, result)) {
|
2014-12-18 09:26:41 +00:00
|
|
|
return null;
|
|
|
|
}
|
2014-12-17 17:49:39 +00:00
|
|
|
/*render folder icon, show path beneath filename,
|
|
|
|
show size and last modified date on the right */
|
2014-12-31 13:28:01 +00:00
|
|
|
this.updateLegacyMimetype(result);
|
2014-12-17 17:49:39 +00:00
|
|
|
|
2014-12-18 09:26:41 +00:00
|
|
|
var $pathDiv = $('<div class="path"></div>').text(result.path);
|
2014-12-17 17:49:39 +00:00
|
|
|
$row.find('td.info div.name').after($pathDiv).text(result.name);
|
2014-10-24 10:50:54 +00:00
|
|
|
|
2014-12-17 17:49:39 +00:00
|
|
|
$row.find('td.result a').attr('href', result.link);
|
|
|
|
$row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/folder') + ')');
|
2014-12-18 09:26:41 +00:00
|
|
|
return $row;
|
2014-12-17 17:49:39 +00:00
|
|
|
},
|
|
|
|
renderFileResult: function($row, result) {
|
2014-12-31 13:28:01 +00:00
|
|
|
if (this.inFileList($row, result)) {
|
2014-12-18 09:26:41 +00:00
|
|
|
return null;
|
|
|
|
}
|
2014-12-17 17:49:39 +00:00
|
|
|
/*render preview icon, show path beneath filename,
|
|
|
|
show size and last modified date on the right */
|
2014-12-31 13:28:01 +00:00
|
|
|
this.updateLegacyMimetype(result);
|
2014-12-04 12:43:38 +00:00
|
|
|
|
2014-12-30 23:14:02 +00:00
|
|
|
var $pathDiv = $('<div class="path"></div>').text(result.path);
|
2014-12-11 15:23:39 +00:00
|
|
|
$row.find('td.info div.name').after($pathDiv).text(result.name);
|
2014-12-04 12:43:38 +00:00
|
|
|
|
2014-12-11 15:23:39 +00:00
|
|
|
$row.find('td.result a').attr('href', result.link);
|
2014-12-04 12:43:38 +00:00
|
|
|
|
2014-12-31 13:28:01 +00:00
|
|
|
if (this.fileAppLoaded()) {
|
2014-12-11 15:23:39 +00:00
|
|
|
OCA.Files.App.fileList.lazyLoadPreview({
|
|
|
|
path: result.path,
|
|
|
|
mime: result.mime,
|
|
|
|
callback: function (url) {
|
|
|
|
$row.find('td.icon').css('background-image', 'url(' + url + ')');
|
|
|
|
}
|
|
|
|
});
|
2014-12-10 16:11:02 +00:00
|
|
|
} else {
|
2014-12-11 15:23:39 +00:00
|
|
|
// 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 = '/';
|
2011-07-30 19:18:54 +00:00
|
|
|
}
|
2014-12-11 15:23:39 +00:00
|
|
|
$row.find('td.info a').attr('href',
|
|
|
|
OC.generateUrl('/apps/files/?dir={dir}&scrollto={scrollto}', {dir: dir, scrollto: result.name})
|
|
|
|
);
|
2011-07-30 19:18:54 +00:00
|
|
|
}
|
2014-12-18 09:26:41 +00:00
|
|
|
return $row;
|
2014-12-17 17:49:39 +00:00
|
|
|
},
|
|
|
|
renderAudioResult: function($row, result) {
|
|
|
|
/*render preview icon, show path beneath filename,
|
|
|
|
show size and last modified date on the right
|
|
|
|
show Artist and Album */
|
2014-12-31 13:28:01 +00:00
|
|
|
$row = this.renderFileResult($row, result);
|
2014-12-18 23:24:46 +00:00
|
|
|
if ($row) {
|
|
|
|
$row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/audio') + ')');
|
|
|
|
}
|
2014-12-18 09:26:41 +00:00
|
|
|
return $row;
|
2014-12-17 17:49:39 +00:00
|
|
|
},
|
|
|
|
renderImageResult: function($row, result) {
|
|
|
|
/*render preview icon, show path beneath filename,
|
|
|
|
show size and last modified date on the right
|
|
|
|
show width and height */
|
2014-12-31 13:28:01 +00:00
|
|
|
$row = this.renderFileResult($row, result);
|
|
|
|
if ($row && !this.fileAppLoaded()) {
|
2014-12-18 23:24:46 +00:00
|
|
|
$row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/image') + ')');
|
|
|
|
}
|
2014-12-18 09:26:41 +00:00
|
|
|
return $row;
|
|
|
|
},
|
|
|
|
inFileList: function($row, result){
|
2014-12-31 13:28:01 +00:00
|
|
|
return this.fileAppLoaded() && OCA.Files.App.fileList.inList(result.name);
|
2014-12-17 17:49:39 +00:00
|
|
|
},
|
2014-12-18 23:24:46 +00:00
|
|
|
updateLegacyMimetype: function(result){
|
|
|
|
// backward compatibility:
|
|
|
|
if (!result.mime && result.mime_type) {
|
|
|
|
result.mime = result.mime_type;
|
|
|
|
}
|
|
|
|
},
|
2014-12-17 17:49:39 +00:00
|
|
|
handleFolderClick: function($row, result, event) {
|
|
|
|
// open folder
|
2014-12-31 13:28:01 +00:00
|
|
|
if (this.fileAppLoaded()) {
|
2014-12-17 17:49:39 +00:00
|
|
|
OCA.Files.App.fileList.changeDirectory(result.path);
|
2014-12-11 15:23:39 +00:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
2013-09-17 15:27:47 +00:00
|
|
|
}
|
2014-12-17 17:49:39 +00:00
|
|
|
},
|
|
|
|
handleFileClick: function($row, result, event) {
|
2014-12-31 13:28:01 +00:00
|
|
|
if (this.fileAppLoaded()) {
|
2014-12-17 17:49:39 +00:00
|
|
|
OCA.Files.App.fileList.changeDirectory(OC.dirname(result.path));
|
|
|
|
OCA.Files.App.fileList.scrollTo(result.name);
|
2014-12-11 15:23:39 +00:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
2014-12-05 23:53:06 +00:00
|
|
|
}
|
2014-12-18 09:26:41 +00:00
|
|
|
},
|
|
|
|
fileAppLoaded: function() {
|
2014-12-19 15:37:44 +00:00
|
|
|
return !!OCA.Files && !!OCA.Files.App;
|
2014-12-17 17:49:39 +00:00
|
|
|
}
|
|
|
|
};
|
2014-12-31 13:28:01 +00:00
|
|
|
new Files();
|
2014-12-17 17:49:39 +00:00
|
|
|
})();
|