Commit ebbdf285169ea286d091673e5738b2a9ed18effa

Authored by janek37
2 parents e3e2cb3f 716765bf

merge z default

--HG--
branch : beta
rename : dictionary/static/js/edit.js => common/static/js/edit.js
common/static/js/common.js
... ... @@ -142,6 +142,27 @@ var common = {
142 142 strip: function(str) {
143 143 "use strict";
144 144 return str.replace(/^\s+|\s+$/g, '');
  145 + },
  146 +
  147 + init_selection: function(jq) {
  148 + "use strict";
  149 + jq.find('option:selected').addClass('last-selected');
  150 + },
  151 +
  152 + revert_selection: function(jq) {
  153 + "use strict";
  154 + jq.find('option.last-selected').prop('selected', true);
  155 + },
  156 +
  157 + confirm_selection: function(jq) {
  158 + "use strict";
  159 + jq.find('option.last-selected').removeClass('last-selected');
  160 + jq.find('option:selected').addClass('last-selected');
  161 + },
  162 +
  163 + previous_value: function(jq) {
  164 + "use strict";
  165 + return jq.find('option.last-selected').val();
145 166 }
146 167 };
147 168  
... ...
dictionary/static/js/lexeme-edit.js
... ... @@ -102,7 +102,7 @@ $.extend(edit, {
102 102 $(document).on('click', '#add-row', function () {
103 103 var id = edit.get_id();
104 104 var new_row = $(get_new_row_html(id));
105   - init_selection(new_row.find('.gender'));
  105 + common.init_selection(new_row.find('.gender'));
106 106 var pattern_list = $('#pattern-list');
107 107 pattern_list.append(new_row);
108 108 edit.qualifier_select(pattern_list.find('.lip-qualifiers').last());
... ... @@ -266,11 +266,11 @@ $.extend(edit, {
266 266 msg + ' ' + join_classifications(stale_classifications) +
267 267 '. ' + gettext("Kontynuować?"));
268 268 if (!confirmed) {
269   - revert_selection($(this));
  269 + common.revert_selection($(this));
270 270 }
271 271 }
272 272 if (confirmed || stale_classifications.length === 0) {
273   - confirm_selection($(this));
  273 + common.confirm_selection($(this));
274 274 reload_classifications();
275 275 }
276 276 });
... ... @@ -286,11 +286,11 @@ $.extend(edit, {
286 286 interpolate(fmt, [join_attrs(stale_attrs)]) +
287 287 ' ' + gettext("Kontynuować?"));
288 288 if (!confirmed) {
289   - revert_selection($(this));
  289 + common.revert_selection($(this));
290 290 }
291 291 }
292 292 if (confirmed || stale_attrs.length === 0) {
293   - confirm_selection($(this));
  293 + common.confirm_selection($(this));
294 294 reload_attributes();
295 295 }
296 296 });
... ... @@ -356,9 +356,9 @@ $.extend(edit, {
356 356 deleted = [];
357 357 deleted_cr = [];
358 358 edit.created = false;
359   - init_selection($('#id_part_of_speech'));
360   - init_selection($('.gender'));
361   - init_selection(new_owner_elem);
  359 + common.init_selection($('#id_part_of_speech'));
  360 + common.init_selection($('.gender'));
  361 + common.init_selection(new_owner_elem);
362 362 edit.hide_changed();
363 363 edit.busy_off();
364 364 },
... ... @@ -500,22 +500,6 @@ function create_auto_derivatives() {
500 500  
501 501 var deleted, deleted_cr;
502 502  
503   -function init_selection(jq) {
504   - "use strict";
505   - jq.find('option:selected').addClass('last-selected');
506   -}
507   -
508   -function revert_selection(jq) {
509   - "use strict";
510   - jq.find('option.last-selected').prop('selected', true);
511   -}
512   -
513   -function confirm_selection(jq) {
514   - "use strict";
515   - jq.find('option.last-selected').removeClass('last-selected');
516   - jq.find('option:selected').addClass('last-selected');
517   -}
518   -
519 503 function get_pos() {
520 504 "use strict";
521 505 return $('#id_part_of_speech').val();
... ... @@ -910,12 +894,12 @@ var check_pos = function () {
910 894 gettext("Zostaną usunięte:") + '\n' + lips_text + cr_text +
911 895 attr_text + clas_text + gettext("Kontynuować?"));
912 896 if (!confirmed) {
913   - revert_selection($(this));
  897 + common.revert_selection($(this));
914 898 }
915 899 }
916 900 if (confirmed || !(bad_lips || cr_row_elems.length > 0 ||
917 901 stale_attrs.length > 0 || stale_classifications.length > 0)) {
918   - confirm_selection($(this));
  902 + common.confirm_selection($(this));
919 903 var reload_preview = false;
920 904 if (bad_lips) {
921 905 lip_row_elems.each(function () {
... ...
patterns/ajax_pattern_view.py
... ... @@ -129,6 +129,15 @@ def new_ending_row(request, pattern_id):
129 129 return {'ending': ending, 'editable': True, 'form': form, 'pattern': p}
130 130  
131 131  
  132 +@render_ajax(template='ending_table_row.html', method='get')
  133 +def new_ending_table_row(request, bfl_id):
  134 + return {
  135 + 'base_form_label': BaseFormLabel.objects.get(id=bfl_id),
  136 + 'ending_groups': [],
  137 + 'editable': True,
  138 + }
  139 +
  140 +
132 141 @ajax(method='post', permission_required='dictionary.change_pattern')
133 142 def update_pattern(request, form_data):
134 143 form_dict = dict((x['name'], x['value']) for x in form_data)
... ...
patterns/static/js/pattern-edit.js
1   -/* global $dj, edit, common, slickgrid, gettext */
  1 +/* global $dj, edit, common, slickgrid, gettext, ngettext, interpolate */
2 2  
3 3 var deleted;
4 4  
... ... @@ -49,6 +49,40 @@ $.extend(edit, {
49 49 clone_pattern();
50 50 $('#more-actions-dialog').dialog('close');
51 51 });
  52 + $(document).on('change', '#id_type', function () {
  53 + var $t = $(this);
  54 + var old_bfls = $dj.base_form_labels[common.previous_value($t)];
  55 + var new_bfls = $dj.base_form_labels[$t.val()];
  56 + var stale_bfls = [], fresh_bfls = [];
  57 + var confirmed;
  58 + $.each(old_bfls, function(i, bfl) {
  59 + if (new_bfls.indexOf(bfl) === -1)
  60 + stale_bfls.push(bfl);
  61 + });
  62 + $.each(new_bfls, function(i, bfl) {
  63 + if (old_bfls.indexOf(bfl) === -1)
  64 + fresh_bfls.push(bfl);
  65 + });
  66 + if (stale_bfls.length > 0) {
  67 + var fmt = ngettext(
  68 + "Etykieta: %s zostanie usunięta.",
  69 + "Etykiety: %s zostaną usunięte.", stale_bfls.length);
  70 + var bfl_symbols = $.map(
  71 + stale_bfls, function(bfl_id) {
  72 + return $dj.bfl_symbols[bfl_id];
  73 + });
  74 + confirmed = window.confirm(
  75 + interpolate(fmt, [bfl_symbols.join(', ')]) +
  76 + ' ' + gettext("Kontynuować?"));
  77 + if (!confirmed) {
  78 + common.revert_selection($t);
  79 + }
  80 + }
  81 + if (confirmed || stale_bfls.length === 0) {
  82 + common.confirm_selection($t);
  83 + reload_endings(stale_bfls, fresh_bfls);
  84 + }
  85 + });
52 86 },
53 87  
54 88 load_content: function(id, is_created, check_callback) {
... ... @@ -92,6 +126,7 @@ $.extend(edit, {
92 126 //$('#ending-list').disableSelection();
93 127 edit.qualifier_select($('#ending-list').find('.qualifiers'));
94 128 deleted = [];
  129 + common.init_selection($('#id_type'));
95 130 edit.hide_changed();
96 131 edit.busy_off();
97 132 },
... ... @@ -171,4 +206,27 @@ function clone_pattern() {
171 206 slickgrid.row_index(data.new_id);
172 207 }
173 208 });
  209 +}
  210 +
  211 +function reload_endings(stale_bfls, fresh_bfls) {
  212 + "use strict";
  213 + // skasować nieświeże zakończenia
  214 + $.each(stale_bfls, function(i, bfl_id) {
  215 + var bfl_row = $('[data-bfl-id='+bfl_id+']');
  216 + bfl_row.find('.ending-row').each(function() {
  217 + $(this).find('span.remove').click();
  218 + });
  219 + bfl_row.remove();
  220 + });
  221 + $.each(fresh_bfls, function(i, bfl_id) {
  222 + // dodać wiersz w tabelce
  223 + $.ajaxJSON({
  224 + method: 'get',
  225 + url: $dj.ajax_new_ending_table_row,
  226 + data: {bfl_id: bfl_id},
  227 + callback: function(data) {
  228 + $('#ending-list').prepend(data.html);
  229 + }
  230 + });
  231 + });
174 232 }
175 233 \ No newline at end of file
... ...
patterns/templates/ending_row.html
1   -<li class="ending-row ui-state-default ui-corner-all">
  1 +<li class="ending-row ui-state-default ui-corner-all" data-ending-id="{{ ending.id }}">
2 2 {% if editable %}
3 3 <span class="remove ui-icon ui-icon-closethick"></span>
4 4 <span class="arrows ui-icon ui-icon-arrowthick-2-n-s"></span>
... ...
patterns/templates/ending_table_row.html 0 → 100644
  1 +<tr data-bfl-id="{{ base_form_label.id }}">
  2 + <td><strong>{{ base_form_label.symbol }}</strong></td>
  3 + <td>
  4 + <ul class="ending-group">
  5 + {% for ending, ro_qualifiers, form in ending_group %}
  6 + {% include 'ending_row.html' %}
  7 + {% endfor %}
  8 + </ul>
  9 + </td>
  10 + <td>
  11 + {% if editable %}
  12 + <button type="button" class="add-ending">
  13 + <span class="ui-icon ui-icon-plus"></span>
  14 + </button>
  15 + {% endif %}
  16 + </td>
  17 +</tr>
0 18 \ No newline at end of file
... ...
patterns/templates/pattern_edit_form.html
... ... @@ -26,26 +26,10 @@
26 26 </button>
27 27 </p>
28 28 </div>
29   - <table id="ending-list" {{ editable|yesno:'class="editable",'|safe }}>
  29 + <table id="ending-list" {{ editable|yesno:'class="editable",'|safe }}
  30 + data-bfl-id="{{ base_form_label.id }}">
30 31 {% for base_form_label, ending_group in ending_groups.iteritems %}
31   - <tr>
32   - <td><strong>{{ base_form_label.symbol }}</strong></td>
33   - <td>
34   - <ul class="ending-group"
35   - id="bfl-{{ base_form_label.symbol }}">
36   - {% for ending, ro_qualifiers, form in ending_group %}
37   - {% include 'ending_row.html' %}
38   - {% endfor %}
39   - </ul>
40   - </td>
41   - <td>
42   - {% if editable %}
43   - <button type="button" class="add-ending">
44   - <span class="ui-icon ui-icon-plus"></span>
45   - </button>
46   - {% endif %}
47   - </td>
48   - </tr>
  32 + {% include "ending_table_row.html" %}
49 33 {% endfor %}
50 34 </table>
51 35 </form>
... ...
patterns/urls.py
... ... @@ -16,6 +16,7 @@ urlpatterns += patterns(
16 16 url(r'^ajax/save-columns/$', 'save_columns', name='patterns_save_columns'),
17 17 url(r'^ajax/pattern-edit-form/$', 'pattern_edit_form'),
18 18 url(r'^ajax/new-ending-row/$', 'new_ending_row'),
  19 + url(r'^ajax/new-bfl-row/$', 'new_ending_table_row'),
19 20 url(r'^ajax/update-pattern/$', 'update_pattern'),
20 21 url(r'^ajax/create-pattern/$', 'create_pattern'),
21 22 url(r'^ajax/clone-pattern/$', 'clone_pattern'),
... ...
patterns/views.py
... ... @@ -3,13 +3,17 @@ from django.contrib.auth.decorators import permission_required
3 3 from django.core.urlresolvers import reverse
4 4 from common.decorators import render
5 5 from dictionary.models import LexicalClass, editable_vocabularies, \
6   - get_exclusion_classes, PatternType
  6 + get_exclusion_classes, PatternType, BaseFormLabel
7 7 from patterns.ajax_pattern_view import PatternQuery
8 8  
9 9  
10 10 def common_pattern_js_vars(request):
11 11 lexical_class_options = [
12 12 (lc.symbol, lc.symbol) for lc in LexicalClass.objects.all()]
  13 + base_form_labels = dict(
  14 + (pt.id, list(pt.base_form_labels.values_list('id', flat=True)))
  15 + for pt in PatternType.objects.all())
  16 + bfl_symbols = dict(BaseFormLabel.objects.values_list('id', 'symbol'))
13 17 js_vars = {
14 18 'ajax_get_page': reverse('get_patterns'),
15 19 'ajax_search_index': reverse('patterns_search_index'),
... ... @@ -19,6 +23,8 @@ def common_pattern_js_vars(request):
19 23 'ajax_get_name': reverse('get_name'),
20 24 'lexical_class_options': lexical_class_options,
21 25 'pattern_type_options': PatternType.options(),
  26 + 'base_form_labels': base_form_labels,
  27 + 'bfl_symbols': bfl_symbols,
22 28 'initial_columns': PatternQuery.default_columns,
23 29 }
24 30 session_variables = (
... ... @@ -44,6 +50,7 @@ def pattern_view(request):
44 50 'ajax_edit_form': reverse('pattern_edit_form'),
45 51 'ajax_update_pattern': reverse('update_pattern'),
46 52 'ajax_new_ending_row': reverse('new_ending_row'),
  53 + 'ajax_new_ending_table_row': reverse('new_ending_table_row'),
47 54 'ajax_create_pattern': reverse('create_pattern'),
48 55 'ajax_clone_pattern': reverse('clone_pattern'),
49 56 'ajax_history_table': reverse('pattern_table'),
... ...