Total Complexity | 11 |
Complexity/F | 1.1 |
Lines of Code | 86 |
Function Count | 10 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | (function ( $ ) { |
||
2 | 'use strict'; |
||
3 | |||
4 | $.fn.extend({ |
||
5 | reportAutoComplete: function () |
||
6 | { |
||
7 | $(this).each(function(idx, el) { |
||
8 | var element = $(el); |
||
9 | var criteriaName = element |
||
10 | .data('criteria-name'); |
||
11 | var choiceName = element |
||
12 | .data('choice-name'); |
||
13 | var choiceValue = element |
||
14 | .data('choice-value'); |
||
15 | var autocompleteValue = element |
||
16 | .find('input.autocomplete') |
||
17 | .val(); |
||
18 | var loadForEditUrl = element |
||
19 | .data('load-edit-url'); |
||
20 | |||
21 | element |
||
22 | .dropdown({ |
||
23 | delay: { |
||
24 | search: 250 |
||
25 | }, |
||
26 | minCharacters: 3, |
||
27 | forceSelection: false, |
||
28 | apiSettings: { |
||
29 | dataType: 'JSON', |
||
30 | cache: false, |
||
31 | beforeSend: function beforeSend(settings) { |
||
32 | /* eslint-disable-next-line no-param-reassign */ |
||
33 | settings.data[criteriaName] = settings.urlData.query; |
||
34 | |||
35 | return settings; |
||
36 | }, |
||
37 | onResponse: function onResponse(response) { |
||
38 | return { |
||
39 | success: true, |
||
40 | results: response.map(function (item) { |
||
41 | return { |
||
42 | name: item[choiceName], |
||
43 | value: item[choiceValue] |
||
44 | }; |
||
45 | }) |
||
46 | }; |
||
47 | } |
||
48 | } |
||
49 | }); |
||
50 | |||
51 | if (autocompleteValue.split(',') |
||
52 | .filter(String).length > 0) { |
||
53 | var menuElement = element |
||
54 | .find('div.menu'); |
||
55 | |||
56 | menuElement.api({ |
||
57 | on: 'now', |
||
58 | method: 'GET', |
||
59 | url: loadForEditUrl, |
||
60 | beforeSend: function beforeSend(settings) { |
||
61 | /* eslint-disable-next-line no-param-reassign */ |
||
62 | settings.data[choiceValue] = autocompleteValue.split(',') |
||
63 | .filter(String); |
||
64 | |||
65 | return settings; |
||
66 | }, |
||
67 | onSuccess: function onSuccess(response) { |
||
68 | response.forEach(function (item) { |
||
69 | menuElement.append($('<div class="item" data-value="' + item[choiceValue] + '">' + item[choiceName] + '</div>')); |
||
70 | }); |
||
71 | } |
||
72 | }); |
||
73 | } |
||
74 | |||
75 | window.setTimeout(function () { |
||
76 | element |
||
77 | .dropdown('set selected', element |
||
78 | .find('input.autocomplete') |
||
79 | .val() |
||
80 | .split(',') |
||
81 | .filter(String)); |
||
82 | }, 5000); |
||
83 | }); |
||
84 | } |
||
85 | }); |
||
86 | })(jQuery); |
||
87 |