2016-09-13 15:14:17 -04:00
|
|
|
export default Ember.Component.extend({
|
2018-06-15 11:03:24 -04:00
|
|
|
classNames: ["invite-list"],
|
2016-09-13 15:14:17 -04:00
|
|
|
users: null,
|
2018-06-15 11:03:24 -04:00
|
|
|
inviteEmail: "",
|
|
|
|
inviteRole: "",
|
2016-09-13 15:14:17 -04:00
|
|
|
invalid: false,
|
|
|
|
|
|
|
|
init() {
|
2019-01-19 04:05:51 -05:00
|
|
|
this._super(...arguments);
|
2018-06-15 11:03:24 -04:00
|
|
|
this.set("users", []);
|
2016-09-13 15:14:17 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
this.set("roles", [
|
|
|
|
{ id: "moderator", label: I18n.t("wizard.invites.roles.moderator") },
|
|
|
|
{ id: "regular", label: I18n.t("wizard.invites.roles.regular") }
|
2016-09-13 15:14:17 -04:00
|
|
|
]);
|
|
|
|
|
|
|
|
this.updateField();
|
|
|
|
},
|
|
|
|
|
|
|
|
keyPress(e) {
|
|
|
|
if (e.keyCode === 13) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2018-06-15 11:03:24 -04:00
|
|
|
this.send("addUser");
|
2016-09-13 15:14:17 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
updateField() {
|
2019-05-27 04:15:39 -04:00
|
|
|
const users = this.users;
|
2016-09-20 12:28:22 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
this.set("field.value", JSON.stringify(users));
|
2016-09-21 17:15:57 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
const staffCount = this.get("step.fieldsById.staff_count.value") || 1;
|
|
|
|
const showWarning = staffCount < 3 && users.length === 0;
|
2016-09-21 17:15:57 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
this.set("field.warning", showWarning ? "invites.none_added" : null);
|
2016-09-13 15:14:17 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
addUser() {
|
|
|
|
const user = {
|
2019-05-27 04:15:39 -04:00
|
|
|
email: this.inviteEmail || "",
|
|
|
|
role: this.inviteRole
|
2016-09-13 15:14:17 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
if (!/(.+)@(.+){2,}\.(.+){2,}/.test(user.email)) {
|
2018-06-15 11:03:24 -04:00
|
|
|
return this.set("invalid", true);
|
2016-09-13 15:14:17 -04:00
|
|
|
}
|
|
|
|
|
2019-05-27 04:15:39 -04:00
|
|
|
const users = this.users;
|
2018-06-15 11:03:24 -04:00
|
|
|
if (users.findBy("email", user.email)) {
|
|
|
|
return this.set("invalid", true);
|
2016-09-13 15:14:17 -04:00
|
|
|
}
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
this.set("invalid", false);
|
2016-09-13 15:14:17 -04:00
|
|
|
|
|
|
|
users.pushObject(user);
|
|
|
|
this.updateField();
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
this.set("inviteEmail", "");
|
|
|
|
Ember.run.scheduleOnce("afterRender", () =>
|
|
|
|
this.$(".invite-email").focus()
|
|
|
|
);
|
2016-09-13 15:14:17 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
removeUser(user) {
|
2019-05-27 04:15:39 -04:00
|
|
|
this.users.removeObject(user);
|
2016-09-13 15:14:17 -04:00
|
|
|
this.updateField();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|