diff --git a/ckanext-hdx_theme/ckanext/hdx_theme/fanstatic/landing_pages/hdx_signals.js b/ckanext-hdx_theme/ckanext/hdx_theme/fanstatic/landing_pages/hdx_signals.js index df1ad7739f..f8ce10af1f 100644 --- a/ckanext-hdx_theme/ckanext/hdx_theme/fanstatic/landing_pages/hdx_signals.js +++ b/ckanext-hdx_theme/ckanext/hdx_theme/fanstatic/landing_pages/hdx_signals.js @@ -1,6 +1,23 @@ $(document).ready(function () { - var $form = $('#mc_embed_signup form'); - var DATASETS_GROUP = '[4389]'; + + var $form = $('#signals-form-card form'); + var $button = $form.find('#mc-embedded-subscribe'); + var $fields = $form.find('#mce-EMAIL, #mce-FNAME, #mce-ORG'); + + var DATASETS_GROUPS = [ + '[4389]' + ]; + var LOCATIONS_GROUPS = [ + '[4397]', + '[4405]', + '[4417]', + '[4409]', + '[4401]', + '[4421]', + '[4425]' + ]; + var DATASETS_LOCATIONS_GROUPS = DATASETS_GROUPS.concat(LOCATIONS_GROUPS); + var ALL_LOCATIONS = [ '[4397][16384]', '[4405][8388608]', @@ -38,24 +55,32 @@ $(document).ready(function () { '[4421][8]', ]; - function select_group(group) { - $form.find('input[name^="group' + group + '"]').prop('checked', true); + function select_groups(groups) { + groups.forEach(function (group) { + $form.find('input[name^="group' + group + '"]').prop('checked', true); + }); + disable_submit_button(); } - function unselect_group(group) { - $form.find('input[name^="group' + group + '"]').prop('checked', false); + function unselect_group(groups) { + groups.forEach(function (group) { + $form.find('input[name^="group' + group + '"]').prop('checked', false); + }); + disable_submit_button(); } function select_values(values) { values.forEach(function (value) { $form.find('input[name="group' + value + '"]').prop('checked', true); }); + disable_submit_button(); } function unselect_values(values) { values.forEach(function (value) { $form.find('input[name="group' + value + '"]').prop('checked', false); }); + disable_submit_button(); } function add_select_buttons(group_label, group) { @@ -66,15 +91,36 @@ $(document).ready(function () { group_label.append(unselect_btn); select_btn.click(function () { - select_group(group); + select_groups([group]); }); unselect_btn.click(function () { - unselect_group(group); + unselect_group([group]); + }); + } + + function disable_submit_button() { + var dataset_checked = DATASETS_GROUPS.some(function (group) { + return $form.find('input[name^="group' + group + '"]:checked').length > 0; + }); + + var location_checked = LOCATIONS_GROUPS.some(function (group) { + return $form.find('input[name^="group' + group + '"]:checked').length > 0; + }); + + var fields_filled = $fields.toArray().every(function(field) { + return $(field).val().trim() !== ''; }); + + if(dataset_checked && location_checked && fields_filled) { + $button.removeClass('disabled').removeAttr('disabled'); + } + else { + $button.addClass('disabled').attr('disabled', 'disabled'); + } } $form.find('#select-all-datasets').on('click', function () { - select_group(DATASETS_GROUP); + select_groups(DATASETS_GROUPS); }); $form.find('#select-all-locations').on('click', function () { select_values(ALL_LOCATIONS); @@ -97,4 +143,14 @@ $(document).ready(function () { } }); + DATASETS_LOCATIONS_GROUPS.forEach(function (group) { + $form.find('input[name^="group' + group + '"]').on('change', function () { + disable_submit_button(); + }); + }); + + $fields.on('input', function() { + disable_submit_button(); + }); + }); diff --git a/ckanext-hdx_theme/ckanext/hdx_theme/templates/landing_pages/signals.html b/ckanext-hdx_theme/ckanext/hdx_theme/templates/landing_pages/signals.html index 9ba83dca2e..b9724940eb 100644 --- a/ckanext-hdx_theme/ckanext/hdx_theme/templates/landing_pages/signals.html +++ b/ckanext-hdx_theme/ckanext/hdx_theme/templates/landing_pages/signals.html @@ -30,7 +30,7 @@
-
+
@@ -69,37 +69,37 @@
  • + id="mce-group[4389]-4389-0" value="" checked>
  • + id="mce-group[4389]-4389-1" value="" checked>
  • + id="mce-group[4389]-4389-2" value="" checked>
  • + id="mce-group[4389]-4389-3" value="" checked>
  • + id="mce-group[4389]-4389-4" value="" checked>
  • + id="mce-group[4389]-4389-5" value="" checked>
  • @@ -123,7 +123,7 @@
    • + id="mce-group[4397]-4397-0" value="" checked>
    • @@ -147,7 +147,7 @@
      • + id="mce-group[4405]-4405-0" value="" checked>
      • @@ -166,7 +166,7 @@
        • + id="mce-group[4417]-4417-0" value="" checked>
        • @@ -211,7 +211,7 @@
          • + id="mce-group[4409]-4409-0" value="" checked>
          • @@ -242,7 +242,7 @@
            • + id="mce-group[4401]-4401-0" value="" checked>
            • @@ -281,7 +281,7 @@
              • + id="mce-group[4421]-4421-0" value="" checked>
              • @@ -337,7 +337,7 @@
                • + id="mce-group[4425]-4425-0" value="" checked>
                • @@ -353,9 +353,10 @@
- +