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