Ghost/ghost/admin/app/components/gh-benefit-item.js
Rishabh Garg 46b311b561 Wired benefits section to API (#2023)
refs https://github.com/TryGhost/Team/issues/792

- updates product benefit to use `name` instead of `label` attribute for benefit text
- updates model/serializer/validator to correctly handle benefit attributes
- added `+` button for adding new labels as the enter behavior is closing the popup(needs fix)
2021-06-28 15:19:54 +05:30

61 lines
1.7 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 && this.get('benefitItem.isNew')) {
event.preventDefault();
run.scheduleOnce('actions', this, this.send, 'addItem', this.benefitItem);
}
}
});