reader-view.js
3.68 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* global $dj, getBusyOverlay, common, slickgrid */
var AJAX_URLS = {
'variant0': $dj.ajax_inflection_tables,
'variant1': $dj.ajax_inflection_tables
};
$(function () {
"use strict";
var sort_rules = slickgrid.loader.getSort();
function set_sort() {
// copypasta z lexeme-view.js
slickgrid.update_sort_button(sort_rules);
var active_id = slickgrid.active_id();
slickgrid.loader.setSort(sort_rules);
if (active_id)
slickgrid.row_index(active_id);
}
$('#afronte-button').click(function() {
var $t = $(this);
if (!$t.hasClass('menu-button-active')) {
sort_rules[0] = 'a_fronte';
set_sort();
}
});
$('#atergo-button').click(function() {
var $t = $(this);
if (!$t.hasClass('menu-button-active')) {
sort_rules[0] = 'a_tergo';
set_sort();
}
});
});
var edit = {
reader: true,
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 = function() {
edit.busy_off();
if (tab_id === 'variant0' || tab_id === 'variant1') {
$('#' + tab_id).find('.form').each(function() {
if ($(this).text().trim() === edit.highlight_form) {
$(this).addClass('searched-form');
}
});
}
};
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');
$.ajaxJSON({
url: $dj.ajax_get_entry,
method: 'get',
data: {
lexeme_id: id
},
callback: function(data) {
common.update_hash('' + id + '/' + data.entry);
}
});
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;
}
};
var backup_update_sort_button = slickgrid.update_sort_button;
slickgrid.update_sort_button = function(sort_rules) {
"use strict";
var a_fronte = sort_rules[0] === 'a_fronte';
if (a_fronte) {
$('#afronte-button').addClass('menu-button-active');
$('#atergo-button').removeClass('menu-button-active');
} else {
$('#atergo-button').addClass('menu-button-active');
$('#afronte-button').removeClass('menu-button-active');
}
backup_update_sort_button(sort_rules);
};