Commit Graph

15065 Commits

Author SHA1 Message Date
Javi Martín
cf5b538c1c Check page between AJAX requests
While the test should work without this assertion, the intention of the
test is to check what happens if a user selects and investment and, once
it's selected, clicks the "next" link.
2019-09-11 19:38:35 +02:00
Javi Martín
9d6ed7a085 Show only defined columns on inserted rows
When we were inserting a row or replacing an existing one (just like we
do when we click the link to select an investment), we were entering a
row containing all columns, and all of them were displayed even if they
had been excluded using the column selector.

This caused the table to move in a strange way, which sometimes made the
investment selection tests fail.
2019-09-11 19:38:34 +02:00
Javi Martín
c6fc0062d7 Fix typo 2019-09-11 18:49:59 +02:00
decabeza
08e820c134 Hide polls created by users on admin poll booth assigments 2019-09-11 18:44:32 +02:00
Javier Martín
cb6539d170 Merge pull request #3537 from PierreMesure/set-locales-in-test-environment
Set locales in test environment to avoid failed specs
2019-09-11 18:43:03 +02:00
Javi Martín
7f8474ea95 Reduce locales used in remote translations tests
This way we can reduce the number of locales used in the test
environment as well, while still testing every possible scenario for
remote translations.
2019-09-11 16:33:25 +02:00
Javier Martín
88afeda085 Merge pull request #3656 from consul/fix_alert_text
Fix text confirming investment heading support
2019-09-11 15:34:50 +02:00
Javier Martín
f362939eb3 Merge pull request #3653 from consul/migrate_coffeescript
Migrate CoffeeScript to JavaScript
2019-09-11 15:30:44 +02:00
Javi Martín
8231096854 Add JavaScript rule to disallow array constructors
Using `Array(0, 1, 2)` will *not* create an Array with the elements
[0, 1, 2]. This is a mistake I've seen in the past, and the JavaScript
community recommends adding this rule.
2019-09-11 14:03:24 +02:00
Javi Martín
af6a494344 Apply JavaScript rule to use the dot notation
We were using the dot notation in most places, but not everywhere.
2019-09-11 14:03:24 +02:00
Javi Martín
25bfd01e69 Add JavaScript rule to return a value in callbacks
It's very easy for Ruby developers to omit the `return` statement in an
array callback, such as the ones in `map` or `filter`. Doing so will
make those funcions have the same effect as `forEach`, which is usually
not the intended behaviour.
2019-09-11 14:03:24 +02:00
Javi Martín
044da18af1 Apply JavaScript rules to prevent shadowing
Using the same variable name makes the code more difficult to read.

We're also enabling the `no-param-reassing` rule since we accidentally
reassigned params in commit 824dd26d, and this rule will prevent us from
doing so in the future.
2019-09-11 14:03:24 +02:00
Javi Martín
efc32bc764 Enable Yoda JavaScript rule
The rule is not the most important one, but the name is awesome!
2019-09-11 14:03:24 +02:00
Javi Martín
d9bb553894 Add JavaScript rule for comparisons
Using `==` and `!=` sometimes causes unexpected behaviour in JavaScript,
and it's easy for Ruby developers to use them incorrectly.
2019-09-11 14:03:24 +02:00
Javi Martín
392095a379 Add JavaScript rule for maximum line length
I'm using the same criteria we use in Ruby: 110 characters, and the
severity set as a warning, since it's a rule we break sometimes.
2019-09-11 14:03:24 +02:00
Javi Martín
9185c0bcc6 Add JavaScript rule for semi colons
While I personally prefer the "never" option for this rule, we haven't
discussed which guideline to follow, so for now I'm applying the rule
CoffeeScript used when generating these files.
2019-09-11 14:03:24 +02:00
Javi Martín
86c9f53c2d Use undefined instead of void
We originally wrote `undefined` in CoffeeScript.

