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

enh(host templates): change host template dropdown to be select2 inst… #7208

Merged
merged 1 commit into from
Feb 25, 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
9 changes: 8 additions & 1 deletion www/class/centreonHost.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ public function __construct($db)
/**
* @param bool $enable
* @param bool $template
* @param null|int $exclude - host id to exclude in returned result
* @return array
* @throws Exception
*/
public function getList($enable = false, $template = false)
public function getList($enable = false, $template = false, $exclude = null)
{
$hostType = 1;
if ($template) {
Expand All @@ -93,9 +94,15 @@ public function getList($enable = false, $template = false)
if ($enable) {
$queryList .= 'AND host_activate = "1" ';
}
if ($exclude !== null) {
$queryList .= 'AND host_id <> :exclude_id ';
}
$queryList .= 'ORDER BY host_name';
$stmt = $this->db->prepare($queryList);
$stmt->bindParam(':register', $hostType, PDO::PARAM_STR);
if ($exclude !== null) {
$stmt->bindParam(':exclude_id', $exclude, PDO::PARAM_INT);
}
$dbResult = $stmt->execute();
if (!$dbResult) {
throw new \Exception("An error occured");
Expand Down
15 changes: 15 additions & 0 deletions www/include/configuration/configObject/host/formHost.ihtml
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,21 @@ jQuery(function() {
});

function setListener(elem){
elem.centreonSelect2({
multiple: false,
select2: {
allowClear: false,
placeholder: "{/literal}{$select_template}{literal}"
}
});
var id = elem.attr('id').replace('tpSelect_', '');
if (!isNaN(id) && typeof(jQuery("#clone-values-template").data('clone-values-template')[id]) != 'undefined') {
var selected = jQuery("#clone-values-template").data('clone-values-template')[id]['tpSelect_#index#'];
if (!isNaN(selected)) {
elem.val(selected).trigger('change');
}
}

elem.on('change',function(event,data){
if(typeof data != "undefined" && typeof data.origin !=undefined
&& data.origin == "select2defaultinit"){
Expand Down
4 changes: 3 additions & 1 deletion www/include/configuration/configObject/host/formHost.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,11 @@ function allInSameInstance($hosts, $instanceId)
$cloneSetTemplate[] = $form->addElement(
'select',
'tpSelect[#index#]',
_("Template"),
'',
(array(null => null) + $hostObj->getList(false, true)),
array(
"id" => "tpSelect_#index#",
"class" => "select2",
"type" => "select-one"
)
);
Expand Down Expand Up @@ -1250,6 +1251,7 @@ function myReplace()
$tpl->assign('custom_macro_label', _('Custom macros'));
$tpl->assign('template_inheritance', _('Template inheritance'));
$tpl->assign('command_inheritance', _('Command inheritance'));
$tpl->assign('select_template', _('Select a template'));
$tpl->assign('cloneSetMacro', $cloneSetMacro);
$tpl->assign('cloneSetTemplate', $cloneSetTemplate);
$tpl->assign('centreon_path', $centreon->optGen['oreon_path']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,19 +279,14 @@
$cloneSetTemplate[] = $form->addElement(
'select',
'tpSelect[#index#]',
_("Template"),
(array(null => null) + $hostObj->getList(false, true)),
'',
(array(null => null) + $hostObj->getList(false, true, $host_id)),
array(
"id" => "tpSelect_#index#",
"class" => "select2",
"type" => "select-one"
)
);
$cloneSetMacro[] = $form->addElement(
'hidden',
'macroFrom[#index#]',
'direct',
array('id' => 'macroFrom_#index#')
);

/*
* Check information
Expand Down Expand Up @@ -943,6 +938,7 @@ function myReplace()
$tpl->assign("History_Options", _("History Options"));
$tpl->assign("Event_Handler", _("Event Handler"));
$tpl->assign("add_mtp_label", _("Add a template"));
$tpl->assign('select_template', _('Select a template'));
$tpl->assign("seconds", _("seconds"));
$tpl->assign("tpl", 1);
$tpl->display("formHost.ihtml");
Expand Down