mirror of
https://github.com/discourse/discourse.git
synced 2026-08-13 06:25:11 -05:00
Fixes some Ember Deprecations for 1.13:
- Remove ArrayController
- Remove {{view}} from templates
- Replace many cases of needs: [‘controller’] with inject
- Enable Ember Legacy Views
This commit is contained in:
@@ -3,14 +3,14 @@ import BufferedContent from 'discourse/mixins/buffered-content';
|
||||
import { propertyNotEqual } from 'discourse/lib/computed';
|
||||
|
||||
export default Ember.Controller.extend(BufferedContent, {
|
||||
needs: ['admin-badges'],
|
||||
adminBadges: Ember.inject.controller(),
|
||||
saving: false,
|
||||
savingStatus: '',
|
||||
|
||||
badgeTypes: Em.computed.alias('controllers.admin-badges.badgeTypes'),
|
||||
badgeGroupings: Em.computed.alias('controllers.admin-badges.badgeGroupings'),
|
||||
badgeTriggers: Em.computed.alias('controllers.admin-badges.badgeTriggers'),
|
||||
protectedSystemFields: Em.computed.alias('controllers.admin-badges.protectedSystemFields'),
|
||||
badgeTypes: Em.computed.alias('adminBadges.badgeTypes'),
|
||||
badgeGroupings: Em.computed.alias('adminBadges.badgeGroupings'),
|
||||
badgeTriggers: Em.computed.alias('adminBadges.badgeTriggers'),
|
||||
protectedSystemFields: Em.computed.alias('adminBadges.protectedSystemFields'),
|
||||
|
||||
readOnly: Ember.computed.alias('buffered.system'),
|
||||
showDisplayName: propertyNotEqual('name', 'displayName'),
|
||||
@@ -30,16 +30,15 @@ export default Ember.Controller.extend(BufferedContent, {
|
||||
}.observes('model.id'),
|
||||
|
||||
actions: {
|
||||
save: function() {
|
||||
save() {
|
||||
if (!this.get('saving')) {
|
||||
var fields = ['allow_title', 'multiple_grant',
|
||||
'listable', 'auto_revoke',
|
||||
'enabled', 'show_posts',
|
||||
'target_posts', 'name', 'description',
|
||||
'long_description',
|
||||
'icon', 'image', 'query', 'badge_grouping_id',
|
||||
'trigger', 'badge_type_id'],
|
||||
self = this;
|
||||
let fields = ['allow_title', 'multiple_grant',
|
||||
'listable', 'auto_revoke',
|
||||
'enabled', 'show_posts',
|
||||
'target_posts', 'name', 'description',
|
||||
'long_description',
|
||||
'icon', 'image', 'query', 'badge_grouping_id',
|
||||
'trigger', 'badge_type_id'];
|
||||
|
||||
if (this.get('buffered.system')){
|
||||
var protectedFields = this.get('protectedSystemFields');
|
||||
@@ -51,54 +50,55 @@ export default Ember.Controller.extend(BufferedContent, {
|
||||
this.set('saving', true);
|
||||
this.set('savingStatus', I18n.t('saving'));
|
||||
|
||||
var boolFields = ['allow_title', 'multiple_grant',
|
||||
'listable', 'auto_revoke',
|
||||
'enabled', 'show_posts',
|
||||
'target_posts' ];
|
||||
const boolFields = ['allow_title', 'multiple_grant',
|
||||
'listable', 'auto_revoke',
|
||||
'enabled', 'show_posts',
|
||||
'target_posts' ];
|
||||
|
||||
var data = {},
|
||||
buffered = this.get('buffered');
|
||||
const data = {};
|
||||
const buffered = this.get('buffered');
|
||||
fields.forEach(function(field){
|
||||
var d = buffered.get(field);
|
||||
if (_.include(boolFields, field)) { d = !!d; }
|
||||
data[field] = d;
|
||||
});
|
||||
|
||||
var newBadge = !this.get('id'),
|
||||
model = this.get('model');
|
||||
this.get('model').save(data).then(function() {
|
||||
const newBadge = !this.get('id');
|
||||
const model = this.get('model');
|
||||
this.get('model').save(data).then(() => {
|
||||
if (newBadge) {
|
||||
var adminBadgesController = self.get('controllers.admin-badges');
|
||||
if (!adminBadgesController.contains(model)) adminBadgesController.pushObject(model);
|
||||
self.transitionToRoute('adminBadges.show', model.get('id'));
|
||||
const adminBadges = this.get('adminBadges.model');
|
||||
if (!adminBadges.contains(model)) {
|
||||
adminBadges.pushObject(model);
|
||||
}
|
||||
this.transitionToRoute('adminBadges.show', model.get('id'));
|
||||
} else {
|
||||
self.commitBuffer();
|
||||
self.set('savingStatus', I18n.t('saved'));
|
||||
this.commitBuffer();
|
||||
this.set('savingStatus', I18n.t('saved'));
|
||||
}
|
||||
|
||||
}).catch(popupAjaxError).finally(function() {
|
||||
self.set('saving', false);
|
||||
self.set('savingStatus', '');
|
||||
}).catch(popupAjaxError).finally(() => {
|
||||
this.set('saving', false);
|
||||
this.set('savingStatus', '');
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
var self = this,
|
||||
adminBadgesController = this.get('controllers.admin-badges'),
|
||||
model = this.get('model');
|
||||
destroy() {
|
||||
const adminBadges = this.get('adminBadges.model');
|
||||
const model = this.get('model');
|
||||
|
||||
if (!model.get('id')) {
|
||||
self.transitionToRoute('adminBadges.index');
|
||||
this.transitionToRoute('adminBadges.index');
|
||||
return;
|
||||
}
|
||||
|
||||
return bootbox.confirm(I18n.t("admin.badges.delete_confirm"), I18n.t("no_value"), I18n.t("yes_value"), function(result) {
|
||||
return bootbox.confirm(I18n.t("admin.badges.delete_confirm"), I18n.t("no_value"), I18n.t("yes_value"), result => {
|
||||
if (result) {
|
||||
model.destroy().then(function() {
|
||||
adminBadgesController.removeObject(model);
|
||||
self.transitionToRoute('adminBadges.index');
|
||||
}).catch(function() {
|
||||
model.destroy().then(() => {
|
||||
adminBadges.removeObject(model);
|
||||
this.transitionToRoute('adminBadges.index');
|
||||
}).catch(() => {
|
||||
bootbox.alert(I18n.t('generic_error'));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user