1 var ComponentsDropdowns = function() {
3 var handleSelect2 = function() {
5 $('#select2_sample1').select2({
6 placeholder: "Select an option",
10 $('#select2_sample2').select2({
11 placeholder: "Select a State",
15 $("#select2_sample3").select2({
16 placeholder: "Select...",
18 minimumInputLength: 1,
19 query: function(query) {
24 for (i = 1; i < 5; i++) {
26 for (j = 0; j < i; j++) {
38 function format(state) {
39 if (!state.id) return state.text; // optgroup
40 return "<img class='flag' src='" + Metronic.getGlobalImgPath() +
41 "flags/" + state.id.toLowerCase() + ".png'/> " + state.text;
43 $("#select2_sample4").select2({
44 placeholder: "Select a Country",
47 formatSelection: format,
48 escapeMarkup: function(m) {
53 $("#select2_sample5").select2({
54 tags: ["red", "green", "blue", "yellow", "pink"]
58 function movieFormatResult(movie) {
59 var markup = "<table class='movie-result'><tr>";
60 if (movie.posters !== undefined && movie.posters.thumbnail !==
62 markup += "<td valign='top'><img src='" + movie.posters.thumbnail +
65 markup += "<td valign='top'><h5>" + movie.title + "</h5>";
66 if (movie.critics_consensus !== undefined) {
67 markup += "<div class='movie-synopsis'>" + movie.critics_consensus +
69 } else if (movie.synopsis !== undefined) {
70 markup += "<div class='movie-synopsis'>" + movie.synopsis +
73 markup += "</td></tr></table>"
77 function movieFormatSelection(movie) {
81 $("#select2_sample6").select2({
82 placeholder: "Search for a movie",
83 minimumInputLength: 1,
84 ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
85 url: "http://api.rottentomatoes.com/api/public/v1.0/movies.json",
87 data: function(term, page) {
89 q: term, // search term
91 apikey: "ju6z9mjyajq2djue3gbvv26t" // please do not use so this example keeps working
94 results: function(data, page) { // parse the results into the format expected by Select2.
95 // since we are using custom formatting functions we do not need to alter remote JSON data
101 initSelection: function(element, callback) {
102 // the input tag has a value attribute preloaded that points to a preselected movie's id
103 // this function resolves that id attribute to an object that select2 can render
104 // using its formatResult renderer - that way the movie name is shown preselected
105 var id = $(element).val();
108 "http://api.rottentomatoes.com/api/public/v1.0/movies/" +
111 apikey: "ju6z9mjyajq2djue3gbvv26t"
114 }).done(function(data) {
119 formatResult: movieFormatResult, // omitted for brevity, see the source of this page
120 formatSelection: movieFormatSelection, // omitted for brevity, see the source of this page
121 dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
122 escapeMarkup: function(m) {
124 } // we do not want to escape markup since we are displaying html in results
128 var handleSelect2Modal = function() {
130 $('#select2_sample_modal_1').select2({
131 placeholder: "Select an option",
135 $('#select2_sample_modal_2').select2({
136 placeholder: "Select a State",
140 $("#select2_sample_modal_3").select2({
142 minimumInputLength: 1,
143 query: function(query) {
148 for (i = 1; i < 5; i++) {
150 for (j = 0; j < i; j++) {
158 query.callback(data);
162 function format(state) {
163 if (!state.id) return state.text; // optgroup
164 return "<img class='flag' src='" + Metronic.getGlobalImgPath() +
165 "flags/" + state.id.toLowerCase() + ".png'/> " + state.text;
167 $("#select2_sample_modal_4").select2({
169 formatResult: format,
170 formatSelection: format,
171 escapeMarkup: function(m) {
176 $("#select2_sample_modal_5").select2({
177 tags: ["red", "green", "blue", "yellow", "pink"]
181 function movieFormatResult(movie) {
182 var markup = "<table class='movie-result'><tr>";
183 if (movie.posters !== undefined && movie.posters.thumbnail !==
185 markup += "<td valign='top'><img src='" + movie.posters.thumbnail +
188 markup += "<td valign='top'><h5>" + movie.title + "</h5>";
189 if (movie.critics_consensus !== undefined) {
190 markup += "<div class='movie-synopsis'>" + movie.critics_consensus +
192 } else if (movie.synopsis !== undefined) {
193 markup += "<div class='movie-synopsis'>" + movie.synopsis +
196 markup += "</td></tr></table>"
200 function movieFormatSelection(movie) {
204 $("#select2_sample_modal_6").select2({
205 placeholder: "Search for a movie",
206 minimumInputLength: 1,
207 ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
208 url: "http://api.rottentomatoes.com/api/public/v1.0/movies.json",
210 data: function(term, page) {
212 q: term, // search term
214 apikey: "ju6z9mjyajq2djue3gbvv26t" // please do not use so this example keeps working
217 results: function(data, page) { // parse the results into the format expected by Select2.
218 // since we are using custom formatting functions we do not need to alter remote JSON data
224 initSelection: function(element, callback) {
225 // the input tag has a value attribute preloaded that points to a preselected movie's id
226 // this function resolves that id attribute to an object that select2 can render
227 // using its formatResult renderer - that way the movie name is shown preselected
228 var id = $(element).val();
231 "http://api.rottentomatoes.com/api/public/v1.0/movies/" +
234 apikey: "ju6z9mjyajq2djue3gbvv26t"
237 }).done(function(data) {
242 formatResult: movieFormatResult, // omitted for brevity, see the source of this page
243 formatSelection: movieFormatSelection, // omitted for brevity, see the source of this page
244 dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
245 escapeMarkup: function(m) {
247 } // we do not want to escape markup since we are displaying html in results
251 var handleBootstrapSelect = function() {
252 $('.bs-select').selectpicker({
258 var handleMultiSelect = function() {
259 $('#my_multi_select1').multiSelect();
260 $('#my_multi_select2').multiSelect({
261 selectableOptgroup: true,
262 afterSelect: function(values) {
265 afterDeselect: function(values) {
271 var bindTeam = function(teamAgents, agents, teams) {
272 var select = document.createElement('select');
273 select.className = 'multi-select';
274 select.setAttribute('multiple', 'multiple');
276 for (var agent in agents) {
277 var option = document.createElement('option');
278 option.value = agents[agent].id;
279 option.text = agents[agent].fullname + ' <' + agents[agent].name +
280 ',' + agents[agent].internal + '>';
282 if (_.includes(teamAgents, agents[agent].id)) {
283 option.setAttribute('selected', '');
286 select.appendChild(option);
289 var div = document.getElementById('multi-select-team');
291 div.appendChild(select);
293 $(select).multiSelect({
294 selectableFooter: 'Agents available',
295 selectionFooter: 'Agents associated',
296 selectableHeader: "<input type='text' class='search-input form-control' autocomplete='off' placeholder='Search...'>",
297 selectionHeader: "<input type='text' class='search-input form-control' autocomplete='off' placeholder='Search...'>",
298 afterInit: function(ms) {
300 $selectableSearch = that.$selectableUl.prev(),
301 $selectionSearch = that.$selectionUl.prev(),
302 selectableSearchString = '#' + that.$container.attr('id') +
303 ' .ms-elem-selectable:not(.ms-selected)',
304 selectionSearchString = '#' + that.$container.attr('id') +
305 ' .ms-elem-selection.ms-selected';
307 that.qs1 = $selectableSearch.quicksearch(
308 selectableSearchString)
309 .on('keydown', function(e) {
310 if (e.which === 40) {
311 that.$selectableUl.focus();
316 that.qs2 = $selectionSearch.quicksearch(selectionSearchString)
317 .on('keydown', function(e) {
319 that.$selectionUl.focus();
324 afterSelect: function(values) {
327 teams().select(values);
329 afterDeselect: function(values) {
332 teams().deselect(values);
337 var bindQueue = function(teams, queues, agents) {
338 var select = document.createElement('select');
339 select.className = 'multi-select';
340 select.setAttribute('multiple', 'multiple');
342 for (var team in teams) {
343 var optgroup = document.createElement('optgroup');
344 optgroup.label = teams[team].name;
346 for (var user in teams[team].Users) {
347 var option = document.createElement('option');
348 option.value = teams[team].Users[user].id;
349 option.text = teams[team].Users[user].fullname + ' <' + teams[team]
350 .Users[user].name + ',' + teams[team].Users[user].internal + '>';
351 if (_.includes(_.map(queues, 'id'), teams[team].Users[user].id)) {
352 option.setAttribute('selected', '');
353 var user = _.find(queues, {
354 id: teams[team].Users[user].id
356 option.text += user.hasOwnProperty('penalty') ? ' (' + user.penalty +
360 optgroup.appendChild(option);
362 select.appendChild(optgroup);
365 var div = document.getElementById('multi-select-team');
367 div.appendChild(select);
369 $(select).multiSelect({
370 selectableFooter: 'Agents available',
371 selectionFooter: 'Agents associated',
372 selectableOptgroup: true,
373 selectableHeader: "<input type='text' class='search-input form-control' autocomplete='off' placeholder='Search...'>",
374 selectionHeader: "<input type='text' class='search-input form-control' autocomplete='off' placeholder='Search...'>",
375 afterInit: function(ms) {
377 $selectableSearch = that.$selectableUl.prev(),
378 $selectionSearch = that.$selectionUl.prev(),
379 selectableSearchString = '#' + that.$container.attr('id') +
380 ' .ms-elem-selectable:not(.ms-selected)',
381 selectionSearchString = '#' + that.$container.attr('id') +
382 ' .ms-elem-selection.ms-selected';
384 that.qs1 = $selectableSearch.quicksearch(
385 selectableSearchString)
386 .on('keydown', function(e) {
387 if (e.which === 40) {
388 that.$selectableUl.focus();
393 that.qs2 = $selectionSearch.quicksearch(selectionSearchString)
394 .on('keydown', function(e) {
396 that.$selectionUl.focus();
401 afterSelect: function(values) {
404 agents().select(values);
406 afterDeselect: function(values) {
409 agents().deselect(values);
414 var bindPermit = function(dataQueues, dataPermits, channel, userId,
416 var select = document.createElement('select');
417 select.className = 'multi-select';
418 select.setAttribute('multiple', 'multiple');
420 _.forEach(dataQueues, function(queues) {
421 var optgroup = document.createElement('optgroup');
422 optgroup.label = 'ALL';
424 queues.forEach(function(queue) {
425 var option = document.createElement('option');
429 _query.id = queue.id;
431 _query.name = queue.name;
434 option.value = queue.id || queue.name;
435 option.text = queue.name;
437 if (_.find(dataPermits.queues, _query)) {
438 option.setAttribute('selected', '');
441 optgroup.appendChild(option);
444 select.appendChild(optgroup);
447 var div = document.getElementById('multi-select-permit');
449 div.appendChild(select);
451 $(select).multiSelect({
452 selectableFooter: 'Queues available',
453 selectionFooter: 'Queues associated',
454 selectableOptgroup: true,
455 selectableHeader: "<input type='text' class='search-input form-control' autocomplete='off' placeholder='Search...'>",
456 selectionHeader: "<input type='text' class='search-input form-control' autocomplete='off' placeholder='Search...'>",
457 afterInit: function(ms) {
459 $selectableSearch = that.$selectableUl.prev(),
460 $selectionSearch = that.$selectionUl.prev(),
461 selectableSearchString = '#' + that.$container.attr('id') +
462 ' .ms-elem-selectable:not(.ms-selected)',
463 selectionSearchString = '#' + that.$container.attr('id') +
464 ' .ms-elem-selection.ms-selected';
466 that.qs1 = $selectableSearch.quicksearch(
467 selectableSearchString)
468 .on('keydown', function(e) {
469 if (e.which === 40) {
470 that.$selectableUl.focus();
475 that.qs2 = $selectionSearch.quicksearch(selectionSearchString)
476 .on('keydown', function(e) {
478 that.$selectionUl.focus();
483 afterSelect: function(values) {
489 controller: 'allowed',
490 controller2: channel,
491 controller3: 'queues'
494 .catch(function(err) {
498 afterDeselect: function(values) {
504 controller: 'allowed',
505 controller2: channel,
506 controller3: 'queues',
510 .catch(function(err) {
517 var bindAgent = function(dataQueues, dataAgent, channel, userId,
519 var select = document.createElement('select');
520 select.className = 'multi-select';
521 select.setAttribute('multiple', 'multiple');
523 _.forEach(dataQueues, function(queues) {
524 var optgroup = document.createElement('optgroup');
525 optgroup.label = 'ALL';
527 queues.forEach(function(queue) {
528 var option = document.createElement('option');
532 _query.id = queue.id;
534 _query.name = queue.name;
537 option.value = queue.id || queue.name;
538 option.text = queue.name;
540 if (_.find(dataAgent.queues, _query)) {
541 option.setAttribute('selected', '');
544 optgroup.appendChild(option);
547 select.appendChild(optgroup);
550 var div = document.getElementById('multi-select-queues');
552 div.appendChild(select);
554 $(select).multiSelect({
555 selectableFooter: 'Queues available',
556 selectionFooter: 'Queues associated',
557 selectableOptgroup: true,
558 selectableHeader: "<input type='text' class='search-input form-control' autocomplete='off' placeholder='Search...'>",
559 selectionHeader: "<input type='text' class='search-input form-control' autocomplete='off' placeholder='Search...'>",
560 afterInit: function(ms) {
562 $selectableSearch = that.$selectableUl.prev(),
563 $selectionSearch = that.$selectionUl.prev(),
564 selectableSearchString = '#' + that.$container.attr('id') +
565 ' .ms-elem-selectable:not(.ms-selected)',
566 selectionSearchString = '#' + that.$container.attr('id') +
567 ' .ms-elem-selection.ms-selected';
569 that.qs1 = $selectableSearch.quicksearch(
570 selectableSearchString)
571 .on('keydown', function(e) {
572 if (e.which === 40) {
573 that.$selectableUl.focus();
578 that.qs2 = $selectionSearch.quicksearch(selectionSearchString)
579 .on('keydown', function(e) {
581 that.$selectionUl.focus();
586 afterSelect: function(values) {
593 controller2: 'queues',
596 .catch(function(err) {
600 afterDeselect: function(values) {
607 controller2: 'queues',
611 .catch(function(err) {
619 //main function to initiate the module
622 handleSelect2Modal();
624 handleBootstrapSelect();
627 bindMailQueue: bindQueue,
628 bindChatQueue: bindQueue,
629 bindFaxQueue: bindQueue,
630 bindSmsQueue: bindQueue,
631 bindQueue: bindQueue,
632 bindPermit: bindPermit,