mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-12 16:51:14 -05:00
0cbdf6f5bb
* Editing a badge's title would show it as changed in the side even if you didn't hit save * Clicking a badge would not scroll to the top * If there was an error saving a badge there was a missing i18n key * URLs were using queryParams instead of paths * User `label` tags for checkboxes for larger click targets * Saved! text would persist when viewing another badge * After creating a new badge it would show nothing * Validation errors were not being properly released to the client * Query errors were surrounded by an extra array
52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
export default Ember.Route.extend({
|
|
serialize: function(m) {
|
|
return {badge_id: Em.get(m, 'id') || 'new'};
|
|
},
|
|
|
|
model: function(params) {
|
|
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: {
|
|
saveError: function(e) {
|
|
var msg = I18n.t("generic_error");
|
|
if (e.responseJSON && e.responseJSON.errors) {
|
|
msg = I18n.t("generic_error_with_reason", {error: e.responseJSON.errors.join('. ')});
|
|
}
|
|
bootbox.alert(msg);
|
|
},
|
|
|
|
editGroupings: function() {
|
|
var groupings = this.controllerFor('admin-badges').get('badgeGroupings');
|
|
Discourse.Route.showModal(this, 'admin_edit_badge_groupings', groupings);
|
|
},
|
|
|
|
preview: function(badge, explain) {
|
|
var self = this;
|
|
|
|
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'),
|
|
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");
|
|
});
|
|
}
|
|
}
|
|
|
|
});
|