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 + ',' + agents[agent].internal + '>';
281 if (_.includes(teamAgents, agents[agent].id)) {
282 option.setAttribute('selected', '');
285 select.appendChild(option);
288 var div = document.getElementById('multi-select-team');
290 div.appendChild(select);
292 $(select).multiSelect({
293 selectableFooter: 'Agents available',
294 selectionFooter: 'Agents associated',
295 selectableHeader: "<input type='text' class='search-input form-control' autocomplete='off' placeholder='Search...'>",
296 selectionHeader: "<input type='text' class='search-input form-control' autocomplete='off' placeholder='Search...'>",
297 afterInit: function(ms) {
299 $selectableSearch = that.$selectableUl.prev(),
300 $selectionSearch = that.$selectionUl.prev(),
301 selectableSearchString = '#' + that.$container.attr('id') + ' .ms-elem-selectable:not(.ms-selected)',
302 selectionSearchString = '#' + that.$container.attr('id') + ' .ms-elem-selection.ms-selected';
304 that.qs1 = $selectableSearch.quicksearch(selectableSearchString)
305 .on('keydown', function(e) {
306 if (e.which === 40) {
307 that.$selectableUl.focus();
312 that.qs2 = $selectionSearch.quicksearch(selectionSearchString)
313 .on('keydown', function(e) {
315 that.$selectionUl.focus();
320 afterSelect: function(values) {
323 teams().select(values);
325 afterDeselect: function(values) {
328 teams().deselect(values);
333 var bindQueue = function(teams, queues, agents) {
334 var select = document.createElement('select');
335 select.className = 'multi-select';
336 select.setAttribute('multiple', 'multiple');
338 for (var team in teams) {
339 var optgroup = document.createElement('optgroup');
340 optgroup.label = teams[team].name;
342 for (var user in teams[team].Users) {
343 var option = document.createElement('option');
344 option.value = teams[team].Users[user].id;
345 option.text = teams[team].Users[user].fullname + ' <' + teams[team].Users[user].name + ',' + teams[team].Users[user].internal + '>';
346 if (_.includes(_.map(queues, 'id'), teams[team].Users[user].id)) {
347 option.setAttribute('selected', '');
348 var user = _.find(queues, {
349 id: teams[team].Users[user].id
351 option.text += user.hasOwnProperty('penalty') ? ' (' + user.penalty + ')' : '';
354 optgroup.appendChild(option);
356 select.appendChild(optgroup);
359 var div = document.getElementById('multi-select-team');
361 div.appendChild(select);
363 $(select).multiSelect({
364 selectableFooter: 'Agents available',
365 selectionFooter: 'Agents associated',
366 selectableOptgroup: true,
367 selectableHeader: "<input type='text' class='search-input form-control' autocomplete='off' placeholder='Search...'>",
368 selectionHeader: "<input type='text' class='search-input form-control' autocomplete='off' placeholder='Search...'>",
369 afterInit: function(ms) {
371 $selectableSearch = that.$selectableUl.prev(),
372 $selectionSearch = that.$selectionUl.prev(),
373 selectableSearchString = '#' + that.$container.attr('id') + ' .ms-elem-selectable:not(.ms-selected)',
374 selectionSearchString = '#' + that.$container.attr('id') + ' .ms-elem-selection.ms-selected';
376 that.qs1 = $selectableSearch.quicksearch(selectableSearchString)
377 .on('keydown', function(e) {
378 if (e.which === 40) {
379 that.$selectableUl.focus();
384 that.qs2 = $selectionSearch.quicksearch(selectionSearchString)
385 .on('keydown', function(e) {
387 that.$selectionUl.focus();
392 afterSelect: function(values) {
395 agents().select(values);
397 afterDeselect: function(values) {
400 agents().deselect(values);
406 //main function to initiate the module
409 handleSelect2Modal();
411 handleBootstrapSelect();
414 bindMailQueue: bindQueue,
415 bindChatQueue: bindQueue,
416 bindFaxQueue: bindQueue,