1
|
|
|
/* |
2
|
|
|
* FullTextSearch - Full text search framework for Nextcloud |
3
|
|
|
* |
4
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
5
|
|
|
* later. See the COPYING file. |
6
|
|
|
* |
7
|
|
|
* @author Maxence Lange <[email protected]> |
8
|
|
|
* @copyright 2018 |
9
|
|
|
* @license GNU AGPL version 3 or any later version |
10
|
|
|
* |
11
|
|
|
* This program is free software: you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU Affero General Public License as |
13
|
|
|
* published by the Free Software Foundation, either version 3 of the |
14
|
|
|
* License, or (at your option) any later version. |
15
|
|
|
* |
16
|
|
|
* This program is distributed in the hope that it will be useful, |
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19
|
|
|
* GNU Affero General Public License for more details. |
20
|
|
|
* |
21
|
|
|
* You should have received a copy of the GNU Affero General Public License |
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
23
|
|
|
* |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** global: OC */ |
28
|
|
|
/** global: settings */ |
29
|
|
|
/** global: result */ |
30
|
|
|
/** global: search */ |
31
|
|
|
/** global: nav */ |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
var api = { |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
search: function (request, callback, callbackError) { |
38
|
|
|
var res = {status: -1, error: 'failed to connect to Nextcloud'}; |
39
|
|
|
|
40
|
|
|
nav.onSearchRequest(request); |
41
|
|
|
|
42
|
|
|
$.ajax({ |
43
|
|
|
method: 'GET', |
44
|
|
|
url: OC.generateUrl('/apps/fulltextsearch/v1/search'), |
45
|
|
|
data: { |
46
|
|
|
request: JSON.stringify(request) |
47
|
|
|
} |
48
|
|
|
}).done(function (res) { |
49
|
|
|
if (_.has(res, 'error')) { |
|
|
|
|
50
|
|
|
result.displayError(res); |
51
|
|
|
nav.onError(res.error); |
52
|
|
|
api.onCallback(callbackError, res); |
53
|
|
|
return; |
54
|
|
|
} |
55
|
|
|
result.displayResult(res); |
56
|
|
|
nav.onResultDisplayed(res); |
57
|
|
|
api.onCallback(callback, res); |
58
|
|
|
}).fail(function () { |
59
|
|
|
nav.failedToAjax(res); |
60
|
|
|
nav.onError(res.error); |
61
|
|
|
api.onCallback(callbackError, res); |
62
|
|
|
}); |
63
|
|
|
}, |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
retrieveOptions: function (providerId, callback) { |
67
|
|
|
var res = {status: -1}; |
68
|
|
|
|
69
|
|
|
$.ajax({ |
70
|
|
|
method: 'GET', |
71
|
|
|
url: OC.generateUrl('/apps/fulltextsearch/options/' + providerId) |
72
|
|
|
}).done(function (res) { |
73
|
|
|
searchbox.onOptionsLoaded(res); |
|
|
|
|
74
|
|
|
api.onCallback(callback, res); |
75
|
|
|
}).fail(function () { |
76
|
|
|
nav.failedToAjax(); |
77
|
|
|
api.onCallback(callback, res); |
78
|
|
|
}); |
79
|
|
|
}, |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
onCallback: function (callback, result) { |
83
|
|
|
if (callback && (typeof callback === 'function')) { |
84
|
|
|
if (typeof result === 'object') { |
85
|
|
|
callback(result); |
86
|
|
|
} else { |
87
|
|
|
callback({status: -1}); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
}; |
93
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.