From b4f4cf794bd365b9fd1cfde32a43667856725074 Mon Sep 17 00:00:00 2001 From: cpradio Date: Sun, 3 Apr 2016 11:33:56 -0400 Subject: [PATCH 1/3] Add warning input to flag dialog Added isWarning property pass is_warning along to post_action Added is_warning to possible arguments to receive from post_actions route Only show warning checkbox for staff Only permit the is_warning argument if the user is staff --- .../discourse/controllers/flag-action-type.js.es6 | 1 + .../javascripts/discourse/controllers/flag.js.es6 | 14 +++++++++++++- .../discourse/models/action-summary.js.es6 | 1 + .../javascripts/discourse/templates/modal/flag.hbs | 4 ++++ app/controllers/post_actions_controller.rb | 1 + app/models/post_action.rb | 3 ++- config/locales/client.en.yml | 1 + 7 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/flag-action-type.js.es6 b/app/assets/javascripts/discourse/controllers/flag-action-type.js.es6 index 4e1ed438c6d..d706a88e1c1 100644 --- a/app/assets/javascripts/discourse/controllers/flag-action-type.js.es6 +++ b/app/assets/javascripts/discourse/controllers/flag-action-type.js.es6 @@ -5,6 +5,7 @@ export default Ember.Controller.extend({ needs: ['flag'], message: Em.computed.alias('controllers.flag.message'), + isWarning: Em.computed.alias('controllers.flag.isWarning'), customPlaceholder: function(){ return I18n.t("flagging.custom_placeholder_" + this.get('model.name_key')); diff --git a/app/assets/javascripts/discourse/controllers/flag.js.es6 b/app/assets/javascripts/discourse/controllers/flag.js.es6 index 5537c7bb6b9..445dd273fa1 100644 --- a/app/assets/javascripts/discourse/controllers/flag.js.es6 +++ b/app/assets/javascripts/discourse/controllers/flag.js.es6 @@ -7,6 +7,7 @@ export default Ember.Controller.extend(ModalFunctionality, { selected: null, flagTopic: null, message: null, + isWarning: false, topicActionByName: null, onShow() { @@ -97,7 +98,7 @@ export default Ember.Controller.extend(ModalFunctionality, { postAction = this.get('topicActionByName.' + this.get('selected.name_key')); } - let params = this.get('selected.is_custom_flag') ? {message: this.get('message')} : {}; + let params = this.get('selected.is_custom_flag') ? {message: this.get('message') } : {}; if (opts) { params = $.extend(params, opts); } this.send('hideModal'); @@ -118,6 +119,11 @@ export default Ember.Controller.extend(ModalFunctionality, { }); }, + createFlagAsWarning() { + this.send('createFlag', {isWarning: true}); + this.set('model.hidden', true); + }, + changePostActionType(action) { this.set('selected', action); }, @@ -133,6 +139,12 @@ export default Ember.Controller.extend(ModalFunctionality, { } }.property('selected.name_key', 'userDetails.can_be_deleted', 'userDetails.can_delete_all_posts'), + canSendWarning: function() { + if (this.get("flagTopic")) return false; + + return (Discourse.User.currentProp('staff') && this.get('selected.name_key') === 'notify_user'); + }.property('selected.name_key'), + usernameChanged: function() { this.set('userDetails', null); this.fetchUserDetails(); diff --git a/app/assets/javascripts/discourse/models/action-summary.js.es6 b/app/assets/javascripts/discourse/models/action-summary.js.es6 index 1a58dc4a0ec..a4f50f52ded 100644 --- a/app/assets/javascripts/discourse/models/action-summary.js.es6 +++ b/app/assets/javascripts/discourse/models/action-summary.js.es6 @@ -59,6 +59,7 @@ export default RestModel.extend({ id: this.get('flagTopic') ? this.get('flagTopic.id') : post.get('id'), post_action_type_id: this.get('id'), message: opts.message, + is_warning: opts.isWarning, take_action: opts.takeAction, flag_topic: this.get('flagTopic') ? true : false }, diff --git a/app/assets/javascripts/discourse/templates/modal/flag.hbs b/app/assets/javascripts/discourse/templates/modal/flag.hbs index 51709ea2dd1..190613c1c84 100644 --- a/app/assets/javascripts/discourse/templates/modal/flag.hbs +++ b/app/assets/javascripts/discourse/templates/modal/flag.hbs @@ -38,6 +38,10 @@