Skip to content

Commit 7ed139f

Browse files
authored
Fix default notification translation selection
1 parent 943bafc commit 7ed139f

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

js/common.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,8 +1868,7 @@ function setupAdaptDropdown(config)
18681868
// to avoid issues with jQuery.
18691869
const field_id = $.escapeSelector(config.field_id);
18701870

1871-
const select2_el = $('#' + field_id).select2({
1872-
placeholder: config.placeholder,
1871+
const options = {
18731872
width: config.width,
18741873
dropdownAutoWidth: true,
18751874
dropdownCssClass: config.dropdown_css_class,
@@ -1956,10 +1955,15 @@ function setupAdaptDropdown(config)
19561955
},
19571956
templateResult: config.templateresult,
19581957
templateSelection: config.templateselection,
1959-
})
1960-
.bind('setValue', function (e, value) {
1961-
$('#' + field_id).val(value).trigger('change');
1962-
});
1958+
};
1959+
if (config.placeholder !== undefined && config.placeholder !== '') {
1960+
options.placeholder = config.placeholder;
1961+
}
1962+
const select2_el = $('#' + field_id).select2(options);
1963+
1964+
select2_el.bind('setValue', (e, value) => {
1965+
$('#' + field_id).val(value).trigger('change');
1966+
});
19631967
$('label[for=' + field_id + ']').on('click', function () {
19641968
$('#' + field_id).select2('open');
19651969
});

src/NotificationTemplateTranslation.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,16 @@ public function showForm($ID, array $options = [])
104104
$template = new NotificationTemplate();
105105
$template->getFromDB($notificationtemplates_id);
106106

107+
$used_languages = self::getAllUsedLanguages($notificationtemplates_id);
108+
// Remove current language
109+
if (!$this->isNewItem()) {
110+
$used_languages = array_diff($used_languages, [$this->getField('language')]);
111+
}
112+
107113
TemplateRenderer::getInstance()->display('pages/setup/notification/translation.html.twig', [
108114
'item' => $this,
109115
'template' => $template,
110-
'used_languages' => self::getAllUsedLanguages($notificationtemplates_id),
116+
'used_languages' => $used_languages,
111117
]);
112118
return true;
113119
}

src/Notification_NotificationTemplate.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ public static function showForNotification(Notification $notif, $withtemplate =
140140
// language=Twig
141141
echo TemplateRenderer::getInstance()->renderFromStringTemplate(<<<TWIG
142142
<div class="text-center mb-3">
143-
<a class="btn btn-primary" href="{{ 'Notification_NotificationTemplate'|itemtype_form_path }}?notifications_id={{ id }}&withtemplate={{ withtemplate}}">
143+
<a class="btn btn-primary" role="button"
144+
href="{{ 'Notification_NotificationTemplate'|itemtype_form_path }}?notifications_id={{ id }}&withtemplate={{ withtemplate}}">
144145
{{ add_msg }}
145146
</a>
146147
</div>

tests/cypress/e2e/notifications.cy.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,26 @@ describe('Notifications', () => {
6969
});
7070
});
7171

72-
cy.get('.tab-content .tab-pane.active[id^="tab"] .btn').contains('Add a template').click();
72+
cy.findByRole('tabpanel').within(() => {
73+
cy.findByRole('button', { name: /Add a template/ }).click();
74+
});
75+
7376
// Should be redirected to notification_notificationtemplate form
7477
cy.url().should('include', '/front/notification_notificationtemplate.form.php').and('include', 'notifications_id=2');
7578
cy.get('label').contains('Notification').next().find('a').invoke('attr', 'href').should('contain', '/front/notification.form.php?id=2');
7679

7780
// Go back to the notification form
7881
cy.go('back');
79-
cy.get('#tabspanel .nav-item').contains('Templates').click();
80-
// Click the first template link
81-
cy.get('table.table tbody td:nth-of-type(2) a').first().click();
82-
cy.url().should('include', '/front/notification_notificationtemplate.form.php').and('not.include', 'notifications_id=2');
83-
cy.get('label').contains('Notification').next().find('a').invoke('attr', 'href').should('contain', '/front/notification.form.php?id=2');
82+
cy.findByRole('tab', { name: /Templates/ }).click();
83+
84+
cy.findByRole('table').findByRole('link', {name: "Tickets"}).click();
85+
cy.findByRole('tab', { name: /Template translations/ }).click();
86+
// Click the default template translation link
87+
cy.findByRole('link', {name: "Default translation"}).click();
88+
cy.findByRole('tab', { name: /Template translation/ }).click();
89+
cy.findByRole('tabpanel').within(() => {
90+
cy.get('select[name=language]').should('have.value', '');
91+
cy.get('select[name=language] option:selected').should('have.text', 'Default translation');
92+
});
8493
});
8594
});

0 commit comments

Comments
 (0)