2017-08-22 09:53:26 +02:00
|
|
|
import Component from '@ember/component';
|
2017-05-29 20:50:03 +02:00
|
|
|
import ValidationState from 'ghost-admin/mixins/validation-state';
|
2017-08-22 09:53:26 +02:00
|
|
|
import {computed} from '@ember/object';
|
2018-01-10 23:57:43 +01:00
|
|
|
import {readOnly} from '@ember/object/computed';
|
2017-08-22 09:53:26 +02:00
|
|
|
import {run} from '@ember/runloop';
|
2015-06-13 16:34:09 +02:00
|
|
|
|
2017-10-31 10:10:49 +01:00
|
|
|
export default Component.extend(ValidationState, {
|
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,
|
|
|
|
|
2019-01-02 10:58:55 +01:00
|
|
|
// closure actions
|
|
|
|
addItem() {},
|
|
|
|
deleteItem() {},
|
|
|
|
updateUrl() {},
|
|
|
|
updateLabel() {},
|
|
|
|
|
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 () {
|
2019-06-24 17:33:21 +02:00
|
|
|
return this.hasError ? 'gh-blognav-item--error' : '';
|
2015-09-16 19:02:06 +02:00
|
|
|
}),
|
2015-02-03 17:29:01 +01:00
|
|
|
|
2015-01-18 01:16:54 +01:00
|
|
|
actions: {
|
2019-12-04 05:14:45 +01:00
|
|
|
addItem(item) {
|
|
|
|
this.addItem(item);
|
2015-01-18 01:16:54 +01:00
|
|
|
},
|
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
deleteItem(item) {
|
2019-01-02 10:58:55 +01:00
|
|
|
this.deleteItem(item);
|
2015-01-18 01:16:54 +01:00
|
|
|
},
|
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
updateUrl(value) {
|
2019-01-02 10:58:55 +01:00
|
|
|
return this.updateUrl(value, this.navItem);
|
2016-02-09 18:16:18 +01:00
|
|
|
},
|
|
|
|
|
2017-10-31 16:27:25 +01:00
|
|
|
updateLabel(value) {
|
2019-01-02 10:58:55 +01:00
|
|
|
return this.updateLabel(value, this.navItem);
|
2017-10-31 16:27:25 +01:00
|
|
|
},
|
|
|
|
|
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
|
|
|
}
|
2018-01-11 18:43:23 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
keyPress(event) {
|
|
|
|
// enter key
|
|
|
|
if (event.keyCode === 13 && this.get('navItem.isNew')) {
|
|
|
|
event.preventDefault();
|
2020-01-16 18:01:12 +01:00
|
|
|
run.scheduleOnce('actions', this, this.send, 'addItem', this.navItem);
|
2018-01-11 18:43:23 +01:00
|
|
|
}
|
2015-01-18 01:16:54 +01:00
|
|
|
}
|
|
|
|
});
|