aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/js
diff options
context:
space:
mode:
authorJörn Friedrich Dreyer <jfd@butonic.de>2014-12-18 10:26:41 +0100
committerJörn Friedrich Dreyer <jfd@butonic.de>2015-01-02 10:28:41 +0100
commit7e6c660b008d158de92a664b56359ed0750b82a8 (patch)
treee47dba072d47b84fc087c6d1aaec8f1664fc4c77 /apps/files/js
parentd063c8e0429b680c9998f91075b18297f55ae62d (diff)
downloadnextcloud-server-7e6c660b008d158de92a664b56359ed0750b82a8.tar.gz
nextcloud-server-7e6c660b008d158de92a664b56359ed0750b82a8.zip
filter new rows
Diffstat (limited to 'apps/files/js')
-rw-r--r--apps/files/js/filelist.js50
-rw-r--r--apps/files/js/search.js44
2 files changed, 77 insertions, 17 deletions
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js
index 08017e3fef1..88c81fb43af 100644
--- a/apps/files/js/filelist.js
+++ b/apps/files/js/filelist.js
@@ -112,6 +112,12 @@
_selectionSummary: null,
/**
+ * If not empty, only files containing this string will be shown
+ * @type String
+ */
+ _filter: '',
+
+ /**
* Sort attribute
* @type String
*/
@@ -551,6 +557,7 @@
_nextPage: function(animate) {
var index = this.$fileList.children().length,
count = this.pageSize(),
+ hidden,
tr,
fileData,
newTrs = [],
@@ -562,7 +569,12 @@
while (count > 0 && index < this.files.length) {
fileData = this.files[index];
- tr = this._renderRow(fileData, {updateSummary: false, silent: true});
+ if (this._filter) {
+ hidden = fileData.name.toLowerCase().indexOf(this._filter.toLowerCase()) === -1;
+ } else {
+ hidden = false;
+ }
+ tr = this._renderRow(fileData, {updateSummary: false, silent: true, hidden: hidden});
this.$fileList.append(tr);
if (isAllSelected || this._selectedFiles[fileData.id]) {
tr.addClass('selected');
@@ -1638,17 +1650,41 @@
});
});
},
+ /**
+ * @deprecated use setFilter(filter)
+ */
filter:function(query) {
+ this.setFilter('');
+ },
+ /**
+ * @deprecated use setFilter('')
+ */
+ unfilter:function() {
+ this.setFilter('');
+ },
+ /**
+ * hide files matching the given filter
+ * @param filter
+ */
+ setFilter:function(filter) {
+ this._filter = filter;
+ var that = this;
this.$fileList.find('tr').each(function(i,e) {
- if ($(e).data('file').toString().toLowerCase().indexOf(query.toLowerCase()) === -1) {
- $(e).hide();
+ var $e = $(e);
+ if ($e.data('file').toString().toLowerCase().indexOf(filter.toLowerCase()) === -1) {
+ $e.addClass('hidden');
+ that.$container.trigger('scroll');
+ } else {
+ $e.removeClass('hidden');
}
});
},
- unfilter:function() {
- this.$fileList.find('tr:hidden').each(function(i,e) {
- $(e).show();
- });
+ /**
+ * get the current filter
+ * @param filter
+ */
+ getFilter:function(filter) {
+ return this._filter;
},
/**
* Update UI based on the current selection
diff --git a/apps/files/js/search.js b/apps/files/js/search.js
index a2d3a261259..e6d71cf0f60 100644
--- a/apps/files/js/search.js
+++ b/apps/files/js/search.js
@@ -14,12 +14,10 @@
OCA.Files.Search = {
attach: function(search) {
search.setFilter('files', function (query) {
- if (query) {
- if (OCA.Files) {
- OCA.Files.App.fileList.filter(query);
- }
- } else {
- if (OCA.Files) {
+ if (OCA.Files.Search.fileAppLoaded()) {
+ if (query) {
+ OCA.Files.App.fileList.setFilter(query);
+ } else {
OCA.Files.App.fileList.unfilter();
}
}
@@ -34,6 +32,9 @@
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:
@@ -43,13 +44,17 @@
result.mime = result.mime_type;
}
- var $pathDiv = $('<div class="path"></div>').text(result.path)
+ 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:
@@ -64,7 +69,7 @@
$row.find('td.result a').attr('href', result.link);
- if (OCA.Files) {
+ if (OCA.Files.Search.fileAppLoaded()) {
OCA.Files.App.fileList.lazyLoadPreview({
path: result.path,
mime: result.mime,
@@ -84,20 +89,36 @@
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) {
+ if (OCA.Files.Search.fileAppLoaded()) {
OCA.Files.App.fileList.changeDirectory(result.path);
return false;
} else {
@@ -105,13 +126,16 @@
}
},
handleFileClick: function($row, result, event) {
- if (OCA.Files) {
+ 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;
}
};
})();