Fire appEvents as users take action (#19)

Fire appEvents as users take action (#19)

diff --git a/assets/javascripts/discourse/components/endorsement-button.js b/assets/javascripts/discourse/components/endorsement-button.js
index 4cba71a..a16a07b 100644
--- a/assets/javascripts/discourse/components/endorsement-button.js
+++ b/assets/javascripts/discourse/components/endorsement-button.js
@@ -49,11 +49,20 @@ export default Component.extend({
       this.close();
     }
 
+    if (this.location) {
+      this.appEvents.trigger("category-experts:endorse-clicked", {
+        location: this.location,
+        user_id: this.currentUser.id,
+        endorsed_user_id: this.user.id,
+      });
+    }
+
     showModal("endorse-user", {
       model: {
         categories: this.categoriesAllowingEndorsements,
         user: this.user,
         endorsements: this.endorsements,
+        location: this.location
       },
       title: "category_experts.manage_endorsements.title",
     });
diff --git a/assets/javascripts/discourse/components/endorsement-checkboxes.js b/assets/javascripts/discourse/components/endorsement-checkboxes.js
index acc036b..cc80bab 100644
--- a/assets/javascripts/discourse/components/endorsement-checkboxes.js
+++ b/assets/javascripts/discourse/components/endorsement-checkboxes.js
@@ -72,6 +72,15 @@ export default Component.extend({
             saving: false,
           });
         }, 300);
+
+        if (this.location) {
+          this.appEvents.trigger("category-experts:endorsement-given", {
+            location: this.location,
+            user_id: this.currentUser.id,
+            categoryIds: this.selectedCategoryIds,
+            endorsed_user_id: this.user.id,
+          });
+        }
       })
       .catch(popupAjaxError);
   },
diff --git a/assets/javascripts/discourse/connectors/user-card-additional-buttons/endorsement-button.hbs b/assets/javascripts/discourse/connectors/user-card-additional-buttons/endorsement-button.hbs
index 7e70467..57d70dd 100644
--- a/assets/javascripts/discourse/connectors/user-card-additional-buttons/endorsement-button.hbs
+++ b/assets/javascripts/discourse/connectors/user-card-additional-buttons/endorsement-button.hbs
@@ -1 +1 @@
-{{endorsement-button user=user close=close}}
+{{endorsement-button user=user close=close location="user-card"}}
diff --git a/assets/javascripts/discourse/connectors/user-profile-controls/endorsement-button.hbs b/assets/javascripts/discourse/connectors/user-profile-controls/endorsement-button.hbs
index 7758aed..45f83a8 100644
--- a/assets/javascripts/discourse/connectors/user-profile-controls/endorsement-button.hbs
+++ b/assets/javascripts/discourse/connectors/user-profile-controls/endorsement-button.hbs
@@ -1 +1 @@
-{{endorsement-button user=model}}
+{{endorsement-button user=model location="user-profile"}}
diff --git a/assets/javascripts/discourse/templates/modal/endorse-user.hbs b/assets/javascripts/discourse/templates/modal/endorse-user.hbs
index 00bac57..1b18bfc 100644
--- a/assets/javascripts/discourse/templates/modal/endorse-user.hbs
+++ b/assets/javascripts/discourse/templates/modal/endorse-user.hbs
@@ -2,5 +2,6 @@
   categories=model.categories
   user=model.user
   endorsements=model.endorsements
+  location=model.location
   afterSave=afterSave
   }}

GitHub sha: f9d8ec24

This commit appears in #19 which was approved by pmusaraj. It was merged by markvanlan.