From eebc5e752b718048a8f844db39fb774b19beecb6 Mon Sep 17 00:00:00 2001 From: Agus Hilman Date: Fri, 20 Dec 2024 20:08:44 +0700 Subject: [PATCH] OC-23960 Repeat buttons in grid theme using icon instead of text --- packages/enketo-core/src/js/print.js | 13 +------------ packages/enketo-core/src/js/repeat.js | 25 +++++++++++++++++++------ packages/enketo-core/src/js/utils.js | 13 +++++++++++++ 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/packages/enketo-core/src/js/print.js b/packages/enketo-core/src/js/print.js index b4113cbf0..f662c169b 100644 --- a/packages/enketo-core/src/js/print.js +++ b/packages/enketo-core/src/js/print.js @@ -7,6 +7,7 @@ import $ from 'jquery'; import dialog from 'enketo/dialog'; import { MutationsTracker } from './dom-utils'; +import { isGrid } from './utils'; let dpi; let printStyleSheet; @@ -105,18 +106,6 @@ function styleReset() { $('.back-to-screen-view').off('click').remove(); } -/** - * Tests if the form element is set to use the Grid Theme. - * - * @static - * @return {boolean} whether the form definition was defined to use the Grid theme - */ -function isGrid() { - return /theme-.*grid.*/.test( - document.querySelector('form.or').getAttribute('class') - ); -} - /** * Fixes a Grid Theme layout programmatically by imitating CSS multi-line flexbox in JavaScript. * diff --git a/packages/enketo-core/src/js/repeat.js b/packages/enketo-core/src/js/repeat.js index 10766ad84..25f6be836 100644 --- a/packages/enketo-core/src/js/repeat.js +++ b/packages/enketo-core/src/js/repeat.js @@ -112,6 +112,7 @@ import { getChildren, getSiblingElementsAndSelf, } from './dom-utils'; +import { isGrid } from './utils'; import { isStaticItemsetFromSecondaryInstance } from './itemset'; import { invalidateRepeatCaches } from './dom'; @@ -183,17 +184,29 @@ export default { $repeatInfos .filter('*:not([data-repeat-fixed]):not([data-repeat-count])') .append( - `` + `` ) .siblings('.or-repeat') .append( `
` + }class="btn btn-default remove" ${ + isGrid() ? '' : 'data-i18n="repeat.remove.btn"' + }> + ${ + isGrid() + ? ' ' + : t('repeat.remove.btn') + } + ` ); /** * The model also requires storing repeat templates for repeats that do not have a jr:template. diff --git a/packages/enketo-core/src/js/utils.js b/packages/enketo-core/src/js/utils.js index d11bca568..5c3ee27a9 100644 --- a/packages/enketo-core/src/js/utils.js +++ b/packages/enketo-core/src/js/utils.js @@ -260,6 +260,18 @@ function encodeHtmlEntities(text) { .replace(/"/g, '"'); } +/** + * Tests if the form element is set to use the Grid Theme. + * + * @static + * @return {boolean} whether the form definition was defined to use the Grid theme + */ +function isGrid() { + return /theme-.*grid.*/.test( + document.querySelector('form.or').getAttribute('class') + ); +} + export { parseFunctionFromExpression, stripQuotes, @@ -272,4 +284,5 @@ export { joinPath, getScript, encodeHtmlEntities, + isGrid, };