reader-view.js 1.73 KB
var AJAX_URLS = {
    'variant0': $dj.ajax_inflection_tables,
    'variant1': $dj.ajax_inflection_tables
};

var edit = {
    changed: false,

    get_id: function() {
        "use strict";
        return edit.active_id;
    },
    load_tab: function(tab_id, lexeme_id, check_callback) {
        "use strict";
        var key, callback;
        key = 'lexeme_id';
        callback = edit.busy_off;
        var data = {};
        data[key] = lexeme_id;
        if (tab_id === 'variant0') {
            data.variant = 0;
        }
        if (tab_id === 'variant1') {
            data.variant = 1;
        }
        $.ajaxJSON({
            method: 'get',
            url: AJAX_URLS[tab_id],
            dest: $('#' + tab_id),
            data: data,
            callback: callback,
            check_callback: check_callback,
            error_callback: function() {
                edit.busy_off();
            }
        });
    },
    load_content: function(id, is_created, check_callback) {
        "use strict";
        var tabs = $('#lexeme-tabs');
        tabs.find('.ui-tabs-panel').each(function(i, tab) {
            $(tab).empty();
        });
        var tab_no = tabs.tabs('option', 'active');
        var tab_id = tabs.children().get(tab_no + 1).id;
        edit.load_tab(tab_id, id, check_callback);
        edit.active_id = id;
    },

    // busy
    busy_ctrl: null,
    busy_on: function() {
        "use strict";
        if (!edit.busy_ctrl) {
            edit.busy_ctrl = getBusyOverlay(
                $('#right')[0],
                {color: 'black', opacity: 0.2},
                {size: 30});
        }
    },
    busy_off: function() {
        "use strict";
        if (edit.busy_ctrl) edit.busy_ctrl.remove();
        edit.busy_ctrl = null;
    }
};