Skip to content

Commit

Permalink
Don't save if nav items have empty labels
Browse files Browse the repository at this point in the history
Closes #4942, Closes #4944
- Also adds the `order` prop to the lastItem on save, so it doesn't jump about
  • Loading branch information
novaugust committed Feb 24, 2015
1 parent 174b0ea commit 299fbf9
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions core/client/controllers/settings/navigation.js
Expand Up @@ -5,9 +5,10 @@ NavItem = Ember.Object.extend({
label: '',
url: '',
order: '',
last: false,

isComplete: Ember.computed('label', 'url', function () {
return !(Ember.isBlank(this.get('label')) || Ember.isBlank(this.get('url')));
return !(Ember.isBlank(this.get('label').trim()) || Ember.isBlank(this.get('url')));
})
});

Expand Down Expand Up @@ -116,9 +117,21 @@ NavigationController = Ember.Controller.extend({
navSetting,
blogUrl = this.get('config').blogUrl,
blogUrlRegex = new RegExp('^' + blogUrl + '(.*)', 'i'),
navItems = this.get('navigationItems'),
lastItem = navItems.get('lastObject'),
match;

navSetting = this.get('navigationItems').map(function (item) {
// Don't save if there's a blank label.
if (navItems.find(function (item) { return !item.get('isComplete') && !item.get('last');})) {
self.notifications.showErrors(['One of your navigation items has an empty label.<br>Please enter a new label or delete the item before saving.']);
return;
}
// The last item is typically ignored in ordering, give it
// the last spot in case it has a label & url and hasn't been
// added yet.
if (lastItem.get('order') !== 0 && !lastItem.get('order')) {
lastItem.set('order', navItems.length);
}
navSetting = navItems.map(function (item) {
var label,
url,
order;
Expand Down Expand Up @@ -146,14 +159,8 @@ NavigationController = Ember.Controller.extend({
url = '/' + url;
}

// if navItem label is empty and URL is still the default, don't save
if (!label && url === '/') {
return;
}

return {label: label, url: url, order: order};
}).compact();

// Sort JSON so nav items are stored in the correct order
navSetting.sort(function (a, b) {
return a.order - b.order;
Expand Down

0 comments on commit 299fbf9

Please sign in to comment.