mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 13:54:35 +03:00
984b4a6739
refs https://github.com/TryGhost/Team/issues/874 In the product benefits modal in Admin, hitting Enter has been updated to work as - - when hit with focus in an empty benefit field: does nothing - when hit with focus in any field outside benefit fields: does nothing - add new benefit and focus on it when hit while on a non-empty benefit
65 lines
1.9 KiB
JavaScript
65 lines
1.9 KiB
JavaScript
import Component from '@ember/component';
|
|
import ValidationState from 'ghost-admin/mixins/validation-state';
|
|
import boundOneWay from 'ghost-admin/utils/bound-one-way';
|
|
import {computed} from '@ember/object';
|
|
import {readOnly} from '@ember/object/computed';
|
|
import {run} from '@ember/runloop';
|
|
|
|
export default Component.extend(ValidationState, {
|
|
classNames: 'gh-blognav-item',
|
|
classNameBindings: ['errorClass', 'benefitItem.isNew::gh-blognav-item--sortable'],
|
|
|
|
new: false,
|
|
|
|
// closure actions
|
|
addItem() {},
|
|
deleteItem() {},
|
|
updateLabel() {},
|
|
name: boundOneWay('benefitItem.name'),
|
|
|
|
errors: readOnly('benefitItem.errors'),
|
|
|
|
errorClass: computed('hasError', function () {
|
|
return this.hasError ? 'gh-blognav-item--error' : '';
|
|
}),
|
|
|
|
actions: {
|
|
addItem(item) {
|
|
this.addItem(item);
|
|
},
|
|
|
|
deleteItem(item) {
|
|
this.deleteItem(item);
|
|
},
|
|
|
|
updateLabel(value) {
|
|
this.set('name', value);
|
|
return this.updateLabel(value, this.benefitItem);
|
|
},
|
|
|
|
clearLabelErrors(event) {
|
|
// enter key
|
|
if (event.keyCode === 13 && this.get('benefitItem.isNew')) {
|
|
event.preventDefault();
|
|
run.scheduleOnce('actions', this, this.send, 'addItem', this.benefitItem);
|
|
} else {
|
|
if (this.get('benefitItem.errors')) {
|
|
this.get('benefitItem.errors').remove('name');
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
keyPress(event) {
|
|
// enter key
|
|
if (event.keyCode === 13) {
|
|
event.preventDefault();
|
|
if (this.get('benefitItem.isNew')) {
|
|
run.scheduleOnce('actions', this, this.send, 'addItem', this.benefitItem);
|
|
} else {
|
|
run.scheduleOnce('actions', this, this.send, 'focusItem', this.benefitItem);
|
|
}
|
|
}
|
|
}
|
|
});
|