Mercurial > hg > isophonics-drupal-site
comparison core/modules/quickedit/js/models/EntityModel.js @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
67 case 'opened': | 67 case 'opened': |
68 this.set('isActive', true); | 68 this.set('isActive', true); |
69 break; | 69 break; |
70 | 70 |
71 case 'committing': | 71 case 'committing': |
72 var fields = this.get('fields'); | 72 { |
73 | 73 var fields = this.get('fields'); |
74 fields.chain().filter(function (fieldModel) { | 74 |
75 return _.intersection([fieldModel.get('state')], ['active']).length; | 75 fields.chain().filter(function (fieldModel) { |
76 }).each(function (fieldModel) { | 76 return _.intersection([fieldModel.get('state')], ['active']).length; |
77 fieldModel.set('state', 'candidate'); | 77 }).each(function (fieldModel) { |
78 }); | 78 fieldModel.set('state', 'candidate'); |
79 | 79 }); |
80 fields.chain().filter(function (fieldModel) { | 80 |
81 return _.intersection([fieldModel.get('state')], Drupal.quickedit.app.changedFieldStates).length; | 81 fields.chain().filter(function (fieldModel) { |
82 }).each(function (fieldModel) { | 82 return _.intersection([fieldModel.get('state')], Drupal.quickedit.app.changedFieldStates).length; |
83 fieldModel.set('state', 'saving'); | 83 }).each(function (fieldModel) { |
84 }); | 84 fieldModel.set('state', 'saving'); |
85 break; | 85 }); |
86 break; | |
87 } | |
86 | 88 |
87 case 'deactivating': | 89 case 'deactivating': |
88 var changedFields = this.get('fields').filter(function (fieldModel) { | 90 { |
89 return _.intersection([fieldModel.get('state')], ['changed', 'invalid']).length; | 91 var changedFields = this.get('fields').filter(function (fieldModel) { |
90 }); | 92 return _.intersection([fieldModel.get('state')], ['changed', 'invalid']).length; |
91 | 93 }); |
92 if ((changedFields.length || this.get('fieldsInTempStore').length) && !options.saved && !options.confirmed) { | 94 |
93 this.set('state', 'opened', { confirming: true }); | 95 if ((changedFields.length || this.get('fieldsInTempStore').length) && !options.saved && !options.confirmed) { |
94 | 96 this.set('state', 'opened', { confirming: true }); |
95 _.defer(function () { | 97 |
96 Drupal.quickedit.app.confirmEntityDeactivation(entityModel); | 98 _.defer(function () { |
97 }); | 99 Drupal.quickedit.app.confirmEntityDeactivation(entityModel); |
98 } else { | 100 }); |
99 var invalidFields = this.get('fields').filter(function (fieldModel) { | 101 } else { |
100 return _.intersection([fieldModel.get('state')], ['invalid']).length; | 102 var invalidFields = this.get('fields').filter(function (fieldModel) { |
101 }); | 103 return _.intersection([fieldModel.get('state')], ['invalid']).length; |
102 | 104 }); |
103 entityModel.set('reload', this.get('fieldsInTempStore').length || invalidFields.length); | 105 |
104 | 106 entityModel.set('reload', this.get('fieldsInTempStore').length || invalidFields.length); |
105 entityModel.get('fields').each(function (fieldModel) { | 107 |
106 if (_.intersection([fieldModel.get('state')], ['candidate', 'highlighted']).length) { | 108 entityModel.get('fields').each(function (fieldModel) { |
107 fieldModel.trigger('change:state', fieldModel, fieldModel.get('state'), options); | 109 if (_.intersection([fieldModel.get('state')], ['candidate', 'highlighted']).length) { |
108 } else { | 110 fieldModel.trigger('change:state', fieldModel, fieldModel.get('state'), options); |
109 fieldModel.set('state', 'candidate', options); | 111 } else { |
110 } | 112 fieldModel.set('state', 'candidate', options); |
111 }); | 113 } |
112 } | 114 }); |
113 break; | 115 } |
116 break; | |
117 } | |
114 | 118 |
115 case 'closing': | 119 case 'closing': |
116 options.reason = 'stop'; | 120 options.reason = 'stop'; |
117 this.get('fields').each(function (fieldModel) { | 121 this.get('fields').each(function (fieldModel) { |
118 fieldModel.set({ | 122 fieldModel.set({ |
164 this._updateInTempStoreAttributes(entityModel, fieldModel); | 168 this._updateInTempStoreAttributes(entityModel, fieldModel); |
165 } | 169 } |
166 break; | 170 break; |
167 | 171 |
168 case 'committing': | 172 case 'committing': |
169 if (fieldState === 'invalid') { | 173 { |
170 _.defer(function () { | 174 if (fieldState === 'invalid') { |
171 entityModel.set('state', 'opened', { reason: 'invalid' }); | 175 _.defer(function () { |
172 }); | 176 entityModel.set('state', 'opened', { reason: 'invalid' }); |
173 } else { | 177 }); |
174 this._updateInTempStoreAttributes(entityModel, fieldModel); | 178 } else { |
175 } | 179 this._updateInTempStoreAttributes(entityModel, fieldModel); |
176 | 180 } |
177 var options = { | 181 |
178 'accept-field-states': Drupal.quickedit.app.readyFieldStates | 182 var options = { |
179 }; | 183 'accept-field-states': Drupal.quickedit.app.readyFieldStates |
180 if (entityModel.set('isCommitting', true, options)) { | 184 }; |
181 entityModel.save({ | 185 if (entityModel.set('isCommitting', true, options)) { |
182 success: function success() { | 186 entityModel.save({ |
183 entityModel.set({ | 187 success: function success() { |
184 state: 'deactivating', | 188 entityModel.set({ |
185 isCommitting: false | 189 state: 'deactivating', |
186 }, { saved: true }); | 190 isCommitting: false |
187 }, | 191 }, { saved: true }); |
188 error: function error() { | 192 }, |
189 entityModel.set('isCommitting', false); | 193 error: function error() { |
190 | 194 entityModel.set('isCommitting', false); |
191 entityModel.set('state', 'opened', { reason: 'networkerror' }); | 195 |
192 | 196 entityModel.set('state', 'opened', { reason: 'networkerror' }); |
193 var message = Drupal.t('Your changes to <q>@entity-title</q> could not be saved, either due to a website problem or a network connection problem.<br>Please try again.', { '@entity-title': entityModel.get('label') }); | 197 |
194 Drupal.quickedit.util.networkErrorModal(Drupal.t('Network problem!'), message); | 198 var message = Drupal.t('Your changes to <q>@entity-title</q> could not be saved, either due to a website problem or a network connection problem.<br>Please try again.', { '@entity-title': entityModel.get('label') }); |
195 } | 199 Drupal.quickedit.util.networkErrorModal(Drupal.t('Network problem!'), message); |
196 }); | 200 } |
197 } | 201 }); |
198 break; | 202 } |
203 break; | |
204 } | |
199 | 205 |
200 case 'deactivating': | 206 case 'deactivating': |
201 _.defer(function () { | 207 _.defer(function () { |
202 entityModel.set('state', 'closing', { | 208 entityModel.set('state', 'closing', { |
203 'accept-field-states': Drupal.quickedit.app.readyFieldStates | 209 'accept-field-states': Drupal.quickedit.app.readyFieldStates |