Sha256: 3b1313197dfd70ff6cb87804cd3494c26dceef28f6aa607b44570ade8e8a7fed

Contents?: true

Size: 1.8 KB

Versions: 32

Compression:

Stored size: 1.8 KB

Contents

// Define the global Renalware namespace if not already defined.
var Renalware = typeof Renalware === 'undefined' ? {} : Renalware;

// Define the Renalware.PdRegimes closure.
Renalware.PdRegimes = (function () {
  // private functions and vars here
  var deselectAllBagDays = function() {
    $(document).on( "click", "a.deselect-bag-days", function(event) {
      event.preventDefault();
      var parent = $(this).closest(".bag-days");
      var checkboxes = $(parent).find("input[type='checkbox']");
      checkboxes.prop('checked', false);
    });
  };

  var duplicateBag = function() {
    $(document).on( "click", "#pd-regime-bags a.duplicate-bag", function(event) {
      event.preventDefault();

      $("a.add-bag").trigger("click");

      var bagToClone = $(this).closest(".fields").first();
      var newBag = $("#pd-regime-bags .fields").last();

      bagToClone.find('select').each(function(i) {
        newBag.find('select').eq(i).val($(this).val());
      });

      var checkedSelector = 'input[type=checkbox],[type=radio]';
      bagToClone.find(checkedSelector).each(function(i) {
        var checked = $(this).is(':checked');
        newBag.find(checkedSelector).eq(i).prop('checked', checked);
      });
    });
  };

  // public functions and vars here
  return {
    init : function() {
      deselectAllBagDays();
      duplicateBag();
    },
    toggleAddRemoveBags : function () {
      $('input.add-bag').hide();
      $('input.remove-bag').hide();
      $('a.add-bag').show();
      $('a.remove-bag').show();
    }
  }
}());
// Bind DOM ready and nested_form:fieldAdded events
// so that buttons are toggled when JS is active.
$(document).ready(Renalware.PdRegimes.init);
$(document).ready(Renalware.PdRegimes.toggleAddRemoveBags);
$(document).on('nested:fieldAdded:bags', Renalware.PdRegimes.toggleAddRemoveBags);

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
renalware-core-2.0.75 app/assets/javascripts/renalware/pd.js
renalware-core-2.0.74 app/assets/javascripts/renalware/pd.js
renalware-core-2.0.73 app/assets/javascripts/renalware/pd.js
renalware-core-2.0.72 app/assets/javascripts/renalware/pd.js
renalware-core-2.0.71 app/assets/javascripts/renalware/pd.js
renalware-core-2.0.70 app/assets/javascripts/renalware/pd.js
renalware-core-2.0.69 app/assets/javascripts/renalware/pd.js
renalware-core-2.0.68 app/assets/javascripts/renalware/pd.js
renalware-core-2.0.67 app/assets/javascripts/renalware/pd.js
renalware-core-2.0.64 app/assets/javascripts/renalware/pd.js
renalware-core-2.0.63 app/assets/javascripts/renalware/pd.js
renalware-core-2.0.62 app/assets/javascripts/renalware/pd.js
renalware-core-2.0.61 app/assets/javascripts/renalware/pd.js
renalware-core-2.0.60 app/assets/javascripts/renalware/pd.js
renalware-core-2.0.58 app/assets/javascripts/renalware/pd.js
renalware-core-2.0.57 app/assets/javascripts/renalware/pd.js
renalware-core-2.0.56 app/assets/javascripts/renalware/pd.js
renalware-core-2.0.55 app/assets/javascripts/renalware/pd.js
renalware-core-2.0.54 app/assets/javascripts/renalware/pd.js
renalware-core-2.0.53 app/assets/javascripts/renalware/pd.js