Commit fe03ab20 authored by o@immerda.ch's avatar o@immerda.ch
Browse files

random name picker feature

parent 02c1c118
Array.prototype.sample = function(){
return this[Math.floor(Math.random()*this.length)];
}
function lazyLoad() {
var tag = document.createElement('script');
tag.src = '/random_names.js';
document.body.appendChild(tag);
}
random_loaded = false;
random_loading = false;
function waitForLazyLoad(update) {
if (random_loaded) {
update();
} else {
if (random_loading) {
setTimeout(function(){waitForLazyLoad(update)}, 300);
} else {
random_loading = true;
lazyLoad();
setTimeout(function(){waitForLazyLoad(update)}, 300);
}
}
}
function randomUsername(update) {
waitForLazyLoad(function() {
var res = random_forenames.sample().toLowerCase() + '.' +
random_surnames.sample().toLowerCase() + (Math.random()*100).toFixed();
update(res);
});
}
function randomGermanProjectname(n, update) {
waitForLazyLoad(function() {
var res = []
for (var i = 0; i < n; i++) {
var r = random_german_words.sample().toLowerCase();
if (r.match(/[^\w]+/g))
i--;
else
res.push(r);
}
update(res.join("-"));
});
}
function randomProjectname(n, update) {
waitForLazyLoad(function() {
var res = []
for (var i = 0; i < n; i++) {
var r = random_english_words.sample().toLowerCase();
if (r.match(/[^\w]+/g))
i--;
else
res.push(r);
}
update(res.join("-"));
});
}
......@@ -2,3 +2,4 @@
//= require signup_helpers
//= require pwhelp
//= require qrtoggle.js
//= require random
<div style="display:inline; padding-left: 150px; font-size: 70%"%>
<%= select_tag(:radomize,
options_for_select([
[t(:random),nil],
[t(:username),'username'],
["#{t(:words)} (de)",'words_de'],
["#{t(:words)} (en)",'words_en']
]),
onclick: "
function update(name) {
var v = document.getElementById('data_name');
if (!v)
v = document.getElementById('email');
v.value = name;
}
var val = this.value;
if (val == 'username')
randomUsername(update);
if (val == 'words_en')
randomProjectname(3, update);
if (val == 'words_de')
randomGermanProjectname(3, update);
") %>
</div>
......@@ -36,6 +36,9 @@ allowed = [q['max'].to_i - q['cur'].to_i, 0].max
<% @resource_schema.each do |n,v| %>
<div class="form-group">
<%= label_tag n %>
<% if n == 'name' %>
<%= render 'random' %>
<% end %>
<%= case v
when Array
select_tag('data_'+n, options_for_select(v), class: 'form-control')
......
......@@ -12,6 +12,7 @@
<%= form_tag("#{signup_path}/#{URI::escape(@token)}", method: "post") do %>
<div class="form-group">
<%= label_tag(:email, (t :email)) %>
<%= render 'random' %>
<%= text_field_tag(:email, '', value: @email || 'ig', autofill: 'off', class: "form-control") %>
@
<%= select_tag :domain, options_for_select(@domains.map{|d| [d,d]}, 'immerda.ch'), class: "form-control" %>
......
......@@ -225,6 +225,9 @@ de:
other: "Du kannst aktuell noch %{count} neue erstellen."
one: "Du kannst aktuell noch eine neue erstellen."
random: zufällig
words: Wörter
activerecord:
errors:
messages:
......
......@@ -226,6 +226,9 @@ en:
one: "You can still create one."
other: "You can still create up to %{count} fresh ones."
random: random
words: Words
activerecord:
errors:
messages:
......
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment