lexeme-view.js
8.43 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
function list_searchoptions(list) {
"use strict";
return {
searchhidden: true,
sopt: ['eq', 'ne'],
value: list
};
}
function list_column(name, displayed, list) {
"use strict";
return {
name: name,
index: name,
hidden: true,
hidedlg: !displayed,
sortable: false,
searchoptions: list_searchoptions(list),
stype: 'select'
};
}
function text_column(name) {
"use strict";
return {
name: name,
index: name,
hidden: true,
hidedlg: true,
sortable: false,
searchoptions: {searchhidden: true}
};
}
function lip_column(name) {
"use strict";
return {
name: name,
index: name,
hidden: true,
sortable: false,
searchoptions: {searchhidden: true, sopt: ['eq', 'ne']}
};
}
function count_column(name) {
"use strict";
return {
name: name,
index: name,
hidden: true,
hidedlg: true,
sortable: false,
searchoptions: {searchhidden: true, sopt: ['eq', 'ge', 'le']}
};
}
var text_ops = ['eq', 'ne', 'bw', 'bn', 'ew', 'en', 'cn', 'nc', 're', 'nr'];
var eqne = ['eq', 'ne'];
var count_ops = ['eq', 'ge', 'le'];
$.extend(slickgrid, {
grid_element_id: 'lexeme-grid',
main_field: 'entry',
columns: [
{id: "entry", name: "Hasło", field: "entry"},
{id: "pos", name: "Część mowy", field: "pos"}
],
all_columns: {
id: {id: "id", name: "Nr", field: "id"},
entry: {id: "entry", name: "Hasło", field: "entry"},
pos: {id: "pos", name: "Część mowy", field: "pos"},
patterns: {id: "patterns", name: "Wzory", field: "patterns"},
ics: {id: "ics", name: "Char. fleks.", field: "ics"},
vocabs: {id: "vocabs", name: "Słowniki", field: "vocabs"},
owner: {id: "owner", name: "Sł. właściciel", field: "owner"},
status: {id: "status", name: "Status", field: "status"}
},
filter_fields: {
'entry': {name: 'Hasło', gender: 'n', ops: text_ops},
'part_of_speech': {
name: 'Część mowy',
gender: 'f',
ops: eqne,
options: $dj.parts_of_speech
},
'pattern_name': {name: 'Wzór', gender: 'm', ops: eqne},
'pattern_count': {name: 'Liczba wzorów', gender: 'f', ops: count_ops},
'inflection_characteristic': {
name: 'Char. fleks.', gender: 'f', ops: eqne},
'ic_count': {name: 'Liczba char. fleks.', gender: 'f', ops: count_ops},
'form': {name: 'Forma', gender: 'f', ops: text_ops},
'containing_vocabulary': {
name: 'Słownik',
gender: 'm',
ops: eqne,
options: $dj.visible_vocabularies
},
'owner_vocabulary': {
name: 'Słownik właściciel',
gender: 'm',
ops: eqne,
options: $dj.visible_vocabularies
},
'status': {
name: 'Status',
gender: 'm',
ops: eqne,
options: $dj.status_options
},
'comment': {name: 'Komentarz', gender: 'm', ops: text_ops},
'lexeme_qualifier': {
name: 'Kwal. leksemu',
gender: 'm',
ops: eqne,
options: $dj.qualifier_options
},
'lip_qualifier': {
name: 'Kwal. odmieniasia',
gender: 'm',
ops: eqne,
options: $dj.qualifier_options
},
'qualifier': {
name: 'Kwal. przy dow. formie',
gender: 'm',
ops: eqne,
options: $dj.qualifier_options
},
'classification_value': {
name: 'Wartość klasyfikacji',
gender: 'f',
ops: eqne,
options: $dj.cv_options
},
'gloss': {name: 'Glosa', gender: 'f', ops: text_ops},
'nota': {name: 'Nota', gender: 'f', ops: text_ops},
'cr_type': {
name: 'Typ odsyłacza',
gender: 'm',
ops: eqne,
options: $dj.cr_type_options
}
},
initial_sort_rules: [
{field: 'entry', order: 'asc', a_tergo: false},
{field: 'part_of_speech', order: 'asc'},
{field: 'id', order: 'asc'}
],
grid_caption: "Leksemy"
});
slickgrid.sort_rule_special_features = function(rule) {
"use strict";
$('#entries_a_tergo').prop('checked', rule.a_tergo);
};
slickgrid.prepare_sort_rules = function(sort_rules, old_sort_rules) {
"use strict";
if (sort_rules[0].field === 'entry') {
var a_tergo = false;
$.each(old_sort_rules, function (i, rule) {
if (rule.field === 'entry') {
a_tergo = rule.a_tergo;
return false;
}
return null;
});
sort_rules[0].a_tergo = a_tergo;
}
};
slickgrid.load_content = function(id, is_created) {
"use strict";
function check() {
return id === slickgrid.active_id();
}
edit.load_content(id, is_created, check);
};
// filtry
function create_button(button_class, icon_class, text) {
"use strict";
var button = $('<a/>')
.addClass('ui-state-default ui-corner-all ' + button_class)
.addClass('fm-button fm-button-icon-left');
var icon = $('<span/>').addClass('ui-icon ' + icon_class);
button.append(icon).append(text);
return button;
}
slickgrid.add_filter_buttons = function(f) {
"use strict";
if (f[0].p) {
var button_save = create_button(
'ui-save', 'ui-icon-disk', 'Zapisz filtr');
var button_load = create_button(
'ui-load', 'ui-icon-arrowthickstop-1-s', 'Załaduj filtr');
f.next().find('tr').last().children().first()
.append(button_save).append(button_load);
button_save.click(function () {
var filter_name, filters, post_data;
filter_name = window.prompt("Wybierz nazwę filtru do zapisania");
if (filter_name) {
filters = $('.searchFilter').jqFilter('filterData');
post_data = {
name: filter_name,
serialized_filter: $.toJSON(filters)
};
var save_filter_data = {
method: 'post',
url: $dj.ajax_save_filter,
data: post_data,
description: 'Zapisanie filtru'
};
$.ajaxJSON($.extend(save_filter_data, {
callback: function (data) {
if (data.exists && window.confirm(
"Filtr o tej nazwie już istnieje. Nadpisać?")) {
$.ajaxJSON($.extend(save_filter_data, {
data: $.extend(post_data, {force: true})
}));
}
}
}));
}
return false;
});
button_load.click(function () {
$.ajaxJSON({
method: 'get',
url: $dj.ajax_get_filters,
data: {},
description: 'Pobranie listy filtrów',
callback: filter_choice
});
return false;
});
}
};
function filter_choice(ajax_data) {
"use strict";
var filters = ajax_data.filters;
var list = $('#filter-list');
list.html('');
// napakować okienko na podstawie wyniku z ajaxa
$.each(filters, function (i, filter) {
var item = $('<li/>').addClass('ui-state-default').attr('id', filter.id);
var delete_button = $('<span/>')
.addClass('remove ui-icon ui-icon-closethick');
delete_button.click(function () {
if (window.confirm('Usunąć filtr "' + filter.name + '"?')) {
$.ajaxJSON({
method: 'post',
url: $dj.ajax_delete_filter,
data: {id: filter.id},
description: 'Usunięcie filtru',
callback: function () {
item.remove();
}
});
}
return false;
});
item.append(delete_button);
item.append(filter.name);
item.click(function () {
slickgrid.put_filter(filter.json);
$("#load-filter-dialog").dialog('close');
});
list.append(item);
});
$("#load-filter-dialog").dialog('open');
}