File size: 2,711 Bytes
27867f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
$(document).ready(setTimeout(function() {
    $('table.sortable th img.sortit').each(function() {
        
        $(this).click(function() {
            if ( $(this).hasClass("sortnone") ) {
                newDirection = 'sortasc';
            } else if ( $(this).hasClass("sortasc") ) {
                newDirection = 'sortdesc';
            } else if ( $(this).hasClass("sortdesc") ) {
                newDirection = 'sortnone';
            } else {
                newDirection = 'sortasc';
            }
            var text = getCellText($(this));
            $('input[name=sort_col]').val(text)
            $('input[name=sort_dir]').val(newDirection)
            $('form:first').submit()
            $('input[name=sort_col]').val(null)
            $('input[name=sort_dir]').val(null)
        });
    });
    
    $('table.sortable th img.filterit').each(function() {
        $(this).click(function() {
            var text = getCellText($(this));
            var outerWidth = 0;
            var innerWidth = 0;
            var popupElem;
            var isVisible = $('div#'+text+'-menu').is(':visible');
            $('div[id$=-menu]').each(function() {
                $(this).hide();
            });
            $('div#'+text+'-menu').each(function() {
                if ( !isVisible ) {
                    $(this).show();
                }
                outerWidth = $(this).outerWidth();
                innerWidth = $(this).innerWidth();
                popupElem = $(this);
            });
            var $left = $(this).offset().left - $('table.sortable').offset().left - $('#tablecontent').scrollLeft();
            var $farleft = $('table.sortable').width() - outerWidth -2 - $('#tablecontent').scrollLeft();
            var $width = innerWidth;
            if ($left > $farleft) {
                $left = $farleft;
            }
            var $bottom = $(this).offset().top + $(this).outerHeight() + 1 +$('.scrollFrameY').scrollTop();
            popupElem.css({
                left: $left,
                top: $bottom,
                width: $width,
            });
        });
    });
    
    $('table.sortable th input[type=checkbox]').each(function() {
        $(this).change(function() {
            var id = $(this).attr('id');
            var checked = $(this).is(':checked');
            $('table.sortable tr:not([class$="-hide"]) td input.'+id+':checkbox').each(function() {
                $(this).prop('checked', checked);
            });
        });
    });
    
    function getCellText(elem) {
        text = elem.parent().text();
        if (!text) {
            text = elem.parent().parent().find("input").attr("id");
        }
        return text
    }

}, 1000));