feat(dossier): autosave en construction
This commit is contained in:
parent
d35ceb7214
commit
d6f5be622c
14 changed files with 66 additions and 82 deletions
|
@ -188,19 +188,15 @@ module Users
|
|||
|
||||
def update
|
||||
@dossier = dossier_with_champs
|
||||
errors = update_dossier_and_compute_errors
|
||||
|
||||
if check_conditions?
|
||||
assign_dossier_and_check_conditions
|
||||
render :update_brouillon
|
||||
else
|
||||
errors = update_dossier_and_compute_errors
|
||||
if errors.present?
|
||||
flash.now.alert = errors
|
||||
end
|
||||
|
||||
if errors.present?
|
||||
flash.now.alert = errors
|
||||
render :modifier
|
||||
else
|
||||
redirect_to demande_dossier_path(@dossier)
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html { render :modifier }
|
||||
format.turbo_stream { render layout: false }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -308,18 +304,6 @@ module Users
|
|||
|
||||
private
|
||||
|
||||
def check_conditions?
|
||||
params[:check_conditions] && champs_params[:dossier]
|
||||
end
|
||||
|
||||
def assign_dossier_and_check_conditions
|
||||
@dossier.assign_attributes(champs_params[:dossier])
|
||||
# We need to set dossier on champs, otherwise dossier will be reloaded
|
||||
@dossier.champs.each do |champ|
|
||||
champ.association(:dossier).target = @dossier
|
||||
end
|
||||
end
|
||||
|
||||
# if the status tab is filled, then this tab
|
||||
# else first filled tab
|
||||
# else en-cours
|
||||
|
|
|
@ -42,7 +42,10 @@ export class AutosaveController extends ApplicationController {
|
|||
this.#latestPromise = Promise.resolve();
|
||||
this.onGlobal('autosave:retry', () => this.didRequestRetry());
|
||||
this.on('change', (event) => this.onChange(event));
|
||||
this.on('input', (event) => this.onInput(event));
|
||||
|
||||
if (this.saveOnInput) {
|
||||
this.on('input', (event) => this.onInput(event));
|
||||
}
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
|
@ -80,7 +83,8 @@ export class AutosaveController extends ApplicationController {
|
|||
this.debounce(this.enqueueAutosaveRequest, AUTOSAVE_DEBOUNCE_DELAY);
|
||||
} else if (
|
||||
isSelectElement(target) ||
|
||||
isCheckboxOrRadioInputElement(target)
|
||||
isCheckboxOrRadioInputElement(target) ||
|
||||
(!this.saveOnInput && isTextInputElement(target))
|
||||
) {
|
||||
this.enqueueAutosaveRequest();
|
||||
}
|
||||
|
@ -99,6 +103,10 @@ export class AutosaveController extends ApplicationController {
|
|||
}
|
||||
}
|
||||
|
||||
private get saveOnInput() {
|
||||
return !!this.form?.dataset.saveOnInput;
|
||||
}
|
||||
|
||||
private didRequestRetry() {
|
||||
if (this.#needsRetry) {
|
||||
this.enqueueAutosaveRequest();
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
.autosave.autosave-state-idle{ data: { controller: 'autosave-status' } }
|
||||
%p.autosave-explanation
|
||||
%span.autosave-explanation-text
|
||||
= t('views.instructeurs.dossiers.autosave.autosave_draft')
|
||||
|
||||
%p.autosave-status.succeeded
|
||||
%span.autosave-icon.icon.accept
|
||||
%span.autosave-label
|
||||
= t('views.instructeurs.dossiers.autosave.autosave_confirmation')
|
||||
|
||||
%p.autosave-status.failed
|
||||
%span.autosave-icon ⚠️
|
||||
%span.autosave-label Impossible d’enregistrer les annotations
|
||||
%button.button.small.autosave-retry{ type: :button, data: { action: 'autosave-status#onClickRetryButton', autosave_status_target: 'retryButton' } }
|
||||
%span.autosave-retry-label réessayer
|
||||
%span.autosave-retrying-label enregistrement en cours…
|
||||
|
|
@ -1,13 +1,19 @@
|
|||
.autosave.autosave-state-idle{ data: { controller: 'autosave-status' } }
|
||||
%p.autosave-explanation
|
||||
%span.autosave-explanation-text
|
||||
= t('views.users.dossiers.autosave.autosave_draft')
|
||||
= link_to t('views.users.dossiers.autosave.more_infos'), FAQ_AUTOSAVE_URL, target: '_blank', rel: 'noopener', class: 'autosave-more-infos'
|
||||
- if dossier.brouillon?
|
||||
= t('views.users.dossiers.autosave.draft_explanation')
|
||||
- else
|
||||
= t('views.users.dossiers.autosave.explanation')
|
||||
= link_to t('views.users.dossiers.autosave.more_information'), FAQ_AUTOSAVE_URL, target: '_blank', rel: 'noopener', class: 'autosave-more-infos'
|
||||
|
||||
%p.autosave-status.succeeded
|
||||
%span.autosave-icon.icon.accept
|
||||
%span.autosave-label
|
||||
= t('views.users.dossiers.autosave.autosave_confirmation')
|
||||
- if dossier.brouillon?
|
||||
= t('views.users.dossiers.autosave.draft_confirmation')
|
||||
- else
|
||||
= t('views.users.dossiers.autosave.confirmation')
|
||||
= link_to t('views.users.dossiers.autosave.more_information'), FAQ_AUTOSAVE_URL, target: '_blank', rel: 'noopener', class: 'autosave-more-infos'
|
||||
|
||||
%p.autosave-status.failed
|
|
@ -2,7 +2,7 @@
|
|||
= render partial: "shared/dossiers/submit_is_over", locals: { dossier: dossier }
|
||||
|
||||
- if dossier.brouillon?
|
||||
- form_options = { url: brouillon_dossier_url(dossier), method: :patch }
|
||||
- form_options = { url: brouillon_dossier_url(dossier), method: :patch, data: { save_on_input: true } }
|
||||
- else
|
||||
- form_options = { url: modifier_dossier_url(dossier), method: :patch }
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
|||
%hr
|
||||
|
||||
- if dossier.show_groupe_instructeur_selector?
|
||||
%span{ data: { controller: dossier.brouillon? ? 'autosave' : 'check-conditions' } }
|
||||
%span{ data: { controller: 'autosave' } }
|
||||
= f.label :groupe_instructeur_id do
|
||||
= dossier.procedure.routing_criteria_name
|
||||
%span.mandatory *
|
||||
|
@ -38,20 +38,14 @@
|
|||
- if !dossier.for_procedure_preview?
|
||||
.dossier-edit-sticky-footer
|
||||
.send-dossier-actions-bar
|
||||
- if dossier.brouillon?
|
||||
= render partial: 'users/dossiers/autosave'
|
||||
= render partial: 'shared/dossiers/autosave', locals: { dossier: dossier }
|
||||
|
||||
- if dossier.can_transition_to_en_construction?
|
||||
= f.button t('views.shared.dossiers.edit.submit_dossier'),
|
||||
name: :submit_draft,
|
||||
value: true,
|
||||
class: 'button send primary',
|
||||
disabled: !current_user.owns?(dossier),
|
||||
data: { 'disable-with': "Envoi en cours…" }
|
||||
|
||||
- else
|
||||
= f.button t('views.shared.dossiers.edit.save_changes'),
|
||||
- if dossier.can_transition_to_en_construction?
|
||||
= f.button t('views.shared.dossiers.edit.submit_dossier'),
|
||||
name: :submit_draft,
|
||||
value: true,
|
||||
class: 'button send primary',
|
||||
disabled: !current_user.owns?(dossier),
|
||||
data: { 'disable-with': "Envoi en cours…" }
|
||||
|
||||
- if dossier.brouillon? && !current_user.owns?(dossier)
|
||||
|
|
5
app/views/users/dossiers/update.turbo_stream.haml
Normal file
5
app/views/users/dossiers/update.turbo_stream.haml
Normal file
|
@ -0,0 +1,5 @@
|
|||
- @dossier.champs.filter(&:conditional?).each do |champ|
|
||||
- if champ.visible?
|
||||
= turbo_stream.show champ.input_group_id
|
||||
- else
|
||||
= turbo_stream.hide champ.input_group_id
|
Loading…
Add table
Add a link
Reference in a new issue