export.js
1.71 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
// straszna i zła copypasta
function selected_qualifiers_text(num, total, checked) {
if (num >= 4)
return num + ' kwalifikatorów';
grouped = {};
$.each(checked, function(i, elem) {
id = elem.value;
vocab = vocabs[id];
if (grouped[vocab] === undefined)
grouped[vocab] = [];
grouped[vocab].push(elem.title);
});
vocab_table = [];
owner = $('#owner-vocabulary').text();
if (grouped[owner])
vocab_table.push(owner + ': ' + grouped[owner].join(', '));
for (vocab in grouped) {
if (vocab != owner)
vocab_table.push(vocab + ': ' + grouped[vocab].join(', '));
}
return vocab_table.join('; ');
}
var qualifier_options = {
noneSelectedText: 'Wybierz',
selectedText: selected_qualifiers_text,
selectedList: 4,
header: false,
};
var new_row_counter = 1;
function get_new_qualifier_row_html() {
var new_row_html = $.ajax({
type: 'get',
url: ajax_new_qualifier_row,
async: false
}).responseText;
var row_html = new_row_html.replace(/NUM/g, new_row_counter);
new_row_counter++;
return row_html;
}
function add_qualifier_row() {
var new_row = $(get_new_qualifier_row_html());
$('#magic-qualifiers').append(new_row);
new_row.find('button').button();
}
function remove_qualifier_row() {
$(this).closest('li').remove();
}
$(function() {
var opts = {
noneSelectedText: 'Wybierz słowniki',
selectedText: '# słowników',
selectedList: 4,
header: false
};
$('#id_vocabs').multiselect(opts);
$('#id_antivocabs').multiselect(opts);
$('#id_excluding_qualifiers').multiselect(qualifier_options);
$('#add-magic-qualifier-row').on('click', add_qualifier_row);
$(document).on('click', '#magic-qualifiers .remove', remove_qualifier_row);
})