Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(block): add options to hide block #497

Merged
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
61 changes: 61 additions & 0 deletions ajax/container_display_condition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/**
* -------------------------------------------------------------------------
* Fields plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Fields.
*
* Fields is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Fields is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Fields. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2013-2022 by Fields plugin team.
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/pluginsGLPI/fields
* -------------------------------------------------------------------------
*/

include ("../../../inc/includes.php");

if (isset($_GET['action'])) {
if ($_GET['action'] === 'get_add_form') {
$status_override = new PluginFieldsContainerDisplayCondition();
$status_override->showForm(0, $_GET);
} else if ($_GET['action'] === 'get_edit_form') {
$status_override = new PluginFieldsContainerDisplayCondition();
$status_override->getFromDB($_GET['id']);
$status_override->showForm($_GET['id'], $_GET);
}

} else if (isset($_POST['action'])) {
if($_POST['action'] === 'get_itemtype_so') {
if(isset($_POST['itemtype']) && class_exists($_POST['itemtype'])) {
echo PluginFieldsContainerDisplayCondition::showItemtypeFieldForm($_POST['itemtype']) ;
} else {
echo "";
}
} else if($_POST['action'] === 'get_condition_switch_so') {
if(isset($_POST['search_option_id']) && (isset($_POST['itemtype']) && class_exists($_POST['itemtype']))) {
echo PluginFieldsContainerDisplayCondition::showSearchOptionCondition($_POST['search_option_id'], $_POST['itemtype']);
} else {
echo "";
}

}
} else {
http_response_code(400);
die();
}
49 changes: 49 additions & 0 deletions front/containerdisplaycondition.form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/**
* -------------------------------------------------------------------------
* Fields plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Fields.
*
* Fields is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Fields is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Fields. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2013-2022 by Fields plugin team.
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/pluginsGLPI/fields
* -------------------------------------------------------------------------
*/

include ("../../../inc/includes.php");

$status_override = new PluginFieldsContainerDisplayCondition();
if (isset($_POST["add"])) {
$status_override->check(-1, CREATE, $_POST);
$status_override->add($_POST);
Html::back();
} else if (isset($_POST["update"])) {
$status_override->check(-1, UPDATE);
$status_override->update($_POST);
Html::back();
} else if (isset($_POST["delete"])) {
$status_override->check($_POST['id'], PURGE);
$status_override->delete([
'id' => $_POST['id']
]);
Html::back();
}
Html::back();
6 changes: 4 additions & 2 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ function plugin_fields_install() {
'PluginFieldsValue',
'PluginFieldsProfile',
'PluginFieldsMigration',
'PluginFieldsStatusOverride'
'PluginFieldsStatusOverride',
'PluginFieldsContainerDisplayCondition',
];

$migration = new Migration($version);
Expand Down Expand Up @@ -131,7 +132,8 @@ function plugin_fields_uninstall() {
'PluginFieldsField',
'PluginFieldsValue',
'PluginFieldsProfile',
'PluginFieldsMigration'
'PluginFieldsMigration',
'PluginFieldsContainerDisplayCondition'
];

foreach ($classesToUninstall as $class) {
Expand Down
13 changes: 12 additions & 1 deletion inc/container.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ function defineTabs($options = []) {
$this->addStandardTab('PluginFieldsField', $ong, $options);
$this->addStandardTab('PluginFieldsStatusOverride', $ong, $options);
$this->addStandardTab('PluginFieldsProfile', $ong, $options);
$this->addStandardTab('PluginFieldsContainerDisplayCondition', $ong, $options);
$this->addStandardTab('PluginFieldsLabelTranslation', $ong, $options);

return $ong;
Expand Down Expand Up @@ -564,6 +565,12 @@ function pre_deleteItem() {
'plugin_fields_containers_id' => $this->fields['id']
]);

//delete display condition
$field_obj = new PluginFieldsContainerDisplayCondition();
$field_obj->deleteByCriteria([
'plugin_fields_containers_id' => $this->fields['id']
]);

//delete profiles
$profile_obj = new PluginFieldsProfile;
$profile_obj->deleteByCriteria([
Expand Down Expand Up @@ -1033,7 +1040,11 @@ function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
}

if (!$item->isEntityAssign() || in_array($item->fields['entities_id'], $entities)) {
$tabs_entries[$tab_name] = $tab_label;

$display_condition = new PluginFieldsContainerDisplayCondition();
if($display_condition->computeDisplayContainer($item, $data['id'])) {
$tabs_entries[$tab_name] = $tab_label;
}
}
}
}
Expand Down
Loading