- }
- // Handling of edit mode state changes is more granular.
- else {
- // In general, enforce the states sequence. Disallow going back from a
- // "later" state to an "earlier" state, except in explicitly allowed
- // cases.
- if (!Drupal.quickedit.FieldModel.followsStateSequence(from, to)) {
- accept = false;
- // Allow: activating/active -> candidate.
- // Necessary to stop editing a field.
- if (_.indexOf(this.activeFieldStates, from) !== -1 && to === 'candidate') {
- accept = true;
- }
- // Allow: changed/invalid -> candidate.
- // Necessary to stop editing a field when it is changed or invalid.
- else if ((from === 'changed' || from === 'invalid') && to === 'candidate') {
- accept = true;
- }
- // Allow: highlighted -> candidate.
- // Necessary to stop highlighting a field.
- else if (from === 'highlighted' && to === 'candidate') {
- accept = true;
- }
- // Allow: saved -> candidate.
- // Necessary when successfully saved a field.
- else if (from === 'saved' && to === 'candidate') {
- accept = true;
- }
- // Allow: invalid -> saving.
- // Necessary to be able to save a corrected, invalid field.
- else if (from === 'invalid' && to === 'saving') {
- accept = true;
- }
- // Allow: invalid -> activating.
- // Necessary to be able to correct a field that turned out to be
- // invalid after the user already had moved on to the next field
- // (which we explicitly allow to have a fluent UX).
- else if (from === 'invalid' && to === 'activating') {
- accept = true;
- }
- }
-
- // If it's not against the general principle, then here are more
- // disallowed cases to check.
- if (accept) {
- var activeField;
- var activeFieldState;
- // Ensure only one field (editor) at a time is active … but allow a
- // user to hop from one field to the next, even if we still have to
- // start saving the field that is currently active: assume it will be
- // valid, to allow for a fluent UX. (If it turns out to be invalid,
- // this block of code also handles that.)
- if ((this.readyFieldStates.indexOf(from) !== -1 || from === 'invalid') && this.activeFieldStates.indexOf(to) !== -1) {
- activeField = this.model.get('activeField');
- if (activeField && activeField !== fieldModel) {
- activeFieldState = activeField.get('state');
- // Allow the state change. If the state of the active field is:
- // - 'activating' or 'active': change it to 'candidate'
- // - 'changed' or 'invalid': change it to 'saving'
- // - 'saving' or 'saved': don't do anything.
- if (this.activeFieldStates.indexOf(activeFieldState) !== -1) {
- activeField.set('state', 'candidate');
- }
- else if (activeFieldState === 'changed' || activeFieldState === 'invalid') {
- activeField.set('state', 'saving');
- }