Sha256: d37c84ceebf8da47b428e57fc79715a92e4924608405094fd367743a37079316

Contents?: true

Size: 1.17 KB

Versions: 6

Compression:

Stored size: 1.17 KB

Contents

$(function() {
  $('.toggle-bool-switch').click(function(e) {
    var boolSwitch = $(e.target);
    var model = boolSwitch.data('model');
    var objectId = boolSwitch.data('object_id');
    var field = boolSwitch.data('field');
    var value = boolSwitch.data('value');
    var otherValue = String(value) !== 'true';
    var switchId = boolSwitch.attr('id');
    var otherSwitch = $('#' + switchId.substr(0, switchId.lastIndexOf('-') + 1) + otherValue);
    var url = boolSwitch.data('url');
    var successMessage = boolSwitch.data('success_message');
    var data = { id: objectId };
    data[model] = {};
    data[model][field] = otherValue;
    $.ajax({
      url: url,
      data: data,
      dataType: 'json',
      error: function() {
        var errorMsg = 'Error: Update Unsuccessful';
        alert(errorMsg);
      },
      success: function() {
        boolSwitch.addClass('hidden-switch');
        otherSwitch.removeClass('hidden-switch');
        if (!boolSwitch.hasClass('notify-success')) return;
        $(function() {
          var successMsg = 'Update Successful!';
          setTimeout(alert(successMessage), 500);
        });
      },
      type: 'PATCH',
    });
  });
});

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
activeadmin_addons-1.4.0 app/assets/javascripts/activeadmin_addons/addons/toggle_bool.js
activeadmin_addons-1.3.0 app/assets/javascripts/activeadmin_addons/addons/toggle_bool.js
activeadmin_addons-1.2.0 app/assets/javascripts/activeadmin_addons/addons/toggle_bool.js
activeadmin_addons-1.1.2 app/assets/javascripts/activeadmin_addons/addons/toggle_bool.js
activeadmin_addons-1.1.1 app/assets/javascripts/activeadmin_addons/addons/toggle_bool.js
activeadmin_addons-1.1.0 app/assets/javascripts/activeadmin_addons/addons/toggle_bool.js