discourse/app/assets/javascripts/admin/routes/admin_badges_route.js

55 lines
1.7 KiB
JavaScript
Raw Normal View History

2014-03-05 07:52:20 -05:00
Discourse.AdminBadgesRoute = Discourse.Route.extend({
setupController: function(controller) {
Discourse.ajax('/admin/badges.json').then(function(json){
2014-07-27 04:22:01 -04:00
controller.set('badgeGroupings', Em.A(json.badge_groupings));
2014-03-05 07:52:20 -05:00
controller.set('badgeTypes', json.badge_types);
controller.set('protectedSystemFields', json.admin_badges.protected_system_fields);
var triggers = [];
_.each(json.admin_badges.triggers,function(v,k){
triggers.push({id: v, name: I18n.t('admin.badges.trigger_type.'+k)});
});
controller.set('badgeTriggers', triggers);
controller.set('model', Discourse.Badge.createFromJson(json));
2014-03-05 07:52:20 -05:00
});
2014-07-27 04:22:01 -04:00
},
actions: {
editGroupings: function(model) {
2014-07-27 04:22:01 -04:00
Discourse.Route.showModal(this, 'admin_edit_badge_groupings', model);
},
saveError: function(jqXhr) {
if (jqXhr.status === 422) {
Discourse.Route.showModal(this, 'admin_badge_preview', jqXhr.responseJSON);
} else {
Em.Logger.error(jqXhr);
bootbox.alert(I18n.t('errors.description.unknown'));
}
},
preview: function(badge, explain) {
var self = this;
badge.set('preview_loading', true);
Discourse.ajax('/admin/badges/preview.json', {
method: 'post',
data: {
sql: badge.query,
target_posts: !!badge.target_posts,
trigger: badge.trigger,
explain: explain
}
}).then(function(json) {
badge.set('preview_loading', false);
Discourse.Route.showModal(self, 'admin_badge_preview', json);
}).catch(function(error) {
badge.set('preview_loading', false);
Em.Logger.error(error);
bootbox.alert("Network error");
});
2014-07-27 04:22:01 -04:00
}
2014-03-05 07:52:20 -05:00
}
});