diff --git a/app/components/forms/orders/attendee-list.js b/app/components/forms/orders/attendee-list.js index 89111ef698d..0c6377fe448 100644 --- a/app/components/forms/orders/attendee-list.js +++ b/app/components/forms/orders/attendee-list.js @@ -84,23 +84,6 @@ export default class AttendeeList extends Component { return groupBy(customFields, field => field.get('form')); } - prepareFieldId(fieldIdentifier, holderIndex, fieldIndex) { - return `${fieldIdentifier}_${holderIndex}_${fieldIndex}`; - } - - get fieldNameConvertRichText() { - const fields = orderBy(this.fields.toArray(), 'position'); - this.holders.forEach((holder, indexHolder) => { - fields.forEach((field, index) => { - const elem = document.getElementById(this.prepareFieldId(field.fieldIdentifier, indexHolder, index)); - if (elem) { - elem.innerHTML = field.transName; - } - }); - }); - return null; - } - @action toggleEditFields() { this.editFields = !this.editFields; diff --git a/app/components/forms/orders/order-form.js b/app/components/forms/orders/order-form.js index f5d4cd64a01..b05766eeef4 100644 --- a/app/components/forms/orders/order-form.js +++ b/app/components/forms/orders/order-form.js @@ -630,7 +630,9 @@ export default Component.extend(FormMixin, { if ((main_language && main_language.split('-')[0] === current_locale) || !field.translations || !field.translations.length) { field.transName = field.name; } else if (field.translations?.length) { + const transName = field.translations.filter(trans => trans.language_code.split('-')[0] === current_locale); + if (transName.length) { field.transName = transName[0].name; } else { @@ -639,6 +641,7 @@ export default Component.extend(FormMixin, { } else { field.transName = field.name; } + return !isFixed; }), ['position']); return groupBy(requiredFixed.concat(customFields), field => field.get('form')); @@ -661,23 +664,6 @@ export default Component.extend(FormMixin, { return 'hello'; }, - prepareFieldId(fieldIdentifier, holderIndex, fieldIndex) { - return `${fieldIdentifier}_${holderIndex}_${fieldIndex}`; - }, - - get fieldNameConvertRichText() { - const fields = orderBy(this.fields.toArray(), 'position'); - this.holders.forEach((holder, indexHolder) => { - fields.forEach((field, index) => { - const elem = document.getElementById(this.prepareFieldId(field.fieldIdentifier, indexHolder, index)); - if (elem) { - elem.innerHTML = field.transName; - } - }); - }); - return null; - }, - actions: { submit(data) { this.onValid(() => { diff --git a/app/components/forms/wizard/custom-form-input-translation.hbs b/app/components/forms/wizard/custom-form-input-translation.hbs index 0265176b974..4b6a435c623 100644 --- a/app/components/forms/wizard/custom-form-input-translation.hbs +++ b/app/components/forms/wizard/custom-form-input-translation.hbs @@ -1,34 +1,25 @@ -{{#if (eq @type "number")}} -
- +{{#if (not-eq @type "number")}} +
+
{{else}} -
- +
+
{{/if}} -
- - -
- {{ @data.selectedLang }} -
- - -
-
-
- - -
\ No newline at end of file + +
+ {{ @data.selectedLang }} +
+ + +
+ \ No newline at end of file diff --git a/app/components/forms/wizard/custom-form-input.hbs b/app/components/forms/wizard/custom-form-input.hbs index 6c3146f6cff..5cd4b682f6e 100644 --- a/app/components/forms/wizard/custom-form-input.hbs +++ b/app/components/forms/wizard/custom-form-input.hbs @@ -30,14 +30,14 @@ {{/if}} {{#if (or (eq this.type "number") (eq this.type "year"))}} -
+
-
+
{{#each this.visibleForm as |sub|}} -
+
{{#unless sub.isDeleted }}
-
- - - {{t 'Add Custom Form Field'}} - -
-
-
- {{#if (eq this.type "number")}} -
- -
- {{else}} -
- -
- {{/if}} -
- - {{#if (eq @form 'attendee')}} - -
- {{ this.mainLanguage }} -
- - -
- {{/if}} -
-
- {{#if (eq this.type "number")}} - -
- - -
- {{/if}} -
-
- - -
- {{ this.type }} -
- - -
-
-
- - {{#if (eq @form 'attendee')}} - - {{/if}} - -
-
-
-
- {{#each this.visibleForm as |sub|}} -
- {{#unless sub.isDeleted }} - - {{/unless}} -
- {{/each}} -
diff --git a/app/components/forms/wizard/custom-form-rich-text.ts b/app/components/forms/wizard/custom-form-rich-text.ts deleted file mode 100644 index 8e4a92fa38d..00000000000 --- a/app/components/forms/wizard/custom-form-rich-text.ts +++ /dev/null @@ -1,249 +0,0 @@ -import Component from '@glimmer/component'; -import { slugify } from 'open-event-frontend/utils/text'; -import { action, computed } from '@ember/object'; -import { inject as service } from '@ember/service'; -import DS from 'ember-data'; -import { tracked } from '@glimmer/tracking'; -import { translateLanguages, LANGUAGE_CODE_ENUM } from 'open-event-frontend/utils/dictionary/translate-language'; -import { A } from '@ember/array'; - -interface CustomForm { - fieldIdentifier: string, - name: string, - type: string, - min: number, - max: number, - formIdentifier: string, - translations: Translate[], - mainLanguage: string -} - -interface SubForm { - ignoreLanguages: string[], - name: string, - languages: object, - selectedLang: string, - isDeleted: boolean, - id: any, - form_id: string -} - -interface Translate { - name: string, - isDeleted: boolean, - id: string, - form_id: string, - language_code: string -} - -function getIdentifier(name: string, fields: CustomForm[]): string { - const fieldIdentifiers = new Set(fields.map(field => field.fieldIdentifier)); - let identifier = slugify(name, '_'); - while (fieldIdentifiers.has(identifier)) { - identifier += '_'; - } - - return identifier; -} - -interface Args { - field: CustomForm | null, - customForms: CustomForm[], - form: string, - event: any, - formIdentifier: string | '', - mainLanguage: string | 'en', - min: number | 0, - max: number | 10, - onSave: (() => void) | null -} - -export default class CustomFormInput extends Component { - @tracked - name = ''; - - @tracked - type = 'text'; - - @service - store!: DS.Store; - - MIN_VAL = 0; - MAX_VAL = 10; - - @tracked - min = this.MIN_VAL; - - @tracked - max = this.MAX_VAL; - - @tracked - mainLanguage = LANGUAGE_CODE_ENUM.ENGLISH; - - @tracked - selectedLanguage: string[] = [this.mainLanguage] - - @tracked - subForm: SubForm[] = A([]); - - translations: Translate[] = []; - - @action - updated(): void { - this.subForm.clear() - if (this.args.field) { - this.name = this.args.field.name; - this.type = this.args.field.type; - this.min = this.args.field.min; - this.max = this.args.field.max; - this.mainLanguage = this.args.field.mainLanguage; - this.translations = this.args.field.translations; - this.selectedLanguage.clear(); - this.selectedLanguage.pushObject(this.mainLanguage) - const selectedLanguage = this.translations?.map(trans => trans.language_code); - this.selectedLanguage.pushObjects(selectedLanguage) - this.translations?.forEach((trans: Translate) => { - const { name, language_code, form_id, isDeleted, id } = trans; - if (isDeleted || (name && language_code)) { - this.subForm.pushObject({ - id, - form_id, - name, - languages : translateLanguages, - ignoreLanguages : this.selectedLanguage, - selectedLang : language_code, - isDeleted - }) - } - }) - } else { - this.name = ''; - this.min = this.MIN_VAL; - this.max = this.MAX_VAL; - this.mainLanguage = LANGUAGE_CODE_ENUM.ENGLISH; - } - } - - @computed('name') - get identifier(): string { - return getIdentifier(this.name, this.args.customForms); - } - - @computed('name', 'selectedLanguage.@each', 'subForm.@each.name') - get validIdentifier(): boolean { - const nameValid = this.identifier.trim().length > 0 && this.name.trim().length > 0; - const transInValid = this.subForm.filter(field => !field.isDeleted && (!field.name || !field.selectedLang)) - return nameValid && !transInValid?.length; - } - - get languageList(): object[] { - return translateLanguages.filter(language => - language.code === this.mainLanguage || !this.selectedLanguage.includes(language.code) - ) - } - - // @computed('translations') - get translationsList(): Translate[] { - const translations: Translate[] = [] - this.subForm.forEach(field => { - const { id, form_id, name, isDeleted, selectedLang } = field - if (isDeleted || (name && selectedLang)) { - translations.pushObject({ - id, - form_id, - name, - language_code: selectedLang, - isDeleted - }) - } - }) - return translations; - } - - @computed('name', 'type') - get field(): CustomForm { - return this.store.createRecord('custom-form', { - fieldIdentifier : this.identifier, - name : this.name, - form : this.args.form, - type : this.type, - isRequired : false, - isIncluded : true, - isComplex : true, - event : this.args.event, - formID : this.args.formIdentifier, - min : this.min, - max : this.max, - translations : this.translationsList, - mainLanguage : this.mainLanguage || LANGUAGE_CODE_ENUM.ENGLISH - }); - } - - @action - addFormField(): void { - if (!this.validIdentifier) { - return; - } - if (this.args.field) { - this.args.field.name = this.name; - this.args.field.type = this.type; - this.args.field.fieldIdentifier = this.identifier; - this.args.field.min = this.min; - this.args.field.max = this.max; - this.args.field.translations = this.translationsList; - this.args.field.mainLanguage = this.mainLanguage - } else { - this.args.customForms.pushObject(this.field); - } - this.name = ''; - this.min = 0; - this.max = 10; - this.subForm.clear(); - this.selectedLanguage.clear(); - this.mainLanguage = 'en' - this.selectedLanguage.pushObject(this.mainLanguage); - this.args.onSave && this.args.onSave(); - } - - @action - addTranslation(): void { - const obj: any = { - name : '', - languages : translateLanguages, - ignoreLanguages : this.selectedLanguage, - selectedLang : '', - isDeleted : false - } - this.subForm.pushObject(obj); - } - - @action - onMainLanguageChange(code: string): void { - this.onSelectedLanguage(this.mainLanguage, code); - this.mainLanguage = code; - } - - @action - onChildChangeLanguage(form: SubForm, new_code: string) { - this.onSelectedLanguage(form.selectedLang, new_code) - form.selectedLang = new_code; - } - - @action - onSelectedLanguage(old_code: string, new_code: string): void { - if (old_code) { - this.selectedLanguage.removeObject(old_code) - } - this.selectedLanguage.pushObject(new_code) - } - - @computed('subForm.@each.isDeleted') - get disableAddTranslation() { - return this.subForm.filter(item => !item.isDeleted).length === translateLanguages.length - 1; - } - - @computed('subForm.@each.isDeleted') - get visibleForm() { - return this.subForm.filter(item => !item.isDeleted); - } -} diff --git a/app/components/forms/wizard/custom-forms/table.hbs b/app/components/forms/wizard/custom-forms/table.hbs index d680ec417fd..97419de82c3 100644 --- a/app/components/forms/wizard/custom-forms/table.hbs +++ b/app/components/forms/wizard/custom-forms/table.hbs @@ -52,21 +52,27 @@