New Feature: Staff can choose to "Take Action" when flagging to immediately reach hiding
thresholds.
This commit is contained in:
@@ -9,70 +9,58 @@
|
||||
**/
|
||||
Discourse.FlagController = Discourse.ObjectController.extend(Discourse.ModalFunctionality, {
|
||||
|
||||
// trick to bind user / post to flag
|
||||
boundFlags: function() {
|
||||
var _this = this;
|
||||
var original = this.get('flagsAvailable');
|
||||
if(original){
|
||||
return $.map(original, function(v){
|
||||
var b = Discourse.BoundPostActionType.create(v);
|
||||
b.set('post', _this.get('model'));
|
||||
return b;
|
||||
});
|
||||
}
|
||||
}.property('flagsAvailable.@each'),
|
||||
|
||||
changePostActionType: function(action) {
|
||||
if (this.get('postActionTypeId') === action.id) return false;
|
||||
|
||||
this.get('boundFlags').setEach('selected', false);
|
||||
action.set('selected', true);
|
||||
|
||||
this.set('postActionTypeId', action.id);
|
||||
this.set('isCustomFlag', action.is_custom_flag);
|
||||
this.set('selected', action);
|
||||
return false;
|
||||
},
|
||||
|
||||
showSubmit: function() {
|
||||
if (this.get('postActionTypeId')) {
|
||||
if (this.get('isCustomFlag')) {
|
||||
var m = this.get('selected.message');
|
||||
return m && m.length >= 10 && m.length <= 500;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
submitEnabled: function() {
|
||||
var selected = this.get('selected');
|
||||
if (!selected) return false;
|
||||
|
||||
if (selected.get('is_custom_flag')) {
|
||||
var len = this.get('message.length') || 0;
|
||||
return len >= Discourse.PostActionType.MIN_MESSAGE_LENGTH &&
|
||||
len <= Discourse.PostActionType.MAX_MESSAGE_LENGTH;
|
||||
}
|
||||
return false;
|
||||
}.property('isCustomFlag', 'selected.customMessageLength', 'postActionTypeId'),
|
||||
return true;
|
||||
}.property('selected.is_custom_flag', 'message.length'),
|
||||
|
||||
submitDisabled: Em.computed.not('submitEnabled'),
|
||||
|
||||
// Staff accounts can "take action"
|
||||
canTakeAction: function() {
|
||||
// We can only take actions on non-custom flags
|
||||
if (this.get('selected.is_custom_flag')) return false;
|
||||
return Discourse.User.current('staff');
|
||||
}.property('selected.is_custom_flag'),
|
||||
|
||||
submitText: function(){
|
||||
var action = this.get('selected');
|
||||
if (this.get('selected.is_custom_flag')) {
|
||||
return Em.String.i18n("flagging.notify_action");
|
||||
} else {
|
||||
return Em.String.i18n("flagging.action");
|
||||
}
|
||||
}.property('selected'),
|
||||
}.property('selected.is_custom_flag'),
|
||||
|
||||
createFlag: function() {
|
||||
var _this = this;
|
||||
takeAction: function() {
|
||||
this.createFlag({takeAction: true})
|
||||
this.set('hidden', true);
|
||||
},
|
||||
|
||||
var action = this.get('selected');
|
||||
var postAction = this.get('actionByName.' + (action.get('name_key')));
|
||||
createFlag: function(opts) {
|
||||
var flagController = this;
|
||||
var postAction = this.get('actionByName.' + this.get('selected.name_key'));
|
||||
var params = this.get('selected.is_custom_flag') ? {message: this.get('message')} : {}
|
||||
|
||||
var actionType = Discourse.Site.instance().postActionTypeById(this.get('postActionTypeId'));
|
||||
if (postAction) {
|
||||
postAction.act({
|
||||
message: action.get('message')
|
||||
}).then(function() {
|
||||
return $('#discourse-modal').modal('hide');
|
||||
}, function(errors) {
|
||||
return _this.displayErrors(errors);
|
||||
});
|
||||
}
|
||||
return false;
|
||||
if (opts) params = $.extend(params, opts);
|
||||
|
||||
postAction.act(params).then(function() {
|
||||
flagController.closeModal();
|
||||
}, function(errors) {
|
||||
flagController.displayErrors(errors);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user