summaryrefslogtreecommitdiff
path: root/res/javas/bidding.js
blob: bacbeca83f3fa918c2a12ec0bd13344a394ead22 (plain)
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
var BIDDING_DATA = {
    toggle_bidding: function() {
        var element = $(this);
        if (element.data('bidding-row')) {
            element.data('bidding-row').remove();
            element.removeData('bidding-row');
        } else {
            var popup = $('<tr class="bidding_popup"><td class="n">&nbsp;</td><td class="bidding_cell noc" colspan="1000"></td></tr>');
            var bidding = BIDDING_DATA.data[element.attr('data-bidding-link')] || BIDDING_DATA.errorString;
            popup.find('.bidding_cell').html(bidding);
            element.closest('tr').after(popup);
            element.data('bidding-row', popup);
        }
        return false;
    },

    load_bidding: function() {
        $('a.biddingLink').hide();
        var dataLink = $('link[rel="bidding-file"]');
        if (dataLink.size() > 0) {
            $.ajax(
                {
                    url: dataLink.eq(0).attr('src'),
                    complete: function(xhr, status) {
                        if (status == 'success') {
                            BIDDING_DATA.data = JSON.parse(xhr.responseText);
                        }
                        $('a.biddingLink').show();
                    }
                }
            );
        }
    },

    bind_bidding_links: function() {
        $('a.biddingLink').each(function() {
            $(this).unbind('click').attr('title', 'Pokaż/ukryj licytację').click(BIDDING_DATA.toggle_bidding);
        });
    },

    data: {},
    errorString: 'Brak danych'
};

$(document).ready(function() {
    BIDDING_DATA.load_bidding();
    setInterval(BIDDING_DATA.bind_bidding_links, 1000);
});