pattern-reader-view.js 2.34 KB
/* global $dj, getBusyOverlay, common, slickgrid, gettext */

var default_root;

var edit = {
    reader: true,
    changed: false,

    load_content: function(id, is_created, check_callback) {
        "use strict";
        $.ajaxJSON({
            url: $dj.ajax_get_name,
            method: 'get',
            data: {
                pattern_id: id
            },
            callback: function(data) {
                common.update_hash('' + id + '/' + data.name);
                slickgrid.main_field_value = data.name;
                slickgrid.refresh_title();
            }
        });
        $.ajaxJSON({
            method: 'get',
            url: $dj.ajax_pattern_preview,
            dest: $('#preview'),
            data: {id: id},
            check_callback: check_callback,
            callback: function() {
                edit.busy_off();
                default_root = $('.root').first().text();
            }
        });
        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;
    }
};

slickgrid.title_part = function() {
    "use strict";
    return (gettext("Wzór") + ' ' + slickgrid.main_field_value) ||
        slickgrid.grid_caption;
};

(function() {
    "use strict";
    var narrowed_filter_fields = [
        'name',
        'lexical_class',
        'type'
        //'base_form_label'
    ];

    var new_filter_fields = {};
    $.each(narrowed_filter_fields, function (i, field) {
        new_filter_fields[field] = slickgrid.filter_fields[field];
    });
    slickgrid.filter_fields = new_filter_fields;
    //slickgrid.filter_fields.base_form_label.name = gettext("Etykieta");
    //slickgrid.filter_fields.base_form_label.gender = 'f';

})();

$(function() {
    "use strict";

    $(document).on('click', '.switch-example', function () {
        var $t = $(this);
        var root = $t.attr('data-example');
        $('.active-example').removeClass('active-example checked');
        $t.addClass('checked active-example');
        $('.root').text(root);
    });
});