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

[main] OC-23960 Repeat buttons in grid theme using icon instead of text #229

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
13 changes: 1 addition & 12 deletions packages/enketo-core/src/js/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down
25 changes: 19 additions & 6 deletions packages/enketo-core/src/js/repeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ import {
getChildren,
getSiblingElementsAndSelf,
} from './dom-utils';
import { isGrid } from './utils';
import { isStaticItemsetFromSecondaryInstance } from './itemset';
import { invalidateRepeatCaches } from './dom';

Expand Down Expand Up @@ -183,17 +184,29 @@ export default {
$repeatInfos
.filter('*:not([data-repeat-fixed]):not([data-repeat-count])')
.append(
`<button type="button" class="btn btn-default add-repeat-btn" data-i18n="repeat.addanother.btn">${t(
'repeat.addanother.btn'
)}</button>`
`<button type="button" class="btn btn-default add-repeat-btn" ${
isGrid() ? '' : 'data-i18n="repeat.addanother.btn"'
}>
${
isGrid()
? '<i class="icon icon-plus"> </i>'
: t('repeat.addanother.btn')
}
</button>`
)
.siblings('.or-repeat')
.append(
`<div class="repeat-buttons"><button type="button" ${
disableFirstRepeatRemoval ? ' disabled ' : ' '
}class="btn btn-default remove" data-i18n="repeat.remove.btn">${t(
'repeat.remove.btn'
)}</button></div>`
}class="btn btn-default remove" ${
isGrid() ? '' : 'data-i18n="repeat.remove.btn"'
}>
${
isGrid()
? '<i class="icon icon-minus"> </i>'
: t('repeat.remove.btn')
}
</button></div>`
);
/**
* The model also requires storing repeat templates for repeats that do not have a jr:template.
Expand Down
13 changes: 13 additions & 0 deletions packages/enketo-core/src/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,18 @@ function encodeHtmlEntities(text) {
.replace(/"/g, '&quot;');
}

/**
* 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,
Expand All @@ -272,4 +284,5 @@ export {
joinPath,
getScript,
encodeHtmlEntities,
isGrid,
};
Loading