Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
fix(front): optimize select all in select2 component (#7926)
Browse files Browse the repository at this point in the history
Refs: MON-4197
  • Loading branch information
kduret authored Oct 22, 2019
1 parent eaf4fa5 commit f1a6dfa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
13 changes: 6 additions & 7 deletions www/include/common/javascript/centreon/centreon-select2.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,24 +519,23 @@
selectElements: function (elements) {
var self = this;
var item;
var option;
var selectedElements;

if (this.remoteData) {
/* Append new elements */
let options = '';
for (var i = 0; i < elements.length; i++) {
item = elements[i];

/* Create DOM option that is pre-selected by default */
option = '<option selected value="' + item.id + '"';
options += '<option selected value="' + item.id + '"';
if (item.hide === true) {
option += ' hidden';
options += ' hidden';
}
option += '>' + item.text + '</option>';

/* Append it to select */
self.$elem.append(option);
options += '>' + item.text + '</option>';
}
/* Append it to select */
self.$elem.append(options);
} else {
/* Select existing elements */
selectedElements = elements.map(function (object) {
Expand Down
20 changes: 10 additions & 10 deletions www/lib/HTML/QuickForm/select2.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,28 +477,28 @@ public function setDefaultAjaxDatas()
$ajaxDefaultDatas = '$request' . $this->getName() . ' = jQuery.ajax({
url: "' . $this->_defaultDatasetRoute . '",
});
$request' . $this->getName() . '.success(function (data) {
let options = "";
for (var d = 0; d < data.length; d++) {
var item = data[d];
// Create the DOM option that is pre-selected by default
var option = "<option selected=\"selected\" value=\"" + item.id + "\" ";
options += "<option selected=\"selected\" value=\"" + item.id + "\" ";
if (item.hide === true) {
option += "hidden";
options += "hidden";
}
option += ">" + item.text + "</option>";
// Append it to the select
$currentSelect2Object' . $this->getName() . '.append(option);
options += ">" + item.text + "</option>";
}
// Append it to the select
$currentSelect2Object' . $this->getName() . '.append(options);
// Update the selected options that are displayed
$currentSelect2Object' . $this->getName() . '.trigger("change",[{origin:\'select2defaultinit\'}]);
});
$request' . $this->getName() . '.error(function(data) {
});
';

Expand Down

0 comments on commit f1a6dfa

Please sign in to comment.