pattern-view.js 2.44 KB
/* global $dj, slickgrid, edit, gettext */

var text_ops = ['eq', 'ne', 'bw', 'bn', 'ew', 'en', 'cn', 'nc', 're', 'nr'];
var eqne = ['in', '-in'];

var column_names = {
    name: gettext("nazwa"),
    type: gettext("typ"),
    lexical_class: gettext("typ odm."),
    example: gettext("przykład")
};

var columns = {};
var main_field = 'name';

$.each(column_names, function(key, name) {
    "use strict";
    columns[key] = {id: key, field: key, name: name};
    if (key === main_field)
        columns[key].cssClass = 'main-column';
});

$.extend(slickgrid, {
    grid_caption: gettext("Wzory"),
    genitive: gettext("wzorów"),
    grid_element_id: 'pattern-grid',
    main_field: main_field,
    initial_columns: $dj.initial_columns,
    initial_sort_rules: [],
    all_columns: columns,
    filter_fields: {
        'name': {name: gettext("Nazwa"), gender: 'f', ops: text_ops},
        'old_name': {name: gettext("Stara nazwa"), gender: 'f', ops: text_ops},
        'lexical_class': {
            name: gettext("Typ odmiany"),
            gender: 'f',
            ops: eqne,
            options: $dj.lexical_class_options
        },
        'type': {
            name: gettext("Typ"),
            gender: 'm',
            ops: eqne,
            optgroups: $dj.pattern_type_options
        },
        'base_form_label': {name: gettext("Efobaz"), gender: 'm', ops: text_ops}
    },
    load_content: function(id) {
        "use strict";
        function check() {
            return id === slickgrid.active_id();
        }
        edit.busy_on();
        edit.load_content(id, check);
    },
    init_sort: function() {},
    init: function() {},
    // copypasta
    row_index: function(id) {
        "use strict";
        $.ajaxJSON({
            url: $dj.ajax_row_index,
            method: 'get',
            data: {
                id: id,
                sort_rules: slickgrid.loader.getSort(),
                filter: slickgrid.loader.getFilter()
            },
            callback: function(data) {
                var index = data.index;
                if (index === null) {
                    slickgrid.load_content(id);
                    slickgrid.last_active_row = undefined;
                    slickgrid.grid.resetActiveCell();
                } else {
                    slickgrid.set_active_when_loaded = index;
                    slickgrid.grid.scrollRowToCenter(index);
                    slickgrid.ensure_data();
                }
            }
        });
    }
});