2021-06-18 16:39:02 +03:00
|
|
|
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() {},
|
2021-06-28 12:49:54 +03:00
|
|
|
name: boundOneWay('benefitItem.name'),
|
2021-06-18 16:39:02 +03:00
|
|
|
|
|
|
|
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) {
|
2021-06-28 12:49:54 +03:00
|
|
|
this.set('name', value);
|
2021-06-18 16:39:02 +03:00
|
|
|
return this.updateLabel(value, this.benefitItem);
|
|
|
|
},
|
|
|
|
|
2021-09-02 12:40:33 +03:00
|
|
|
clearLabelErrors() {
|
|
|
|
if (this.get('benefitItem.errors')) {
|
|
|
|
this.get('benefitItem.errors').remove('name');
|
2021-06-18 16:39:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
keyPress(event) {
|
|
|
|
// enter key
|
2021-08-20 11:49:50 +03:00
|
|
|
if (event.keyCode === 13) {
|
2021-06-18 16:39:02 +03:00
|
|
|
event.preventDefault();
|
2021-08-20 11:49:50 +03:00
|
|
|
if (this.get('benefitItem.isNew')) {
|
|
|
|
run.scheduleOnce('actions', this, this.send, 'addItem', this.benefitItem);
|
|
|
|
} else {
|
|
|
|
run.scheduleOnce('actions', this, this.send, 'focusItem', this.benefitItem);
|
|
|
|
}
|
2021-06-18 16:39:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|