Completed
Push — master ( dd0888...3b0b80 )
by Maxence
07:17
created

settings.setResultFooter   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
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
/** global: searchbar */
27
/** global: api */
28
29
var settings = {
30
31
	delay_provider: 300,
32
	delay_result: 150,
33
34
	// 0.6.0
35
	searchTimer: 1000,
36
	parent: null,
37
	searchProviderId: '',
38
	searchProviderName: '',
39
	resultContainer: null,
40
	resultHeader: null,
41
	resultFooter: null,
42
	entryTemplate: null,
43
	entryTemplateDefault: null,
44
	// divNoResult: null,
45
	options: [],
46
47
	/**
48
	 * generate the default template to dsplay search result entries
49
	 */
50
	generateDefaultTemplate: function () {
51
52
		var divLeft = $('<div>', {class: 'result_entry_left'});
53
		divLeft.append($('<div>', {id: 'title'}));
54
		divLeft.append($('<div>', {id: 'line1'}));
55
		divLeft.append($('<div>', {id: 'line2'}));
56
57
		var divRight = $('<div>', {class: 'result_entry_right'});
58
		//divRight.append($('<div>', {id: 'score'}));
59
60
		var div = $('<div>', {class: 'result_entry_default'});
61
		div.append(divLeft);
62
		div.append(divRight);
63
64
		return $('<div>').append(div);
65
	},
66
67
	//
68
	// /**
69
	//  * generate a no result display
70
	//  */
71
	// generateNoResultDiv: function () {
72
	// 	var div = $('<div>', {id: 'noresult'});
73
	// 	div.html('no result');
74
	// 	div.hide();
75
	// 	settings.divNoResult = div;
76
	// },
77
78
79
	/**
80
	 * @param template
81
	 */
82
	setResultHeader: function (template) {
83
		settings.resultHeader = template;
84
	},
85
86
	/**
87
	 * @param template
88
	 */
89
	setResultFooter: function (template) {
90
		settings.resultFooter = template;
91
	},
92
93
94
	/**
95
	 * used to set the template to display search result entries
96
	 *
97
	 * @param template
98
	 */
99
	setEntryTemplate: function (template) {
100
		settings.entryTemplate = template;
101
	},
102
103
104
	/**
105
	 * used to set the container for the search result entries
106
	 *
107
	 * @param container
108
	 */
109
	setResultContainer: function (container) {
110
		settings.resultContainer = container;
111
		// settings.resultContainer.prepend(settings.divNoResult);
112
	},
113
114
115
	/**
116
	 *  initialize the full text search and assign a providerId
117
	 *
118
	 * @param providerId
119
	 * @param providerName
120
	 * @param parent
121
	 */
122
	initFullTextSearch: function (providerId, providerName, parent) {
123
		settings.searchProviderId = providerId;
124
		settings.searchProviderName = providerName;
125
		settings.parent = parent;
126
		searchbox.init();
0 ignored issues
show
Bug introduced by
The variable searchbox seems to be never declared. If this is a global, consider adding a /** global: searchbox */ comment.

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.

Loading history...
127
	},
128
129
130
	/**
131
	 * check that the app that call the lib contains a specific method
132
	 *
133
	 * @param method
134
	 * @returns {boolean}
135
	 */
136
	parentHasMethod: function (method) {
137
		if (settings.parent === null) {
138
			return false;
139
		}
140
		return (typeof eval('settings.parent. ' + method) === "function");
0 ignored issues
show
Security Performance introduced by
Calls to eval are slow and potentially dangerous, especially on untrusted code. Please consider whether there is another way to achieve your goal.
Loading history...
Coding Style Security introduced by
The use of eval is generally not recommended.

The use of eval is discouraged because it can potentially make your code vulnerable to various injection attacks.

Besides it will also prevent certain optimizations that runtimes otherwise could make.

Loading history...
141
	}
142
};
143