aboutsummaryrefslogtreecommitdiffstats
path: root/view/js/mod_new_channel.js
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2018-07-25 10:19:19 +0200
committerMario Vavti <mario@mariovavti.com>2018-07-25 10:19:19 +0200
commit1b1d11dcf1091158232e98abad966d4900e2ccc9 (patch)
tree380d5e04c73391089bf3d658ea4b27eecffa4916 /view/js/mod_new_channel.js
parentb655d04b3474893ee3dea99b77f2e7dd764729a0 (diff)
parent35200e5f1b10cdd18af8f0ea646996e438b97011 (diff)
downloadvolse-hubzilla-1b1d11dcf1091158232e98abad966d4900e2ccc9.tar.gz
volse-hubzilla-1b1d11dcf1091158232e98abad966d4900e2ccc9.tar.bz2
volse-hubzilla-1b1d11dcf1091158232e98abad966d4900e2ccc9.zip
Merge branch '3.6RC'
Diffstat (limited to 'view/js/mod_new_channel.js')
-rw-r--r--view/js/mod_new_channel.js95
1 files changed, 70 insertions, 25 deletions
diff --git a/view/js/mod_new_channel.js b/view/js/mod_new_channel.js
index e78de2596..10a94796c 100644
--- a/view/js/mod_new_channel.js
+++ b/view/js/mod_new_channel.js
@@ -1,43 +1,88 @@
$(document).ready(function() {
-
- $("#newchannel-submit-button").attr('disabled','disabled');
+ $("#id_name").focus();
$("#id_name").blur(function() {
- $("#name-spinner").show();
- var zreg_name = $("#id_name").val();
- $.get("new_channel/autofill.json?f=&name=" + encodeURIComponent(zreg_name),function(data) {
- $("#id_nickname").val(data);
- if(data.error) {
- $("#help_name").html("");
- zFormError("#help_name",data.error);
- }
- else {
- $("#newchannel-submit-button").removeAttr('disabled');
- }
- $("#name-spinner").hide();
- });
+ if(validate_name()) {
+ var zreg_name = $("#id_name").val();
+ $("#name_help_loading").show();
+ $("#name_help_text").hide();
+ $.get("new_channel/autofill.json?f=&name=" + encodeURIComponent(zreg_name),function(data) {
+ $("#id_nickname").val(data);
+ $("#id_nickname").addClass('is-validated');
+ $("#name_help_loading").hide();
+ $("#name_help_text").show();
+ });
+ }
});
- $("#id_nickname").click(function() {
- $("#newchannel-submit-button").attr('disabled','disabled');
+ $("#id_nickname").on('input', function() {
+ $("#id_nickname").removeClass('is-validated');
});
- });
+ $("#newchannel-form").on('submit', function(event) {
+ if(! validate_name()) {
+ $("#id_name").focus()
+ return false;
+ }
+
+ if(! validate_channel()) {
+ $("#id_nickname").focus()
+ return false;
+ }
+
+ if(! $("#id_nickname").hasClass('is-validated')) {
+ event.preventDefault();
+ }
+ });
+ });
function validate_channel() {
- $("#nick-spinner").show();
+ if($("#id_nickname").hasClass('is-validated'))
+ return true;
+
+ $("#nick_help_loading").show();
+ $("#nick_help_text").hide();
+ var zreg_name = $("#id_name").val();
var zreg_nick = $("#id_nickname").val();
- $.get("new_channel/checkaddr.json?f=&nick=" + encodeURIComponent(zreg_nick),function(data) {
+ $.get("new_channel/checkaddr.json?f=&nick=" + encodeURIComponent(zreg_nick) + '&name=' + encodeURIComponent(zreg_name),function(data) {
$("#id_nickname").val(data);
- if(data.error) {
- $("#help_nickname").html("");
- zFormError("#help_nickname",data.error);
+ if(data !== zreg_nick) {
+ $("#id_nickname").addClass('is-validated');
+ $("#help_nickname").addClass('text-danger').removeClass('text-muted');
+ $("#help_nickname").html(aStr['nick_invld1'] + data + aStr['nick_invld2']);
+ $("#id_nickname").focus();
}
else {
- $("#newchannel-submit-button").removeAttr('disabled');
+ $("#id_nickname").addClass('is-validated');
+ $("#help_nickname").addClass('text-success').removeClass('text-muted').removeClass('text-danger');
+ $("#help_nickname").html(aStr['nick_valid']);
}
- $("#nick-spinner").hide();
+ $("#nick_help_loading").hide();
+ $("#nick_help_text").show();
+
});
+ return true;
+
+ }
+
+ function validate_name() {
+ if($("#id_name").hasClass('is-validated'))
+ return true;
+
+ var verbs = [ aStr['lovely'], aStr['wonderful'], aStr['fantastic'], aStr['great'] ];
+ var verb = verbs[Math.floor((Math.random() * 4) + 0)];
+ if(! $("#id_name").val()) {
+ $("#id_name").focus();
+ $("#help_name").addClass('text-danger').removeClass('text-muted');
+ $("#help_name").html(aStr['name_empty']);
+ return false;
+ }
+ else {
+ $("#help_name").addClass('text-success').removeClass('text-muted').removeClass('text-danger');
+ $("#help_name").html(aStr['name_ok1'] + verb + aStr['name_ok2']);
+ $("#id_name").addClass('is-validated');
+ return true;
+ }
}