2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
2021-02-28 01:18:00 +01:00
|
|
|
import _ from "lodash";
|
|
|
|
|
|
|
|
import render_settings_api_key_modal from "../templates/settings/api_key_modal.hbs";
|
|
|
|
import render_settings_custom_user_profile_field from "../templates/settings/custom_user_profile_field.hbs";
|
|
|
|
import render_settings_dev_env_email_access from "../templates/settings/dev_env_email_access.hbs";
|
|
|
|
|
|
|
|
import * as avatar from "./avatar";
|
2021-03-16 23:38:59 +01:00
|
|
|
import * as blueslip from "./blueslip";
|
2021-02-28 01:18:00 +01:00
|
|
|
import * as channel from "./channel";
|
|
|
|
import * as common from "./common";
|
2021-03-25 23:20:18 +01:00
|
|
|
import {csrf_token} from "./csrf";
|
2021-04-13 05:18:25 +02:00
|
|
|
import {$t_html} from "./i18n";
|
2021-02-28 01:18:00 +01:00
|
|
|
import * as overlays from "./overlays";
|
2021-03-25 22:35:45 +01:00
|
|
|
import {page_params} from "./page_params";
|
2021-02-28 01:18:00 +01:00
|
|
|
import * as people from "./people";
|
|
|
|
import * as pill_typeahead from "./pill_typeahead";
|
|
|
|
import * as popovers from "./popovers";
|
2021-02-28 01:19:16 +01:00
|
|
|
import * as settings_bots from "./settings_bots";
|
2021-03-21 16:46:13 +01:00
|
|
|
import * as settings_data from "./settings_data";
|
2021-02-28 01:18:00 +01:00
|
|
|
import * as settings_ui from "./settings_ui";
|
|
|
|
import * as setup from "./setup";
|
|
|
|
import * as ui_report from "./ui_report";
|
|
|
|
import * as user_pill from "./user_pill";
|
|
|
|
|
2021-04-23 21:27:13 +02:00
|
|
|
let password_quality; // Loaded asynchronously
|
|
|
|
|
2021-02-28 01:18:00 +01:00
|
|
|
export function update_email(new_email) {
|
2020-07-15 01:29:15 +02:00
|
|
|
const email_input = $("#email_value");
|
2017-04-06 02:28:57 +02:00
|
|
|
|
|
|
|
if (email_input) {
|
|
|
|
email_input.text(new_email);
|
|
|
|
}
|
2021-02-28 01:18:00 +01:00
|
|
|
}
|
2017-04-06 02:28:57 +02:00
|
|
|
|
2021-02-28 01:18:00 +01:00
|
|
|
export function update_full_name(new_full_name) {
|
2020-02-22 20:39:48 +01:00
|
|
|
const full_name_field = $("#full_name_value");
|
2018-02-02 01:24:26 +01:00
|
|
|
if (full_name_field) {
|
|
|
|
full_name_field.text(new_full_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Arguably, this should work more like how the `update_email`
|
|
|
|
// flow works, where we update the name in the modal on open,
|
|
|
|
// rather than updating it here, but this works.
|
2019-11-02 00:06:25 +01:00
|
|
|
const full_name_input = $(".full_name_change_container input[name='full_name']");
|
2018-02-02 01:24:26 +01:00
|
|
|
if (full_name_input) {
|
|
|
|
full_name_input.val(new_full_name);
|
|
|
|
}
|
2021-02-28 01:18:00 +01:00
|
|
|
}
|
2018-02-02 01:24:26 +01:00
|
|
|
|
2021-02-28 01:18:00 +01:00
|
|
|
export function update_name_change_display() {
|
2021-03-21 16:46:13 +01:00
|
|
|
if (!settings_data.user_can_change_name()) {
|
2020-07-22 02:59:06 +02:00
|
|
|
$("#full_name").prop("disabled", true);
|
2018-03-02 21:44:14 +01:00
|
|
|
$(".change_name_tooltip").show();
|
|
|
|
} else {
|
2020-07-22 02:59:06 +02:00
|
|
|
$("#full_name").prop("disabled", false);
|
2018-03-02 21:44:14 +01:00
|
|
|
$(".change_name_tooltip").hide();
|
|
|
|
}
|
2021-02-28 01:18:00 +01:00
|
|
|
}
|
2018-03-02 21:44:14 +01:00
|
|
|
|
2021-02-28 01:18:00 +01:00
|
|
|
export function update_email_change_display() {
|
2018-03-02 21:44:14 +01:00
|
|
|
if (page_params.realm_email_changes_disabled && !page_params.is_admin) {
|
2020-07-22 02:59:06 +02:00
|
|
|
$("#change_email .button").prop("disabled", true);
|
2018-03-02 21:44:14 +01:00
|
|
|
$(".change_email_tooltip").show();
|
|
|
|
} else {
|
2020-07-22 02:59:06 +02:00
|
|
|
$("#change_email .button").prop("disabled", false);
|
2018-03-02 21:44:14 +01:00
|
|
|
$(".change_email_tooltip").hide();
|
|
|
|
}
|
2021-02-28 01:18:00 +01:00
|
|
|
}
|
2018-03-02 21:44:14 +01:00
|
|
|
|
2021-02-28 01:18:00 +01:00
|
|
|
export function update_avatar_change_display() {
|
2021-03-21 16:46:13 +01:00
|
|
|
if (!settings_data.user_can_change_avatar()) {
|
2020-07-22 02:59:06 +02:00
|
|
|
$("#user-avatar-upload-widget .image_upload_button").prop("disabled", true);
|
|
|
|
$("#user-avatar-upload-widget .image-delete-button .button").prop("disabled", true);
|
2019-04-23 04:51:04 +02:00
|
|
|
} else {
|
2020-07-22 02:59:06 +02:00
|
|
|
$("#user-avatar-upload-widget .image_upload_button").prop("disabled", false);
|
|
|
|
$("#user-avatar-upload-widget .image-delete-button .button").prop("disabled", false);
|
2019-04-23 04:51:04 +02:00
|
|
|
}
|
2021-02-28 01:18:00 +01:00
|
|
|
}
|
2019-04-23 04:51:04 +02:00
|
|
|
|
2020-04-02 09:55:16 +02:00
|
|
|
function display_avatar_upload_complete() {
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#user-avatar-upload-widget .upload-spinner-background").css({visibility: "hidden"});
|
2020-07-15 21:20:36 +02:00
|
|
|
$("#user-avatar-upload-widget .image-upload-text").show();
|
2020-07-15 20:58:34 +02:00
|
|
|
$("#user-avatar-upload-widget .image-delete-button").show();
|
2020-04-02 09:55:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function display_avatar_upload_started() {
|
|
|
|
$("#user-avatar-source").hide();
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#user-avatar-upload-widget .upload-spinner-background").css({visibility: "visible"});
|
2020-07-15 21:20:36 +02:00
|
|
|
$("#user-avatar-upload-widget .image-upload-text").hide();
|
2020-07-15 20:58:34 +02:00
|
|
|
$("#user-avatar-upload-widget .image-delete-button").hide();
|
2020-04-02 09:55:16 +02:00
|
|
|
}
|
|
|
|
|
2021-04-13 05:18:25 +02:00
|
|
|
function settings_change_error(message_html, xhr) {
|
|
|
|
ui_report.error(message_html, xhr, $("#account-settings-status").expectOne());
|
2017-04-06 02:28:57 +02:00
|
|
|
}
|
|
|
|
|
2019-07-10 22:18:45 +02:00
|
|
|
function update_custom_profile_field(field, method) {
|
2019-11-02 00:06:25 +01:00
|
|
|
let field_id;
|
2019-07-10 22:18:45 +02:00
|
|
|
if (method === channel.del) {
|
|
|
|
field_id = field;
|
|
|
|
} else {
|
|
|
|
field_id = field.id;
|
|
|
|
}
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const spinner_element = $(
|
2021-02-03 23:23:32 +01:00
|
|
|
`.custom_user_field[data-field-id="${CSS.escape(field_id)}"] .custom-field-status`,
|
2020-07-15 00:34:28 +02:00
|
|
|
).expectOne();
|
|
|
|
settings_ui.do_settings_change(
|
|
|
|
method,
|
|
|
|
"/json/users/me/profile_data",
|
|
|
|
{data: JSON.stringify([field])},
|
|
|
|
spinner_element,
|
|
|
|
);
|
2019-07-10 22:18:45 +02:00
|
|
|
}
|
|
|
|
|
2018-06-05 12:57:02 +02:00
|
|
|
function update_user_custom_profile_fields(fields, method) {
|
|
|
|
if (method === undefined) {
|
|
|
|
blueslip.error("Undefined method in update_user_custom_profile_fields");
|
|
|
|
}
|
js: Automatically convert _.each to for…of.
This commit was automatically generated by the following script,
followed by lint --fix and a few small manual lint-related cleanups.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import { Context } from "ast-types/lib/path-visitor";
import K from "ast-types/gen/kinds";
import { NodePath } from "ast-types/lib/node-path";
import assert from "assert";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
const checkStatement = (node: n.Node): node is K.StatementKind =>
n.Statement.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
let inLoop = false;
let replaceReturn = false;
const visitLoop = (...args: string[]) =>
function(this: Context, path: NodePath) {
for (const arg of args) {
this.visit(path.get(arg));
}
const old = { inLoop };
inLoop = true;
this.visit(path.get("body"));
inLoop = old.inLoop;
return false;
};
recast.visit(ast, {
visitDoWhileStatement: visitLoop("test"),
visitExpressionStatement(path) {
const { expression, comments } = path.node;
let valueOnly;
if (
n.CallExpression.check(expression) &&
n.MemberExpression.check(expression.callee) &&
!expression.callee.computed &&
n.Identifier.check(expression.callee.object) &&
expression.callee.object.name === "_" &&
n.Identifier.check(expression.callee.property) &&
["each", "forEach"].includes(expression.callee.property.name) &&
[2, 3].includes(expression.arguments.length) &&
checkExpression(expression.arguments[0]) &&
(n.FunctionExpression.check(expression.arguments[1]) ||
n.ArrowFunctionExpression.check(expression.arguments[1])) &&
[1, 2].includes(expression.arguments[1].params.length) &&
n.Identifier.check(expression.arguments[1].params[0]) &&
((valueOnly = expression.arguments[1].params[1] === undefined) ||
n.Identifier.check(expression.arguments[1].params[1])) &&
(expression.arguments[2] === undefined ||
n.ThisExpression.check(expression.arguments[2]))
) {
const old = { inLoop, replaceReturn };
inLoop = false;
replaceReturn = true;
this.visit(
path
.get("expression")
.get("arguments")
.get(1)
.get("body")
);
inLoop = old.inLoop;
replaceReturn = old.replaceReturn;
const [right, { body, params }] = expression.arguments;
const loop = b.forOfStatement(
b.variableDeclaration("let", [
b.variableDeclarator(
valueOnly ? params[0] : b.arrayPattern([params[1], params[0]])
),
]),
valueOnly
? right
: b.callExpression(
b.memberExpression(right, b.identifier("entries")),
[]
),
checkStatement(body) ? body : b.expressionStatement(body)
);
loop.comments = comments;
path.replace(loop);
changed = true;
}
this.traverse(path);
},
visitForStatement: visitLoop("init", "test", "update"),
visitForInStatement: visitLoop("left", "right"),
visitForOfStatement: visitLoop("left", "right"),
visitFunction(path) {
this.visit(path.get("params"));
const old = { replaceReturn };
replaceReturn = false;
this.visit(path.get("body"));
replaceReturn = old.replaceReturn;
return false;
},
visitReturnStatement(path) {
if (replaceReturn) {
assert(!inLoop); // could use labeled continue if this ever fires
const { argument, comments } = path.node;
if (argument === null) {
const s = b.continueStatement();
s.comments = comments;
path.replace(s);
} else {
const s = b.expressionStatement(argument);
s.comments = comments;
path.replace(s, b.continueStatement());
}
return false;
}
this.traverse(path);
},
visitWhileStatement: visitLoop("test"),
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 06:19:47 +01:00
|
|
|
|
|
|
|
for (const field of fields) {
|
2019-07-10 22:18:45 +02:00
|
|
|
update_custom_profile_field(field, method);
|
js: Automatically convert _.each to for…of.
This commit was automatically generated by the following script,
followed by lint --fix and a few small manual lint-related cleanups.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import { Context } from "ast-types/lib/path-visitor";
import K from "ast-types/gen/kinds";
import { NodePath } from "ast-types/lib/node-path";
import assert from "assert";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
const checkStatement = (node: n.Node): node is K.StatementKind =>
n.Statement.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
let inLoop = false;
let replaceReturn = false;
const visitLoop = (...args: string[]) =>
function(this: Context, path: NodePath) {
for (const arg of args) {
this.visit(path.get(arg));
}
const old = { inLoop };
inLoop = true;
this.visit(path.get("body"));
inLoop = old.inLoop;
return false;
};
recast.visit(ast, {
visitDoWhileStatement: visitLoop("test"),
visitExpressionStatement(path) {
const { expression, comments } = path.node;
let valueOnly;
if (
n.CallExpression.check(expression) &&
n.MemberExpression.check(expression.callee) &&
!expression.callee.computed &&
n.Identifier.check(expression.callee.object) &&
expression.callee.object.name === "_" &&
n.Identifier.check(expression.callee.property) &&
["each", "forEach"].includes(expression.callee.property.name) &&
[2, 3].includes(expression.arguments.length) &&
checkExpression(expression.arguments[0]) &&
(n.FunctionExpression.check(expression.arguments[1]) ||
n.ArrowFunctionExpression.check(expression.arguments[1])) &&
[1, 2].includes(expression.arguments[1].params.length) &&
n.Identifier.check(expression.arguments[1].params[0]) &&
((valueOnly = expression.arguments[1].params[1] === undefined) ||
n.Identifier.check(expression.arguments[1].params[1])) &&
(expression.arguments[2] === undefined ||
n.ThisExpression.check(expression.arguments[2]))
) {
const old = { inLoop, replaceReturn };
inLoop = false;
replaceReturn = true;
this.visit(
path
.get("expression")
.get("arguments")
.get(1)
.get("body")
);
inLoop = old.inLoop;
replaceReturn = old.replaceReturn;
const [right, { body, params }] = expression.arguments;
const loop = b.forOfStatement(
b.variableDeclaration("let", [
b.variableDeclarator(
valueOnly ? params[0] : b.arrayPattern([params[1], params[0]])
),
]),
valueOnly
? right
: b.callExpression(
b.memberExpression(right, b.identifier("entries")),
[]
),
checkStatement(body) ? body : b.expressionStatement(body)
);
loop.comments = comments;
path.replace(loop);
changed = true;
}
this.traverse(path);
},
visitForStatement: visitLoop("init", "test", "update"),
visitForInStatement: visitLoop("left", "right"),
visitForOfStatement: visitLoop("left", "right"),
visitFunction(path) {
this.visit(path.get("params"));
const old = { replaceReturn };
replaceReturn = false;
this.visit(path.get("body"));
replaceReturn = old.replaceReturn;
return false;
},
visitReturnStatement(path) {
if (replaceReturn) {
assert(!inLoop); // could use labeled continue if this ever fires
const { argument, comments } = path.node;
if (argument === null) {
const s = b.continueStatement();
s.comments = comments;
path.replace(s);
} else {
const s = b.expressionStatement(argument);
s.comments = comments;
path.replace(s, b.continueStatement());
}
return false;
}
this.traverse(path);
},
visitWhileStatement: visitLoop("test"),
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 06:19:47 +01:00
|
|
|
}
|
2018-05-25 20:58:14 +02:00
|
|
|
}
|
|
|
|
|
2021-02-28 01:18:00 +01:00
|
|
|
export function append_custom_profile_fields(element_id, user_id) {
|
2020-02-05 14:30:59 +01:00
|
|
|
const person = people.get_by_user_id(user_id);
|
2019-04-07 17:29:53 +02:00
|
|
|
if (person.is_bot) {
|
|
|
|
return;
|
|
|
|
}
|
2019-11-02 00:06:25 +01:00
|
|
|
const all_custom_fields = page_params.custom_profile_fields;
|
|
|
|
const all_field_types = page_params.custom_profile_field_types;
|
2019-06-06 11:51:53 +02:00
|
|
|
|
2020-02-12 07:19:14 +01:00
|
|
|
const all_field_template_types = new Map([
|
|
|
|
[all_field_types.LONG_TEXT.id, "text"],
|
|
|
|
[all_field_types.SHORT_TEXT.id, "text"],
|
2021-03-24 11:41:29 +01:00
|
|
|
[all_field_types.SELECT.id, "select"],
|
2020-02-12 07:19:14 +01:00
|
|
|
[all_field_types.USER.id, "user"],
|
|
|
|
[all_field_types.DATE.id, "date"],
|
|
|
|
[all_field_types.EXTERNAL_ACCOUNT.id, "text"],
|
|
|
|
[all_field_types.URL.id, "url"],
|
|
|
|
]);
|
2018-10-24 16:32:30 +02:00
|
|
|
|
2021-01-22 22:29:08 +01:00
|
|
|
for (const field of all_custom_fields) {
|
2019-11-02 00:06:25 +01:00
|
|
|
let field_value = people.get_custom_profile_data(user_id, field.id);
|
2021-03-24 11:41:29 +01:00
|
|
|
const is_select_field = field.type === all_field_types.SELECT.id;
|
2019-11-02 00:06:25 +01:00
|
|
|
const field_choices = [];
|
2019-06-06 11:51:53 +02:00
|
|
|
|
2018-12-31 06:41:06 +01:00
|
|
|
if (field_value === undefined || field_value === null) {
|
|
|
|
field_value = {value: "", rendered_value: ""};
|
|
|
|
}
|
2021-03-24 11:41:29 +01:00
|
|
|
if (is_select_field) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const field_choice_dict = JSON.parse(field.field_data);
|
|
|
|
for (const choice in field_choice_dict) {
|
2018-10-24 16:32:30 +02:00
|
|
|
if (choice) {
|
|
|
|
field_choices[field_choice_dict[choice].order] = {
|
|
|
|
value: choice,
|
|
|
|
text: field_choice_dict[choice].text,
|
2018-12-31 06:41:06 +01:00
|
|
|
selected: choice === field_value.value,
|
2018-10-24 16:32:30 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const html = render_settings_custom_user_profile_field({
|
2020-07-20 22:18:43 +02:00
|
|
|
field,
|
2020-02-12 07:19:14 +01:00
|
|
|
field_type: all_field_template_types.get(field.type),
|
2020-07-20 22:18:43 +02:00
|
|
|
field_value,
|
2019-06-06 11:51:53 +02:00
|
|
|
is_long_text_field: field.type === all_field_types.LONG_TEXT.id,
|
|
|
|
is_user_field: field.type === all_field_types.USER.id,
|
|
|
|
is_date_field: field.type === all_field_types.DATE.id,
|
2021-03-24 11:41:29 +01:00
|
|
|
is_select_field,
|
2020-07-20 22:18:43 +02:00
|
|
|
field_choices,
|
2018-10-24 16:32:30 +02:00
|
|
|
});
|
|
|
|
$(element_id).append(html);
|
2021-01-22 22:29:08 +01:00
|
|
|
}
|
2021-02-28 01:18:00 +01:00
|
|
|
}
|
2018-10-24 16:32:30 +02:00
|
|
|
|
2021-02-28 01:18:00 +01:00
|
|
|
export function initialize_custom_date_type_fields(element_id) {
|
2018-10-22 10:20:33 +02:00
|
|
|
$(element_id).find(".custom_user_field .datepicker").flatpickr({
|
|
|
|
altInput: true,
|
2020-06-07 06:16:34 +02:00
|
|
|
altFormat: "F j, Y",
|
|
|
|
allowInput: true,
|
|
|
|
});
|
2019-07-29 20:54:30 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
$(element_id)
|
|
|
|
.find(".custom_user_field .datepicker")
|
|
|
|
.on("mouseenter", function () {
|
|
|
|
if ($(this).val().length <= 0) {
|
|
|
|
$(this).parent().find(".remove_date").hide();
|
|
|
|
} else {
|
|
|
|
$(this).parent().find(".remove_date").show();
|
|
|
|
}
|
|
|
|
});
|
2019-07-29 20:59:33 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
$(element_id)
|
|
|
|
.find(".custom_user_field .remove_date")
|
|
|
|
.on("click", function () {
|
|
|
|
$(this).parent().find(".custom_user_field_value").val("");
|
|
|
|
});
|
2021-02-28 01:18:00 +01:00
|
|
|
}
|
2018-10-22 10:20:33 +02:00
|
|
|
|
2021-02-28 01:18:00 +01:00
|
|
|
export function initialize_custom_user_type_fields(
|
2020-07-15 00:34:28 +02:00
|
|
|
element_id,
|
|
|
|
user_id,
|
|
|
|
is_editable,
|
|
|
|
set_handler_on_update,
|
|
|
|
) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const field_types = page_params.custom_profile_field_types;
|
2020-02-03 09:42:50 +01:00
|
|
|
const user_pills = new Map();
|
2018-10-23 19:46:12 +02:00
|
|
|
|
2020-02-05 14:30:59 +01:00
|
|
|
const person = people.get_by_user_id(user_id);
|
2019-04-07 17:29:53 +02:00
|
|
|
if (person.is_bot) {
|
2020-01-16 20:37:29 +01:00
|
|
|
return user_pills;
|
2019-04-07 17:29:53 +02:00
|
|
|
}
|
|
|
|
|
2021-01-22 22:29:08 +01:00
|
|
|
for (const field of page_params.custom_profile_fields) {
|
2019-11-02 00:06:25 +01:00
|
|
|
let field_value_raw = people.get_custom_profile_data(user_id, field.id);
|
2018-10-23 19:46:12 +02:00
|
|
|
|
2018-12-31 06:41:06 +01:00
|
|
|
if (field_value_raw) {
|
|
|
|
field_value_raw = field_value_raw.value;
|
|
|
|
}
|
|
|
|
|
2018-10-23 19:46:12 +02:00
|
|
|
// If field is not editable and field value is null, we don't expect
|
|
|
|
// pill container for that field and proceed further
|
|
|
|
if (field.type === field_types.USER.id && (field_value_raw || is_editable)) {
|
2020-07-15 00:34:28 +02:00
|
|
|
const pill_container = $(element_id)
|
2021-02-03 23:23:32 +01:00
|
|
|
.find(`.custom_user_field[data-field-id="${CSS.escape(field.id)}"] .pill-container`)
|
2020-07-15 00:34:28 +02:00
|
|
|
.expectOne();
|
2019-11-02 00:06:25 +01:00
|
|
|
const pills = user_pill.create_pills(pill_container);
|
2018-10-23 19:46:12 +02:00
|
|
|
|
|
|
|
function update_custom_user_field() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const fields = [];
|
|
|
|
const user_ids = user_pill.get_user_ids(pills);
|
2018-10-23 19:46:12 +02:00
|
|
|
if (user_ids.length < 1) {
|
|
|
|
fields.push(field.id);
|
|
|
|
update_user_custom_profile_fields(fields, channel.del);
|
|
|
|
} else {
|
|
|
|
fields.push({id: field.id, value: user_ids});
|
|
|
|
update_user_custom_profile_fields(fields, channel.patch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (field_value_raw) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const field_value = JSON.parse(field_value_raw);
|
2018-10-23 19:46:12 +02:00
|
|
|
if (field_value) {
|
2021-01-22 22:29:08 +01:00
|
|
|
for (const pill_user_id of field_value) {
|
2020-02-05 14:30:59 +01:00
|
|
|
const user = people.get_by_user_id(pill_user_id);
|
2018-10-23 19:46:12 +02:00
|
|
|
user_pill.append_user(user, pills);
|
2021-01-22 22:29:08 +01:00
|
|
|
}
|
2018-10-23 19:46:12 +02:00
|
|
|
}
|
|
|
|
}
|
2018-12-31 07:45:33 +01:00
|
|
|
|
2018-10-23 19:46:12 +02:00
|
|
|
if (is_editable) {
|
2020-07-15 01:29:15 +02:00
|
|
|
const input = pill_container.children(".input");
|
2018-10-23 19:46:12 +02:00
|
|
|
if (set_handler_on_update) {
|
2021-05-25 10:11:21 +02:00
|
|
|
const opts = {update_func: update_custom_user_field, user: true};
|
2020-07-24 18:04:15 +02:00
|
|
|
pill_typeahead.set_up(input, pills, opts);
|
2020-07-02 01:45:54 +02:00
|
|
|
pills.onPillRemove(() => {
|
2018-10-23 19:46:12 +02:00
|
|
|
update_custom_user_field();
|
|
|
|
});
|
|
|
|
} else {
|
2021-05-25 10:11:21 +02:00
|
|
|
pill_typeahead.set_up(input, pills, {user: true});
|
2018-10-23 19:46:12 +02:00
|
|
|
}
|
|
|
|
}
|
2020-01-16 20:37:29 +01:00
|
|
|
user_pills.set(field.id, pills);
|
2018-10-23 19:46:12 +02:00
|
|
|
}
|
2021-01-22 22:29:08 +01:00
|
|
|
}
|
2019-04-07 17:29:53 +02:00
|
|
|
|
2018-10-23 19:46:12 +02:00
|
|
|
return user_pills;
|
2021-02-28 01:18:00 +01:00
|
|
|
}
|
2018-10-23 19:46:12 +02:00
|
|
|
|
2021-02-28 01:18:00 +01:00
|
|
|
export function add_custom_profile_fields_to_settings() {
|
2018-06-10 07:03:22 +02:00
|
|
|
if (!overlays.settings_open()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const element_id = "#account-settings .custom-profile-fields-form";
|
2018-10-22 10:20:33 +02:00
|
|
|
$(element_id).html("");
|
2018-06-07 11:39:12 +02:00
|
|
|
if (page_params.custom_profile_fields.length > 0) {
|
|
|
|
$("#account-settings #custom-field-header").show();
|
|
|
|
} else {
|
|
|
|
$("#account-settings #custom-field-header").hide();
|
|
|
|
}
|
|
|
|
|
2021-02-28 01:18:00 +01:00
|
|
|
append_custom_profile_fields(element_id, people.my_current_user_id());
|
|
|
|
initialize_custom_user_type_fields(element_id, people.my_current_user_id(), true, true);
|
|
|
|
initialize_custom_date_type_fields(element_id);
|
|
|
|
}
|
2017-04-06 02:28:57 +02:00
|
|
|
|
2021-02-28 01:18:00 +01:00
|
|
|
export function set_up() {
|
2018-02-26 20:09:07 +01:00
|
|
|
// Add custom profile fields elements to user account settings.
|
2021-02-28 01:18:00 +01:00
|
|
|
add_custom_profile_fields_to_settings();
|
2017-04-06 02:28:57 +02:00
|
|
|
$("#account-settings-status").hide();
|
2017-06-13 17:57:33 +02:00
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
const setup_api_key_modal = _.once(() => {
|
2020-06-05 20:34:18 +02:00
|
|
|
function request_api_key(data) {
|
2019-08-12 16:43:20 +02:00
|
|
|
channel.post({
|
2020-07-15 01:29:15 +02:00
|
|
|
url: "/json/fetch_api_key",
|
2020-07-20 22:18:43 +02:00
|
|
|
data,
|
|
|
|
success(data) {
|
2019-08-12 16:43:20 +02:00
|
|
|
$("#get_api_key_password").val("");
|
|
|
|
$("#api_key_value").text(data.api_key);
|
|
|
|
// The display property on the error bar is set to important
|
|
|
|
// so instead of making display: none !important we just
|
|
|
|
// remove it.
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#api_key_status").remove();
|
2019-08-12 16:43:20 +02:00
|
|
|
$("#password_confirmation").hide();
|
|
|
|
$("#show_api_key").show();
|
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
error(xhr) {
|
2021-04-13 05:18:25 +02:00
|
|
|
ui_report.error(
|
|
|
|
$t_html({defaultMessage: "Error"}),
|
|
|
|
xhr,
|
|
|
|
$("#api_key_status").expectOne(),
|
|
|
|
);
|
2019-08-12 16:43:20 +02:00
|
|
|
$("#show_api_key").hide();
|
|
|
|
$("#api_key_modal").show();
|
|
|
|
},
|
|
|
|
});
|
2020-06-05 20:34:18 +02:00
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$(".account-settings-form").append(render_settings_api_key_modal());
|
2020-06-05 20:34:18 +02:00
|
|
|
$("#api_key_value").text("");
|
|
|
|
$("#show_api_key").hide();
|
2021-04-05 09:53:15 +02:00
|
|
|
common.setup_password_visibility_toggle(
|
|
|
|
"#get_api_key_password",
|
|
|
|
"#get_api_key_password + .password_visibility_toggle",
|
2021-04-20 16:49:39 +02:00
|
|
|
{tippy_tooltips: true},
|
2021-04-05 09:53:15 +02:00
|
|
|
);
|
2020-06-05 20:34:18 +02:00
|
|
|
|
|
|
|
if (page_params.realm_password_auth_enabled === false) {
|
|
|
|
// Skip the password prompt step, since the user doesn't have one.
|
|
|
|
request_api_key({});
|
|
|
|
} else {
|
2020-07-02 01:45:54 +02:00
|
|
|
$("#get_api_key_button").on("click", (e) => {
|
2020-06-05 20:34:18 +02:00
|
|
|
const data = {};
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
data.password = $("#get_api_key_password").val();
|
|
|
|
request_api_key(data);
|
|
|
|
});
|
|
|
|
}
|
2018-05-18 15:21:44 +02:00
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$("#show_api_key").on("click", "button.regenerate_api_key", (e) => {
|
2019-08-12 16:43:20 +02:00
|
|
|
channel.post({
|
2020-07-15 01:29:15 +02:00
|
|
|
url: "/json/users/me/api_key/regenerate",
|
2020-07-20 22:18:43 +02:00
|
|
|
success(data) {
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#api_key_value").text(data.api_key);
|
2019-08-12 16:43:20 +02:00
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
error(xhr) {
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#user_api_key_error").text(JSON.parse(xhr.responseText).msg).show();
|
2019-08-12 16:43:20 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2018-05-18 15:21:44 +02:00
|
|
|
});
|
2017-06-13 17:57:33 +02:00
|
|
|
|
2019-08-12 16:43:20 +02:00
|
|
|
$("#download_zuliprc").on("click", function () {
|
2020-02-01 00:04:23 +01:00
|
|
|
const bot_object = {
|
|
|
|
user_id: people.my_current_user_id(),
|
2020-04-09 22:22:58 +02:00
|
|
|
email: page_params.delivery_email,
|
2020-02-01 00:04:23 +01:00
|
|
|
api_key: $("#api_key_value").text(),
|
|
|
|
};
|
|
|
|
const data = settings_bots.generate_zuliprc_content(bot_object);
|
2019-08-12 16:43:20 +02:00
|
|
|
$(this).attr("href", settings_bots.encode_zuliprc_as_uri(data));
|
2017-06-13 17:57:33 +02:00
|
|
|
});
|
2021-04-05 09:53:15 +02:00
|
|
|
|
|
|
|
$("#api_key_modal [data-dismiss=modal]").on("click", () => {
|
|
|
|
common.reset_password_toggle_icons(
|
|
|
|
"#get_api_key_password",
|
|
|
|
"#get_api_key_password + .password_visibility_toggle",
|
|
|
|
);
|
|
|
|
});
|
2017-06-13 17:57:33 +02:00
|
|
|
});
|
|
|
|
|
2020-07-20 21:26:58 +02:00
|
|
|
$("#api_key_button").on("click", (e) => {
|
2019-08-12 16:43:20 +02:00
|
|
|
setup_api_key_modal();
|
2020-07-15 01:29:15 +02:00
|
|
|
overlays.open_modal("#api_key_modal");
|
2019-08-12 16:43:20 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2017-06-13 17:57:33 +02:00
|
|
|
});
|
2017-04-06 02:28:57 +02:00
|
|
|
|
|
|
|
function clear_password_change() {
|
|
|
|
// Clear the password boxes so that passwords don't linger in the DOM
|
|
|
|
// for an XSS attacker to find.
|
2021-04-05 09:53:15 +02:00
|
|
|
common.reset_password_toggle_icons(
|
|
|
|
"#old_password",
|
|
|
|
"#old_password + .password_visibility_toggle",
|
|
|
|
);
|
|
|
|
common.reset_password_toggle_icons(
|
|
|
|
"#new_password",
|
|
|
|
"#new_password + .password_visibility_toggle",
|
|
|
|
);
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#old_password, #new_password").val("");
|
2021-04-23 21:27:13 +02:00
|
|
|
password_quality?.("", $("#pw_strength .bar"), $("#new_password"));
|
2017-04-06 02:28:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
clear_password_change();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#change_full_name").on("click", (e) => {
|
2018-01-30 08:56:15 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2021-03-21 16:46:13 +01:00
|
|
|
if (settings_data.user_can_change_name()) {
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#change_full_name_modal").find("input[name='full_name']").val(page_params.full_name);
|
|
|
|
overlays.open_modal("#change_full_name_modal");
|
2018-02-02 15:40:15 +01:00
|
|
|
}
|
2018-01-30 08:56:15 +01:00
|
|
|
});
|
|
|
|
|
2021-02-28 21:16:38 +01:00
|
|
|
$("#change_password").on("click", async (e) => {
|
2017-04-06 02:28:57 +02:00
|
|
|
e.preventDefault();
|
2017-12-24 19:00:29 +01:00
|
|
|
e.stopPropagation();
|
2020-07-15 01:29:15 +02:00
|
|
|
overlays.open_modal("#change_password_modal");
|
|
|
|
$("#pw_change_controls").show();
|
2017-04-20 08:21:31 +02:00
|
|
|
if (page_params.realm_password_auth_enabled !== false) {
|
2017-04-06 02:28:57 +02:00
|
|
|
// zxcvbn.js is pretty big, and is only needed on password
|
|
|
|
// change, so load it asynchronously.
|
2021-04-23 21:27:13 +02:00
|
|
|
password_quality = (await import("./password_quality")).password_quality;
|
2021-02-28 21:16:38 +01:00
|
|
|
$("#pw_strength .bar").removeClass("fade");
|
2017-04-06 02:28:57 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#change_password_modal")
|
|
|
|
.find("[data-dismiss=modal]")
|
|
|
|
.on("click", () => {
|
|
|
|
clear_password_change();
|
|
|
|
});
|
2018-01-24 13:30:27 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#change_password_button").on("click", (e) => {
|
2017-12-24 19:00:29 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2020-07-15 00:34:28 +02:00
|
|
|
const change_password_error = $("#change_password_modal")
|
|
|
|
.find(".change_password_info")
|
|
|
|
.expectOne();
|
2017-12-24 19:00:29 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const data = {
|
2020-07-15 01:29:15 +02:00
|
|
|
old_password: $("#old_password").val(),
|
|
|
|
new_password: $("#new_password").val(),
|
|
|
|
confirm_password: $("#confirm_password").val(),
|
2017-12-24 19:00:29 +01:00
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const new_pw_field = $("#new_password");
|
2019-11-02 00:06:25 +01:00
|
|
|
const new_pw = data.new_password;
|
2020-07-15 01:29:15 +02:00
|
|
|
if (new_pw !== "") {
|
2021-04-23 21:27:13 +02:00
|
|
|
if (password_quality === undefined) {
|
|
|
|
// password_quality didn't load, for whatever reason.
|
2019-03-19 06:10:47 +01:00
|
|
|
settings_change_error(
|
2020-07-15 01:29:15 +02:00
|
|
|
"An internal error occurred; try reloading the page. " +
|
2020-07-15 00:34:28 +02:00
|
|
|
"Sorry for the trouble!",
|
|
|
|
);
|
2019-03-19 06:10:47 +01:00
|
|
|
return;
|
2021-04-23 21:27:13 +02:00
|
|
|
} else if (!password_quality(new_pw, undefined, new_pw_field)) {
|
2021-04-13 05:18:25 +02:00
|
|
|
settings_change_error($t_html({defaultMessage: "New password is too weak"}));
|
2019-03-19 06:10:47 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-24 05:23:09 +02:00
|
|
|
setup.set_password_change_in_progress(true);
|
2019-11-02 00:06:25 +01:00
|
|
|
const opts = {
|
2020-07-20 22:18:43 +02:00
|
|
|
success_continuation() {
|
2020-09-24 05:23:09 +02:00
|
|
|
setup.set_password_change_in_progress(false);
|
2020-05-09 15:45:54 +02:00
|
|
|
overlays.close_modal("#change_password_modal");
|
2017-12-24 19:00:29 +01:00
|
|
|
},
|
2020-08-25 18:37:48 +02:00
|
|
|
error_continuation() {
|
2020-09-24 05:23:09 +02:00
|
|
|
setup.set_password_change_in_progress(false);
|
2020-08-25 18:37:48 +02:00
|
|
|
},
|
2019-07-10 19:17:26 +02:00
|
|
|
error_msg_element: change_password_error,
|
2021-04-20 16:41:39 +02:00
|
|
|
failure_msg_html: null,
|
2019-07-10 19:17:26 +02:00
|
|
|
};
|
2020-07-15 00:34:28 +02:00
|
|
|
settings_ui.do_settings_change(
|
|
|
|
channel.patch,
|
|
|
|
"/json/settings",
|
|
|
|
data,
|
|
|
|
$("#account-settings-status").expectOne(),
|
|
|
|
opts,
|
|
|
|
);
|
2019-07-10 19:17:26 +02:00
|
|
|
clear_password_change();
|
2017-12-24 19:00:29 +01:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#new_password").on("input", () => {
|
|
|
|
const field = $("#new_password");
|
2021-04-23 21:27:13 +02:00
|
|
|
password_quality?.(field.val(), $("#pw_strength .bar"), field);
|
2017-04-06 02:28:57 +02:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#change_full_name_button").on("click", (e) => {
|
2018-01-30 08:56:15 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2020-07-15 00:34:28 +02:00
|
|
|
const change_full_name_error = $("#change_full_name_modal")
|
|
|
|
.find(".change_full_name_info")
|
|
|
|
.expectOne();
|
2019-11-02 00:06:25 +01:00
|
|
|
const data = {};
|
2018-01-30 08:56:15 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
data.full_name = $(".full_name_change_container").find("input[name='full_name']").val();
|
2019-07-10 19:17:26 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const opts = {
|
2020-07-20 22:18:43 +02:00
|
|
|
success_continuation() {
|
2020-05-09 15:45:54 +02:00
|
|
|
overlays.close_modal("#change_full_name_modal");
|
2018-01-30 08:56:15 +01:00
|
|
|
},
|
2019-07-10 19:17:26 +02:00
|
|
|
error_msg_element: change_full_name_error,
|
|
|
|
};
|
2020-07-15 00:34:28 +02:00
|
|
|
settings_ui.do_settings_change(
|
|
|
|
channel.patch,
|
|
|
|
"/json/settings",
|
|
|
|
data,
|
|
|
|
$("#account-settings-status").expectOne(),
|
|
|
|
opts,
|
|
|
|
);
|
2017-04-06 02:28:57 +02:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#change_email_button").on("click", (e) => {
|
2017-04-06 02:28:57 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2020-07-15 01:29:15 +02:00
|
|
|
const change_email_error = $("#change_email_modal").find(".change_email_info").expectOne();
|
2019-11-02 00:06:25 +01:00
|
|
|
const data = {};
|
2020-07-15 01:29:15 +02:00
|
|
|
data.email = $(".email_change_container").find("input[name='email']").val();
|
2017-04-06 02:28:57 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const opts = {
|
2020-07-20 22:18:43 +02:00
|
|
|
success_continuation() {
|
2019-07-10 19:17:26 +02:00
|
|
|
if (page_params.development_environment) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const email_msg = render_settings_dev_env_email_access();
|
2020-07-15 00:34:28 +02:00
|
|
|
ui_report.success(
|
|
|
|
email_msg,
|
|
|
|
$("#dev-account-settings-status").expectOne(),
|
|
|
|
4000,
|
|
|
|
);
|
2017-04-06 02:28:57 +02:00
|
|
|
}
|
2020-07-15 01:29:15 +02:00
|
|
|
overlays.close_modal("#change_email_modal");
|
2017-04-06 02:28:57 +02:00
|
|
|
},
|
2019-07-10 19:17:26 +02:00
|
|
|
error_msg_element: change_email_error,
|
2021-04-13 05:18:25 +02:00
|
|
|
success_msg_html: $t_html(
|
|
|
|
{defaultMessage: "Check your email ({email}) to confirm the new address."},
|
|
|
|
{email: data.email},
|
|
|
|
),
|
2019-07-10 19:17:26 +02:00
|
|
|
};
|
2020-07-15 00:34:28 +02:00
|
|
|
settings_ui.do_settings_change(
|
|
|
|
channel.patch,
|
|
|
|
"/json/settings",
|
|
|
|
data,
|
|
|
|
$("#account-settings-status").expectOne(),
|
|
|
|
opts,
|
|
|
|
);
|
2017-04-06 02:28:57 +02:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#change_email").on("click", (e) => {
|
2017-04-06 02:28:57 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2018-02-02 16:54:26 +01:00
|
|
|
if (!page_params.realm_email_changes_disabled || page_params.is_admin) {
|
2020-07-15 01:29:15 +02:00
|
|
|
overlays.open_modal("#change_email_modal");
|
|
|
|
const email = $("#email_value").text().trim();
|
|
|
|
$(".email_change_container").find("input[name='email']").val(email);
|
2018-02-02 15:40:15 +01:00
|
|
|
}
|
2017-04-06 02:28:57 +02:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#user_deactivate_account_button").on("click", (e) => {
|
2018-05-23 22:29:00 +02:00
|
|
|
// This click event must not get propagated to parent container otherwise the modal
|
|
|
|
// will not show up because of a call to `close_active_modal` in `settings.js`.
|
2017-04-06 02:28:57 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
$("#deactivate_self_modal").modal("show");
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#account-settings").on("click", ".custom_user_field .remove_date", (e) => {
|
2018-06-09 15:28:55 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2020-07-15 01:29:15 +02:00
|
|
|
const field = $(e.target).closest(".custom_user_field").expectOne();
|
2020-10-07 09:17:30 +02:00
|
|
|
const field_id = Number.parseInt($(field).attr("data-field-id"), 10);
|
2018-06-09 15:28:55 +02:00
|
|
|
update_user_custom_profile_fields([field_id], channel.del);
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#account-settings").on("change", ".custom_user_field_value", function (e) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const fields = [];
|
|
|
|
const value = $(this).val();
|
2020-10-07 09:17:30 +02:00
|
|
|
const field_id = Number.parseInt(
|
2020-07-15 00:34:28 +02:00
|
|
|
$(e.target).closest(".custom_user_field").attr("data-field-id"),
|
|
|
|
10,
|
|
|
|
);
|
2018-06-05 12:57:02 +02:00
|
|
|
if (value) {
|
2020-07-20 22:18:43 +02:00
|
|
|
fields.push({id: field_id, value});
|
2018-06-05 12:57:02 +02:00
|
|
|
update_user_custom_profile_fields(fields, channel.patch);
|
|
|
|
} else {
|
|
|
|
fields.push(field_id);
|
|
|
|
update_user_custom_profile_fields(fields, channel.del);
|
|
|
|
}
|
2018-02-26 20:42:37 +01:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#do_deactivate_self_button").on("click", () => {
|
|
|
|
$("#do_deactivate_self_button .loader").css("display", "inline-block");
|
2018-01-26 08:01:58 +01:00
|
|
|
$("#do_deactivate_self_button span").hide();
|
|
|
|
$("#do_deactivate_self_button object").on("load", function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const doc = this.getSVGDocument();
|
|
|
|
const $svg = $(doc).find("svg");
|
2018-01-26 08:01:58 +01:00
|
|
|
$svg.find("rect").css("fill", "#000");
|
2017-04-06 02:28:57 +02:00
|
|
|
});
|
2018-01-26 08:01:58 +01:00
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
setTimeout(() => {
|
2018-01-26 08:01:58 +01:00
|
|
|
channel.del({
|
2020-07-15 01:29:15 +02:00
|
|
|
url: "/json/users/me",
|
2020-07-20 22:18:43 +02:00
|
|
|
success() {
|
2018-01-26 08:01:58 +01:00
|
|
|
$("#deactivate_self_modal").modal("hide");
|
2018-12-04 02:12:08 +01:00
|
|
|
window.location.href = "/login/";
|
2018-01-26 08:01:58 +01:00
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
error(xhr) {
|
2021-04-13 02:00:33 +02:00
|
|
|
const error_last_owner = $t_html({
|
|
|
|
defaultMessage: "Error: Cannot deactivate the only organization owner.",
|
|
|
|
});
|
|
|
|
const error_last_user = $t_html(
|
|
|
|
{
|
|
|
|
defaultMessage:
|
|
|
|
"Error: Cannot deactivate the only user. You can deactivate the whole organization though in your <z-link>organization profile settings</z-link>.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"z-link": (content_html) =>
|
|
|
|
`<a target="_blank" href="/#organization/organization-profile">${content_html}</a>`,
|
|
|
|
},
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2019-11-02 00:06:25 +01:00
|
|
|
let rendered_error_msg;
|
2018-08-21 08:14:46 +02:00
|
|
|
if (xhr.responseJSON.code === "CANNOT_DEACTIVATE_LAST_USER") {
|
2020-08-22 00:28:49 +02:00
|
|
|
if (xhr.responseJSON.is_last_owner) {
|
|
|
|
rendered_error_msg = error_last_owner;
|
2018-08-21 08:14:46 +02:00
|
|
|
} else {
|
|
|
|
rendered_error_msg = error_last_user;
|
|
|
|
}
|
|
|
|
}
|
2018-01-26 08:01:58 +01:00
|
|
|
$("#deactivate_self_modal").modal("hide");
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#account-settings-status")
|
|
|
|
.addClass("alert-error")
|
|
|
|
.html(rendered_error_msg)
|
|
|
|
.show();
|
2018-01-26 08:01:58 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}, 5000);
|
2017-04-06 02:28:57 +02:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#show_my_user_profile_modal").on("click", () => {
|
2018-08-25 15:27:28 +02:00
|
|
|
overlays.close_overlay("settings");
|
2020-02-05 14:30:59 +01:00
|
|
|
const user = people.get_by_user_id(people.my_current_user_id());
|
2020-07-02 01:45:54 +02:00
|
|
|
setTimeout(() => {
|
2018-11-29 01:46:15 +01:00
|
|
|
popovers.show_user_profile(user);
|
2018-08-25 15:27:28 +02:00
|
|
|
}, 100);
|
2018-09-02 20:29:37 +02:00
|
|
|
|
|
|
|
// If user opened the "preview profile" modal from user
|
|
|
|
// settings, then closing preview profile modal should
|
|
|
|
// send them back to the settings modal.
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").one("hidden.bs.modal", "#user-profile-modal", (e) => {
|
2018-09-02 20:29:37 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
setTimeout(() => {
|
2018-09-02 20:29:37 +02:00
|
|
|
if (!overlays.settings_open()) {
|
|
|
|
overlays.open_settings();
|
|
|
|
}
|
|
|
|
}, 100);
|
|
|
|
});
|
2018-08-25 15:27:28 +02:00
|
|
|
});
|
|
|
|
|
2017-04-06 02:28:57 +02:00
|
|
|
function upload_avatar(file_input) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const form_data = new FormData();
|
2017-04-06 02:28:57 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
form_data.append("csrfmiddlewaretoken", csrf_token);
|
2020-02-08 01:53:49 +01:00
|
|
|
for (const [i, file] of Array.prototype.entries.call(file_input[0].files)) {
|
2020-07-15 01:29:15 +02:00
|
|
|
form_data.append("file-" + i, file);
|
2020-02-08 01:53:49 +01:00
|
|
|
}
|
2020-04-02 09:55:16 +02:00
|
|
|
display_avatar_upload_started();
|
2017-07-05 19:15:15 +02:00
|
|
|
channel.post({
|
2020-07-15 01:29:15 +02:00
|
|
|
url: "/json/users/me/avatar",
|
2017-04-06 02:28:57 +02:00
|
|
|
data: form_data,
|
|
|
|
cache: false,
|
|
|
|
processData: false,
|
|
|
|
contentType: false,
|
2020-07-20 22:18:43 +02:00
|
|
|
success() {
|
2020-04-02 09:55:16 +02:00
|
|
|
display_avatar_upload_complete();
|
2020-06-15 08:28:41 +02:00
|
|
|
$("#user-avatar-upload-widget .image_file_input_error").hide();
|
2018-03-02 18:33:20 +01:00
|
|
|
$("#user-avatar-source").hide();
|
2018-10-18 10:04:43 +02:00
|
|
|
// Rest of the work is done via the user_events -> avatar_url event we will get
|
2018-03-02 18:33:20 +01:00
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
error(xhr) {
|
2020-04-02 09:55:16 +02:00
|
|
|
display_avatar_upload_complete();
|
2020-07-15 01:29:15 +02:00
|
|
|
if (page_params.avatar_source === "G") {
|
2018-03-02 18:33:20 +01:00
|
|
|
$("#user-avatar-source").show();
|
|
|
|
}
|
2020-06-15 08:28:41 +02:00
|
|
|
const $error = $("#user-avatar-upload-widget .image_file_input_error");
|
2019-01-13 09:11:41 +01:00
|
|
|
$error.text(JSON.parse(xhr.responseText).msg);
|
|
|
|
$error.show();
|
2017-04-06 02:28:57 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
avatar.build_user_avatar_widget(upload_avatar);
|
|
|
|
|
2017-04-20 08:13:16 +02:00
|
|
|
if (page_params.realm_name_changes_disabled) {
|
2017-04-06 02:28:57 +02:00
|
|
|
$(".name_change_container").hide();
|
|
|
|
}
|
2021-02-28 01:18:00 +01:00
|
|
|
}
|