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

fix(front): optimize select all in select2 component #7926

Merged
merged 2 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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