Commit 736fb797ae2af6ab16f9a96a99aba8642e23767f

Authored by janek37
1 parent 5f000cef

wstęp do wyszukiwania wg form

dictionary/ajax_lexeme_slickgrid.py
... ... @@ -222,6 +222,19 @@ def get_lexemes(request, from_page, to_page, rows, sort_rules, filter,
222 222 'page': from_page,
223 223 }
224 224  
  225 +@ajax(login_required=False, method='get')
  226 +def search_by_form(request, sort_rules, filter, exponent):
  227 + query = LexemeQuery(
  228 + filter=filter, sort_rules=sort_rules, user=request.user, mask='')
  229 + id_list = query.get_id_list()
  230 + lexemes = query.get_queryset().filter(lexemeform__form=exponent)
  231 + rows = query.prepare_rows(lexemes)
  232 + for row in rows:
  233 + row['row'] = id_list.index(row['id'])
  234 + return {
  235 + 'rows': rows,
  236 + }
  237 +
225 238 def prefetch(queryset):
226 239 return queryset.select_related(
227 240 'owner_vocabulary', 'part_of_speech').prefetch_related(
... ...
dictionary/views.py
... ... @@ -164,6 +164,7 @@ def reader_view(request):
164 164 'ajax_get_page': reverse('get_lexemes'),
165 165 'ajax_inflection_tables': reverse('inflection_tables'),
166 166 'ajax_search_index': reverse('search_index'),
  167 + 'ajax_search_by_form': reverse('search_by_form'),
167 168 'ajax_row_index': reverse('row_index'),
168 169 'ajax_save_filter': reverse('save_filter'),
169 170 'ajax_get_filters': reverse('get_filters'),
... ...
media/js/lexeme-view.js
... ... @@ -197,17 +197,38 @@ $.extend(slickgrid, {
197 197 edit.load_tab(ui.newPanel.attr('id'), edit.get_id());
198 198 }
199 199 });
  200 + },
  201 +
  202 + search_enter: function() {
  203 + // lista leksemów z daną formą
  204 + "use strict";
  205 + if ($dj.ajax_search_by_form) {
  206 + $.ajaxJSON({
  207 + url: $dj.ajax_search_by_form,
  208 + method: 'get',
  209 + data: {
  210 + filter: slickgrid.loader.getFilter(),
  211 + sort_rules: slickgrid.loader.getSort(),
  212 + exponent: slickgrid.search_string()
  213 + },
  214 + callback: function(data) {
  215 +
  216 + }
  217 + });
  218 + } else {
  219 + slickgrid.search();
  220 + }
200 221 }
201 222 });
202 223  
203 224 function export_list(filename) {
204 225 "use strict";
205 226 var param = {
206   - 'filter': JSON.stringify(slickgrid.loader.getFilter()),
207   - 'sort_rules': JSON.stringify(slickgrid.loader.getSort()),
208   - 'columns': JSON.stringify($.map(
  227 + filter: JSON.stringify(slickgrid.loader.getFilter()),
  228 + sort_rules: JSON.stringify(slickgrid.loader.getSort()),
  229 + columns: JSON.stringify($.map(
209 230 slickgrid.grid.getColumns(), function(col) {return col.field;})),
210   - 'filename': filename
  231 + filename: filename
211 232 };
212 233 location.href = $dj.ajax_export_list + '?' + $.param(param);
213 234 }
214 235 \ No newline at end of file
... ...
media/js/slickgrid.js
... ... @@ -77,6 +77,11 @@ var slickgrid = {
77 77 }
78 78 },
79 79  
  80 + search_enter: function() {
  81 + "use strict";
  82 + slickgrid.search();
  83 + },
  84 +
80 85 ensure_data: function() {
81 86 "use strict";
82 87 $('#filter-button').children().first().toggleClass('ui-state-highlight',
... ... @@ -370,7 +375,7 @@ $(function() {
370 375 var search_timeout_handler;
371 376 $("#text-search").keyup(function (e) {
372 377 if (e.which === 13) {
373   - slickgrid.search();
  378 + slickgrid.search_enter();
374 379 } else if ($dj.auto_search) {
375 380 clearTimeout(search_timeout_handler);
376 381 search_timeout_handler = setTimeout(slickgrid.search, 500);
... ...
... ... @@ -56,9 +56,10 @@ urlpatterns += patterns('dictionary.ajax_lexeme_view',
56 56 )
57 57  
58 58 urlpatterns += patterns('dictionary.ajax_lexeme_slickgrid',
59   - url(r'^ajax/lexemes/$', 'get_lexemes', name='get_lexemes'),
60   - url(r'^ajax/search-index/$', 'search_index', name='search_index'),
61   - url(r'^ajax/row-index/$', 'row_index', name='row_index'),
  59 + url(r'^ajax/lexemes/$', 'get_lexemes'),
  60 + url(r'^ajax/search-index/$', 'search_index'),
  61 + url(r'^ajax/row-index/$', 'row_index'),
  62 + url(r'^ajax/search-by-form/$', 'search_by_form'),
62 63 )
63 64  
64 65 urlpatterns += patterns('dictionary.ajax_filters',
... ...