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

Auth Twig UI (Part 1) #16951

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -62,6 +62,7 @@ The present file will list all changes made to the project; according to the
- External Links `Link or filename` and `File content` fields now use Twig templates instead of a custom tag syntax.
- Itemtypes associated with External links are now in the main form rather than a separate tab.
- The `Computer_Item` class has been replaced by the `\Glpi\Asset\Asset_PeripheralAsset` class.
- Testing LDAP replicates now shows results as toast notifications rather than inside the replicate tab after a page reload.

### Deprecated
- Survey URL tags `TICKETCATEGORY_ID` and `TICKETCATEGORY_NAME` are deprecated and replaced by `ITILCATEGORY_ID` and `ITILCATEGORY_NAME` respectively.
Expand All @@ -84,6 +85,7 @@ The present file will list all changes made to the project; according to the
#### Added
- `phpCAS` library is now bundled in GLPI, to prevent version compatibility issues.
- `Glpi\DBAL\QueryFunction` class with multiple static methods for building SQL query function strings in an abstract way.
- `fetchSessionMessages()` global JS function to display new session messages as toast notifications without requiring a page reload.

#### Changes
- Many methods have their signature changed to specify both their return type and the types of their parameters.
Expand Down Expand Up @@ -326,6 +328,7 @@ The present file will list all changes made to the project; according to the
- `$CFG_GLPI['debug_sql']` and `$CFG_GLPI['debug_vars']` configuration options.
- `DropdownTranslation::getTranslationByName()`
- `addgroup` and `deletegroup` actions in `front/user.form.php`.
- `test_ldap` and `test_ldap_replicate` actions in `front/authldap.form.php`. Use `ajax/ldap.php` instead.


## [10.0.15] unreleased
Expand Down
41 changes: 0 additions & 41 deletions front/authldap.form.php
Expand Up @@ -75,47 +75,6 @@
$config_ldap->delete($_POST, 1);
$_SESSION['glpi_authconfig'] = 1;
$config_ldap->redirectToList();
} else if (isset($_POST["test_ldap"])) {
$config_ldap->getFromDB($_POST["id"]);

if (AuthLDAP::testLDAPConnection($_POST["id"])) {
//TRANS: %s is the description of the test
$_SESSION["LDAP_TEST_MESSAGE"] = sprintf(
__('Test successful: %s'),
//TRANS: %s is the name of the LDAP main server
sprintf(__('Main server %s'), $config_ldap->fields["name"])
);
} else {
//TRANS: %s is the description of the test
$_SESSION["LDAP_TEST_MESSAGE"] = sprintf(
__('Test failed: %s'),
//TRANS: %s is the name of the LDAP main server
sprintf(__('Main server %s'), $config_ldap->fields["name"])
);
GLPINetwork::addErrorMessageAfterRedirect();
}
Html::back();
} else if (isset($_POST["test_ldap_replicate"])) {
$replicate = new AuthLdapReplicate();
$replicate->getFromDB($_POST["ldap_replicate_id"]);

if (AuthLDAP::testLDAPConnection($_POST["id"], $_POST["ldap_replicate_id"])) {
//TRANS: %s is the description of the test
$_SESSION["LDAP_TEST_MESSAGE"] = sprintf(
__('Test successful: %s'),
//TRANS: %s is the name of the LDAP replica server
sprintf(__('Replicate %s'), $replicate->fields["name"])
);
} else {
//TRANS: %s is the description of the test
$_SESSION["LDAP_TEST_MESSAGE"] = sprintf(
__('Test failed: %s'),
//TRANS: %s is the name of the LDAP replica server
sprintf(__('Replicate %s'), $replicate->fields["name"])
);
GLPINetwork::addErrorMessageAfterRedirect();
}
Html::back();
} else if (isset($_POST["add_replicate"])) {
$replicate = new AuthLdapReplicate();
unset($_POST["next"]);
Expand Down
33 changes: 31 additions & 2 deletions js/common.js
Expand Up @@ -35,6 +35,7 @@
/* global L */
/* global glpi_html_dialog */
/* global fuzzy */
/* global glpi_toast_info, glpi_toast_warning, glpi_toast_error */

var timeoutglobalvar;

Expand Down Expand Up @@ -1864,7 +1865,8 @@ function setupAjaxDropdown(config) {
return select2_el;
}

function setupAdaptDropdown(config) {
function setupAdaptDropdown(config)
{
// Field ID is used as a selector, so we need to escape special characters
// to avoid issues with jQuery.
const field_id = $.escapeSelector(config.field_id);
Expand Down Expand Up @@ -1960,7 +1962,9 @@ function setupAdaptDropdown(config) {
.bind('setValue', function (e, value) {
$('#$id').val(value).trigger('change');
});
$('label[for=' + field_id + ']').on('click', function () { $('#' + field_id).select2('open'); });
$('label[for=' + field_id + ']').on('click', function () {
$('#' + field_id).select2('open');
});
$('#' + field_id).on('select2:open', function () {
const search_input = document.querySelector(`.select2-search__field[aria-controls='select2-\${e.target.id}-results']`);
if (search_input) {
Expand All @@ -1970,3 +1974,28 @@ function setupAdaptDropdown(config) {

return select2_el;
}

function fetchSessionMessages() {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
function fetchSessionMessages() {
function displaySessionMessages() {

$.ajax({
method: 'GET',
url: (CFG_GLPI.root_doc + "/ajax/displayMessageAfterRedirect.php"),
data: {
'get_raw': true
}
}).done((messages) => {
$.each(messages, (level, level_messages) => {
$.each(level_messages, (index, message) => {
switch (parseInt(level)) {
case 1:
glpi_toast_error(message);
break;
case 2:
glpi_toast_warning(message);
break;
default:
glpi_toast_info(message);
}
});
});
});
}
23 changes: 1 addition & 22 deletions js/src/vue/Kanban/Column.vue
Expand Up @@ -149,28 +149,7 @@
closeItemForms();
showAddItemForm(itemtype, is_bulk);
}).always(() => {
$.ajax({
method: 'GET',
url: (CFG_GLPI.root_doc + "/ajax/displayMessageAfterRedirect.php"),
data: {
'get_raw': true
}
}).done((messages) => {
$.each(messages, (level, level_messages) => {
$.each(level_messages, (index, message) => {
switch (parseInt(level)) {
case 1:
glpi_toast_error(message);
break;
case 2:
glpi_toast_warning(message);
break;
default:
glpi_toast_info(message);
}
});
});
});
fetchSessionMessages();
});
}

Expand Down