diff --git a/app/components/forms/wizard/attendee-step.js b/app/components/forms/wizard/attendee-step.js index 51d55d6b016..0e85f4eb5df 100644 --- a/app/components/forms/wizard/attendee-step.js +++ b/app/components/forms/wizard/attendee-step.js @@ -4,14 +4,18 @@ import FormMixin from 'open-event-frontend/mixins/form'; export default Component.extend(FormMixin, { - fixedFields: computed('data.customForms', function() { + fixedFields: computed('data.customForms.@each', function() { return this.data.customForms?.filter(field => field.isFixed); }), - editableFields: computed('data.customForms', function() { + editableFields: computed('data.customForms.@each', function() { return this.data.customForms?.filter(field => !field.isFixed); }), + showEditColumn: computed('editableFields.@each', function() { + return this.editableFields?.some(field => field.isComplex); + }), + actions: { saveDraft() { this.onValid(() => { diff --git a/app/components/forms/wizard/custom-form-input.hbs b/app/components/forms/wizard/custom-form-input.hbs index 603e9f8d30a..20df2078ad4 100644 --- a/app/components/forms/wizard/custom-form-input.hbs +++ b/app/components/forms/wizard/custom-form-input.hbs @@ -5,11 +5,11 @@ {{t 'Add Custom Form Field'}} -
- - +
+ +
- {{ @newFormField.type}} + {{ this.type }}
- +
\ No newline at end of file diff --git a/app/components/forms/wizard/custom-form-input.ts b/app/components/forms/wizard/custom-form-input.ts index 2fc38258f12..8c9be19a37f 100644 --- a/app/components/forms/wizard/custom-form-input.ts +++ b/app/components/forms/wizard/custom-form-input.ts @@ -1,10 +1,11 @@ import Component from '@glimmer/component'; import { slugify } from 'open-event-frontend/utils/text'; -import { action, computed, set } from '@ember/object'; +import { action, computed } from '@ember/object'; import { inject as service } from '@ember/service'; import DS from 'ember-data'; +import { tracked } from '@glimmer/tracking'; -interface CustomForm { fieldIdentifier: string } +interface CustomForm { fieldIdentifier: string, name: string, type: string } function getIdentifier(name: string, fields: CustomForm[]): string { const fieldIdentifiers = new Set(fields.map(field => field.fieldIdentifier)); @@ -17,43 +18,72 @@ function getIdentifier(name: string, fields: CustomForm[]): string { } interface Args { - newFormField: { - name: string, - type: string - }, + field: CustomForm | null, customForms: CustomForm[], form: string, - event: any + event: any, + onSave: (() => void) | null } export default class CustomFormInput extends Component { + @tracked + name = ''; + + @tracked + type = 'text'; + @service store!: DS.Store; + @action + updated(): void { + if (this.args.field) { + this.name = this.args.field.name; + this.type = this.args.field.type; + } else { + this.name = ''; + } + } + + @computed('name') get identifier(): string { - return getIdentifier(this.args.newFormField.name, this.args.customForms); + return getIdentifier(this.name, this.args.customForms); } - @computed('args.newFormField.name') + @computed('name') get validIdentifier(): boolean { - return this.identifier.trim().length > 0 && this.args.newFormField.name.trim().length > 0; + return this.identifier.trim().length > 0 && this.name.trim().length > 0; } - @action - addFormField(): void { - if (!this.validIdentifier) { - return; - } - this.args.customForms.pushObject(this.store.createRecord('custom-form', { + @computed('name', 'type') + get field(): CustomForm { + return this.store.createRecord('custom-form', { fieldIdentifier : this.identifier, - name : this.args.newFormField.name, + name : this.name, form : this.args.form, - type : this.args.newFormField.type, + type : this.type, isRequired : false, isIncluded : false, + isComplex : true, event : this.args.event - })); - set(this.args.newFormField, 'name', ''); + }); + } + + @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; + } else { + this.args.customForms.pushObject(this.field); + } + this.name = ''; + + this.args.onSave && this.args.onSave(); } } diff --git a/app/templates/components/forms/wizard/custom-forms/table.hbs b/app/components/forms/wizard/custom-forms/table.hbs similarity index 58% rename from app/templates/components/forms/wizard/custom-forms/table.hbs rename to app/components/forms/wizard/custom-forms/table.hbs index 8e11771f821..087085a1f3d 100644 --- a/app/templates/components/forms/wizard/custom-forms/table.hbs +++ b/app/components/forms/wizard/custom-forms/table.hbs @@ -1,5 +1,12 @@ + {{#if @headerText}} + + + + {{/if}} {{#if this.device.isMobile}} + {{#if this.editColumn}} + + {{/if}} {{/if}} @@ -27,6 +39,11 @@ + {{#if this.editColumn}} + + {{/if}} {{/each}} diff --git a/app/components/forms/wizard/custom-forms/table.ts b/app/components/forms/wizard/custom-forms/table.ts new file mode 100644 index 00000000000..90119ab5bad --- /dev/null +++ b/app/components/forms/wizard/custom-forms/table.ts @@ -0,0 +1,15 @@ +import Component from '@glimmer/component'; + + +interface CustomForm { isComplex: boolean } + +interface Args { + fields: CustomForm[], + updateField: (field: CustomForm) => void +} + +export default class CustomFormTable extends Component { + get editColumn(): boolean { + return this.args.fields?.some(field => field.isComplex); + } +} diff --git a/app/routes/events/view/edit/attendee.js b/app/routes/events/view/edit/attendee.js index 8e35d6d6a4b..9cfbf642221 100644 --- a/app/routes/events/view/edit/attendee.js +++ b/app/routes/events/view/edit/attendee.js @@ -22,11 +22,7 @@ export default class AttendeeRoute extends Route.extend(CustomFormMixin) { filter : filterOptions, sort : 'id', 'page[size]' : 50 - })).toArray().filter(field => field.form === 'attendee'), - newFormField: { - name : '', - type : 'text' - } + })).toArray().filter(field => field.form === 'attendee') }; return data; diff --git a/app/routes/events/view/edit/sessions-speakers.js b/app/routes/events/view/edit/sessions-speakers.js index f6bfdb42ed5..e0ac7101335 100644 --- a/app/routes/events/view/edit/sessions-speakers.js +++ b/app/routes/events/view/edit/sessions-speakers.js @@ -43,15 +43,7 @@ export default class SessionsSpeakersRoute extends Route.extend(EventWizardMixin microlocations, sessionTypes, speakersCall, - customForms, - newSpeakerForm: { - name : '', - type : 'text' - }, - newSessionForm: { - name : '', - type : 'text' - } + customForms }; } } diff --git a/app/styles/libs/_helpers.scss b/app/styles/libs/_helpers.scss index e8f02368cc4..b4181e234f5 100644 --- a/app/styles/libs/_helpers.scss +++ b/app/styles/libs/_helpers.scss @@ -66,3 +66,7 @@ $spacer-heights: 50 100 200 300 400 500 600 700 800 900; .d-flex.wrap { flex-wrap: wrap; } + +.d-inline { + display: inline; +} diff --git a/app/templates/components/forms/wizard/attendee-step.hbs b/app/templates/components/forms/wizard/attendee-step.hbs index ca44701031c..9a36b63ca3e 100644 --- a/app/templates/components/forms/wizard/attendee-step.hbs +++ b/app/templates/components/forms/wizard/attendee-step.hbs @@ -48,14 +48,16 @@
+ @fields={{this.editableFields}} + @updateField={{action (mut this.field)}} />
+ @form="attendee" + @field={{this.field}} + @onSave={{action (mut this.field) null}} /> {{/if}}
diff --git a/app/templates/components/forms/wizard/sessions-speakers-step.hbs b/app/templates/components/forms/wizard/sessions-speakers-step.hbs index 4c15cd4314b..48ffef22c72 100644 --- a/app/templates/components/forms/wizard/sessions-speakers-step.hbs +++ b/app/templates/components/forms/wizard/sessions-speakers-step.hbs @@ -61,11 +61,11 @@ {{#each this.microlocations as |microlocation|}}
- +
- + {{#if (gt this.microlocations.length 1)}}
+ {{t @headerText}} +
@@ -18,6 +25,11 @@ {{t 'Require'}} + {{t 'Actions'}} +
@@ -48,6 +65,19 @@ @onChange={{action (mut field.isRequired)}} @label={{if this.device.isMobile (t "Require")}} /> + {{#if field.isComplex}} + + {{!-- Hiding till implemented --}} + + {{/if}} +
- - - - - - {{#if this.device.isMobile}} - - {{else}} - - - - - {{/if}} - - - - {{#each this.customForm.speaker as |field|}} - - - - - - - {{/each}} - -
- {{t 'Collect Speaker Details'}} -
- {{t 'Options'}} - - {{t 'Option'}} - - {{t 'Type'}} - - {{t 'Include'}} - - {{t 'Require'}} -
- - - {{field.type}} - - - - -
+ + @form="speaker" + @field={{this.speakerField}} + @onSave={{action (mut this.speakerField) null}} />
- - - - - - - {{#if this.device.isMobile}} - - {{else}} - - - - - {{/if}} - - - - {{#each this.customForm.session as |field|}} - - - - - - - {{/each}} - -
- {{t 'Collect Session Details'}} -
- {{t 'Options'}} - - {{t 'Option'}} - - {{t 'Type'}} - - {{t 'Include'}} - - {{t 'Require'}} -
- - - {{field.type}} - - - - -
+ + @form="session" + @field={{this.sessionField}} + @onSave={{action (mut this.sessionField) null}} />
diff --git a/package.json b/package.json index f64b4e70572..924c3862ffd 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "@babel/plugin-transform-block-scoping": "^7.11.1", "@ember/jquery": "^1.1.0", "@ember/optional-features": "^2.0.0", + "@ember/render-modifiers": "^1.0.2", "@glimmer/component": "^1.0.1", "@glimmer/tracking": "^1.0.1", "@open-event/theme": "^0.2.2",