1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//! Server-side support for the popular
//! [Select2](https://select2.org/) jQuery plug-in. Select2 gives you a
//! customizable
//! [HTML \<select\> box](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select)
//! with support for searching, tagging, remote data sets, infinite scrolling,
//! and many other highly used options.
//!
//! **The documentation for Select2 server-side support is a bit wanting at
//! the moment. I will continue working on improving this.**
//!
//! Before you begin: implement the [`Selectable`] and/or [`Groupable`]
//! traits for your `struct`.
//!
//! [`Selectable`]: flat/trait.Selectable.html
//! [`Groupable`]: grouped/trait.Groupable.html
//!
//! What is the difference between `flat` response and `grouped` response? A
//! `grouped` response means that there is support for
//! [\<optgroup\>](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/optgroup)
//! in the response, while `flat` provides no `<optgroup>` support.
//!
//! Steps for processing a Select2 request:
//!
//! 1. Setup a route to your Select2 server in your Rust web framework. In your
//! route function, convert the query-string received from the Select2
//! plug-in into a [`Request`] struct. Your chosen web framework should
//! provide some facilities for processing a query-string into a `struct`.
//!
//! 2. Your search index must already be initialized. Search the index using the
//! [`search_select2`] method, supplying it with the `Request` struct you've
//! built from the query-string. This search function will return keys as the
//! search results.
//!
//! 3. If desired, filter (and further process) the search results.
//!
//! 4. Using the keys returned from the `search_select2` search, get the values
//! from your collection. This crate does not know how to look up values from
//! your collection, so you must get them.
//!
//! 5. Use either the [`flat_response`] or [`grouped_response`] method to
//! produce a response for the Select2 plug-in, providing:
//! * the `Request` struct _in step #1_,
//! * the keys from `search_select2` _in step #2_,
//! * and the values you got from your collection _in step #4_,
//!
//! [`flat_response`]: struct.Request.html#method.flat_response
//! [`grouped_response`]: struct.Request.html#method.grouped_response
//!
//! 6. Depending on whether flat or grouped output was selected, convert the
//! [`FlatResults`] or [`GroupedResults`] struct into `JSON` and return it to
//! the client.
//!
//! [`FlatResults`]: flat/struct.FlatResults.html
//! [`GroupedResults`]: grouped/struct.GroupedResults.html
// Directories:
// Methods & structs:
// -----------------------------------------------------------------------------
use ;
use ;
use Debug;
use Hash;
// -----------------------------------------------------------------------------
//
/// Select2 supports pagination ("infinite scrolling") for remote data sources
/// out of the box.
///
/// To use pagination, you must tell Select2 to add any necessary pagination
/// parameters to the request by overriding the `ajax.data` setting. The current
/// page to be retrieved is stored in the `params.page` property.
// Pagination
// -----------------------------------------------------------------------------
//
/// Select2 can render programmatically supplied data from an array or remote
/// data source (AJAX) as dropdown options. In order to accomplish this, Select2
/// expects a very specific data format. This format consists of a JSON object
/// containing an array of objects keyed by the `results` key.
///
/// Select2 requires that each object contain an `id` and a `text` property.
/// Additional parameters passed in with data objects will be included on the
/// data objects that Select2 exposes.
// Record
// -----------------------------------------------------------------------------
//
/// Your web application will receive a query-string from the Select2 plug-in
/// that need to be parsed into this `Request` struct.
///
/// Select2 will issue a request to the specified URL when the user opens the
/// control (unless there is a `minimumInputLength` set as a Select2 option),
/// and again every time the user types in the search box. By default, it will
/// send the following as query string parameters:
// Record
// -----------------------------------------------------------------------------
// impl
// -----------------------------------------------------------------------------
// impl