|
| 1 | +import PixButton from '@1024pix/pix-ui/components/pix-button'; |
| 2 | +import PixCheckbox from '@1024pix/pix-ui/components/pix-checkbox'; |
| 3 | +import PixInput from '@1024pix/pix-ui/components/pix-input'; |
| 4 | +import PixSelect from '@1024pix/pix-ui/components/pix-select'; |
| 5 | +import { concat, fn } from '@ember/helper'; |
| 6 | +import { on } from '@ember/modifier'; |
| 7 | +import { action } from '@ember/object'; |
| 8 | +import Component from '@glimmer/component'; |
| 9 | +import { tracked } from '@glimmer/tracking'; |
| 10 | +import { t } from 'ember-intl'; |
| 11 | + |
| 12 | +import { types } from '../../models/certification-center'; |
| 13 | + |
| 14 | +export default class CertificationCenterForm extends Component { |
| 15 | + @tracked habilitations = []; |
| 16 | + certificationCenterTypes = types; |
| 17 | + |
| 18 | + constructor() { |
| 19 | + super(...arguments); |
| 20 | + Promise.resolve(this.args.certificationCenter.habilitations).then((habilitations) => { |
| 21 | + this.habilitations = habilitations; |
| 22 | + }); |
| 23 | + } |
| 24 | + @action |
| 25 | + handleCenterNameChange(event) { |
| 26 | + this.args.certificationCenter.name = event.target.value; |
| 27 | + } |
| 28 | + |
| 29 | + @action |
| 30 | + handleExternalIdChange(event) { |
| 31 | + this.args.certificationCenter.externalId = event.target.value; |
| 32 | + } |
| 33 | + |
| 34 | + @action |
| 35 | + handleIsV3PilotChange(event) { |
| 36 | + this.args.certificationCenter.isV3Pilot = event.target.checked; |
| 37 | + } |
| 38 | + |
| 39 | + @action |
| 40 | + handleDataProtectionOfficerFirstNameChange(event) { |
| 41 | + this.args.certificationCenter.dataProtectionOfficerFirstName = event.target.value; |
| 42 | + } |
| 43 | + |
| 44 | + @action |
| 45 | + handleDataProtectionOfficerLastNameChange(event) { |
| 46 | + this.args.certificationCenter.dataProtectionOfficerLastName = event.target.value; |
| 47 | + } |
| 48 | + |
| 49 | + @action |
| 50 | + handleDataProtectionOfficerEmailChange(event) { |
| 51 | + this.args.certificationCenter.dataProtectionOfficerEmail = event.target.value; |
| 52 | + } |
| 53 | + |
| 54 | + @action |
| 55 | + selectCertificationCenterType(value) { |
| 56 | + this.args.certificationCenter.type = value; |
| 57 | + } |
| 58 | + |
| 59 | + @action |
| 60 | + updateGrantedHabilitation(habilitation) { |
| 61 | + const habilitations = this.habilitations; |
| 62 | + if (habilitations.includes(habilitation)) { |
| 63 | + habilitations.removeObject(habilitation); |
| 64 | + } else { |
| 65 | + habilitations.addObject(habilitation); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + <template> |
| 70 | + <form class="form certification-center-form" {{on "submit" @onSubmit}}> |
| 71 | + |
| 72 | + <PixInput |
| 73 | + @id="certificationCenterName" |
| 74 | + onchange={{this.handleCenterNameChange}} |
| 75 | + class="form-field" |
| 76 | + required={{true}} |
| 77 | + aria-required={{true}} |
| 78 | + > |
| 79 | + <:label>Nom du centre</:label> |
| 80 | + </PixInput> |
| 81 | + |
| 82 | + <div class="form-field"> |
| 83 | + <PixSelect |
| 84 | + @options={{this.certificationCenterTypes}} |
| 85 | + @placeholder="-- Choisissez --" |
| 86 | + @hideDefaultOption={{true}} |
| 87 | + @onChange={{this.selectCertificationCenterType}} |
| 88 | + @value={{@certificationCenter.type}} |
| 89 | + required={{true}} |
| 90 | + aria-required={{true}} |
| 91 | + > |
| 92 | + <:label>Type d'établissement</:label> |
| 93 | + <:default as |certificationCenterType|>{{certificationCenterType.label}}</:default> |
| 94 | + </PixSelect> |
| 95 | + </div> |
| 96 | + |
| 97 | + <PixInput @id="certificationCenterExternalId" onchange={{this.handleExternalIdChange}} class="form-field"> |
| 98 | + <:label>Identifiant externe</:label> |
| 99 | + </PixInput> |
| 100 | + |
| 101 | + <PixInput |
| 102 | + @id="dataProtectionOfficerFirstName" |
| 103 | + {{on "change" this.handleDataProtectionOfficerFirstNameChange}} |
| 104 | + class="form-field" |
| 105 | + > |
| 106 | + <:label>Prénom du DPO</:label> |
| 107 | + </PixInput> |
| 108 | + |
| 109 | + <PixInput |
| 110 | + @id="dataProtectionOfficerLastName" |
| 111 | + {{on "change" this.handleDataProtectionOfficerLastNameChange}} |
| 112 | + class="form-field" |
| 113 | + > |
| 114 | + <:label>Nom du DPO</:label> |
| 115 | + </PixInput> |
| 116 | + |
| 117 | + <PixInput |
| 118 | + @id="dataProtectionOfficerEmail" |
| 119 | + {{on "change" this.handleDataProtectionOfficerEmailChange}} |
| 120 | + class="form-field" |
| 121 | + > |
| 122 | + <:label>Adresse e-mail du DPO</:label> |
| 123 | + </PixInput> |
| 124 | + |
| 125 | + <div class="form-field"> |
| 126 | + <PixCheckbox @id="isV3Pilot" @size="small" onChange={{this.handleIsV3PilotChange}}> |
| 127 | + <:label>{{t "components.certification-centers.is-v3-pilot-label"}}</:label> |
| 128 | + </PixCheckbox> |
| 129 | + </div> |
| 130 | + |
| 131 | + <section> |
| 132 | + <h2 class="habilitations-title">Habilitations aux certifications complémentaires</h2> |
| 133 | + <ul class="form-field habilitations-checkbox-list"> |
| 134 | + {{#each @habilitations as |habilitation index|}} |
| 135 | + <li class="habilitation-entry"> |
| 136 | + <PixCheckbox |
| 137 | + @id={{concat "habilitation_" index}} |
| 138 | + @size="small" |
| 139 | + onChange={{fn this.updateGrantedHabilitation habilitation}} |
| 140 | + > |
| 141 | + <:label>{{habilitation.label}}</:label> |
| 142 | + </PixCheckbox> |
| 143 | + </li> |
| 144 | + {{/each}} |
| 145 | + </ul> |
| 146 | + </section> |
| 147 | + |
| 148 | + <ul class="form-actions"> |
| 149 | + <li> |
| 150 | + <PixButton @size="small" @variant="secondary" @triggerAction={{@onCancel}}>Annuler</PixButton> |
| 151 | + </li> |
| 152 | + <li> |
| 153 | + <PixButton @type="submit" @size="small">Ajouter</PixButton> |
| 154 | + </li> |
| 155 | + </ul> |
| 156 | + </form> |
| 157 | + </template> |
| 158 | +} |
0 commit comments