Login

Admin actions as buttons instead of a menu [v2]

Author:
itavor
Posted:
December 15, 2011
Language:
JavaScript
Version:
1.3
Tags:
admin actions
Score:
0 (after 0 ratings)

Add this to your admin change_list.html template to replace the actions drop-down with buttons.

This is a rewritten version of snippet 1931 with Django 1.3 compatibility and cleaner code. Thanks to andybak for the idea.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
(function ($) {

    function fix_actions() {
        var container = $('div.actions');

        if (container.find('option').length < 10) {
            container.find('label, button').hide();

            var buttons = $('<div></div>')
                .prependTo(container)
                .css('display', 'inline')
                .addClass('class', 'action-buttons');

            container.find('option:gt(0)').each(function () {
                $('<button>')
                    .appendTo(buttons)
                    .attr('name', this.value)
                    .addClass('button')
                    .text(this.text)
                    .click(function () {
                        container.find('select')
                            .find(':selected').attr('selected', '').end()
                            .find('[value=' + this.name + ']').attr('selected', 'selected');
                        $('#changelist-form button[name="index"]').click();
                    });
            });
        }
    };

    $(function () {
        fix_actions();
    });
})(django.jQuery);

More like this

  1. Improved Button Admin by kunitoki 3 years ago
  2. Generic admin action export selected rows to excel by jordic 3 years, 5 months ago
  3. Generic admin action export selected rows to excel by aemb87 2 years, 4 months ago
  4. Generic CSV export admin action factory by anentropic 4 years, 9 months ago
  5. Generic CSV export admin action factory with labels by losttrekker 2 years, 11 months ago

Comments

Please login first before commenting.