Skip to content

Commit

Permalink
Avoid multiple variable declarations in js code
Browse files Browse the repository at this point in the history
  • Loading branch information
nanego committed Oct 22, 2024
1 parent c0a4165 commit 82d88bd
Showing 1 changed file with 47 additions and 45 deletions.
92 changes: 47 additions & 45 deletions app/views/issues/_select_organizations.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,55 @@
</p>

<script>
let issue_organizations = [];
<% @issue.organizations.each do |organization| %>
issue_organizations.push({id: '<%= organization.id %>', text: '<%= organization.name_with_parents %>'});
<% end %>
$("#issue_organization_ids").select2({
containerCss: {width: '500px', minwidth: '500px'},
width: 'style',
data: issue_organizations,
minimumInputLength: 3,
language: {
inputTooShort: function () {
return "Entrez au moins 3 caractères";
(function () {
let issue_organizations = [];

<% @issue.organizations.each do |organization| %>
issue_organizations.push({id: '<%= organization.id %>', text: '<%= organization.name_with_parents %>'});
<% end %>
$("#issue_organization_ids").select2({
containerCss: {width: '500px', minwidth: '500px'},
width: 'style',
data: issue_organizations,
minimumInputLength: 3,
language: {
inputTooShort: function () {
return "Entrez au moins 3 caractères";
},
noResults: function () {
return "Aucune organisation ne correspond à cette recherche";
}
},
noResults: function () {
return "Aucune organisation ne correspond à cette recherche";
ajax: {
url: "/organizations/search.json?key=<%= User.current.api_key %>",
dataType: 'json',
delay: 250,
method: 'GET',
data: function (params) {
return {
organization: params.term
};
},
processResults: function (data, params) {
return {
results: data.organizations.map(function (org) {
return {
id: org.id,
text: org.name_with_parents
};
})
};
},
cache: true
}
},
ajax: {
url: "/organizations/search.json?key=<%= User.current.api_key %>",
dataType: 'json',
delay: 250,
method: 'GET',
data: function (params) {
return {
organization: params.term
};
},
processResults: function (data, params) {
return {
results: data.organizations.map(function (org) {
return {
id: org.id,
text: org.name_with_parents
};
})
};
},
cache: true
}
}).on('select2:open', function () {
// Forcer le focus dans la zone de texte interne de select2 lorsqu'il s'ouvre
let searchField = $(this).data('select2').dropdown.$search || $(this).data('select2').selection.$search;
if (searchField) {
searchField.focus();
}
});

}).on('select2:open', function () {
// Forcer le focus dans la zone de texte interne de select2 lorsqu'il s'ouvre
let searchField = $(this).data('select2').dropdown.$search || $(this).data('select2').selection.$search;
if (searchField) {
searchField.focus();
}
});
})();
</script>

<% end %>

0 comments on commit 82d88bd

Please sign in to comment.