discourse/app/assets/javascripts/admin/controllers/admin-site-settings.js.es6

77 lines
2.5 KiB
Plaintext
Raw Normal View History

2015-08-11 05:11:27 +08:00
import debounce from 'discourse/lib/debounce';
2015-04-09 02:17:21 +08:00
export default Ember.Controller.extend({
filter: null,
onlyOverridden: false,
filtered: Ember.computed.notEmpty('filter'),
filterContentNow(category) {
// If we have no content, don't bother filtering anything
if (!!Ember.isEmpty(this.get('allSiteSettings'))) return;
2015-03-03 01:12:19 +08:00
let filter;
if (this.get('filter')) {
filter = this.get('filter').toLowerCase();
}
if ((filter === undefined || filter.length < 1) && !this.get('onlyOverridden')) {
this.set('model', this.get('allSiteSettings'));
2014-12-30 04:56:33 +08:00
this.transitionToRoute("adminSiteSettings");
return;
}
const all = {nameKey: 'all_results', name: I18n.t('admin.site_settings.categories.all_results'), siteSettings: []};
const matchesGroupedByCategory = [all];
const matches = [];
this.get('allSiteSettings').forEach(settingsCategory => {
const siteSettings = settingsCategory.siteSettings.filter(item => {
if (this.get('onlyOverridden') && !item.get('overridden')) return false;
if (filter) {
if (item.get('setting').toLowerCase().indexOf(filter) > -1) return true;
if (item.get('setting').toLowerCase().replace(/_/g, ' ').indexOf(filter) > -1) return true;
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 (siteSettings.length > 0) {
matches.pushObjects(siteSettings);
2015-06-09 20:34:06 +08:00
matchesGroupedByCategory.pushObject({
nameKey: settingsCategory.nameKey,
name: I18n.t('admin.site_settings.categories.' + settingsCategory.nameKey),
siteSettings,
count: siteSettings.length
2015-06-09 20:34:06 +08:00
});
}
});
all.siteSettings.pushObjects(matches.slice(0, 30));
all.count = matches.length;
this.set('model', matchesGroupedByCategory);
this.transitionToRoute("adminSiteSettingsCategory", category || "all_results");
},
2015-08-11 05:11:27 +08:00
filterContent: debounce(function() {
if (this.get("_skipBounce")) {
this.set("_skipBounce", false);
} else {
this.filterContentNow();
}
}, 250).observes('filter', 'onlyOverridden'),
actions: {
2015-03-03 01:12:19 +08:00
clearFilter() {
this.setProperties({ filter: '', onlyOverridden: false });
2015-08-17 01:35:23 +08:00
},
toggleMenu() {
$('.admin-detail').toggleClass('mobile-closed mobile-open');
}
}
});