Skip to content
Open
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
25 changes: 15 additions & 10 deletions ajax/subvisibility.php
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this file should be replaced by proper controllers + templates.
I've added it to the backlog so it can be done separately.

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();

if (!empty($_POST['type']) && isset($_POST['items_id']) && ($_POST['items_id'] > 0)) {
if (!empty($_POST['type'])) {
$prefix = '';
$suffix = '';
if (!empty($_POST['prefix'])) {
Expand All @@ -47,21 +47,26 @@
switch ($_POST['type']) {
case 'Group':
case 'Profile':
$params = ['value' => $_SESSION['glpiactive_entity'],
$rand = mt_rand();
$params = [
'value' => $_SESSION['glpiactive_entity'],
'name' => $prefix . 'entities_id' . $suffix,
'width' => '100%',
'rand' => $rand,
];
if (Session::canViewAllEntities()) {
$params['toadd'] = [-1 => __('No restriction')];
}
echo "<table class='tab_format'><tr><td>";
echo htmlescape(Entity::getTypeName(1));
echo "</td><td>";
echo '<div class="col-6">';
echo "<label class=\"form-label\" for=\"dropdown_entities_id$rand\">" . htmlescape(Entity::getTypeName(1)) . "</label>";
Entity::dropdown($params);
echo "</td><td>";
echo __s('Child entities');
echo "</td><td>";
Dropdown::showYesNo($prefix . 'is_recursive' . $suffix);
echo "</td></tr></table>";
echo "</div>";
echo "<div class=\"col-6\">";
echo "<label class=\"form-label\" for=\"dropdown_is_recursive$rand\">" . htmlescape(__('Child entities')) . "</label>";
Dropdown::showYesNo($prefix . 'is_recursive' . $suffix, 1, params: [
'rand' => $rand,
]);
echo "</div>";
break;
}
}
43 changes: 13 additions & 30 deletions ajax/visibility.php
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this file should be replaced by proper controllers + templates.
I've added it to the backlog so it can be done separately.

Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,26 @@
$_POST['prefix'] = '';
}

echo "<div class='d-flex'>";
switch ($_POST['type']) {
case 'User':
$params = [
'right' => isset($_POST['allusers']) ? 'all' : $_POST['right'],
'name' => $prefix . 'users_id' . $suffix,
'name' => $prefix . 'users_id' . $suffix,
'width' => '100%',
'aria_label' => User::getTypeName(1),
];
User::dropdown($params);
$display = true;
break;

case 'Group':
$params = ['rand' => $rand,
'name' => $prefix . 'groups_id' . $suffix,
];
$params['toupdate'] = ['value_fieldname'
=> 'value',
'to_update' => "subvisibility$rand",
'url' => $CFG_GLPI["root_doc"] . "/ajax/subvisibility.php",
'moreparams' => ['items_id' => '__VALUE__',
'type' => $_POST['type'],
'prefix' => $_POST['prefix'],
],
$params = [
'rand' => $rand,
'name' => $prefix . 'groups_id' . $suffix,
'width' => '100%',
'aria_label' => Group::getTypeName(1),
];
Comment on lines -73 to 81
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no related changes in other implementations of CommonDBVisible. Does the feature still works in Reminder and RSSFeed contexts ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I thought this feature was only used for the KB (I searched for usage and found nothing but now I clearly see that it is used elsewhere, weird).

I'll work on it, probably create some dedicated controllers and twig files for the KB then since the original was heavily modified.


Group::dropdown($params);
echo "<span id='subvisibility$rand'></span>";
$display = true;
break;

Expand All @@ -91,9 +84,9 @@
'name' => $prefix . 'entities_id' . $suffix,
'entity' => $_POST['entity'] ?? -1,
'entity_sons' => $_POST['is_recursive'] ?? false,
'width' => '100%',
'aria_label' => Entity::getTypeName(1),
]);
echo '<div class="ms-3">' . __s('Child entities') . '</div>';
Dropdown::showYesNo($prefix . 'is_recursive' . $suffix);
$display = true;
break;

Expand All @@ -104,26 +97,17 @@
$righttocheck = 'knowbase';
$checkright = KnowbaseItem::READFAQ;
}
$params = [
$params = [
'rand' => $rand,
'name' => $prefix . 'profiles_id' . $suffix,
'width' => '100%',
'condition' => [
'glpi_profilerights.name' => $righttocheck,
'glpi_profilerights.rights' => ['&', $checkright],
],
'aria_label' => Profile::getTypeName(1),
];
$params['toupdate'] = ['value_fieldname'
=> 'value',
'to_update' => "subvisibility$rand",
'url' => $CFG_GLPI["root_doc"] . "/ajax/subvisibility.php",
'moreparams' => ['items_id' => '__VALUE__',
'type' => $_POST['type'],
'prefix' => $_POST['prefix'],
],
];

Profile::dropdown($params);
echo "<span id='subvisibility$rand'></span>";
$display = true;
break;
}
Expand All @@ -132,5 +116,4 @@
echo "<input type='submit' name='addvisibility' value=\"" . _sx('button', 'Add') . "\"
class='btn btn-primary ms-3'>";
}
echo "</div>";
}
12 changes: 12 additions & 0 deletions css/includes/components/_kb.scss
Original file line number Diff line number Diff line change
Expand Up @@ -710,3 +710,15 @@
padding: 1rem 1.25rem;
border-top: 1px solid var(--tblr-border-color);
}

