tushar912
737dbb3741
custom profile fields: Rename few functions.
...
Rename few functions referencing the "CHOICE" field to
instead use the new "SELECT" name. This is done so that they
can be reused in "SELECT_MULTIPLE" field.
2021-03-26 11:49:28 -07:00
tushar912
2cf51139cf
custom profile fields: Rename "CHOICE" to "SELECT" in frontend.
...
This requires a small backend change to the label.
2021-03-26 11:49:11 -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
tushar912
c6d1fbd051
settings: Fix input mouse behaviour in custom profile fields.
...
Add input to filter in sortablejs config. This prevents drag
and drog from being called on clicking input field. Also
set preventOnFilter to false. This prevents disabling the
default behaviour on the click event.
Fixes #17619
2021-03-15 11:11:47 -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
92a46888f0
node_tests: Mock sortablejs to avoid __Rewire__.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-12 10:06:34 -08:00
Steve Howell
8006c29748
node tests: Extract create_sortable for testing.
2021-03-06 11:10:57 -05:00
Anders Kaseorg
099e8fb00e
js: Convert static/js/settings_profile_fields.js to ES6 module.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-02 17:06:35 -08:00
Anders Kaseorg
ac4e293da5
settings_profile_fields: Use named export from sortablejs.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-02 17:06:35 -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
3faae49dc0
js: Convert static/js/loading.js to ES6 module.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-28 14:23:00 -08:00
Anders Kaseorg
e16687af83
js: Convert static/js/settings_ui.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
de791b82b6
eslint: Fix unicorn/no-for-loop.
...
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/no-for-loop.md
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-10-07 16:00:33 -07: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
Anders Kaseorg
d72423ef21
eslint: Replace empty-returns with consistent-return.
...
Instead of prohibiting ‘return undefined’ (#8669 ), we require that a
function must return an explicit value always or never. This prevents
you from forgetting to return a value in some cases. It will also be
important for TypeScript, which distinguishes between undefined and
void.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-09-25 15:17:59 -07:00
Anders Kaseorg
9238813135
js: Use destructuring for require statements.
...
This allows import/order to auto-fix blocks including these
statements.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-09-23 09:06:07 -04: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
59ba7e38c0
settings_profile_fields: Fix sortablejs import.
...
Commit 114cc1ec25
(#15949 ) introduced a
subtle bug because sortablejs provides both a CJS module and an ES
module that expose different interfaces to CJS require() under
Webpack. This difference will disappear when we convert
settings_profile_fields to an ES module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-31 20:16:26 -07:00
Anders Kaseorg
114cc1ec25
settings_profile_fields: Use SortableJS as a module.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-28 10:54:35 -07:00
Anders Kaseorg
498fe285fa
js: Access ‘disabled’ as a property, not an attribute.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-22 12:20:23 -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
b65d2e063d
js: Reformat with Prettier.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:25 -07:00
Anders Kaseorg
8046b6477a
js: Remove extra consecutive spaces.
...
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
d671d00cbd
settings_profile_fields: Iterate over field_types with Object.values.
...
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
Anders Kaseorg
f912572887
settings_profile_fields: Iterate over field_data with Object.entries.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-07 14:09:47 -08:00
Anders Kaseorg
f13f744874
settings_profile_fields: Clean up field_id type confusion.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-01-16 13:23:47 -08:00
Anders Kaseorg
28f3dfa284
js: Automatically convert var to let and const in most files.
...
This commit was originally automatically generated using `tools/lint
--only=eslint --fix`. It was then modified by tabbott to contain only
changes to a set of files that are unlikely to result in significant
merge conflicts with any open pull request, excluding about 20 files.
His plan is to merge the remaining changes with more precise care,
potentially involving merging parts of conflicting pull requests
before running the `eslint --fix` operation.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-11-03 12:42:39 -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
Yashashvi Dave
9e343f1a68
custom fields: Update create-field UI for default external account fields.
2019-08-28 15:39:20 -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
Anders Kaseorg
3c3471b720
templates: Rename *.handlebars ↦ *.hbs and - ↦ _.
...
Tweaked by tabbott to avoid accidentally disabling the linter for
handlebars templates.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-07-12 21:11:03 -07:00
Yashashvi Dave
27ead227c0
custom fields: Add separate alert-save widget for create field.
...
Add separate alert-notification widget for create-custom-field
in admin view.
Fixes part of #12748
2019-07-11 12:52:21 -07:00
Yashashvi Dave
d7ee2aced1
models: Add `external_account` in custom profile field types.
...
Add new custom profile field type, External account.
External account field links user's social media
profile with account. e.g. GitHub, Twitter, etc.
Fixes part of #12302
2019-07-09 17:21:54 -07:00
Yashashvi Dave
3368589df2
settings_profile_fields: Refactor function `read_field_data_from_form`.
2019-07-09 17:21:54 -07:00
Thomas Ip
f6aaf43029
refactor: Use explicit path when referencing handlebars templates.
2019-07-02 16:23:30 -07:00
Tim Abbott
09e57389ca
Revert "settings_profile_fields: Refactor `read_field_data_from_form`."
...
This seems to have made our Casper tests fail.
This reverts commit e3237cdee2
.
2019-06-17 16:35:57 -07:00
Yashashvi Dave
e3237cdee2
settings_profile_fields: Refactor `read_field_data_from_form`.
...
This is important setup for supporting external account type fields.
2019-06-17 15:02:36 -07:00
Yashashvi Dave
ac0d60f577
settings_profile_fields: Extract func `set_up_choices_field_edit_form`.
2019-06-06 22:36:16 -07:00
Steve Howell
0543e8fbc1
settings: Call maybe_disable_widgets() in set_up() methods.
...
We now rely on set_up() methods to call their
own module-specific versions of maybe_disable_widgets()
in the codepath for admin_sections.load_admin_section().
And then for live updates, we just explicitly call
all four modules that support maybe_disable_widgets().
This should make switching between sections slightly faster,
and it also reduces the risk of module A messing with
module B's state. (Granted, we have lots of other ways
that modules can mess with each other's state.)
2018-12-17 10:13:18 -08:00
Steve Howell
b88a5700f6
settings: Extract multiple versions of maybe_disable_widgets().
2018-12-17 10:13:16 -08: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
Yashashvi Dave
1d7164225f
custom field: Rename field type List to List of options in UI.
2018-08-27 17:26:07 -07:00
Marco Burstein
87e2231902
settings: Fix an error for non-admins on the custom profile fields page.
...
When non-admin users visit the custom profile fields settings page,
the `Sortable` error
Uncaught Sortable: `el` must be HTMLElement, and not
[object Undefined]
is thrown, with `undefined: undefined | No stacktrace available` being
shown in the browser. Fix this by only using `Sortable` if the user is
an admin.
Fix #10403 .
2018-08-23 23:03:59 -07:00
Yashashvi Dave
583fde4311
custom profile field: Set default values in create-field form on load.
...
Add call of reset function, on load of admin settings page.
This function reset values in create-new-field form, i.e.
field type.
2018-08-21 11:42:59 -07:00
Yashashvi Dave
03f5422ce8
custom profile field: Minor tweaks in field-table in admin settings.
...
This commit add minor changes in profile field table in
admin settings:
- Hide table header if there is no field
- Fix width of table column
2018-08-21 11:42:59 -07:00