Files
nairobi/app/assets/javascripts/managers.js.coffee
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

27 lines
699 B
CoffeeScript

"use strict"
App.Managers =
generatePassword: ->
possible_chars = "aAbcdeEfghiJkmnpqrstuUvwxyz23456789"
chars = Array.apply(null, length: 12).map ->
i = Math.floor(Math.random() * possible_chars.length)
possible_chars.charAt(i)
chars.join("")
togglePassword: (type) ->
$("#user_password").prop "type", type
initialize: ->
$(".generate-random-value").on "click", ->
password = App.Managers.generatePassword()
$("#user_password").val(password)
$(".show-password").on "click", ->
if $("#user_password").is("input[type='password']")
App.Managers.togglePassword("text")
else
App.Managers.togglePassword("password")