2014-03-05 07:52:20 -05:00
|
|
|
/**
|
|
|
|
This controller supports the interface for dealing with badges.
|
|
|
|
|
|
|
|
@class AdminBadgesController
|
|
|
|
@extends Ember.ArrayController
|
|
|
|
@namespace Discourse
|
|
|
|
@module Discourse
|
|
|
|
**/
|
|
|
|
Discourse.AdminBadgesController = Ember.ArrayController.extend({
|
|
|
|
itemController: 'adminBadge',
|
2014-05-19 01:20:57 -04:00
|
|
|
queryParams: ['badgeId'],
|
|
|
|
|
|
|
|
/**
|
|
|
|
ID of the currently selected badge.
|
|
|
|
|
|
|
|
@property badgeId
|
|
|
|
@type {Integer}
|
|
|
|
**/
|
|
|
|
badgeId: Em.computed.alias('selectedItem.id'),
|
2014-03-05 07:52:20 -05:00
|
|
|
|
|
|
|
/**
|
2014-05-19 00:29:12 -04:00
|
|
|
We don't allow setting a description if a translation for the given badge
|
|
|
|
name exists.
|
2014-03-05 07:52:20 -05:00
|
|
|
|
|
|
|
@property canEditDescription
|
|
|
|
@type {Boolean}
|
|
|
|
**/
|
|
|
|
canEditDescription: Em.computed.none('selectedItem.translatedDescription'),
|
|
|
|
|
2014-03-19 01:13:38 -04:00
|
|
|
/**
|
|
|
|
Disable saving if the currently selected item is being saved.
|
|
|
|
|
|
|
|
@property disableSave
|
|
|
|
@type {Boolean}
|
|
|
|
**/
|
|
|
|
disableSave: Em.computed.alias('selectedItem.saving'),
|
|
|
|
|
2014-03-05 07:52:20 -05:00
|
|
|
actions: {
|
|
|
|
|
|
|
|
/**
|
|
|
|
Create a new badge and select it.
|
|
|
|
|
|
|
|
@method newBadge
|
|
|
|
**/
|
|
|
|
newBadge: function() {
|
|
|
|
var badge = Discourse.Badge.create({
|
|
|
|
name: I18n.t('admin.badges.new_badge')
|
|
|
|
});
|
|
|
|
this.pushObject(badge);
|
|
|
|
this.send('selectBadge', badge);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
Select a particular badge.
|
|
|
|
|
|
|
|
@method selectBadge
|
|
|
|
@param {Discourse.Badge} badge The badge to be selected
|
|
|
|
**/
|
|
|
|
selectBadge: function(badge) {
|
|
|
|
this.set('selectedItem', badge);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
Save the selected badge.
|
|
|
|
|
|
|
|
@method save
|
|
|
|
**/
|
|
|
|
save: function() {
|
2014-03-19 01:13:38 -04:00
|
|
|
if (!this.get('disableSave')) {
|
|
|
|
this.get('selectedItem').save();
|
|
|
|
}
|
2014-03-05 07:52:20 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
Confirm before destroying the selected badge.
|
|
|
|
|
|
|
|
@method destroy
|
|
|
|
**/
|
|
|
|
destroy: function() {
|
2014-05-19 01:20:57 -04:00
|
|
|
// Delete immediately if the selected badge is new.
|
|
|
|
if (!this.get('selectedItem.id')) {
|
|
|
|
this.get('model').removeObject(this.get('selectedItem'));
|
|
|
|
this.set('selectedItem', null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-05 07:52:20 -05:00
|
|
|
var self = this;
|
|
|
|
return bootbox.confirm(I18n.t("admin.badges.delete_confirm"), I18n.t("no_value"), I18n.t("yes_value"), function(result) {
|
|
|
|
if (result) {
|
|
|
|
var selected = self.get('selectedItem');
|
|
|
|
selected.destroy().then(function() {
|
|
|
|
// Success.
|
|
|
|
self.set('selectedItem', null);
|
|
|
|
self.get('model').removeObject(selected);
|
|
|
|
}, function() {
|
|
|
|
// Failure.
|
|
|
|
bootbox.alert(I18n.t('generic_error'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|