FIX: Don't lose focus on site settings text field (was changing routes

during filtering)
This commit is contained in:
Robin Ward 2014-11-26 18:01:45 -05:00
parent c7bda41dda
commit 8366fcd78f
2 changed files with 10 additions and 16 deletions

View file

@ -3,29 +3,16 @@ export default Ember.ObjectController.extend({
needs: ['adminSiteSettings'], needs: ['adminSiteSettings'],
filteredContent: function() { filteredContent: function() {
if (!this.get('categoryNameKey')) { return Em.A(); } if (!this.get('categoryNameKey')) { return []; }
var category = this.get('controllers.adminSiteSettings.content').find(function(siteSettingCategory) {
return siteSettingCategory.nameKey === this.get('categoryNameKey');
}, this);
var category = this.get('controllers.adminSiteSettings.content').findProperty('nameKey', this.get('categoryNameKey'));
if (category) { if (category) {
return category.siteSettings; return category.siteSettings;
} else { } else {
return Em.A(); return [];
} }
}.property('controllers.adminSiteSettings.content', 'categoryNameKey'), }.property('controllers.adminSiteSettings.content', 'categoryNameKey'),
emptyContentHandler: function() {
if (this.get('filteredContent').length < 1) {
if ( this.get('controllers.adminSiteSettings.filtered') ) {
this.transitionToRoute('adminSiteSettingsCategory', 'all_results');
} else {
this.transitionToRoute('adminSiteSettings');
}
}
}.observes('filteredContent'),
actions: { actions: {
/** /**

View file

@ -8,6 +8,13 @@
**/ **/
Discourse.AdminSiteSettingsCategoryRoute = Discourse.Route.extend({ Discourse.AdminSiteSettingsCategoryRoute = Discourse.Route.extend({
model: function(params) { model: function(params) {
if (params.category_id === "all_results") {
var category = this.controllerFor('adminSiteSettings').get('content').findProperty('nameKey', 'all_results');
if (!category || !category.siteSettings.length) {
this.replaceWith('adminSiteSettings.index');
return;
}
}
// The model depends on user input, so let the controller do the work: // The model depends on user input, so let the controller do the work:
this.controllerFor('adminSiteSettingsCategory').set('categoryNameKey', params.category_id); this.controllerFor('adminSiteSettingsCategory').set('categoryNameKey', params.category_id);
return Em.Object.create({ return Em.Object.create({