lexeme-view.js 4.66 KB
var text_ops = ['eq', 'ne', 'bw', 'bn', 'ew', 'en', 'cn', 'nc', 're', 'nr'];
var eqne = ['eq', 'ne'];
var count_ops = ['eq', 'ge', 'le'];

$.extend(slickgrid, {
    grid_caption: "Leksemy",
    grid_element_id: 'lexeme-grid',
    main_field: 'entry',
    initial_columns: ["entry", "pos"],
    initial_sort_rules: ['a_fronte'],
    all_columns: {
        id: {id: "id", name: "Nr", field: "id"},
        entry: {id: "entry", name: "Hasło", field: "entry"},
        pos: {id: "pos", name: "Część mowy", field: "pos"},
        patterns: {id: "patterns", name: "Wzory", field: "patterns"},
        ics: {id: "ics", name: "Char. fleks.", field: "ics"},
        vocabs: {id: "vocabs", name: "Słowniki", field: "vocabs"},
        owner: {id: "owner", name: "Sł. właściciel", field: "owner"},
        status: {id: "status", name: "Status", field: "status"}
    },
    filter_fields: {
        entry: {name: 'Hasło', gender: 'n', ops: text_ops},
        part_of_speech: {
            name: 'Część mowy',
            gender: 'f',
            ops: eqne,
            options: $dj.parts_of_speech
        },
        pattern_name: {name: 'Wzór', gender: 'm', ops: eqne},
        pattern_count: {name: 'Liczba wzorów', gender: 'f', ops: count_ops},
        inflection_characteristic: {
            name: 'Char. fleks.', gender: 'f', ops: eqne},
        ic_count: {name: 'Liczba char. fleks.', gender: 'f', ops: count_ops},
        form: {name: 'Forma', gender: 'f', ops: text_ops},
        containing_vocabulary: {
            name: 'Słownik',
            gender: 'm',
            ops: eqne,
            options: $dj.visible_vocabularies
        },
        owner_vocabulary: {
            name: 'Słownik właściciel',
            gender: 'm',
            ops: eqne,
            options: $dj.visible_vocabularies
        },
        status: {
            name: 'Status',
            gender: 'm',
            ops: eqne,
            options: $dj.status_options
        },
        comment: {name: 'Komentarz', gender: 'm', ops: text_ops},
        lexeme_qualifier: {
            name: 'Kwal. leksemu',
            gender: 'm',
            ops: eqne,
            options: $dj.qualifier_options
        },
        lip_qualifier: {
            name: 'Kwal. odmieniasia',
            gender: 'm',
            ops: eqne,
            options: $dj.qualifier_options
        },
        qualifier: {
            name: 'Kwal. przy dow. formie',
            gender: 'm',
            ops: eqne,
            options: $dj.qualifier_options
        },
        classification_value: {
            name: 'Wartość klasyfikacji',
            gender: 'f',
            ops: eqne,
            options: $dj.cv_options
        },
        gloss: {name: 'Glosa', gender: 'f', ops: text_ops},
        note: {name: 'Nota', gender: 'f', ops: text_ops},
        cr_type: {
            name: 'Typ odsyłacza',
            gender: 'm',
            ops: eqne,
            options: $dj.cr_type_options
        }
    },

    load_content: function(id, is_created) {
        "use strict";
        function check() {
            return id === slickgrid.active_id();
        }
        edit.load_content(id, is_created, check);
    },

    update_sort_button: function(sort_rules) {
        "use strict";
        var icon = $('#sort-button').find('.ui-icon');
        if (sort_rules[0] === 'a_fronte') {
            icon.removeClass('ui-icon-sort-atergo').addClass('ui-icon-sort');
        } else {
            icon.removeClass('ui-icon-sort').addClass('ui-icon-sort-atergo');
        }
    },

    init_sort: function() {
        "use strict";
        var sort_rules = slickgrid.loader.getSort();
        slickgrid.update_sort_button(sort_rules);
        $('#sort-button').click(function() {
            if (sort_rules[0] === 'a_fronte')
                sort_rules[0] = 'a_tergo';
            else
                sort_rules[0] = 'a_fronte';
            slickgrid.update_sort_button(sort_rules);
            var active_id = slickgrid.active_id();
            slickgrid.loader.setSort(sort_rules);
            // TODO sprawdzić indeks zaznaczonego rekordu w nowym porządku
            $.ajaxJSON({
                url: $dj.ajax_row_index,
                method: 'get',
                data: {
                    id: active_id,
                    sort_rules: sort_rules,
                    filter: slickgrid.loader.getFilter(),
                    mask: slickgrid.search_string()
                },
                callback: function(data) {
                    var index = data.index;
                    slickgrid.set_active_when_loaded = index;
                    slickgrid.grid.scrollRowToTop(index);
                    slickgrid.ensure_data();
                }
            });
        });
    }
});