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