CoffeeScript compiled it to `void 0` when generating the JavaScript
files. However, the reason to do so was the `undefined` variable was
mutable before ECMAScript 5. Using `undefined` is more intuitive, and
nowadays there's no reason to use `void 0`.
2019-09-11 14:03:24 +02:00
Javi Martín
5211f47842 Add and apply ESLint spacing rules
For now we're only adding rules related to spacing and double quotes,
following the same rules we use in Ruby, which are the same rules
CoffeeScript followed when compiling these files.

We're also using the recommended ESLint rules, which will warn us about
many JavaScript common pitfalls, the `strict` rule which enforces using
strict mode, and the `no-console` rule, which will prevent us from
shipping code meant for debugging.

Although it's arguably more common to use the JSON format to define
these rules, I've chosen YAML because it's the format we use in all our
linters.
2019-09-11 14:03:24 +02:00
Javi Martín
ec5af1f1bc Remove unnecessary return statements
These statements were automatically added by CoffeeScript.

I'm only removing the obvious cases; there might be more cases where the
`return` statement isn't necessary.
2019-09-11 14:03:24 +02:00
Javi Martín
d93a029ce5 Convert CofeeScript to JavaScript
Compiled using `coffee -c` with CoffeeScript 1.12.6.
2019-09-11 14:03:24 +02:00
Javier Martín
2ff2100ebb Merge pull request #3651 from consul/simplify_coffeescript
Clean up CoffeeScript code
2019-09-11 14:01:51 +02:00
Javi Martín
2f10005739 Fix text confirming investment heading support
We accidentally removed the `count` option in commit 55fb14ac, which
made the translation return a hash.

The test is a bit hacky, which makes me think changing the user
interface would probably be a better solution.
2019-09-11 03:18:12 +02:00
Javi Martín
d8be18d6a9 Use double quotes in CoffeeScript
We accidentally added some single quotes recently.
2019-09-11 03:14:17 +02:00
Javi Martín
f83f0f08be Fix typo 2019-09-11 03:14:17 +02:00
Javi Martín
cc7e0d586b Reduce local variables usage in CoffeeScript
Local variables are one of the things CoffeeScript doesn't compile to
modern JavaScript automatically: it uses `var` instead of `const` or
`let`.

Besides, using `$this = $(this)` is usually done to reference the
current object in another function where the current object is a
different one. Here we were using it with no clear purpose.
2019-09-11 03:14:17 +02:00
Javi Martín
ba325526ae Use Array.apply to repeat a loop
In JavaScript we cannot easily repeat something N times, and
CoffeeScript's range loop compiles into complex JavaScript.

We could also use `Array.from({ length: N })`, but that's not supported
by old browsers like Internet Explorer 11.
2019-09-11 03:14:17 +02:00
Javi Martín
00d7c92e86 Don't assign in conditionals
The assignment operator can easily be mistaken with the equality
operator when used in a condition, making the code more difficult to
read.
2019-09-11 03:14:17 +02:00
Javi Martín
86e704d8a4 Use strict mode in JavaScript
Strict mode is supported by 98% of the browsers, including Internet
Explorer 10, and it helps developers avoid common JavaScript pitfalls.
2019-09-11 03:14:17 +02:00
Javi Martín
747767386a Use this instead of @ in CoffeeScript
We're using `this` most of the time, and it's what's used in JavaScript.
2019-09-11 03:14:17 +02:00
Javi Martín
aa458b8c87 Extract functions in foundation extras
In foundation extras we were assigning functions to local variables, but
in the rest of the CoffeeScript files we use them as object properties.
2019-09-11 03:14:17 +02:00
Javi Martín
dcc838b3d8 Make conditions easier to read
Combining both the inline and "traditional" `if` styles made the code
difficult to read, particularly when compiled to JavaScript.
2019-09-11 03:14:17 +02:00
Javi Martín
1634cd5263 Use each instead of $.each
Iterating through the jQuery elements with `each` is more similar to
other iterators we use. Furthermore, we avoid declaring the `index`
variable we don't use.
2019-09-11 03:14:17 +02:00
Javi Martín
3b5d295cdc Simplify function call 2019-09-11 03:14:17 +02:00
Javi Martín
879cc2571f Use different names for variable and parameter
Using the same name means from that point the name doesn't refer to the
original parameter, which might be confusing when reading the method.
2019-09-11 03:14:17 +02:00
Javi Martín
c55a1a9faf Simplify finding rows for sortable tables
Including the table body is more intuitive than excluding the first row
and the table foot.
2019-09-11 03:14:17 +02:00
Javi Martín
936aa7af0f Simplify adding rows to sortable tables
The `append` method can handle arrays, so there's no need to loop
through each element.

