Use new search API when available

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2018-12-04 10:36:29 +01:00
parent 3b403d5576
commit 0296dc78f1

View File

@@ -4,20 +4,20 @@
* @author Julius Härtl <jus@bitgrid.net> * @author Julius Härtl <jus@bitgrid.net>
* *
* @license GNU AGPL version 3 or any later version * @license GNU AGPL version 3 or any later version
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the * published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
import app from '../app/App.js'; import app from '../app/App.js';
@@ -30,22 +30,32 @@ app.directive('search', function ($document, $location) {
'onSearch': '=' 'onSearch': '='
}, },
link: function (scope) { link: function (scope) {
var box = $('#searchbox'); if (OCA.Search && OCA.Search.Core) {
box.val($location.search().search); // eslint-disable-next-line no-unused-vars
const search = new OCA.Search((term) => {
var doSearch = function() { scope.$apply(function () {
var value = box.val(); scope.onSearch(term);
scope.$apply(function () { });
scope.onSearch(value); }, () => {
scope.$apply(function () {
scope.onSearch('');
});
}); });
}; } else {
const box = $('#searchbox');
box.val($location.search().search);
box.on('search keyup', function (event) { var doSearch = function () {
if (event.type === 'search' || event.keyCode === 13 ) { var value = box.val();
scope.$apply(function () {
scope.onSearch(value);
});
};
box.on('search keyup', function (event) {
doSearch(); doSearch();
} });
}); }
} }
}; };
}); });