2017-08-22 10:53:26 +03:00
|
|
|
import Component from '@ember/component';
|
2017-05-29 21:50:03 +03:00
|
|
|
import ValidationState from 'ghost-admin/mixins/validation-state';
|
2020-06-18 15:06:17 +03:00
|
|
|
import boundOneWay from 'ghost-admin/utils/bound-one-way';
|
2017-08-22 10:53:26 +03:00
|
|
|
import {computed} from '@ember/object';
|
2018-01-11 01:57:43 +03:00
|
|
|
import {readOnly} from '@ember/object/computed';
|
2017-08-22 10:53:26 +03:00
|
|
|
import {run} from '@ember/runloop';
|
2015-06-13 17:34:09 +03:00
|
|
|
|
2017-10-31 12:10:49 +03:00
|
|
|
export default Component.extend(ValidationState, {
|
2015-05-25 16:17:14 +03:00
|
|
|
classNames: 'gh-blognav-item',
|
2016-02-09 20:16:18 +03:00
|
|
|
classNameBindings: ['errorClass', 'navItem.isNew::gh-blognav-item--sortable'],
|
2015-01-18 03:16:54 +03:00
|
|
|
|
2016-02-09 20:16:18 +03:00
|
|
|
new: false,
|
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
// closure actions
|
|
|
|
addItem() {},
|
|
|
|
deleteItem() {},
|
|
|
|
updateUrl() {},
|
|
|
|
updateLabel() {},
|
2020-06-18 15:06:17 +03:00
|
|
|
label: boundOneWay('navItem.label'),
|
|
|
|
url: boundOneWay('navItem.url'),
|
2019-01-02 12:58:55 +03:00
|
|
|
|
2016-01-19 16:03:27 +03:00
|
|
|
errors: readOnly('navItem.errors'),
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
errorClass: computed('hasError', function () {
|
2019-06-24 18:33:21 +03:00
|
|
|
return this.hasError ? 'gh-blognav-item--error' : '';
|
2015-09-16 20:02:06 +03:00
|
|
|
}),
|
2015-02-03 19:29:01 +03:00
|
|
|
|
2015-01-18 03:16:54 +03:00
|
|
|
actions: {
|
2019-12-04 07:14:45 +03:00
|
|
|
addItem(item) {
|
|
|
|
this.addItem(item);
|
2015-01-18 03:16:54 +03:00
|
|
|
},
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
deleteItem(item) {
|
2019-01-02 12:58:55 +03:00
|
|
|
this.deleteItem(item);
|
2015-01-18 03:16:54 +03:00
|
|
|
},
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
updateUrl(value) {
|
2019-01-02 12:58:55 +03:00
|
|
|
return this.updateUrl(value, this.navItem);
|
2016-02-09 20:16:18 +03:00
|
|
|
},
|
|
|
|
|
2017-10-31 18:27:25 +03:00
|
|
|
updateLabel(value) {
|
2020-07-07 10:54:00 +03:00
|
|
|
this.set('label', value);
|
2019-01-02 12:58:55 +03:00
|
|
|
return this.updateLabel(value, this.navItem);
|
2017-10-31 18:27:25 +03:00
|
|
|
},
|
|
|
|
|
2016-02-09 20:16:18 +03:00
|
|
|
clearLabelErrors() {
|
|
|
|
this.get('navItem.errors').remove('label');
|
|
|
|
},
|
|
|
|
|
|
|
|
clearUrlErrors() {
|
|
|
|
this.get('navItem.errors').remove('url');
|
2015-01-18 03:16:54 +03:00
|
|
|
}
|
2018-01-11 20:43:23 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
keyPress(event) {
|
|
|
|
// enter key
|
|
|
|
if (event.keyCode === 13 && this.get('navItem.isNew')) {
|
|
|
|
event.preventDefault();
|
2020-01-16 20:01:12 +03:00
|
|
|
run.scheduleOnce('actions', this, this.send, 'addItem', this.navItem);
|
2018-01-11 20:43:23 +03:00
|
|
|
}
|
2015-01-18 03:16:54 +03:00
|
|
|
}
|
|
|
|
});
|