Anders Kaseorg
fc9481a24e
js: Remove some pointless IIFEs.
...
Some of these were there because they predate block-scoped const/let.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-05-06 14:38:57 -07:00
aryanshridhar
c199229aa9
template: Move `admin_user_group_list` template to `settings` folder.
...
Moved `admin_user_group_list` template to `/templates/settings/` folder
as earlier, it was inaccurately placed within the `/templates` folder
and should have been within the `/templates/settings` folder.
Also modified the node tests to reflect the new changes.
2021-04-26 09:37:30 -07:00
Anders Kaseorg
2004a85fb1
i18n: Automatically convert remaining JavaScript messages to FormatJS.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-04-13 17:41:10 -07:00
Anders Kaseorg
00fb1aaadc
confirm_dialog: Convert heading, yes button messages to FormatJS.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-04-13 17:41:10 -07:00
Anders Kaseorg
a397d51670
ui_report: Convert messages to FormatJS.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-04-13 17:41:10 -07:00
Nikhil Maske
66fa31f85c
confirm_dialog_modal: Use Confirm and Cancel label options.
...
Long labels like "Unstar messages" can be confusing for
translators and it can also create bad strings that can
end with like 4 long words in German. It is better to
have the simple options like "Confirm" and "Cancel".
This commit fixes this issue by changing such text
to "Confirm" as default in confirm_dialog_modal.
Part of #17926 .
2021-04-07 18:27:18 -07:00
tushar912
5c50732008
user groups: Add remove event.
...
Before this we did not have remove event in server_events_dispatch.js
for the user group delete event even though server had. This was
leading to blueslip errors. Extracted the logic which was used in
success() of channel.del for user_groups into the remove case in
server_events_dispatch. Also removed the redundant reload call as
we already do that in server events.
2021-03-28 16:18:09 -07:00
Anders Kaseorg
38ffd47b90
js: Convert static/js/page_params.js to ES6 module.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-26 10:17:56 -07:00
Anders Kaseorg
bb1b2048bd
js: Convert static/js/i18n.js to ES6 module.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-26 10:17:56 -07:00
Anders Kaseorg
ea9ca6b7d0
js: Use jQuery as a module.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-12 10:08:25 -08:00
Anders Kaseorg
65840a2001
js: Convert static/js/settings_user_groups.js to ES6 module.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-28 14:23:00 -08:00
Anders Kaseorg
db6e3a41d3
js: Convert static/js/confirm_dialog.js to ES6 module.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-28 14:23:00 -08:00
Anders Kaseorg
26710a4370
js: Convert static/js/ui_report.js to ES6 module.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-28 14:23:00 -08:00
Anders Kaseorg
5a68bda15b
js: Convert static/js/user_groups.js to ES6 module.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-28 14:23:00 -08:00
Anders Kaseorg
09920af211
js: Convert static/js/channel.js to ES6 module.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-28 14:23:00 -08:00
Anders Kaseorg
000865ceb1
js: Convert static/js/user_pill.js to ES6 module.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-28 14:23:00 -08:00
Anders Kaseorg
a935af9243
js: Convert static/js/pill_typeahead.js to ES6 module.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-10 10:27:14 -08:00
Anders Kaseorg
aa650a4c88
js: Escape strings interpolated into CSS selectors with CSS.escape.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-04 11:00:06 -08:00
Anders Kaseorg
552f4e3d22
eslint: Fix unicorn/no-array-for-each.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-01-25 14:53:19 -08:00
Anders Kaseorg
fb233bd994
eslint: Fix unicorn/prefer-number-properties.
...
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/prefer-number-properties.md
MDN says these were added to Number for modularization of globals.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-10-07 16:00:33 -07:00
Priyank Patel
b7998d3160
js: Purge people module from window.
2020-09-01 19:55:58 -07:00
Ryan Rehman
60eef68f59
refactor: Extract `set_up_typeahead_on_pills` to a new file.
...
We move this function from `user_pill.js` to `pill_typeahead.js`.
The function has also been renamed to `set_up`.
The move was made because there are plans to update the pills
typeahead (i.e. to include user-groups/streams in the results).
Thus this function should not belong in `user_pill.js`.
2020-08-04 15:58:12 -07:00
Anders Kaseorg
6ec808b8df
js: Add "use strict" directive to CommonJS files.
...
ES and TypeScript modules are strict by default and don’t need this
directive. ESLint will remind us to add it to new CommonJS files and
remove it from ES and TypeScript modules.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-31 22:09:46 -07:00
Anders Kaseorg
d2520cd7e0
js: Replace underscore with lodash and remove it from globals.
...
Tweaked by tabbott to bump PROVISION_VERSION.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-26 16:12:06 -07:00
Ryan Rehman
6a245d6d93
minor: Refactor `set_up_typeahead_on_pills` function interface.
...
This is a prep commit which passes the `update_func` and `source`
data through an object. This will be helpful as there are plans
to pass furthur information to the function (i.e. whether we should
allow creating pills from streams and/or user-groups).
2020-07-22 17:00:34 -07:00
Anders Kaseorg
96dcc0ce6e
js: Use ES6 object literal shorthand syntax.
...
Generated by ESLint.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-21 12:42:22 -07:00
Anders Kaseorg
a9ca5f603b
js: Replace deprecated jQuery event trigger shorthand.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-21 12:01:26 -07:00
Anders Kaseorg
97feea42a1
js: Replace deprecated jQuery.fn.hover.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-21 12:01:26 -07:00
Anders Kaseorg
b65d2e063d
js: Reformat with Prettier.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:25 -07:00
Anders Kaseorg
a20c12366f
js: Use inside variant of IIFE wrappers.
...
Prettier would do this anyway, but it’s separated out for a more
reviewable diff. Generated by ESLint.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:25 -07:00
Anders Kaseorg
f3726db89a
js: Normalize strings to double quotes.
...
Prettier would do this anyway, but it’s separated out for a more
reviewable diff. Generated by ESLint.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:24 -07:00
Anders Kaseorg
e014ea966a
eslint: Enable comma-dangle for functions.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-03 16:55:51 -07:00
Anders Kaseorg
a79322bc94
eslint: Enable prefer-arrow-callback.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-03 16:55:50 -07:00
Anders Kaseorg
b0253c5a2e
eslint: Enable arrow-parens.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-03 16:53:39 -07:00
Anders Kaseorg
72dddb7af6
zjsunit: Use assert in strict mode.
...
This makes assert.equal and assert.deepEqual compare using === rather
than ==, to catch more bugs.
https://nodejs.org/api/assert.html#assert_strict_mode
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 08:16:26 -05:00
Anders Kaseorg
70ff164f89
js: Convert _.any(a, …), _.some(a, …) to a.some(…).
...
And convert the corresponding function expressions to arrow style
while we’re here.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
02511bff1c
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-07 14:09:47 -08:00
Steve Howell
b8f01f9cda
people: Rename method to get_by_user_id().
...
This name is consistent with:
get_by_email()
get_by_name()
2020-02-05 12:04:56 -08:00
Anders Kaseorg
de3146c137
js: Replace [...x] with Array.from(x).
...
Babel strict generates more code for [...x] than you’d like, while
Babel loose mode assumes x is an array.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-05 11:52:52 -08:00
Steve Howell
ef892271dc
int_dict: Fix type errors for user_groups.
...
This fixes some harmless type errors from the
following commit:
6ec5a1f306
The IntDict code automatically converts strings to
integers, so this was not a user-facing problem, but
we want to have our callers do the conversions
explicitly.
2020-01-27 13:14:40 -05:00
Anders Kaseorg
4341b7b252
user_groups: Convert members from Dict to Set.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-01-16 13:23:47 -08:00
Anders Kaseorg
f9f104a4f8
js: Automatically convert var to let and const in more files.
...
This commit was automatically generated by `tools/lint --only=eslint
--fix`, after an `.eslintrc.json` change.
A half dozen files were removed from the changes by tabbott pending
further work to ensure we avoid breaking valuable PRs with merge
conflicts.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-11-20 14:10:47 -08:00
Matheus Melo
c96762b7a9
settings: Add setting for who can edit user groups.
...
Fixes #12380 .
2019-11-03 16:45:13 -08:00
Anders Kaseorg
d17b577d0c
js: Purge useless IIFEs.
...
With webpack, variables declared in each file are already file-local
(Global variables need to be explicitly exported), so these IIFEs are
no longer needed.
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2019-10-25 13:51:21 -07:00
Anders Kaseorg
db0b33842c
templates: Replace templates.render with require calls.
...
This removes an unnecessary layer of indirection and allows webpack to
catch filename mistakes.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-07-12 21:11:14 -07:00
Tim Abbott
838dd6d273
lint: Add eslint enforcement for comma-spacing.
...
We've been enforcing this manually for a long time, and hadn't
realized it was missing from our eslint configuration.
2018-12-07 12:22:24 -08:00
Steve Howell
3545bc1893
settings: Confirm before deleting user groups.
...
Fixes #10498 .
2018-10-12 10:38:56 -07:00
Steve Howell
19ca7145fc
settings: Extract delete_user_group().
...
This preps us to make delete_user_group() be
a callback in the next commit.
2018-10-12 10:38:54 -07:00
Yashashvi Dave
9812b81a1e
user pills: Rename class `notmem` to `not-editable` for generalization.
2018-08-21 11:50:01 -07:00
Cynthia Lin
300c4c496f
user groups: Display error on user group name edit failure.
...
Fixes #10234 .
2018-08-13 16:13:49 -07:00