FIX: uses taskActions api and removes old buttons (#44)

FIX: uses taskActions api and removes old buttons (#44)

diff --git a/assets/javascripts/discourse-assign/connectors/topic-footer-main-buttons-before-create/assign-button.hbs b/assets/javascripts/discourse-assign/connectors/topic-footer-main-buttons-before-create/assign-button.hbs
deleted file mode 100644
index 9c40acf..0000000
--- a/assets/javascripts/discourse-assign/connectors/topic-footer-main-buttons-before-create/assign-button.hbs
+++ /dev/null
@@ -1,15 +0,0 @@
-{{#unless site.mobileView}}
-  {{#if topic.assigned_to_user.username}}
-  {{d-button class="btn-default assign"
-             icon="user-times"
-             action=(action "unassign")
-             label="discourse_assign.unassign.title"
-             title="discourse_assign.unassign.help"}}
-  {{else}}
-  {{d-button class="btn-default assign"
-             icon="user-plus"
-             action=(action "assign")
-             label="discourse_assign.assign.title"
-             title="discourse_assign.assign.help"}}
-  {{/if}}
-{{/unless}}
diff --git a/assets/javascripts/discourse-assign/connectors/topic-footer-main-buttons-before-create/assign-button.js.es6 b/assets/javascripts/discourse-assign/connectors/topic-footer-main-buttons-before-create/assign-button.js.es6
deleted file mode 100644
index 82366b9..0000000
--- a/assets/javascripts/discourse-assign/connectors/topic-footer-main-buttons-before-create/assign-button.js.es6
+++ /dev/null
@@ -1,27 +0,0 @@
-import { getOwner } from "discourse-common/lib/get-owner";
-
-export default {
-  shouldRender(args, component) {
-    const needsButton =
-      component.currentUser && component.currentUser.get("can_assign");
-    return (
-      needsButton &&
-      (!component.get("site.mobileView") || args.topic.get("isPrivateMessage"))
-    );
-  },
-
-  setupComponent(args, component) {
-    const taskActions = getOwner(this).lookup("service:task-actions");
-    component.set("taskActions", taskActions);
-  },
-
-  actions: {
-    unassign() {
-      this.set("topic.assigned_to_user", null);
-      this.taskActions.unassign(this.get("topic.id"));
-    },
-    assign() {
-      this.taskActions.assign(this.topic);
-    }
-  }
-};
diff --git a/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6 b/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6
index 15ab267..9e3c4c6 100644
--- a/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6
+++ b/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6
@@ -1,15 +1,12 @@
 import { withPluginApi } from "discourse/lib/plugin-api";
 import { default as computed } from "ember-addons/ember-computed-decorators";
-import { ajax } from "discourse/lib/ajax";
-
-// should this be in API ?
-import showModal from "discourse/lib/show-modal";
 import { iconNode } from "discourse-common/lib/icon-library";
 import { h } from "virtual-dom";
 import { iconHTML } from "discourse-common/lib/icon-library";
 
 // TODO: This has to be removed when 2.3 becomes the new stable version.
 import { ListItemDefaults } from "discourse/components/topic-list-item";
+import { getOwner } from "discourse-common/lib/get-owner";
 
 function registerTopicFooterButtons(api) {
   api.registerTopicFooterButton({
@@ -32,28 +29,15 @@ function registerTopicFooterButtons(api) {
         return;
       }
 
+      const taskActions = getOwner(this).lookup("service:task-actions");
       const topic = this.topic;
       const assignedUser = topic.get("assigned_to_user.username");
 
       if (assignedUser) {
-        ajax("/assign/unassign", {
-          type: "PUT",
-          data: { topic_id: topic.id }
-        }).then(result => {
-          if (result.success && result.success === "OK") {
-            topic.set("assigned_to_user", null);
-          }
-        });
+        this.set("topic.assigned_to_user", null);
+        taskActions.unassign(topic.id);
       } else {
-        showModal("assign-user", {
-          model: {
-            topic,
-            username: topic.get("assigned_to_user.username"),
-            onClose: assignedToUser => {
-              topic.set("assigned_to_user", assignedToUser);
-            }
-          }
-        });
+        taskActions.assign(topic);
       }
     },
     dropdown() {
@@ -67,7 +51,7 @@ function registerTopicFooterButtons(api) {
       "topic.assigned_to_user.username"
     ],
     displayed() {
-      return this.get("currentUser.staff");
+      return this.currentUser && this.currentUser.can_assign;
     }
   });
 }

GitHub sha: 49474c94

1 Like