2021-08-31 01:23:33 +02:00
|
|
|
import Component from "@ember/component";
|
2021-09-03 00:38:30 +02:00
|
|
|
import { action } from "@ember/object";
|
2021-09-09 08:07:12 +02:00
|
|
|
import { equal, notEmpty } from "@ember/object/computed";
|
2021-08-31 01:23:33 +02:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
|
|
|
import I18n from "I18n";
|
|
|
|
|
|
|
|
export default Component.extend({
|
2021-09-09 08:07:12 +02:00
|
|
|
classNameBindings: ["value.type"],
|
2021-08-31 01:23:33 +02:00
|
|
|
isText: equal("value.type", "text"),
|
|
|
|
isComposer: equal("value.type", "composer"),
|
|
|
|
isDate: equal("value.type", "date"),
|
|
|
|
isTime: equal("value.type", "time"),
|
|
|
|
isDateTime: equal("value.type", "date_time"),
|
|
|
|
isNumber: equal("value.type", "number"),
|
|
|
|
isCheckbox: equal("value.type", "checkbox"),
|
|
|
|
isUrl: equal("value.type", "url"),
|
|
|
|
isUpload: equal("value.type", "upload"),
|
|
|
|
isDropdown: equal("value.type", "dropdown"),
|
|
|
|
isTag: equal("value.type", "tag"),
|
|
|
|
isCategory: equal("value.type", "category"),
|
|
|
|
isGroup: equal("value.type", "group"),
|
|
|
|
isUserSelector: equal("value.type", "user_selector"),
|
2021-09-09 08:07:12 +02:00
|
|
|
isSubmittedAt: equal("field", "submitted_at"),
|
2021-08-31 01:23:33 +02:00
|
|
|
isComposerPreview: equal("value.type", "composer_preview"),
|
|
|
|
textState: "text-collapsed",
|
2021-09-09 08:07:12 +02:00
|
|
|
toggleText: I18n.t("admin.wizard.expand_text"),
|
|
|
|
|
|
|
|
@discourseComputed("value", "isUser")
|
|
|
|
hasValue(value, isUser) {
|
|
|
|
if (isUser) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
return value && value.value;
|
|
|
|
},
|
|
|
|
|
|
|
|
@discourseComputed("field", "value.type")
|
|
|
|
isUser(field, type) {
|
|
|
|
return field === "username" || field === "user" || type === "user";
|
|
|
|
},
|
|
|
|
|
|
|
|
@discourseComputed("value.type")
|
|
|
|
isLongtext(type) {
|
|
|
|
return type === "textarea" || type === "long_text";
|
|
|
|
},
|
2021-08-31 01:23:33 +02:00
|
|
|
|
|
|
|
@discourseComputed("value")
|
|
|
|
checkboxValue(value) {
|
|
|
|
const isCheckbox = this.get("isCheckbox");
|
|
|
|
if (isCheckbox) {
|
|
|
|
if (value.value.includes("true")) {
|
|
|
|
return true;
|
|
|
|
} else if (value.value.includes("false")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
@action
|
|
|
|
expandText() {
|
|
|
|
const state = this.get("textState");
|
|
|
|
|
|
|
|
if (state === "text-collapsed") {
|
|
|
|
this.set("textState", "text-expanded");
|
2021-09-09 08:07:12 +02:00
|
|
|
this.set("toggleText", I18n.t("admin.wizard.collapse_text"));
|
2021-08-31 01:23:33 +02:00
|
|
|
} else if (state === "text-expanded") {
|
|
|
|
this.set("textState", "text-collapsed");
|
2021-09-09 08:07:12 +02:00
|
|
|
this.set("toggleText", I18n.t("admin.wizard.expand_text"));
|
2021-08-31 01:23:33 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-09-03 00:38:30 +02:00
|
|
|
@discourseComputed("value")
|
2021-08-31 01:23:33 +02:00
|
|
|
file(value) {
|
|
|
|
const isUpload = this.get("isUpload");
|
|
|
|
if (isUpload) {
|
|
|
|
return value.value;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-09-03 00:38:30 +02:00
|
|
|
@discourseComputed("value")
|
2021-08-31 01:23:33 +02:00
|
|
|
submittedUsers(value) {
|
|
|
|
const isUserSelector = this.get("isUserSelector");
|
|
|
|
const users = [];
|
2021-09-01 21:46:39 +02:00
|
|
|
|
2021-08-31 01:23:33 +02:00
|
|
|
if (isUserSelector) {
|
|
|
|
const userData = value.value;
|
|
|
|
const usernames = [];
|
|
|
|
|
2021-09-03 00:38:30 +02:00
|
|
|
if (userData.indexOf(",")) {
|
|
|
|
usernames.push(...userData.split(","));
|
2021-08-31 01:23:33 +02:00
|
|
|
|
2021-09-03 00:38:30 +02:00
|
|
|
usernames.forEach((u) => {
|
2021-08-31 01:23:33 +02:00
|
|
|
const user = {
|
|
|
|
username: u,
|
2021-09-03 00:38:30 +02:00
|
|
|
url: `/u/${u}`,
|
2021-09-01 21:46:39 +02:00
|
|
|
};
|
2021-08-31 01:23:33 +02:00
|
|
|
users.push(user);
|
2021-09-01 21:46:39 +02:00
|
|
|
});
|
2021-08-31 01:23:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return users;
|
|
|
|
},
|
|
|
|
|
2021-09-09 08:07:12 +02:00
|
|
|
@discourseComputed("isUser", "field", "value")
|
|
|
|
username(isUser, field, value) {
|
2021-09-14 05:33:16 +02:00
|
|
|
if (isUser) {
|
|
|
|
return value.username;
|
|
|
|
}
|
|
|
|
if (field === "username") {
|
|
|
|
return value.value;
|
|
|
|
}
|
2021-09-09 08:07:12 +02:00
|
|
|
return null;
|
|
|
|
},
|
2021-08-31 01:23:33 +02:00
|
|
|
|
2021-09-09 08:07:12 +02:00
|
|
|
showUsername: notEmpty("username"),
|
|
|
|
|
|
|
|
@discourseComputed("username")
|
|
|
|
userProfileUrl(username) {
|
2021-09-14 05:33:16 +02:00
|
|
|
if (username) {
|
|
|
|
return `/u/${username}`;
|
|
|
|
}
|
2021-09-09 08:07:12 +02:00
|
|
|
return "/";
|
2021-08-31 01:23:33 +02:00
|
|
|
},
|
|
|
|
|
2021-09-03 00:38:30 +02:00
|
|
|
@discourseComputed("value")
|
2021-08-31 01:23:33 +02:00
|
|
|
categoryUrl(value) {
|
2021-09-03 00:38:30 +02:00
|
|
|
const isCategory = this.get("isCategory");
|
2021-08-31 01:23:33 +02:00
|
|
|
if (isCategory) {
|
|
|
|
return `/c/${value.value}`;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-09-03 00:38:30 +02:00
|
|
|
@discourseComputed("value")
|
2021-08-31 01:23:33 +02:00
|
|
|
groupUrl(value) {
|
2021-09-03 00:38:30 +02:00
|
|
|
const isGroup = this.get("isGroup");
|
2021-08-31 01:23:33 +02:00
|
|
|
if (isGroup) {
|
|
|
|
return `/g/${value.value}`;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|