There's more to improve on this method, like the `asc` variable being
global to a table instead of depending on the current column, but for
now I'm only refactoring and maintaining the current behaviour.
2019-09-11 03:14:16 +02:00
Javi Martín
4d7c124188 Remove unnecessary conditions
The code won't do anything if there are no elements, so there's no need
to check that condition.
2019-09-11 03:14:16 +02:00
Javi Martín
1cc3324468 Use each and forEach instead of for .. in
We're planning to replace CoffeeScript with JavaScript, and CoffeeScript
compiles `for .. in` to complex JavaScript code.
2019-09-11 03:14:16 +02:00
Javi Martín
3120e0aa41 Use ECMAScript 5 array and string methods
These methods were added in 2009 and are supported by 98.5% of the
browsers, including Internet Explorer 9, 10 and 11. We were already
using them in some places.
2019-09-11 03:14:16 +02:00
Javi Martín
49b4a0c71d Simplify banners JavaScript
There were functions which were just simple wrappers to common jQuery
functions.
2019-09-11 03:14:16 +02:00
Javi Martín
1f828bf4d4 Simplify code to check form changes 2019-09-11 03:14:16 +02:00
Javier Martín
de50317d25 Merge pull request #3654 from consul/fix_javascript_typos
Fix JavaScript Lint errors
2019-09-11 03:13:24 +02:00
Javier Martín
031fb08f39 Merge pull request #3652 from consul/remove_unused_javascript
Remove unused JavaScript code
2019-09-11 02:40:54 +02:00
Javi Martín
eab35dc9b0 Don't call hasOwnProperty directly
Calling it directly might make it difficult to detect bugs, particularly
when we don't trust the data we receive:

https://eslint.org/docs/rules/no-prototype-builtins

If we trust the data we receive, then IMHO we shouldn't even check for
`hasOwnProperty`, since we know what we're going to receive.
2019-09-11 02:07:35 +02:00
Javi Martín
5ad41d9ac7 Add a break to avoid case fallthrough
In JavaScript, when there isn't a `break` or `return` statement inside a
`switch` case, the next case will be executed as well.

That wasn't a problem here because CoffeeScript automatically inserts a
`return` statement in this specific situation. However, since we don't
want to return the result of the `hide()` operation, it might be easy to
accidentally remove the `return` statement, causing the code to break.

I've added a test for the scenario where neither `break` nor `return`
statements are present, so we don't run into this error.
2019-09-11 02:05:04 +02:00
taitus
10a2e91f1c Fix wrong js 2019-09-11 02:05:04 +02:00
Alceu Medeiros
1f059d44cf Set current locale as default for datepicker translation 2019-09-11 02:05:04 +02:00
Javi Martín
e4985d371d Remove code added for debugging purposes 2019-09-11 01:56:27 +02:00
Javi Martín
f28a5cc49b Remove unused piwik-related code
This code requires the variable `_paq` to be set somewhere, but we never
set it.

In the past Decide Madrid added some custom JavaScript using this code.
However, in CONSUL we're using Ahoy to track events, and we don't have
any documentation about adding custom JavaScript to use piwik nor we've
got any other piwik integration.
2019-09-11 01:56:27 +02:00
Javi Martín
a9d28bee15 Remove unused code in App.Cookies
The `removeCookie` function is never called, and the `initialize`
function doesn't do anything. The only functions we use here are
`getCookie` and `saveCookie`.
2019-09-11 01:56:27 +02:00