From e969eb14e8f3ba997abd424383dd9922efb1c86a Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 12 Apr 2013 17:55:45 +1000 Subject: [PATCH] added 2 new flag types: notify user and notify moderators fixed up messed up user navigation refactored --- .../discourse/models/action_summary.js | 12 +-- .../javascripts/discourse/models/post.js | 3 +- .../discourse/models/post_action_type.js | 27 ++++++- .../javascripts/discourse/models/site.js | 6 +- .../discourse/routes/user_activity_route.js | 8 +- .../discourse/templates/flag.js.handlebars | 16 ++-- .../discourse/views/modal/flag_view.js | 73 +++++++++---------- .../stylesheets/application/modal.css.scss | 8 ++ app/models/post_action.rb | 39 ++++++++++ app/models/post_action_type.rb | 6 +- .../post_action_type_serializer.rb | 3 +- app/serializers/user_serializer.rb | 3 +- config/locales/client.en.yml | 20 +++-- config/locales/server.en.yml | 14 +++- db/fixtures/post_action_types.rb | 11 ++- .../20130412015502_correct_counts_on_posts.rb | 6 ++ ...20130412020156_correct_counts_on_topics.rb | 6 ++ lib/guardian.rb | 1 + spec/models/post_action_spec.rb | 9 +++ spec/spec_helper.rb | 4 + 20 files changed, 201 insertions(+), 74 deletions(-) create mode 100644 db/migrate/20130412015502_correct_counts_on_posts.rb create mode 100644 db/migrate/20130412020156_correct_counts_on_topics.rb diff --git a/app/assets/javascripts/discourse/models/action_summary.js b/app/assets/javascripts/discourse/models/action_summary.js index d4009f989..ac89f2bd4 100644 --- a/app/assets/javascripts/discourse/models/action_summary.js +++ b/app/assets/javascripts/discourse/models/action_summary.js @@ -9,7 +9,7 @@ Discourse.ActionSummary = Discourse.Model.extend({ // Description for the action - description: (function() { + description: function() { var action = this.get('actionType.name_key'); if (this.get('acted')) { if (this.get('count') <= 1) { @@ -20,12 +20,12 @@ Discourse.ActionSummary = Discourse.Model.extend({ } else { return Em.String.i18n('post.actions.by_others.' + action, { count: this.get('count') }); } - }).property('count', 'acted', 'actionType'), + }.property('count', 'acted', 'actionType'), - canAlsoAction: (function() { + canAlsoAction: function() { if (this.get('hidden')) return false; return this.get('can_act'); - }).property('can_act', 'hidden'), + }.property('can_act', 'hidden'), // Remove it removeAction: function() { @@ -37,12 +37,13 @@ Discourse.ActionSummary = Discourse.Model.extend({ // Perform this action act: function(opts) { + var action = this.get('actionType.name_key'); // Mark it as acted this.set('acted', true); this.set('count', this.get('count') + 1); this.set('can_act', false); - this.set('can_undo', true); + this.set('can_undo', action != 'notify_moderators' && action != 'notify_user'); // Add ourselves to the users who liked it if present if (this.present('users')) { @@ -108,5 +109,4 @@ Discourse.ActionSummary = Discourse.Model.extend({ }); }); } - }); diff --git a/app/assets/javascripts/discourse/models/post.js b/app/assets/javascripts/discourse/models/post.js index ecb8796a6..e2e57d0d4 100644 --- a/app/assets/javascripts/discourse/models/post.js +++ b/app/assets/javascripts/discourse/models/post.js @@ -112,9 +112,10 @@ Discourse.Post = Discourse.Model.extend({ flagsAvailable: (function() { var _this = this; - return Discourse.get('site.flagTypes').filter(function(item) { + flags = Discourse.get('site.flagTypes').filter(function(item) { return _this.get("actionByName." + (item.get('name_key')) + ".can_act"); }); + return flags; }).property('Discourse.site.flagTypes', 'actions_summary.@each.can_act'), actionsHistory: (function() { diff --git a/app/assets/javascripts/discourse/models/post_action_type.js b/app/assets/javascripts/discourse/models/post_action_type.js index 309ea926e..25bd59371 100644 --- a/app/assets/javascripts/discourse/models/post_action_type.js +++ b/app/assets/javascripts/discourse/models/post_action_type.js @@ -7,5 +7,30 @@ @module Discourse **/ Discourse.PostActionType = Discourse.Model.extend({ - +}); + +Discourse.BoundPostActionType = Discourse.PostActionType.extend({ + customPlaceholder: function(){ + return Em.String.i18n("flagging.custom_placeholder_" + this.get('name_key')); + }.property('name_key'), + + formattedName: function(){ + return this.get('name').replace("{{username}}", this.get('post.username')); + }.property('name'), + + messageChanged: function() { + var len, message, minLen, _ref; + minLen = 10; + len = ((_ref = this.get('message')) ? _ref.length : void 0) || 0; + this.set("customMessageLengthClasses", "too-short custom-message-length"); + if (len === 0) { + message = Em.String.i18n("flagging.custom_message.at_least", { n: minLen }); + } else if (len < minLen) { + message = Em.String.i18n("flagging.custom_message.more", { n: minLen - len }); + } else { + message = Em.String.i18n("flagging.custom_message.left", { n: 500 - len }); + this.set("customMessageLengthClasses", "ok custom-message-length"); + } + this.set("customMessageLength", message); + }.observes("message") }); diff --git a/app/assets/javascripts/discourse/models/site.js b/app/assets/javascripts/discourse/models/site.js index 677425ccf..ce3ac8a90 100644 --- a/app/assets/javascripts/discourse/models/site.js +++ b/app/assets/javascripts/discourse/models/site.js @@ -17,14 +17,14 @@ Discourse.Site = Discourse.Model.extend({ return result; }).property('notification_types'), - flagTypes: (function() { + flagTypes: function() { var postActionTypes; postActionTypes = this.get('post_action_types'); if (!postActionTypes) { return []; } return postActionTypes.filterProperty('is_flag', true); - }).property('post_action_types.@each'), + }.property('post_action_types.@each'), postActionTypeById: function(id) { return this.get("postActionByIdLookup.action" + id); @@ -49,7 +49,7 @@ Discourse.Site.reopenClass({ result.postActionByIdLookup = Em.Object.create(); result.post_action_types = result.post_action_types.map(function(p) { var actionType; - actionType = Discourse.Model.create(p); + actionType = Discourse.PostActionType.create(p); result.postActionByIdLookup.set("action" + p.id, actionType); return actionType; }); diff --git a/app/assets/javascripts/discourse/routes/user_activity_route.js b/app/assets/javascripts/discourse/routes/user_activity_route.js index d206bce8a..f07d84a47 100644 --- a/app/assets/javascripts/discourse/routes/user_activity_route.js +++ b/app/assets/javascripts/discourse/routes/user_activity_route.js @@ -14,8 +14,12 @@ Discourse.UserActivityRoute = Discourse.Route.extend({ setupController: function(controller) { var userController = this.controllerFor('user'); - userController.set('filter', null); - controller.set('content', userController.get('content')); + var user = userController.get('content'); + controller.set('content', user); + user.set('filter', null); + if (user.get('streamFilter')) { + user.filterStream(null); + } } }); diff --git a/app/assets/javascripts/discourse/templates/flag.js.handlebars b/app/assets/javascripts/discourse/templates/flag.js.handlebars index 3d1f3e289..eb5f2cb81 100644 --- a/app/assets/javascripts/discourse/templates/flag.js.handlebars +++ b/app/assets/javascripts/discourse/templates/flag.js.handlebars @@ -1,13 +1,13 @@ -