Sha256: d820c7a8d8aa1ee3387ca63947b717dd35b5e09274052041f915a9cd75d15d86

Contents?: true

Size: 1.05 KB

Versions: 13

Compression:

Stored size: 1.05 KB

Contents

(function($) {
    $(function(){
        var button = $('.button.quicksave');
        button.click(function(e) {
            e.preventDefault();

            $.ajaxSetup({
                beforeSend: function(xhr) {
                    xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'));
                }
            });

            var form = $(this).closest('form');
            var url = form.attr('action');
            var textarea = $(this).closest('.active_admin_editor').find('textarea');
            var fields = textarea.attr('id').split('_');
            var content = textarea.val();
            var data = {
                _method: 'PUT'
            };

            data[fields[0]] = {};
            data[fields[0]][fields[1]] = content;

            $.ajax({
                url: url,
                type: 'POST',
                dataType: 'json',
                data: data,
                success: function(response) {
                    console.log('saved');
                }
            });
        });
    });
})(jQuery);

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
active_admin_editor-0.3.6 app/assets/javascripts/active_admin/editor/quicksave.js
active_admin_editor-0.3.5 app/assets/javascripts/active_admin/editor/quicksave.js
active_admin_editor-0.3.4 app/assets/javascripts/active_admin/editor/quicksave.js
active_admin_editor-0.3.3 app/assets/javascripts/active_admin/editor/quicksave.js
active_admin_editor-0.3.2 app/assets/javascripts/active_admin/editor/quicksave.js
active_admin_editor-0.3.1 app/assets/javascripts/active_admin/editor/quicksave.js
active_admin_editor-0.3.0 app/assets/javascripts/active_admin/editor/quicksave.js
active_admin_editor-0.2.4 app/assets/javascripts/active_admin/editor/quicksave.js
active_admin_editor-0.2.3 app/assets/javascripts/active_admin/editor/quicksave.js
active_admin_editor-0.2.2 app/assets/javascripts/active_admin/editor/quicksave.js
active_admin_editor-0.2.1 app/assets/javascripts/active_admin/editor/quicksave.js
active_admin_editor-0.2.0 app/assets/javascripts/active_admin/editor/quicksave.js
active_admin_editor-0.1.0 app/assets/javascripts/active_admin/editor/quicksave.js