.visibility-type-col .select2-selection {
// Merge borders with dropdown to its right
border-start-end-radius: 0 !important;
border-end-end-radius: 0 !important;
}

.visibility-item-col .select2-selection {
// Merge borders with dropdown to its left
border-start-start-radius: 0 !important;
border-end-start-radius: 0 !important;
}
4 changes: 4 additions & 0 deletions css/includes/components/_utils.scss
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
font-size: 5em !important;
}

.flex-grow-30 {
flex-grow: 30;
}

.opacity-100-hover:hover {
opacity: 1 !important;
}
Expand Down
2 changes: 1 addition & 1 deletion js/glpi_dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ var glpi_html_dialog = function({
<div class="modal-dialog ${_.escape(dialogclass)}">
<div class="modal-content">
<div class="modal-header">
<h2 id="${_.escape(id)}_title" class="fs-4 modal-title" tabindex="-1">${title}</h2>
<h2 id="${_.escape(id)}_title" class="fs-4 modal-title d-flex align-items-center" tabindex="-1">${title}</h2>
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="${__("Close")}"></button>
</div>
Expand Down
25 changes: 19 additions & 6 deletions js/modules/Ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,36 @@
* Perform a POST request to a GLPI endpoint.
*
* @param {string} url - The relative URL path (without root_doc prefix).
* @param {Object | null} values - The data to send as JSON in the request body or null if the request doens't send any data.
* @param {Object | FormData | URLSearchParams | null} values - The data to send
* in the request body, or null if no data.
* Plain objects are serialized as JSON. FormData and URLSearchParams are sent
* as-is (form data).
* @returns {Promise<Response>} The fetch Response object.
* @throws {Error} If the request fails or returns a non-ok status.
*/
export async function post(url, values = null)
{
try {
const is_plain_object = values !== null
&& !(values instanceof FormData)
&& !(values instanceof URLSearchParams)
;

const headers = {
'X-Requested-With': 'XMLHttpRequest',
};

if (is_plain_object) {
headers['Content-Type'] = 'application/json';
}

const params = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest',
},
headers,
};

if (values !== null) {
params.body = JSON.stringify(values);
params.body = is_plain_object ? JSON.stringify(values) : values;
}

const response = await fetch(`${CFG_GLPI.root_doc}/${url}`, params);
Expand Down
5 changes: 3 additions & 2 deletions js/modules/Knowbase/ArticleController.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ export class GlpiKnowbaseArticleController
try {
this.#executeAction(e);
} catch (e) {
console.error(e);
glpi_toast_error(__("An unexpected error occurred."));
throw e;
}
});
}
Expand Down Expand Up @@ -468,7 +468,7 @@ export class GlpiKnowbaseArticleController
this.#deleteItem(params.id);
break;
case EditorActionType.OPEN_MODAL:
this.#openModal(params.id, params.key, params.title, params.icon);
this.#openModal(params.id, params.key, params.title, params.icon ?? null);
break;
}
}
Expand Down Expand Up @@ -546,6 +546,7 @@ export class GlpiKnowbaseArticleController
* @param {number} id
* @param {string} key
* @param {string} title
* @param {string | null} icon
*/
#openModal(id, key, title, icon = null)
{
Expand Down
Loading
Loading