Ghost/ghost/admin/app/components/gh-navitem.js
Kevin Ansfield fda94fedab ESLint: Alias model in controllers
no issue
- https://github.com/ember-cli/eslint-plugin-ember/blob/HEAD/docs/rules/alias-model-in-controller.md
- replace `model` with a meaningful property name everywhere possible
- refactor `design` and `general` settings controllers to use a directly injected settings service rather than passing it in as a "model" to be more explicit
2018-01-12 12:17:56 +00:00

69 lines
1.7 KiB
JavaScript

import Component from '@ember/component';
import ValidationState from 'ghost-admin/mixins/validation-state';
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', 'navItem.isNew::gh-blognav-item--sortable'],
new: false,
errors: readOnly('navItem.errors'),
errorClass: computed('hasError', function () {
if (this.get('hasError')) {
return 'gh-blognav-item--error';
}
}),
keyPress(event) {
// enter key
if (event.keyCode === 13 && this.get('navItem.isNew')) {
event.preventDefault();
run.scheduleOnce('actions', this, function () {
this.send('addItem');
});
}
},
actions: {
addItem() {
let action = this.get('addItem');
if (action) {
action();
}
},
deleteItem(item) {
let action = this.get('deleteItem');
if (action) {
action(item);
}
},
updateUrl(value) {
let action = this.get('updateUrl');
if (action) {
action(value, this.get('navItem'));
}
},
updateLabel(value) {
let action = this.get('updateLabel');
if (action) {
action(value, this.get('navItem'));
}
},
clearLabelErrors() {
this.get('navItem.errors').remove('label');
},
clearUrlErrors() {
this.get('navItem.errors').remove('url');
}
}
});