Sha256: c192a5ca1c1c36d141c5e4ee40443dedc5f6a2bcb64ef99680c7bca6e459ed6c

Contents?: true

Size: 1.08 KB

Versions: 6

Compression:

Stored size: 1.08 KB

Contents

var initializer = function() {
  $('.toggle-bool-switch').click(function(e) {
    var boolSwitch = $(e.target);

    var objectId = boolSwitch.data('object_id');
    var model = boolSwitch.data('model');
    var field = boolSwitch.data('field');

    var url = boolSwitch.data('url');
    var value = boolSwitch.data('value');
    var successMessage = boolSwitch.data('success_message');
    var data = { id: objectId };
    data[model] = {};
    data[model][field] = !value;

    $.ajax({
      url: url,
      data: data,
      dataType: 'json',
      headers : {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
      error: function() {
        var errorMsg = 'Error: Update Unsuccessful';
        alert(errorMsg);
      },
      success: function() {
        boolSwitch.data('value', !value);
        boolSwitch.toggleClass('on');
        if (!boolSwitch.hasClass('notify-success')) return;
        $(function() {
          setTimeout(alert(successMessage), 500);
        });
      },
      type: 'PATCH',
    });
  });
};

$(initializer);
$(document).on('turbolinks:load', initializer);

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
activeadmin_addons-1.9.0 app/javascript/activeadmin_addons/addons/toggle_bool.js
activeadmin_addons-1.8.3 app/javascript/activeadmin_addons/addons/toggle_bool.js
activeadmin_addons-1.8.2 app/javascript/activeadmin_addons/addons/toggle_bool.js
activeadmin_addons_rails6-1.7.2 app/javascript/activeadmin_addons/addons/toggle_bool.js
activeadmin_addons-1.7.1 app/assets/javascripts/activeadmin_addons/addons/toggle_bool.js
activeadmin_addons-1.7.0 app/assets/javascripts/activeadmin_addons/addons/toggle_bool.js