2015-03-10 15:01:15 -04:00
|
|
|
import showModal from 'discourse/lib/show-modal';
|
|
|
|
|
2014-10-17 14:27:40 -04:00
|
|
|
export default Ember.Route.extend({
|
2015-03-10 15:01:15 -04:00
|
|
|
serialize(m) {
|
2014-10-17 14:27:40 -04:00
|
|
|
return {badge_id: Em.get(m, 'id') || 'new'};
|
|
|
|
},
|
|
|
|
|
2015-03-10 15:01:15 -04:00
|
|
|
model(params) {
|
2014-10-17 14:27:40 -04:00
|
|
|
if (params.badge_id === "new") {
|
|
|
|
return Discourse.Badge.create({
|
|
|
|
name: I18n.t('admin.badges.new_badge')
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return this.modelFor('adminBadges').findProperty('id', parseInt(params.badge_id));
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
2015-03-10 15:01:15 -04:00
|
|
|
saveError(e) {
|
|
|
|
let msg = I18n.t("generic_error");
|
2014-10-17 14:27:40 -04:00
|
|
|
if (e.responseJSON && e.responseJSON.errors) {
|
|
|
|
msg = I18n.t("generic_error_with_reason", {error: e.responseJSON.errors.join('. ')});
|
|
|
|
}
|
|
|
|
bootbox.alert(msg);
|
|
|
|
},
|
|
|
|
|
2015-03-10 15:01:15 -04:00
|
|
|
editGroupings() {
|
2015-04-09 18:33:37 -04:00
|
|
|
const model = this.controllerFor('admin-badges').get('badgeGroupings');
|
|
|
|
showModal('modals/admin-edit-badge-groupings', { model });
|
2014-10-17 14:27:40 -04:00
|
|
|
},
|
|
|
|
|
2015-03-10 15:01:15 -04:00
|
|
|
preview(badge, explain) {
|
2014-10-17 14:27:40 -04:00
|
|
|
badge.set('preview_loading', true);
|
|
|
|
Discourse.ajax('/admin/badges/preview.json', {
|
|
|
|
method: 'post',
|
|
|
|
data: {
|
|
|
|
sql: badge.get('query'),
|
|
|
|
target_posts: !!badge.get('target_posts'),
|
|
|
|
trigger: badge.get('trigger'),
|
2015-03-10 15:01:15 -04:00
|
|
|
explain
|
2014-10-17 14:27:40 -04:00
|
|
|
}
|
2015-04-09 18:33:37 -04:00
|
|
|
}).then(function(model) {
|
2014-10-17 14:27:40 -04:00
|
|
|
badge.set('preview_loading', false);
|
2015-04-09 18:33:37 -04:00
|
|
|
showModal('modals/admin-badge-preview', { model });
|
2014-10-17 14:27:40 -04:00
|
|
|
}).catch(function(error) {
|
|
|
|
badge.set('preview_loading', false);
|
|
|
|
Em.Logger.error(error);
|
|
|
|
bootbox.alert("Network error");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|