forked from SolDevelo/frontlinesms-multiselector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
327 lines (313 loc) · 15.4 KB
/
index.html
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>The Multiselector demo</title>
<script src="lib/qunit-1.14.0.js"></script>
<script src="lib/jquery-1.10.0.min.js"></script>
<script src="lib/bootstrap.min.js"></script>
<script src="lib/bootstrap-tokenfield.min.js"></script>
<script src="lib/contact_service-master/ContactService.js"></script>
<script src="lib/contact_service-10k/ContactService.js"></script>
<script src="lib/contact_service-sportsTeams/ContactService.js"></script>
<script src="lib/sprintf.min.js"></script>
<script src="js/multiselector.js"></script>
<script src="js/demo.js"></script>
<script src="js/prettify.js"></script>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap-tokenfield.min.css">
<link rel="stylesheet" type="text/css" href="css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="css/multiselector.css">
<link rel="stylesheet" type="text/css" href="css/qunit-1.14.0.css">
<link rel="stylesheet" type="text/css" href="css/demo.css">
<link rel="stylesheet" type="text/css" href="css/prettify.css" />
</head>
<body onload="prettyPrint()">
<div class="content">
<div class='row'>
<div class='col-md-8'>
<h1>The Multiselector</h1>
<p class="lead">is a flexible selector that can allow a user to view, search and select multiple object types</p>
<p><a href="https://github.com/SolDevelo/frontlinesms-multiselector" class="btn btn-info">View source on Github</a></p>
</div>
<div class='col-md-4'>
<img class="pull-right" src="http://frontlinesms.github.io/images/devlogo.png">
</div>
</div>
<div class='row'>
<div class='col-md-12'>
<p>Multiselector is an open source project developed by <a href="http://www.soldevelo.com/">Soldevelo</a> and <a href="http://www.frontlinesms.com/">FrontlineSMS</a>, supported by <a href="http://www.socialcoding4good.org/lending-skills-sol-develos-story">SocialCoding4Good</a>. It is used in <a href="http://www.frontlinesms.com/technologies/download/">FrontlineSMS</a> and <a href="https://cloud.frontlinesms.com/login/auth">FrontlineCloud</a> to select recipients for messages and contact fields for automations.</p>
</div>
</div>
<div class="panel panel-default">
<header class="panel-heading h4 m-t"><strong class="text-info">Used a The Contact Selector</strong></header>
<div class="panel-body">
The Contact selector showing contacts, groups and smart groups.
<div class="container">
<div class="row">
<div id="containerMaster" class="dropdown container-master"></div>
</div>
</div>
If you want use MultiSelector, you must run the <code>multiselect</code> function when your document
is ready. One way to do this is:
<pre class="prettyprint">
$(document).ready(function() {
$("div#containerMaster").multiselect(options, translations, null, contactServiceMaster, "1");
};
</pre>
The parameters <code>multiselect</code> function are described below.
</div>
</div>
<hr>
<div class="panel panel-default">
<header class="panel-heading h4 m-t"><strong class="text-info">Another example: Sports teams in London</strong></header>
<div class="panel-body">
A simple lookup from a database of sports teams in London.
<div class="container">
<div class="row">
<div id="containerSports" class="dropdown container-sports"></div>
</div>
</div>
</div>
</div>
<hr>
<div class="panel panel-default">
<header class="panel-heading h4 m-t"><strong class="text-info">Pre-selected and non-editable items</strong></header>
<div class="panel-body">
A more complex initialisation with pre-selected and non-editable items.
<div class="container">
<div class="row">
<div id="containerPreloaded" class="dropdown container-preload"></div>
</div>
</div>
You can specify items, which should be selected after creating the MultiSelector. To do this, you
need to create an array of items and indicate it as the third parameter the <code>multiselect</code>
function.
<pre class="prettyprint">
var preloadedIDs = ["contact-6", "contact-10", "110", "+48987654321", "smartgroup-2"];
var msPreloaded = $("div#containerPreloaded").multiselect(options, translations, preloadedIDs, contactServiceMaster, "2");
</pre>
You can also add items after the creation of MultiSelector.
<pre class="prettyprint">
msPreloaded.addObject("123456", true);
msPreloaded.addObject("777888999", false);
msPreloaded.addObject("contact-1", true);
</pre>
If the second parameter is <code>true</code>, the item is non-editable.
</div>
</div>
<hr>
<div class="panel panel-default">
<header class="panel-heading h4 m-t"><strong class="text-info">MultiSelector options</strong></header>
<div class="panel-body">
You can set few options to be indicated as first parameter the <code>multiselect</code> function.
<ul>
<li class="h4"><strong>displayLimit</strong></li>
The property specifies the number of elements in each category, which will be displayed when entering text in input.
<pre class="prettyprint">
var options = {
"displayLimit": {
"contacts": 4,
"groups": 1,
"smartgroups": 1
},
</pre>
<li class="h4"><strong>icons</strong></li>
You can set the icon, that appears next to the category.
<pre class="prettyprint">
"icons": {
"contacts": "fa fa-user",
"groups": "fa fa-group",
"smartgroups": "fa fa-cog",
"phone-number": "fa fa-mobile-phone"
},
</pre>
<li class="h4"><strong>language</strong></li>
This property allows you to select the language of the translation (see below).
<pre class="prettyprint">
"language": "en_US",
</pre>
<li class="h4"><strong>minResultsHeight</strong></li>
<pre class="prettyprint">
"minResultsHeight": 100,
</pre>
<li class="h4"><strong>contactLoading</strong></li>
You can set size and time (in milliseconds) between loading a batch of contacts.
<pre class="prettyprint">
"contactLoading": {
"intervalMs": 5,
"batchSize": 10
},
</pre>
<li class="h4"><strong>objectAdded</strong></li>
Function which will be called when you select new element from list (see next example).
<pre class="prettyprint">
objectAdded: function(objectId) {
$("#lastAddedId").text("Last added id: " + objectId);
return objectId;
},
</pre>
<li class="h4"><strong>objectRemoved</strong></li>
Function which will be called when you remove element, which was selected earlier (see next example).
<pre class="prettyprint">
objectRemoved: function(objectId) {
$("#lastRemovedId").text("Last removed id: " + objectId);
return objectId;
}
};
</pre>
</ul>
</div>
</div>
<hr>
<div class="panel panel-default">
<header class="panel-heading h4 m-t"><strong class="text-info">MultiSelector translations</strong></header>
<div class="panel-body">
You can easily customize selector to your, or several languages. Just create a variable that is
similar to the one below and choose the appropriate language in the options.
<pre class="prettyprint">
var translations = {
"en_US": {
"common.item.limit.label": "Showing %s out of %s matches",
"common.item.selected": "Selected",
"common.item.show.all": "Show all contacts",
"common.item.show.all.button": "Show all",
"common.item.select.selected": "This item is already selected.",
"common.group.select.disabled": "This group is disabled and you can not select it.",
"common.item.add.number": "Add this phone number",
"common.progressbar.label": "Loading, please wait..."
},
"pl": {
"common.item.limit.label": "Pokazano %s z %s dopasowań",
"common.item.selected": "Wybrano",
"common.item.show.all": "Pokaż wszystkie kontakty",
"common.item.show.all.button": "Pokaż wszystko",
"common.item.select.selected": "Ta pozycja jest już wybrana,",
"common.group.select.disabled": "Ta grupa jest nieaktywna, nie możesz jej wybrać.",
"common.item.add.number": "Dodaj ten numer telefonu",
"common.progressbar.label": "Ładowanie, proszę czekać..."
}
};
</pre>
</div>
</div>
<hr>
<div class="panel panel-default">
<header class="panel-heading h4 m-t"><strong class="text-info">Properties objectAdded and objectRemoved</strong></header>
<div class="panel-body">
Example of use objectAdded and objectRemoved properties. Select and remove some items.
<div class="container">
<div class="row">
<div id="containerAddedAndRemoved" class="dropdown container-bigger"></div>
</div>
<div id="lastAddedId"></div>
<div id="lastRemovedId"></div>
</div>
</div>
</div>
<hr>
<div class="panel panel-default">
<header class="panel-heading h4 m-t"><strong class="text-info">Contact service</strong></header>
<div class="panel-body">
You can assume a <code>contactService</code> variable will be available in the global scope,
initialised before your function. It should specify the types of objects and 'database' for example:
<pre class="prettyprint">
var types = {
"contacts": {
"name":"contacts",
"displayName" : "Contacts",
"customCssClass": "contacts"
},
"groups": {
"name":"groups",
"displayName" : "Groups",
"customCssClass": "groups"
},
"smartgroups": {
"name":"smartgroups",
"displayName" : "Smart Groups",
"customCssClass": "smartgroups"
}
}, fullContactDatabase = {
"contacts" : [
{
"name" : "Alicia",
"id" : "contact-1",
"metadata" : "+447943419787"
},
... ... ...
{
"name" : "Sturridge Mwakule",
"id" : "contact-16",
"metadata" : "I play for Cheldam"
}
],
"groups" : [
{
"name" : "Support Staff",
"id" : "group-1",
"metadata" : "4 members",
"memberCount" : 4
},
... ... ...
{
"name" : "Android Owners",
"id" : "group-3",
"metadata" : "9 members",
"memberCount" : 9
}
],
"smartgroups" : [
{
"name" : "Heores",
"id" : "smartgroup-1",
"metadata" : "9 members",
"memberCount" : 9
},
... ... ...
{
"name" : "Villains",
"id" : "smartgroup-2",
"metadata" : "12 members",
"memberCount" : 12
}
]
};
</pre>
Each type has:
<ul>
<li><strong>name</strong> - which is used in code</li>
<li><strong>displayName</strong> - which is displayed to the user as the heading when listing entries of this grouping</li>
<li><strong>customCssClass</strong> - which should be given as a css class for each of the members when displaying them</li>
</ul>
A <i>object</i> in the 'database' has:
<ul>
<li><strong>name</strong> - which is displayed to the user</li>
<li><strong>id</strong> - which is a unique identifier of this object, and will form part of the 'getSelectedObjects' response in the javascript library</li>
<li><strong>metaData</strong> - which is user-facing information that should be displayed next to the name in the dropdown</li>
</ul>
<code>contactService</code> variable should contains the following methods:
<ul>
<li><strong>getAll()</strong> - returns all objects</li>
<li><strong>getTypes()</strong> - returns all types of objects</li>
<li><strong>getObjectCount(objectType)</strong> - returns the number of items type 'objectType'</li>
<li><strong>getFilteredMatches(selectedIds, searchString)</strong> - returns all objects that match the 'searchString', but excludes any in the 'selectedIds' list</li>
</ul>
</div>
</div>
<hr>
<div class="panel panel-default">
<header class="panel-heading h4 m-t"><strong class="text-info">Large number of items</strong></header>
<div class="panel-body">
MultiSelector with a 10 thousands items.
<div class="container">
<div class="row">
<div id="containerBigger" class="dropdown container-bigger"></div>
</div>
</div>
</div>
</div>
<hr>
</div>
</body>
</html>