:javascript $('.create-rocket').click(function () { swal({ input: 'text', title: "#{t('keppler.rockets.choose_a_name')}", text: "#{t('keppler.rockets.rocket_name')}", confirmButtonText: "#{t('keppler.rockets.create_rocket')}", cancelButtonText: "#{t('keppler.rockets.cancel')}", showCancelButton: true, }).then((result) => { if (parseRocketName(result.value) && parseRocketName(result.value) != '') { var rocket_name = parseRocketName(result.value); swal({ title: "#{t('keppler.rockets.you_sure')}", html: `#{t('keppler.rockets.will_be_named')}:
keppler_${parseRocketName(result.value)}
`, confirmButtonText: "#{t('keppler.rockets.great')}", showCancelButton: true, }).then((result) => { if (result.value) { swal({ title: "#{t('keppler.rockets.great')}", html: "#{t('keppler.rockets.wait_generator')}", timer: 3000, onOpen: () => { swal.showLoading() }, }).then((result) => { $('.spinner').fadeIn() $('.create_rocket_form') .attr('action', `/admin/rockets/create/${rocket_name}`) .submit() // if (result.dismiss === swal.DismissReason.timer) { // } }) } }) } else { swal({ title: 'Oops!', html: "#{t('keppler.rockets.unpermitted_name')}", timer: 3000 }) } }) }) function parseRocketName(rocket_name) { var rn = rocket_name .toLowerCase() .split('keppler').join('') var valid_chars = []; for (var i = 0; i < rn.split('').length; i++){ var char = rn.split('')[i] if ([' ', '_'].includes(char)) valid_chars.push('_') else if (/[a-zA-Z]/.test(char)) valid_chars.push(char); } rn = valid_chars.join('') while (rn[0]=='_') rn = rn.substring(1, rn.length); return rn }