2015-04-08 13:17:21 -05:00
|
|
|
import Presence from 'discourse/mixins/presence';
|
|
|
|
|
|
|
|
export default Ember.ArrayController.extend(Presence, {
|
2013-02-22 14:41:12 -06:00
|
|
|
filter: null,
|
|
|
|
onlyOverridden: false,
|
2013-11-15 15:43:56 -06:00
|
|
|
filtered: Ember.computed.notEmpty('filter'),
|
2013-02-21 11:58:21 -06:00
|
|
|
|
2013-11-15 15:46:19 -06:00
|
|
|
filterContent: Discourse.debounce(function() {
|
2013-03-01 11:45:25 -06:00
|
|
|
|
|
|
|
// If we have no content, don't bother filtering anything
|
2013-11-14 11:37:41 -06:00
|
|
|
if (!this.present('allSiteSettings')) return;
|
2013-03-01 11:45:25 -06:00
|
|
|
|
2015-03-02 11:12:19 -06:00
|
|
|
let filter;
|
2013-02-22 14:41:12 -06:00
|
|
|
if (this.get('filter')) {
|
|
|
|
filter = this.get('filter').toLowerCase();
|
|
|
|
}
|
2013-02-21 13:42:48 -06:00
|
|
|
|
2013-11-14 11:37:41 -06:00
|
|
|
if ((filter === undefined || filter.length < 1) && !this.get('onlyOverridden')) {
|
|
|
|
this.set('model', this.get('allSiteSettings'));
|
2014-12-29 14:56:33 -06:00
|
|
|
this.transitionToRoute("adminSiteSettings");
|
2013-11-14 11:37:41 -06:00
|
|
|
return;
|
|
|
|
}
|
2013-11-01 15:32:12 -05:00
|
|
|
|
2015-03-02 11:12:19 -06:00
|
|
|
const self = this,
|
|
|
|
matchesGroupedByCategory = [{nameKey: 'all_results', name: I18n.t('admin.site_settings.categories.all_results'), siteSettings: []}];
|
2013-11-14 11:37:41 -06:00
|
|
|
|
2015-03-02 11:12:19 -06:00
|
|
|
this.get('allSiteSettings').forEach(function(settingsCategory) {
|
|
|
|
const matches = settingsCategory.siteSettings.filter(function(item) {
|
2013-11-14 11:37:41 -06:00
|
|
|
if (self.get('onlyOverridden') && !item.get('overridden')) return false;
|
|
|
|
if (filter) {
|
|
|
|
if (item.get('setting').toLowerCase().indexOf(filter) > -1) return true;
|
2014-04-07 10:14:12 -05:00
|
|
|
if (item.get('setting').toLowerCase().replace(/_/g, ' ').indexOf(filter) > -1) return true;
|
2013-11-14 11:37:41 -06:00
|
|
|
if (item.get('description').toLowerCase().indexOf(filter) > -1) return true;
|
|
|
|
if (item.get('value').toLowerCase().indexOf(filter) > -1) return true;
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (matches.length > 0) {
|
2013-11-15 15:43:56 -06:00
|
|
|
matchesGroupedByCategory[0].siteSettings.pushObjects(matches);
|
2013-02-20 12:15:50 -06:00
|
|
|
}
|
2013-11-14 11:37:41 -06:00
|
|
|
});
|
2013-02-21 11:58:21 -06:00
|
|
|
|
2013-11-14 11:37:41 -06:00
|
|
|
this.set('model', matchesGroupedByCategory);
|
2014-12-29 14:56:33 -06:00
|
|
|
this.transitionToRoute("adminSiteSettingsCategory", "all_results");
|
2013-12-20 10:06:07 -06:00
|
|
|
}, 250).observes('filter', 'onlyOverridden'),
|
|
|
|
|
|
|
|
actions: {
|
2015-03-02 11:12:19 -06:00
|
|
|
clearFilter() {
|
2014-12-29 14:56:33 -06:00
|
|
|
this.setProperties({
|
|
|
|
filter: '',
|
|
|
|
onlyOverridden: false
|
|
|
|
});
|
2013-12-20 10:06:07 -06:00
|
|
|
}
|
|
|
|
}
|
2013-03-01 11:45:25 -06:00
|
|
|
|
2013-02-22 14:41:12 -06:00
|
|
|
});
|