FIX: assign state was not correctly updated on mobile (#19)
This commit is contained in:
parent
097bda91a9
commit
922d8515ca
|
@ -14,11 +14,18 @@ export default Ember.Controller.extend({
|
||||||
// return Ember.isEmpty(username);
|
// return Ember.isEmpty(username);
|
||||||
// },
|
// },
|
||||||
|
|
||||||
|
onClose() {
|
||||||
|
if (this.get("model.onClose") && this.get("model.username")) {
|
||||||
|
this.get("model.onClose")(this.get("model.username"));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
assignUser(user) {
|
assignUser(user) {
|
||||||
this.set("model.username", user.username);
|
this.set("model.username", user.username);
|
||||||
this.send("assign");
|
this.send("assign");
|
||||||
},
|
},
|
||||||
|
|
||||||
assign() {
|
assign() {
|
||||||
let path = "/assign/assign";
|
let path = "/assign/assign";
|
||||||
|
|
||||||
|
|
|
@ -8,48 +8,54 @@ import { iconNode } from "discourse-common/lib/icon-library";
|
||||||
import { h } from "virtual-dom";
|
import { h } from "virtual-dom";
|
||||||
import { iconHTML } from "discourse-common/lib/icon-library";
|
import { iconHTML } from "discourse-common/lib/icon-library";
|
||||||
|
|
||||||
|
const ACTION_ID = "assign";
|
||||||
|
|
||||||
function modifySelectKit(api) {
|
function modifySelectKit(api) {
|
||||||
api
|
api
|
||||||
.modifySelectKit("topic-footer-mobile-dropdown")
|
.modifySelectKit("topic-footer-mobile-dropdown")
|
||||||
.modifyContent((context, existingContent) => {
|
.modifyContent((context, existingContent) => {
|
||||||
if (context.get("currentUser.staff")) {
|
if (context.get("currentUser.staff")) {
|
||||||
if (context.get("topic.assigned_to_user")) {
|
const hasAssignement = context.get("topic.assigned_to_user");
|
||||||
existingContent.push({
|
const button = {
|
||||||
id: "unassign",
|
id: ACTION_ID,
|
||||||
icon: "user-times",
|
icon: hasAssignement ? "user-times" : "user-plus",
|
||||||
name: I18n.t("discourse_assign.unassign.title")
|
name: I18n.t(
|
||||||
});
|
`discourse_assign.${hasAssignement ? "unassign" : "assign"}.title`
|
||||||
} else {
|
)
|
||||||
existingContent.push({
|
};
|
||||||
id: "assign",
|
existingContent.push(button);
|
||||||
icon: "user-plus",
|
|
||||||
name: I18n.t("discourse_assign.assign.title")
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return existingContent;
|
return existingContent;
|
||||||
})
|
})
|
||||||
.onSelect((context, value) => {
|
.onSelect((context, value) => {
|
||||||
if (!context.get("currentUser.staff")) {
|
if (!context.get("currentUser.staff") || value !== ACTION_ID) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const topic = context.get("topic");
|
const topic = context.get("topic");
|
||||||
|
const assignedUser = topic.get("assigned_to_user.username");
|
||||||
|
|
||||||
if (value === "assign") {
|
if (assignedUser) {
|
||||||
showModal("assign-user", {
|
|
||||||
model: {
|
|
||||||
topic,
|
|
||||||
username: topic.get("assigned_to_user.username")
|
|
||||||
}
|
|
||||||
});
|
|
||||||
context.set("value", null);
|
|
||||||
} else if (value === "unassign") {
|
|
||||||
topic.set("assigned_to_user", null);
|
|
||||||
|
|
||||||
ajax("/assign/unassign", {
|
ajax("/assign/unassign", {
|
||||||
type: "PUT",
|
type: "PUT",
|
||||||
data: { topic_id: topic.get("id") }
|
data: { topic_id: topic.get("id") }
|
||||||
|
})
|
||||||
|
.then(result => {
|
||||||
|
if (result.success && result.success === "OK") {
|
||||||
|
topic.set("assigned_to_user", null);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.finally(() => context._compute());
|
||||||
|
} else {
|
||||||
|
showModal("assign-user", {
|
||||||
|
model: {
|
||||||
|
topic,
|
||||||
|
username: topic.get("assigned_to_user.username"),
|
||||||
|
onClose: assignedToUser => {
|
||||||
|
topic.set("assigned_to_user", assignedToUser);
|
||||||
|
context._compute();
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -139,10 +145,7 @@ function initialize(api) {
|
||||||
});
|
});
|
||||||
|
|
||||||
api.addUserMenuGlyph(widget => {
|
api.addUserMenuGlyph(widget => {
|
||||||
if (
|
if (widget.currentUser && widget.currentUser.get("staff")) {
|
||||||
widget.currentUser &&
|
|
||||||
widget.currentUser.get("staff")
|
|
||||||
) {
|
|
||||||
return {
|
return {
|
||||||
label: "discourse_assign.assigned",
|
label: "discourse_assign.assigned",
|
||||||
className: "assigned",
|
className: "assigned",
|
||||||
|
@ -220,6 +223,7 @@ export default {
|
||||||
if (!siteSettings.assign_enabled) {
|
if (!siteSettings.assign_enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
withPluginApi("0.8.11", api => initialize(api, container));
|
withPluginApi("0.8.11", api => initialize(api, container));
|
||||||
withPluginApi("0.8.13", api => modifySelectKit(api, container));
|
withPluginApi("0.8.13", api => modifySelectKit(api, container));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue