Commit 325bd722e23f0e5a5b41d976d414124214d2a57a
merge z default
--HG-- branch : beta rename : dictionary/static/js/edit.js => common/static/js/edit.js rename : dictionary/static/js/slickgrid.js => common/static/js/slickgrid.js
Showing
18 changed files
with
240 additions
and
104 deletions
common/static/js/edit.js
... | ... | @@ -74,6 +74,12 @@ var edit = { |
74 | 74 | edit.busy_ctrl = null; |
75 | 75 | }, |
76 | 76 | |
77 | + cleanup: function() { | |
78 | + "use strict"; | |
79 | + edit.changed = false; | |
80 | + edit.busy_off(); | |
81 | + }, | |
82 | + | |
77 | 83 | confirm_discard: function() { |
78 | 84 | "use strict"; |
79 | 85 | return window.confirm( |
... | ... | @@ -128,7 +134,7 @@ $(function() { |
128 | 134 | "use strict"; |
129 | 135 | $(document).on( |
130 | 136 | 'submit', '#' + edit.form_id, function() { |
131 | - $(this).find('button[type=submit]').button('disable'); | |
137 | + $('.' + edit.form_submit_class).button('disable'); | |
132 | 138 | var this_form = $(this); |
133 | 139 | var form_data = this_form.serializeArray(); |
134 | 140 | edit.form_submit(form_data); |
... | ... |
common/static/js/slickgrid.js
... | ... | @@ -152,17 +152,11 @@ function set_columns() { |
152 | 152 | slickgrid.update_sort_button(slickgrid.loader.getSort()); |
153 | 153 | } |
154 | 154 | // slickgrid.grid.autosizeColumns(); |
155 | - $.ajaxJSON({ | |
156 | - method: 'post', | |
157 | - url: $dj.ajax_save_columns, | |
158 | - data: {columns: chosen_column_ids}, | |
159 | - callback: function() { | |
160 | - var column_names = $.map( | |
161 | - slickgrid.grid.getColumns(), function (col) {return col.name;}); | |
162 | - $('#columns').text(column_names.join(', ')); | |
163 | - slickgrid.reload_data(); | |
164 | - } | |
165 | - }); | |
155 | + slickgrid.loader.setColumns(chosen_column_ids); | |
156 | + var column_names = $.map( | |
157 | + slickgrid.grid.getColumns(), function (col) {return col.name;}); | |
158 | + $('#columns').text(column_names.join(', ')); | |
159 | + slickgrid.reload_data(); | |
166 | 160 | } |
167 | 161 | |
168 | 162 | function columns_from_ids(column_ids) { |
... | ... | @@ -367,6 +361,7 @@ $(function() { |
367 | 361 | slickgrid.grid = new Slick.Grid( |
368 | 362 | slickgrid.element, slickgrid.loader.data, columns_from_ids(columns), |
369 | 363 | options); |
364 | + slickgrid.loader.setColumns(columns); | |
370 | 365 | |
371 | 366 | var column_names = $.map( |
372 | 367 | slickgrid.grid.getColumns(), function (col) {return col.name;}); |
... | ... |
common/util.py
... | ... | @@ -113,7 +113,10 @@ def cut_end(s, end): |
113 | 113 | |
114 | 114 | def error_messages(form): |
115 | 115 | return '\n'.join( |
116 | - '%s: %s' % (form.fields[k].label, ' '.join(v)) if k != '__all__' | |
116 | + '%s: %s' % ( | |
117 | + force_unicode(form.fields[k].label), | |
118 | + ' '.join(v)) | |
119 | + if k != '__all__' | |
117 | 120 | else ' '.join(v) for k, v in form.errors.iteritems()) |
118 | 121 | |
119 | 122 | |
... | ... |
dictionary/ajax_lexeme_slickgrid.py
... | ... | @@ -400,12 +400,14 @@ def search_index(request, query_params, search=''): |
400 | 400 | |
401 | 401 | |
402 | 402 | @ajax(login_required=False, method='get') |
403 | -def get_lexemes(request, from_page, to_page, rows, query_params, | |
403 | +def get_lexemes(request, from_page, to_page, rows, query_params, columns, | |
404 | 404 | force_reload=False): |
405 | 405 | check_query_params(request, query_params) |
406 | - request.session['sort_rules'] = query_params['sort_rules'] | |
407 | - request.session['filter'] = query_params['filter'] | |
408 | - columns = request.session.get('columns') | |
406 | + reader = query_params['reader'] | |
407 | + session_prefix = 'reader_' if reader else '' | |
408 | + request.session[session_prefix + 'sort_rules'] = query_params['sort_rules'] | |
409 | + request.session[session_prefix + 'filter'] = query_params['filter'] | |
410 | + request.session[session_prefix + 'columns'] = columns | |
409 | 411 | query = LexemeQuery(query_params, columns=columns) |
410 | 412 | start, response_rowcount = query.count_pages(from_page, to_page, rows) |
411 | 413 | if query.lexeme_list: |
... | ... | @@ -429,9 +431,9 @@ def get_lexemes(request, from_page, to_page, rows, query_params, |
429 | 431 | |
430 | 432 | |
431 | 433 | @ajax(login_required=False, method='get') |
432 | -def search_by_form(request, query_params, exponent): | |
434 | +def search_by_form(request, query_params, columns, exponent): | |
433 | 435 | check_query_params(request, query_params) |
434 | - query = LexemeQuery(query_params, columns=request.session.get('columns')) | |
436 | + query = LexemeQuery(query_params, columns) | |
435 | 437 | lexemes = query.get_sorted_queryset().filter(lexemeform__form=exponent) |
436 | 438 | rows = [row for row in query.prepare_rows(lexemes)] |
437 | 439 | for row in rows: |
... | ... |
dictionary/ajax_lexeme_view.py
... | ... | @@ -263,8 +263,8 @@ def insert_new_lexeme(lexeme, request): |
263 | 263 | query = LexemeQuery({ |
264 | 264 | 'filter': filter, |
265 | 265 | 'sort_rules': sort_rules, |
266 | - 'visible_vocabs': | |
267 | - visible_vocabularies(request.user).values_list('id', flat=True), | |
266 | + 'visible_vocabs': list( | |
267 | + visible_vocabularies(request.user).values_list('id', flat=True)), | |
268 | 268 | 'reader': False, |
269 | 269 | }) |
270 | 270 | id_list = query.get_cached_lexemes() |
... | ... | @@ -339,11 +339,13 @@ def update_lexeme(request, form_data): |
339 | 339 | for cr_pk in form_dict['deleted_cr']: |
340 | 340 | cr = CrossReference.objects.get(pk=cr_pk) |
341 | 341 | for rev_cr in cr.reversed(): |
342 | - proposed_crs['delete'].append({ | |
343 | - 'cr_id': rev_cr.id, | |
344 | - 'entry': rev_cr.from_lexeme.entry, | |
345 | - 'type_desc': rev_cr.type.desc, | |
346 | - }) | |
342 | + if cr.from_lexeme.editable_vocabularies(request.user): | |
343 | + proposed_crs['delete'].append({ | |
344 | + 'cr_id': rev_cr.id, | |
345 | + 'entry': rev_cr.from_lexeme.entry, | |
346 | + 'type_desc': rev_cr.type.desc, | |
347 | + 'no_other_refs': rev_cr.from_lexeme.refs_to.count() == 1, | |
348 | + }) | |
347 | 349 | cr.delete() |
348 | 350 | submitted_lips = [] |
349 | 351 | submitted_crs = [] |
... | ... | @@ -380,16 +382,17 @@ def update_lexeme(request, form_data): |
380 | 382 | cr_form = CrossReferenceForm(data=form_dict, prefix=prefix) |
381 | 383 | if cr_form.is_valid(): |
382 | 384 | cr = cr_form.save() |
383 | - if not cr.reversed(): | |
384 | - rev_type = cr.type.reversed() | |
385 | - if rev_type: | |
386 | - proposed_crs['create'].append({ | |
387 | - 'type_id': rev_type.id, | |
388 | - 'from_lexeme': cr.to_lexeme.id, | |
389 | - 'to_lexeme': cr.from_lexeme.id, | |
390 | - 'entry': cr.to_lexeme.entry, | |
391 | - 'type_desc': rev_type.desc, | |
392 | - }) | |
385 | + if cr.to_lexeme.editable_vocabularies(request.user): | |
386 | + if not cr.reversed(): | |
387 | + rev_type = cr.type.reversed() | |
388 | + if rev_type: | |
389 | + proposed_crs['create'].append({ | |
390 | + 'type_id': rev_type.id, | |
391 | + 'from_lexeme': cr.to_lexeme.id, | |
392 | + 'to_lexeme': cr.from_lexeme.id, | |
393 | + 'entry': cr.to_lexeme.entry, | |
394 | + 'type_desc': rev_type.desc, | |
395 | + }) | |
393 | 396 | else: |
394 | 397 | raise AjaxError(error_messages(cr_form)) |
395 | 398 | if len(submitted_lips) == 0 and l.is_public(): |
... | ... | @@ -485,6 +488,27 @@ def create_derivatives(request, lexeme_id, chosen_derivatives): |
485 | 488 | return {} |
486 | 489 | |
487 | 490 | |
491 | +@ajax(method='post') | |
492 | +def update_back_references(request, deleted_cr, created_cr): | |
493 | + user = request.user | |
494 | + for cr_data in deleted_cr: | |
495 | + cr = CrossReference.objects.get(id=int(cr_data['cr_id'])) | |
496 | + if cr.from_lexeme.perm(user, 'change'): | |
497 | + cr.delete() | |
498 | + else: | |
499 | + raise AjaxError('access denied') | |
500 | + for cr_data in created_cr: | |
501 | + from_lexeme = Lexeme.objects.get(id=int(cr_data['from_lexeme'])) | |
502 | + to_lexeme = Lexeme.objects.get(id=int(cr_data['to_lexeme'])) | |
503 | + cr_type = CrossReferenceType.objects.get(id=cr_data['type_id']) | |
504 | + if from_lexeme.perm(user, 'change'): | |
505 | + CrossReference.objects.create( | |
506 | + from_lexeme=from_lexeme, to_lexeme=to_lexeme, type=cr_type) | |
507 | + else: | |
508 | + raise AjaxError('access denied') | |
509 | + return {} | |
510 | + | |
511 | + | |
488 | 512 | def update_lexeme_qualifiers(lexeme, user, form_dict, form_data): |
489 | 513 | owner = lexeme.owner_vocabulary |
490 | 514 | editable_vocabs = editable_vocabularies(user).exclude(pk=owner.pk) |
... | ... | @@ -672,8 +696,8 @@ def execute_group_actions(request, actions, filter): |
672 | 696 | query = LexemeQuery({ |
673 | 697 | 'filter': filter, |
674 | 698 | 'sort_rules': [], |
675 | - 'visible_vocabs': | |
676 | - visible_vocabularies(request.user).values_list('id', flat=True), | |
699 | + 'visible_vocabs': list( | |
700 | + visible_vocabularies(request.user).values_list('id', flat=True)), | |
677 | 701 | 'reader': False |
678 | 702 | }) |
679 | 703 | pk_list = query.get_id_list() |
... | ... | @@ -706,9 +730,3 @@ def execute_group_actions(request, actions, filter): |
706 | 730 | def get_entry(request, lexeme_id): |
707 | 731 | lexeme = get_object_or_404(Lexeme, id=lexeme_id) |
708 | 732 | return {'entry': lexeme.entry} |
709 | - | |
710 | - | |
711 | -@ajax(method='post', login_required=False) | |
712 | -def save_columns(request, columns): | |
713 | - request.session['columns'] = columns | |
714 | - return {} | |
... | ... |
dictionary/models.py
... | ... | @@ -762,8 +762,9 @@ class Lexeme(Model): |
762 | 762 | |
763 | 763 | def perm(self, user, action): |
764 | 764 | if action == 'view': |
765 | - vocabs = self.vocabularies.all() | |
766 | - return bool(vocabs & visible_vocabularies(user)) | |
765 | + if not user.is_authenticated() and not self.is_public(): | |
766 | + return False | |
767 | + return bool(self.visible_vocabularies(user)) | |
767 | 768 | elif action == 'change': |
768 | 769 | priority = user.has_perm('dictionary.lexeme_priority') |
769 | 770 | priority |= not ( |
... | ... |
dictionary/static/css/lexeme_view.css
dictionary/static/js/lexeme-edit.js
... | ... | @@ -201,6 +201,26 @@ $.extend(edit, { |
201 | 201 | } |
202 | 202 | ] |
203 | 203 | }); |
204 | + $('#back-references-dialog').dialog({ | |
205 | + autoOpen: false, | |
206 | + width: 'auto', | |
207 | + modal: true, | |
208 | + buttons: [ | |
209 | + { | |
210 | + text: gettext("Anuluj"), | |
211 | + click: function() { | |
212 | + $(this).dialog('close'); | |
213 | + } | |
214 | + }, | |
215 | + { | |
216 | + text: gettext("Zastosuj"), | |
217 | + click: function() { | |
218 | + $(this).dialog('close'); | |
219 | + update_back_references(); | |
220 | + } | |
221 | + } | |
222 | + ] | |
223 | + }); | |
204 | 224 | $('#action-button').click(function () { |
205 | 225 | $('#group-action-dialog').dialog('open'); |
206 | 226 | }); |
... | ... | @@ -426,44 +446,50 @@ $.extend(edit, { |
426 | 446 | } else { |
427 | 447 | edit.load_content(edit_id); |
428 | 448 | } |
429 | - if (data.derivatives.length > 0) { | |
430 | - auto_derivatives = data.derivatives; | |
431 | - var ul = $('#auto-derivatives-list'); | |
432 | - ul.empty(); | |
433 | - $.each(data.derivatives, function(i, der_data) { | |
434 | - var li = $('<li/>'); | |
435 | - var name = 'der' + i; | |
436 | - var input = $('<input/>').attr('type', 'checkbox') | |
437 | - .attr('name', name).attr('id', name); | |
438 | - var label = $('<label/>').attr('for', name); | |
439 | - li.append(input).append(label).appendTo(ul); | |
440 | - if (der_data.entry) { | |
441 | - label.text(der_data.cr_type + ', ' + der_data.entry); | |
442 | - } else { | |
443 | - var der_input = $('<input/>').attr('type', 'text') | |
444 | - .addClass('derivative-input'); | |
445 | - label.text(der_data.cr_type + ', '); | |
446 | - li.append(der_input); | |
447 | - } | |
448 | - }); | |
449 | - $('#auto-derivatives-dialog').dialog('open'); | |
450 | - } | |
449 | + suggest_back_references(data.proposed_crs); | |
450 | + suggest_derivatives(data.derivatives); | |
451 | 451 | }, |
452 | 452 | error_callback: function (xhr, status, error) { |
453 | 453 | common.error_alert(status + ': ' + error); |
454 | - edit.busy_off(); | |
454 | + edit.cleanup(); | |
455 | 455 | }, |
456 | 456 | bad_data_callback: function () { |
457 | - edit.busy_off(); | |
457 | + edit.cleanup(); | |
458 | 458 | return true; |
459 | 459 | } |
460 | 460 | }); |
461 | 461 | if (result === false) { |
462 | - edit.busy_off(); | |
462 | + edit.cleanup(); | |
463 | 463 | } |
464 | 464 | } |
465 | 465 | }); |
466 | 466 | |
467 | +function suggest_derivatives(derivatives) { | |
468 | + "use strict"; | |
469 | + if (derivatives.length > 0) { | |
470 | + auto_derivatives = derivatives; | |
471 | + var ul = $('#auto-derivatives-list'); | |
472 | + ul.empty(); | |
473 | + $.each(derivatives, function (i, der_data) { | |
474 | + var li = $('<li/>'); | |
475 | + var name = 'der' + i; | |
476 | + var input = $('<input/>').attr('type', 'checkbox') | |
477 | + .attr('name', name).attr('id', name); | |
478 | + var label = $('<label/>').attr('for', name); | |
479 | + li.append(input).append(label).appendTo(ul); | |
480 | + if (der_data.entry) { | |
481 | + label.text(der_data.cr_type + ', ' + der_data.entry); | |
482 | + } else { | |
483 | + var der_input = $('<input/>').attr('type', 'text') | |
484 | + .addClass('derivative-input'); | |
485 | + label.text(der_data.cr_type + ', '); | |
486 | + li.append(der_input); | |
487 | + } | |
488 | + }); | |
489 | + $('#auto-derivatives-dialog').dialog('open'); | |
490 | + } | |
491 | +} | |
492 | + | |
467 | 493 | function create_auto_derivatives() { |
468 | 494 | "use strict"; |
469 | 495 | // zebrać numery derywatów do utworzenia |
... | ... | @@ -498,6 +524,70 @@ function create_auto_derivatives() { |
498 | 524 | }); |
499 | 525 | } |
500 | 526 | |
527 | +function suggest_back_references(proposed_crs) { | |
528 | + "use strict"; | |
529 | + if (proposed_crs.delete.length > 0 || proposed_crs.create.length > 0) { | |
530 | + var cr_container = $('#proposed-crs'), ul; | |
531 | + cr_container.empty(); | |
532 | + if (proposed_crs.delete.length > 0) { | |
533 | + var delete_label = $('<p/>').text(gettext("Do usunięcia:")); | |
534 | + ul = $('<ul/>').attr('id', 'delete-cr'); | |
535 | + $.each(proposed_crs.delete, function(i, cr_data) { | |
536 | + var li = $('<li/>'); | |
537 | + var name = 'del_cr' + cr_data.cr_id; | |
538 | + var input = $('<input/>').attr('type', 'checkbox') | |
539 | + .attr('name', name).attr('id', name) | |
540 | + .data('cr_data', cr_data); | |
541 | + var label = $('<label/>').attr('for', name) | |
542 | + .text(cr_data.entry + ', ' + cr_data.type_desc); | |
543 | + var info_span = $('<span/>').addClass('cr-info'); | |
544 | + if (cr_data.no_other_refs) { | |
545 | + info_span.text(gettext("brak odsyłaczy do innych leksemów")); | |
546 | + } | |
547 | + li.append(input).append(label).append(info_span).appendTo(ul); | |
548 | + }); | |
549 | + cr_container.append(delete_label).append(ul); | |
550 | + } | |
551 | + if (proposed_crs.create.length > 0) { | |
552 | + var create_label = $('<p/>').text(gettext("Do dodania:")); | |
553 | + ul = $('<ul/>').attr('id', 'create-cr'); | |
554 | + $.each(proposed_crs.create, function(i, cr_data) { | |
555 | + var li = $('<li/>'); | |
556 | + var name = 'new_cr' + cr_data.type_id + '-' + | |
557 | + cr_data.from_lexeme; | |
558 | + var input = $('<input/>').attr('type', 'checkbox') | |
559 | + .attr('name', name).attr('id', name) | |
560 | + .data('cr_data', cr_data); | |
561 | + var label = $('<label/>').attr('for', name) | |
562 | + .text(cr_data.entry + ', ' + cr_data.type_desc); | |
563 | + li.append(input).append(label).appendTo(ul); | |
564 | + }); | |
565 | + cr_container.append(create_label).append(ul); | |
566 | + } | |
567 | + $('#back-references-dialog').dialog('open'); | |
568 | + } | |
569 | +} | |
570 | + | |
571 | +function update_back_references() { | |
572 | + "use strict"; | |
573 | + var chosen_delete = [], chosen_create = []; | |
574 | + $('#delete-cr').find(':checked').each(function(i, elem) { | |
575 | + chosen_delete.push($(elem).data('cr_data')); | |
576 | + }); | |
577 | + $('#create-cr').find(':checked').each(function(i, elem) { | |
578 | + chosen_create.push($(elem).data('cr_data')); | |
579 | + }); | |
580 | + $.ajaxJSON({ | |
581 | + method: 'post', | |
582 | + url: $dj.ajax_update_back_references, | |
583 | + data: { | |
584 | + deleted_cr: chosen_delete, | |
585 | + created_cr: chosen_create | |
586 | + }, | |
587 | + description: gettext("Zaktualizowanie zwrotnych derywatów") | |
588 | + }); | |
589 | +} | |
590 | + | |
501 | 591 | var deleted, deleted_cr; |
502 | 592 | |
503 | 593 | function get_pos() { |
... | ... |
dictionary/static/js/lexeme-view.js
... | ... | @@ -342,7 +342,8 @@ $.extend(slickgrid, { |
342 | 342 | method: 'get', |
343 | 343 | data: { |
344 | 344 | exponent: slickgrid.search_string(), |
345 | - query_params: slickgrid.query_params() | |
345 | + query_params: slickgrid.query_params(), | |
346 | + columns: slickgrid.loader.getColumns() | |
346 | 347 | }, |
347 | 348 | callback: function(data) { |
348 | 349 | var table = $('#by-form-container'); |
... | ... |
dictionary/static/js/remotemodel.js
... | ... | @@ -11,6 +11,7 @@ |
11 | 11 | var ajax_request = null; |
12 | 12 | var sort_rules = null; |
13 | 13 | var filter = {group_op: "AND", rules: []}; |
14 | + var columns = null; | |
14 | 15 | var force_reload = false; |
15 | 16 | |
16 | 17 | // events |
... | ... | @@ -94,7 +95,8 @@ |
94 | 95 | from_page: fromPage || 0, // nie wiem, skąd te nulle |
95 | 96 | to_page: toPage || 0, |
96 | 97 | force_reload: force_reload, |
97 | - query_params: slickgrid.query_params() | |
98 | + query_params: slickgrid.query_params(), | |
99 | + columns: getColumns() | |
98 | 100 | }; |
99 | 101 | force_reload = false; |
100 | 102 | |
... | ... | @@ -161,6 +163,14 @@ |
161 | 163 | return filter; |
162 | 164 | } |
163 | 165 | |
166 | + function setColumns(new_columns) { | |
167 | + columns = new_columns; | |
168 | + } | |
169 | + | |
170 | + function getColumns() { | |
171 | + return columns; | |
172 | + } | |
173 | + | |
164 | 174 | function searchRow(callback) { |
165 | 175 | var search_counter = slickgrid.search_counter; |
166 | 176 | var search_text = slickgrid.search_string(); |
... | ... | @@ -196,6 +206,8 @@ |
196 | 206 | "setSearch": setSearch, |
197 | 207 | "setFilter": setFilter, |
198 | 208 | "getFilter": getFilter, |
209 | + "setColumns": setColumns, | |
210 | + "getColumns": getColumns, | |
199 | 211 | "searchRow": searchRow, |
200 | 212 | |
201 | 213 | // events |
... | ... |
dictionary/templates/lexeme_view.html
dictionary/urls.py
... | ... | @@ -27,7 +27,6 @@ urlpatterns += patterns( |
27 | 27 | url(r'^ajax/update-lexeme/$', 'update_lexeme'), |
28 | 28 | url(r'^ajax/table-preview/$', 'table_preview'), |
29 | 29 | url(r'^ajax/new-lip-row/$', 'new_lip_edit_row'), |
30 | - url(r'^ajax/save-columns/$', 'save_columns'), | |
31 | 30 | url(r'^ajax/new-cr-row/$', 'new_cross_reference_row'), |
32 | 31 | url(r'^ajax/delete-lexeme/$', 'delete_lexeme'), |
33 | 32 | url(r'^ajax/check-pos/$', 'check_pos'), |
... | ... | @@ -43,6 +42,7 @@ urlpatterns += patterns( |
43 | 42 | url(r'^ajax/dynamic-fields/$', 'dynamic_action_fields'), |
44 | 43 | url(r'^ajax/execute-actions/$', 'execute_group_actions'), |
45 | 44 | url(r'^ajax/create-derivatives/$', 'create_derivatives'), |
45 | + url(r'^ajax/update-back-references/$', 'update_back_references'), | |
46 | 46 | url(r'^ajax/clone-lexeme/$', 'clone_lexeme'), |
47 | 47 | url(r'^ajax/get-entry/$', 'get_entry'), |
48 | 48 | ) |
... | ... |
dictionary/views.py
... | ... | @@ -36,7 +36,7 @@ def main(request): |
36 | 36 | return HttpResponseRedirect(reverse('auth_login')) # niezbyt prawdopodobne |
37 | 37 | |
38 | 38 | |
39 | -def common_lexeme_js_vars(request, visible): | |
39 | +def common_lexeme_js_vars(request, visible, reader=False): | |
40 | 40 | qualifier_options = [] |
41 | 41 | lexeme_qualifier_options = [] |
42 | 42 | form_qualifier_options = [] |
... | ... | @@ -81,7 +81,6 @@ def common_lexeme_js_vars(request, visible): |
81 | 81 | 'ajax_search_index': reverse('search_index'), |
82 | 82 | 'ajax_search_by_form': reverse('search_by_form'), |
83 | 83 | 'ajax_row_index': reverse('row_index'), |
84 | - 'ajax_save_columns': reverse('save_columns'), | |
85 | 84 | 'ajax_export_list': reverse('export_list'), |
86 | 85 | 'ajax_get_entry': reverse('get_entry'), |
87 | 86 | 'lexeme_qualifier_options': lexeme_qualifier_options, |
... | ... | @@ -104,10 +103,12 @@ def common_lexeme_js_vars(request, visible): |
104 | 103 | 'commonness': Classification.objects.get(name=u'pospolitość').pk, |
105 | 104 | 'initial_columns': LexemeQuery.default_columns, |
106 | 105 | } |
106 | + session_prefix = 'reader_' if reader else '' | |
107 | 107 | session_variables = ('filter', 'sort_rules', 'columns') |
108 | 108 | js_vars.update(dict( |
109 | - (var, request.session[var]) | |
110 | - for var in session_variables if var in request.session)) | |
109 | + (var, request.session[session_prefix + var]) | |
110 | + for var in session_variables if | |
111 | + (session_prefix + var) in request.session)) | |
111 | 112 | return js_vars |
112 | 113 | |
113 | 114 | |
... | ... | @@ -152,6 +153,7 @@ def lexeme_view(request): |
152 | 153 | 'ajax_dynamic_fields': reverse('dynamic_action_fields'), |
153 | 154 | 'ajax_execute_actions': reverse('execute_group_actions'), |
154 | 155 | 'ajax_create_derivatives': reverse('create_derivatives'), |
156 | + 'ajax_update_back_references': reverse('update_back_references'), | |
155 | 157 | 'ajax_clone_lexeme': reverse('clone_lexeme'), |
156 | 158 | 'vocabs': vocabs, |
157 | 159 | 'bs_options': [ |
... | ... | @@ -173,7 +175,7 @@ def reader_view(request): |
173 | 175 | LexemeAttribute.objects.get(name=u'zwrotność').id, |
174 | 176 | LexemeAttribute.objects.get(name=u'aspekt').id, |
175 | 177 | ] |
176 | - js_vars = common_lexeme_js_vars(request, visible) | |
178 | + js_vars = common_lexeme_js_vars(request, visible, reader=True) | |
177 | 179 | js_vars.update({ |
178 | 180 | 'reader': True, |
179 | 181 | 'vocabs': {}, |
... | ... |
patterns/ajax_pattern_view.py
... | ... | @@ -54,10 +54,12 @@ def search_index(request, query_params, search=''): |
54 | 54 | |
55 | 55 | |
56 | 56 | @ajax(login_required=False, method='get') |
57 | -def get_patterns(request, from_page, to_page, rows, query_params): | |
58 | - request.session['pattern-sort_rules'] = query_params['sort_rules'] | |
59 | - request.session['pattern-filter'] = query_params['filter'] | |
60 | - columns = request.session.get('pattern-columns') | |
57 | +def get_patterns(request, from_page, to_page, rows, query_params, columns): | |
58 | + session_prefix = 'reader_' if query_params['reader'] else '' | |
59 | + request.session[session_prefix + 'pattern-sort_rules'] = \ | |
60 | + query_params['sort_rules'] | |
61 | + request.session[session_prefix + 'pattern-filter'] = query_params['filter'] | |
62 | + request.session[session_prefix + 'pattern-columns'] = columns | |
61 | 63 | query = PatternQuery(query_params, columns=columns) |
62 | 64 | rows, count = query.get_page(from_page, to_page, rows) |
63 | 65 | return { |
... | ... | @@ -185,12 +187,6 @@ def update_pattern(request, form_data): |
185 | 187 | return {} |
186 | 188 | |
187 | 189 | |
188 | -@ajax(login_required=False, method='post') | |
189 | -def save_columns(request, columns): | |
190 | - request.session['pattern-columns'] = columns | |
191 | - return {} | |
192 | - | |
193 | - | |
194 | 190 | @ajax(method='post', permission_required='dictionary.change_pattern') |
195 | 191 | def create_pattern(request): |
196 | 192 | new_name = u'nowy wzór %s' |
... | ... |
patterns/static/js/pattern-edit.js
... | ... | @@ -157,7 +157,7 @@ $.extend(edit, { |
157 | 157 | }); |
158 | 158 | form_data.push({name: 'ending_list', value: ending_list}); |
159 | 159 | edit.busy_on(); |
160 | - $.ajaxJSON({ | |
160 | + var result = $.ajaxJSON({ | |
161 | 161 | method: 'post', |
162 | 162 | url: $dj.ajax_update_pattern, |
163 | 163 | data: { |
... | ... | @@ -171,13 +171,16 @@ $.extend(edit, { |
171 | 171 | }, |
172 | 172 | error_callback: function (xhr, status, error) { |
173 | 173 | common.error_alert(status + ': ' + error); |
174 | - edit.busy_off(); | |
174 | + edit.cleanup(); | |
175 | 175 | }, |
176 | 176 | bad_data_callback: function () { |
177 | - edit.busy_off(); | |
177 | + edit.cleanup(); | |
178 | 178 | return true; |
179 | 179 | } |
180 | 180 | }); |
181 | + if (result === false) { | |
182 | + edit.cleanup(); | |
183 | + } | |
181 | 184 | } |
182 | 185 | }); |
183 | 186 | |
... | ... |
patterns/static/js/pattern-view.js
... | ... | @@ -63,7 +63,8 @@ $.extend(slickgrid, { |
63 | 63 | "use strict"; |
64 | 64 | return { |
65 | 65 | sort_rules: slickgrid.loader.getSort(), |
66 | - filter: slickgrid.loader.getFilter() | |
66 | + filter: slickgrid.loader.getFilter(), | |
67 | + reader: $dj.reader | |
67 | 68 | }; |
68 | 69 | } |
69 | 70 | }); |
70 | 71 | \ No newline at end of file |
... | ... |
patterns/urls.py
... | ... | @@ -13,7 +13,6 @@ urlpatterns += patterns( |
13 | 13 | url(r'^ajax/query/$', 'get_patterns'), |
14 | 14 | url(r'^ajax/search-index/$', 'search_index', name='patterns_search_index'), |
15 | 15 | url(r'^ajax/row-index/$', 'row_index', name='patterns_row_index'), |
16 | - url(r'^ajax/save-columns/$', 'save_columns', name='patterns_save_columns'), | |
17 | 16 | url(r'^ajax/pattern-edit-form/$', 'pattern_edit_form'), |
18 | 17 | url(r'^ajax/new-ending-row/$', 'new_ending_row'), |
19 | 18 | url(r'^ajax/new-bfl-row/$', 'new_ending_table_row'), |
... | ... |
patterns/views.py
... | ... | @@ -7,7 +7,7 @@ from dictionary.models import LexicalClass, editable_vocabularies, \ |
7 | 7 | from patterns.ajax_pattern_view import PatternQuery |
8 | 8 | |
9 | 9 | |
10 | -def common_pattern_js_vars(request): | |
10 | +def common_pattern_js_vars(request, reader=False): | |
11 | 11 | lexical_class_options = [ |
12 | 12 | (lc.symbol, lc.symbol) for lc in LexicalClass.objects.all()] |
13 | 13 | base_form_labels = dict( |
... | ... | @@ -18,7 +18,6 @@ def common_pattern_js_vars(request): |
18 | 18 | 'ajax_get_page': reverse('get_patterns'), |
19 | 19 | 'ajax_search_index': reverse('patterns_search_index'), |
20 | 20 | 'ajax_row_index': reverse('patterns_row_index'), |
21 | - 'ajax_save_columns': reverse('patterns_save_columns'), | |
22 | 21 | 'ajax_pattern_preview': reverse('pattern_preview'), |
23 | 22 | 'ajax_get_name': reverse('get_name'), |
24 | 23 | 'lexical_class_options': lexical_class_options, |
... | ... | @@ -27,14 +26,12 @@ def common_pattern_js_vars(request): |
27 | 26 | 'bfl_symbols': bfl_symbols, |
28 | 27 | 'initial_columns': PatternQuery.default_columns, |
29 | 28 | } |
30 | - session_variables = ( | |
31 | - 'pattern-filter', | |
32 | - 'pattern-sort_rules', | |
33 | - 'pattern-columns', | |
34 | - ) | |
29 | + session_prefix = ('reader_' if reader else '') + 'pattern-' | |
30 | + session_variables = ('filter', 'sort_rules', 'columns') | |
35 | 31 | js_vars.update(dict( |
36 | - (var.split('-', 1)[1], request.session[var]) | |
37 | - for var in session_variables if var in request.session)) | |
32 | + (var, request.session[session_prefix + var]) | |
33 | + for var in session_variables | |
34 | + if (session_prefix + var) in request.session)) | |
38 | 35 | return js_vars |
39 | 36 | |
40 | 37 | |
... | ... | @@ -47,6 +44,7 @@ def pattern_view(request): |
47 | 44 | vocabs.update(dict((str(q.pk), v.id) for q in v.qualifiers.all())) |
48 | 45 | js_vars = common_pattern_js_vars(request) |
49 | 46 | js_vars.update({ |
47 | + 'reader': False, | |
50 | 48 | 'ajax_edit_form': reverse('pattern_edit_form'), |
51 | 49 | 'ajax_update_pattern': reverse('update_pattern'), |
52 | 50 | 'ajax_new_ending_row': reverse('new_ending_row'), |
... | ... | @@ -63,8 +61,9 @@ def pattern_view(request): |
63 | 61 | |
64 | 62 | @render('pattern_reader_view.html') |
65 | 63 | def pattern_reader_view(request): |
66 | - js_vars = common_pattern_js_vars(request) | |
64 | + js_vars = common_pattern_js_vars(request, reader=True) | |
67 | 65 | js_vars.update({ |
66 | + 'reader': True, | |
68 | 67 | 'auto_search': True, |
69 | 68 | 'vocabs': {}, |
70 | 69 | }) |
... | ... |