Commit cf59aaf8 authored by webchick's avatar webchick

Issue #2133877 by Wim Leers: Clean up Edit's AppView variable names.

parent 64c97584
...@@ -4,8 +4,12 @@ ...@@ -4,8 +4,12 @@
Drupal.edit.AppModel = Backbone.Model.extend({ Drupal.edit.AppModel = Backbone.Model.extend({
defaults: { defaults: {
highlightedEditor: null, // The currently state = 'highlighted' Drupal.edit.FieldModel, if any.
activeEditor: null, // @see Drupal.edit.FieldModel.states
highlightedField: null,
// The currently state = 'active' Drupal.edit.FieldModel, if any.
// @see Drupal.edit.FieldModel.states
activeField: null,
// Reference to a Drupal.dialog instance if a state change requires // Reference to a Drupal.dialog instance if a state change requires
// confirmation. // confirmation.
activeModal: null activeModal: null
......
...@@ -100,7 +100,7 @@ Drupal.edit.EntityModel = Backbone.Model.extend({ ...@@ -100,7 +100,7 @@ Drupal.edit.EntityModel = Backbone.Model.extend({
// committing. // committing.
this.get('fields').chain() this.get('fields').chain()
.filter(function (fieldModel) { .filter(function (fieldModel) {
return _.intersection([fieldModel.get('state')], Drupal.edit.app.fieldReadyStates).length; return _.intersection([fieldModel.get('state')], Drupal.edit.app.readyFieldStates).length;
}) })
.each(function (fieldModel) { .each(function (fieldModel) {
fieldModel.trigger('change:state', fieldModel, fieldModel.get('state'), options); fieldModel.trigger('change:state', fieldModel, fieldModel.get('state'), options);
...@@ -117,7 +117,7 @@ Drupal.edit.EntityModel = Backbone.Model.extend({ ...@@ -117,7 +117,7 @@ Drupal.edit.EntityModel = Backbone.Model.extend({
// stored in TempStore. // stored in TempStore.
this.get('fields').chain() this.get('fields').chain()
.filter(function (fieldModel) { .filter(function (fieldModel) {
return _.intersection([fieldModel.get('state')], Drupal.edit.app.changedEditorStates).length; return _.intersection([fieldModel.get('state')], Drupal.edit.app.changedFieldStates).length;
}) })
.each(function (fieldModel) { .each(function (fieldModel) {
fieldModel.set('state', 'saving'); fieldModel.set('state', 'saving');
...@@ -220,7 +220,7 @@ Drupal.edit.EntityModel = Backbone.Model.extend({ ...@@ -220,7 +220,7 @@ Drupal.edit.EntityModel = Backbone.Model.extend({
// A state change in reaction to another state change must be deferred. // A state change in reaction to another state change must be deferred.
_.defer(function () { _.defer(function () {
entityModel.set('state', 'opened', { entityModel.set('state', 'opened', {
'accept-field-states': Drupal.edit.app.fieldReadyStates 'accept-field-states': Drupal.edit.app.readyFieldStates
}); });
}); });
break; break;
...@@ -279,7 +279,7 @@ Drupal.edit.EntityModel = Backbone.Model.extend({ ...@@ -279,7 +279,7 @@ Drupal.edit.EntityModel = Backbone.Model.extend({
// Attempt to save the entity. If the entity's fields are not yet all in // Attempt to save the entity. If the entity's fields are not yet all in
// a ready state, the save will not be processed. // a ready state, the save will not be processed.
var options = { var options = {
'accept-field-states': Drupal.edit.app.fieldReadyStates 'accept-field-states': Drupal.edit.app.readyFieldStates
}; };
if (entityModel.set('isCommitting', true, options)) { if (entityModel.set('isCommitting', true, options)) {
entityModel.save({ entityModel.save({
...@@ -299,7 +299,7 @@ Drupal.edit.EntityModel = Backbone.Model.extend({ ...@@ -299,7 +299,7 @@ Drupal.edit.EntityModel = Backbone.Model.extend({
// A state change in reaction to another state change must be deferred. // A state change in reaction to another state change must be deferred.
_.defer(function() { _.defer(function() {
entityModel.set('state', 'closing', { entityModel.set('state', 'closing', {
'accept-field-states': Drupal.edit.app.fieldReadyStates 'accept-field-states': Drupal.edit.app.readyFieldStates
}); });
}); });
break; break;
......
...@@ -27,10 +27,10 @@ Drupal.edit.AppView = Backbone.View.extend({ ...@@ -27,10 +27,10 @@ Drupal.edit.AppView = Backbone.View.extend({
initialize: function (options) { initialize: function (options) {
// AppView's configuration for handling states. // AppView's configuration for handling states.
// @see Drupal.edit.FieldModel.states // @see Drupal.edit.FieldModel.states
this.activeEditorStates = ['activating', 'active']; this.activeFieldStates = ['activating', 'active'];
this.singleEditorStates = ['highlighted', 'activating', 'active']; this.singleFieldStates = ['highlighted', 'activating', 'active'];
this.changedEditorStates = ['changed', 'saving', 'saved', 'invalid']; this.changedFieldStates = ['changed', 'saving', 'saved', 'invalid'];
this.fieldReadyStates = ['candidate', 'highlighted']; this.readyFieldStates = ['candidate', 'highlighted'];
options.entitiesCollection options.entitiesCollection
// Track app state. // Track app state.
...@@ -134,7 +134,7 @@ Drupal.edit.AppView = Backbone.View.extend({ ...@@ -134,7 +134,7 @@ Drupal.edit.AppView = Backbone.View.extend({
accept = false; accept = false;
// Allow: activating/active -> candidate. // Allow: activating/active -> candidate.
// Necessary to stop editing a field. // Necessary to stop editing a field.
if (_.indexOf(this.activeEditorStates, from) !== -1 && to === 'candidate') { if (_.indexOf(this.activeFieldStates, from) !== -1 && to === 'candidate') {
accept = true; accept = true;
} }
// Allow: changed/invalid -> candidate. // Allow: changed/invalid -> candidate.
...@@ -169,25 +169,25 @@ Drupal.edit.AppView = Backbone.View.extend({ ...@@ -169,25 +169,25 @@ Drupal.edit.AppView = Backbone.View.extend({
// If it's not against the general principle, then here are more // If it's not against the general principle, then here are more
// disallowed cases to check. // disallowed cases to check.
if (accept) { if (accept) {
var activeEditor, activeEditorState; var activeField, activeFieldState;
// Ensure only one editor (field) at a time is active … but allow a user // 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 // 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, // 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 // to allow for a fluent UX. (If it turns out to be invalid, this block
// of code also handles that.) // of code also handles that.)
if ((this.fieldReadyStates.indexOf(from) !== -1 || from === 'invalid') && this.activeEditorStates.indexOf(to) !== -1) { if ((this.readyFieldStates.indexOf(from) !== -1 || from === 'invalid') && this.activeFieldStates.indexOf(to) !== -1) {
activeEditor = this.model.get('activeEditor'); activeField = this.model.get('activeField');
if (activeEditor && activeEditor !== fieldModel) { if (activeField && activeField !== fieldModel) {
activeEditorState = activeEditor.get('state'); activeFieldState = activeField.get('state');
// Allow the state change. If the state of the active editor is: // Allow the state change. If the state of the active field is:
// - 'activating' or 'active': change it to 'candidate' // - 'activating' or 'active': change it to 'candidate'
// - 'changed' or 'invalid': change it to 'saving' // - 'changed' or 'invalid': change it to 'saving'
// - 'saving'or 'saved': don't do anything. // - 'saving'or 'saved': don't do anything.
if (this.activeEditorStates.indexOf(activeEditorState) !== -1) { if (this.activeFieldStates.indexOf(activeFieldState) !== -1) {
activeEditor.set('state', 'candidate'); activeField.set('state', 'candidate');
} }
else if (activeEditorState === 'changed' || activeEditorState === 'invalid') { else if (activeFieldState === 'changed' || activeFieldState === 'invalid') {
activeEditor.set('state', 'saving'); activeField.set('state', 'saving');
} }
// If the field that's being activated is in fact already in the // If the field that's being activated is in fact already in the
...@@ -198,7 +198,7 @@ Drupal.edit.AppView = Backbone.View.extend({ ...@@ -198,7 +198,7 @@ Drupal.edit.AppView = Backbone.View.extend({
// change the active editor. All guarantees and assumptions for this // change the active editor. All guarantees and assumptions for this
// field still hold! // field still hold!
if (from === 'invalid') { if (from === 'invalid') {
this.model.set('activeEditor', fieldModel); this.model.set('activeField', fieldModel);
accept = false; accept = false;
} }
else { else {
...@@ -210,7 +210,7 @@ Drupal.edit.AppView = Backbone.View.extend({ ...@@ -210,7 +210,7 @@ Drupal.edit.AppView = Backbone.View.extend({
} }
// Reject going from activating/active to candidate because of a // Reject going from activating/active to candidate because of a
// mouseleave. // mouseleave.
else if (_.indexOf(this.activeEditorStates, from) !== -1 && to === 'candidate') { else if (_.indexOf(this.activeFieldStates, from) !== -1 && to === 'candidate') {
if (context && context.reason === 'mouseleave') { if (context && context.reason === 'mouseleave') {
accept = false; accept = false;
} }
...@@ -391,24 +391,24 @@ Drupal.edit.AppView = Backbone.View.extend({ ...@@ -391,24 +391,24 @@ Drupal.edit.AppView = Backbone.View.extend({
var from = fieldModel.previous('state'); var from = fieldModel.previous('state');
var to = state; var to = state;
// Keep track of the highlighted editor in the global state. // Keep track of the highlighted field in the global state.
if (_.indexOf(this.singleEditorStates, to) !== -1 && this.model.get('highlightedEditor') !== fieldModel) { if (_.indexOf(this.singleFieldStates, to) !== -1 && this.model.get('highlightedField') !== fieldModel) {
this.model.set('highlightedEditor', fieldModel); this.model.set('highlightedField', fieldModel);
} }
else if (this.model.get('highlightedEditor') === fieldModel && to === 'candidate') { else if (this.model.get('highlightedField') === fieldModel && to === 'candidate') {
this.model.set('highlightedEditor', null); this.model.set('highlightedField', null);
} }
// Keep track of the active editor in the global state. // Keep track of the active field in the global state.
if (_.indexOf(this.activeEditorStates, to) !== -1 && this.model.get('activeEditor') !== fieldModel) { if (_.indexOf(this.activeFieldStates, to) !== -1 && this.model.get('activeField') !== fieldModel) {
this.model.set('activeEditor', fieldModel); this.model.set('activeField', fieldModel);
} }
else if (this.model.get('activeEditor') === fieldModel && to === 'candidate') { else if (this.model.get('activeField') === fieldModel && to === 'candidate') {
// Discarded if it transitions from a changed state to 'candidate'. // Discarded if it transitions from a changed state to 'candidate'.
if (from === 'changed' || from === 'invalid') { if (from === 'changed' || from === 'invalid') {
fieldModel.editorView.revert(); fieldModel.editorView.revert();
} }
this.model.set('activeEditor', null); this.model.set('activeField', null);
} }
}, },
......
...@@ -29,8 +29,8 @@ Drupal.edit.EntityToolbarView = Backbone.View.extend({ ...@@ -29,8 +29,8 @@ Drupal.edit.EntityToolbarView = Backbone.View.extend({
// Rerender whenever the entity state changes. // Rerender whenever the entity state changes.
this.model.on('change:isActive change:isDirty change:state', this.render, this); this.model.on('change:isActive change:isDirty change:state', this.render, this);
// Also rerender whenever the highlighted or active in-place editor changes. // Also rerender whenever a different field is highlighted or activated.
this.appModel.on('change:highlightedEditor change:activeEditor', this.render, this); this.appModel.on('change:highlightedField change:activeField', this.render, this);
// Rerender when a field of the entity changes state. // Rerender when a field of the entity changes state.
this.model.get('fields').on('change:state', this.fieldStateChange, this); this.model.get('fields').on('change:state', this.fieldStateChange, this);
...@@ -179,7 +179,7 @@ Drupal.edit.EntityToolbarView = Backbone.View.extend({ ...@@ -179,7 +179,7 @@ Drupal.edit.EntityToolbarView = Backbone.View.extend({
break; break;
case 1: case 1:
// Position against a form container. // Position against a form container.
activeField = Drupal.edit.app.model.get('activeEditor'); activeField = Drupal.edit.app.model.get('activeField');
of = activeField && activeField.editorView && activeField.editorView.$formContainer && activeField.editorView.$formContainer.find('.edit-form'); of = activeField && activeField.editorView && activeField.editorView.$formContainer && activeField.editorView.$formContainer.find('.edit-form');
break; break;
case 2: case 2:
...@@ -191,7 +191,7 @@ Drupal.edit.EntityToolbarView = Backbone.View.extend({ ...@@ -191,7 +191,7 @@ Drupal.edit.EntityToolbarView = Backbone.View.extend({
break; break;
case 3: case 3:
// Position against a highlighted field. // Position against a highlighted field.
highlightedField = Drupal.edit.app.model.get('highlightedEditor'); highlightedField = Drupal.edit.app.model.get('highlightedField');
of = highlightedField && highlightedField.editorView && highlightedField.editorView.getEditedElement(); of = highlightedField && highlightedField.editorView && highlightedField.editorView.getEditedElement();
delay = 250; delay = 250;
break; break;
...@@ -365,11 +365,11 @@ Drupal.edit.EntityToolbarView = Backbone.View.extend({ ...@@ -365,11 +365,11 @@ Drupal.edit.EntityToolbarView = Backbone.View.extend({
var entityLabel = this.model.get('label'); var entityLabel = this.model.get('label');
// Label of an active field, if it exists. // Label of an active field, if it exists.
var activeEditor = Drupal.edit.app.model.get('activeEditor'); var activeField = Drupal.edit.app.model.get('activeField');
var activeFieldLabel = activeEditor && activeEditor.get('metadata').label; var activeFieldLabel = activeField && activeField.get('metadata').label;
// Label of a highlighted field, if it exists. // Label of a highlighted field, if it exists.
var highlightedEditor = Drupal.edit.app.model.get('highlightedEditor'); var highlightedField = Drupal.edit.app.model.get('highlightedField');
var highlightedFieldLabel = highlightedEditor && highlightedEditor.get('metadata').label; var highlightedFieldLabel = highlightedField && highlightedField.get('metadata').label;
// The label is constructed in a priority order. // The label is constructed in a priority order.
if (activeFieldLabel) { if (activeFieldLabel) {
label = Drupal.theme('editEntityToolbarLabel', { label = Drupal.theme('editEntityToolbarLabel', {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment