2017-08-22 09:53:26 +02:00
|
|
|
import Component from '@ember/component';
|
2017-05-29 20:50:03 +02:00
|
|
|
import SortableItem from 'ember-sortable/mixins/sortable-item';
|
|
|
|
import ValidationState from 'ghost-admin/mixins/validation-state';
|
2017-08-22 09:53:26 +02:00
|
|
|
import {alias, readOnly} from '@ember/object/computed';
|
|
|
|
import {computed} from '@ember/object';
|
|
|
|
import {run} from '@ember/runloop';
|
2015-06-13 16:34:09 +02:00
|
|
|
|
2016-02-09 18:16:18 +01:00
|
|
|
export default Component.extend(ValidationState, SortableItem, {
|
2015-05-25 15:17:14 +02:00
|
|
|
classNames: 'gh-blognav-item',
|
2016-02-09 18:16:18 +01:00
|
|
|
classNameBindings: ['errorClass', 'navItem.isNew::gh-blognav-item--sortable'],
|
2015-01-18 01:16:54 +01:00
|
|
|
|
2016-02-09 18:16:18 +01:00
|
|
|
new: false,
|
|
|
|
handle: '.gh-blognav-grab',
|
|
|
|
|
|
|
|
model: alias('navItem'),
|
2016-01-19 14:03:27 +01:00
|
|
|
errors: readOnly('navItem.errors'),
|
2015-09-16 19:02:06 +02:00
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
errorClass: computed('hasError', function () {
|
2015-09-16 19:02:06 +02:00
|
|
|
if (this.get('hasError')) {
|
|
|
|
return 'gh-blognav-item--error';
|
|
|
|
}
|
|
|
|
}),
|
2015-02-03 17:29:01 +01:00
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
keyPress(event) {
|
2015-01-18 01:16:54 +01:00
|
|
|
// enter key
|
2016-02-09 18:16:18 +01:00
|
|
|
if (event.keyCode === 13 && this.get('navItem.isNew')) {
|
2015-01-18 01:16:54 +01:00
|
|
|
event.preventDefault();
|
2016-02-09 18:16:18 +01:00
|
|
|
run.scheduleOnce('actions', this, function () {
|
|
|
|
this.send('addItem');
|
|
|
|
});
|
2015-01-18 01:16:54 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
2015-10-28 12:36:45 +01:00
|
|
|
addItem() {
|
2015-01-18 01:16:54 +01:00
|
|
|
this.sendAction('addItem');
|
|
|
|
},
|
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
deleteItem(item) {
|
2015-01-18 01:16:54 +01:00
|
|
|
this.sendAction('deleteItem', item);
|
|
|
|
},
|
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
updateUrl(value) {
|
2015-01-18 01:16:54 +01:00
|
|
|
this.sendAction('updateUrl', value, this.get('navItem'));
|
2016-02-09 18:16:18 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
clearLabelErrors() {
|
|
|
|
this.get('navItem.errors').remove('label');
|
|
|
|
},
|
|
|
|
|
|
|
|
clearUrlErrors() {
|
|
|
|
this.get('navItem.errors').remove('url');
|
2015-01-18 01:16:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|