FEATURE: adds an API to register topic footer buttons

FEATURE: adds an API to register topic footer buttons

diff --git a/app/assets/javascripts/discourse/components/d-button.js.es6 b/app/assets/javascripts/discourse/components/d-button.js.es6
index 67132bf..8b96429 100644
--- a/app/assets/javascripts/discourse/components/d-button.js.es6
+++ b/app/assets/javascripts/discourse/components/d-button.js.es6
@@ -39,7 +39,12 @@ export default Ember.Component.extend({
   click() {
     if (typeof this.get("action") === "string") {
       this.sendAction("action", this.get("actionParam"));
-    } else {
+    } else if (
+      typeof this.get("action") === "object" &&
+      this.get("action").value
+    ) {
+      this.get("action").value(this.get("actionParam"));
+    } else if (typeof this.get("action") === "function") {
       this.get("action")(this.get("actionParam"));
     }
 
diff --git a/app/assets/javascripts/discourse/components/topic-footer-buttons.js.es6 b/app/assets/javascripts/discourse/components/topic-footer-buttons.js.es6
index 17b440d..a46a9a5 100644
--- a/app/assets/javascripts/discourse/components/topic-footer-buttons.js.es6
+++ b/app/assets/javascripts/discourse/components/topic-footer-buttons.js.es6
@@ -1,4 +1,5 @@
 import computed from "ember-addons/ember-computed-decorators";
+import { getTopicFooterButtons } from "discourse/lib/register-topic-footer-button";
 
 export default Ember.Component.extend({
   elementId: "topic-footer-buttons",
@@ -11,6 +12,19 @@ export default Ember.Component.extend({
     return this.siteSettings.enable_personal_messages && isPM;
   },
 
+  buttons: getTopicFooterButtons(),
+
+  @computed("buttons.[]")
+  inlineButtons(buttons) {
+    return buttons.filter(button => !button.dropdown);
+  },
+
+  // topic.assigned_to_user is for backward plugin support
+  @computed("buttons.[]", "topic.assigned_to_user")
+  dropdownButtons(buttons) {
+    return buttons.filter(button => button.dropdown);
+  },
+
   @computed("topic.isPrivateMessage")
   showNotificationsButton(isPM) {
     return !isPM || this.siteSettings.enable_personal_messages;
@@ -50,17 +64,5 @@ export default Ember.Component.extend({
 
   @computed("topic.message_archived")
   archiveLabel: archived =>
-    archived ? "topic.move_to_inbox.title" : "topic.archive_message.title",
-
-  @computed("topic.bookmarked")
-  bookmarkClass: bookmarked =>
-    bookmarked ? "bookmark bookmarked" : "bookmark",
-
-  @computed("topic.bookmarked")
-  bookmarkLabel: bookmarked =>
-    bookmarked ? "bookmarked.clear_bookmarks" : "bookmarked.title",
-
-  @computed("topic.bookmarked")
-  bookmarkTitle: bookmarked =>
-    bookmarked ? "bookmarked.help.unbookmark" : "bookmarked.help.bookmark"
+    archived ? "topic.move_to_inbox.title" : "topic.archive_message.title"
 });
diff --git a/app/assets/javascripts/discourse/initializers/topic-footer-buttons.js.es6 b/app/assets/javascripts/discourse/initializers/topic-footer-buttons.js.es6
new file mode 100644
index 0000000..61d84ab
--- /dev/null
+++ b/app/assets/javascripts/discourse/initializers/topic-footer-buttons.js.es6
@@ -0,0 +1,138 @@
+import { registerTopicFooterButton } from "discourse/lib/register-topic-footer-button";
+
+export default {
+  name: "topic-footer-buttons",
+
+  initialize() {
+    registerTopicFooterButton({
+      id: "share",
+      icon: "link",
+      priority: 999,
+      label: "topic.share.title",
+      title: "topic.share.help",
+      action() {
+        this.appEvents.trigger(
+          "share:url",
+          this.get("topic.shareUrl"),
+          $("#topic-footer-buttons")
+        );
+      },
+      dropdown() {
+        return this.site.mobileView;
+      },
+      classNames: ["share"],
+      dependentKeys: ["topic.shareUrl", "topic.isPrivateMessage"],
+      displayed() {
+        return !this.get("topic.isPrivateMessage");
+      }
+    });
+
+    registerTopicFooterButton({
+      id: "flag",
+      icon: "flag",
+      priority: 998,
+      label: "topic.flag_topic.title",
+      title: "topic.flag_topic.help",
+      action: "showFlagTopic",
+      dropdown() {
+        return this.site.mobileView;
+      },
+      classNames: ["flag-topic"],
+      dependentKeys: ["topic.details.can_flag_topic", "topic.isPrivateMessage"],
+      displayed() {
+        return (
+          this.get("topic.details.can_flag_topic") &&
+          !this.get("topic.isPrivateMessage")
+        );
+      }
+    });
+
+    registerTopicFooterButton({
+      id: "invite",
+      icon: "users",
+      priority: 997,
+      label: "topic.invite_reply.title",
+      title: "topic.invite_reply.help",
+      action: "showInvite",
+      dropdown() {
+        return this.site.mobileView;
+      },
+      classNames: ["invite-topic"],
+      dependentKeys: ["canInviteTo", "inviteDisabled"],
+      displayed() {
+        return this.get("canInviteTo");
+      },
+      disabled() {
+        return this.get("inviteDisabled");
+      }
+    });
+
+    registerTopicFooterButton({
+      dependentKeys: ["topic.bookmarked", "topic.isPrivateMessage"],
+      id: "bookmark",
+      icon: "bookmark",
+      priority: 1000,
+      classNames() {
+        const bookmarked = this.get("topic.bookmarked");
+        return bookmarked ? ["bookmark", "bookmarked"] : ["bookmark"];
+      },
+      label() {
+        const bookmarked = this.get("topic.bookmarked");
+        return bookmarked ? "bookmarked.clear_bookmarks" : "bookmarked.title";
+      },
+      title() {
+        const bookmarked = this.get("topic.bookmarked");
+        return bookmarked
+          ? "bookmarked.help.unbookmark"
+          : "bookmarked.help.bookmark";
+      },
+      action: "toggleBookmark",
+      dropdown() {
+        return this.site.mobileView;
+      },
+      displayed() {
+        return !this.get("topic.isPrivateMessage");
+      }
+    });
+
+    registerTopicFooterButton({
+      id: "archive",
+      priority: 1001,
+      icon() {
+        return this.get("archiveIcon");
+      },
+      label() {
+        return this.get("archiveLabel");
+      },
+      title() {
+        return this.get("archiveTitle");
+      },
+      action: "toggleArchiveMessage",
+      classNames: ["standard", "archive-topic"],
+      dependentKeys: [
+        "canArchive",
+        "archiveIcon",
+        "archiveLabel",
+        "archiveTitle",
+        "toggleArchiveMessage"
+      ],
+      displayed() {
+        return this.get("canArchive");
+      }
+    });
+
+    registerTopicFooterButton({
+      id: "edit-message",
+      priority: 750,
+      icon: "pencil-alt",
+      label: "topic.edit_message.title",
+      title: "topic.edit_message.help",
+      action: "editFirstPost",
+      classNames: ["edit-message"],
+      dependentKeys: ["editFirstPost", "showEditOnFooter"],
+      displayed() {
+        return this.get("showEditOnFooter");
+      }
+    });
+  }
+};
diff --git a/app/assets/javascripts/discourse/lib/plugin-api.js.es6 b/app/assets/javascripts/discourse/lib/plugin-api.js.es6
index ecce020..e174b58 100644
--- a/app/assets/javascripts/discourse/lib/plugin-api.js.es6
+++ b/app/assets/javascripts/discourse/lib/plugin-api.js.es6
@@ -19,6 +19,7 @@ import { addFlagProperty } from "discourse/components/site-header";
 import { addPopupMenuOptionsCallback } from "discourse/controllers/composer";
 import { extraConnectorClass } from "discourse/lib/plugin-connectors";
 import { addPostSmallActionIcon } from "discourse/widgets/post-small-action";
+import { registerTopicFooterButton } from "discourse/lib/register-topic-footer-button";
 import { addDiscoveryQueryParam } from "discourse/controllers/discovery-sortable";
 import { addTagsHtmlCallback } from "discourse/lib/render-tags";
 import { addUserMenuGlyph } from "discourse/widgets/user-menu";
@@ -41,7 +42,7 @@ import Sharing from "discourse/lib/sharing";
 import { addComposerUploadHandler } from "discourse/components/composer-editor";
 
 // If you add any methods to the API ensure you bump up this number
-const PLUGIN_API_VERSION = "0.8.27";
+const PLUGIN_API_VERSION = "0.8.28";
 
 class PluginApi {
   constructor(version, container) {

[... diff too long, it was truncated ...]

GitHub sha: 6c195640

1 Like