Commit 2cc66960a6b4dfd6f972205dcc9496e2e1f04370

Authored by Bartłomiej Nitoń
2 parents 951f0d02 877d236c

Merge branch 'bartek'

dictionary/ajax_argument_realizations.py
... ... @@ -25,6 +25,7 @@ import datetime
25 25 import os
26 26 from tempfile import mkdtemp, mkstemp
27 27  
  28 +from django.db.models import Count
28 29 from django.http import HttpResponse
29 30 from django.views.decorators.csrf import csrf_exempt
30 31  
... ... @@ -33,7 +34,10 @@ from dictionary.ajax_argument_form import argument_to_form_values, get_argument_
33 34 create_argument_form, all_fields_filled, \
34 35 get_argument_from_form, validate_argument_form
35 36 from dictionary.forms import ArgRealOpinionForm
36   -from dictionary.models import Argument, ArgRealization, ArgRealOpinion, AttributeParameterModel
  37 +from dictionary.models import Argument, ArgRealization, ArgRealOpinion, AttributeParameterModel, \
  38 + Position, RealizationType, \
  39 + get_or_create_phrase_type_extension, get_or_create_positions_extension,\
  40 + sort_positions
37 41 from settings import PROJECT_PATH
38 42  
39 43 DEFAULT_SAVE_PATH = os.path.join(PROJECT_PATH, 'tmp')
... ... @@ -53,13 +57,14 @@ def show_realizations(request, form_data):
53 57 'manage': form_dict['manage']}
54 58 else:
55 59 arg_obj = get_argument_from_form(form_dict['arg_type'], form_dict['subform_values'])
56   - realizations = arg_obj.realizations.order_by('opinion__priority',
  60 + realizations = arg_obj.realizations.order_by('opinion__priority',
  61 + 'type__priority',
57 62 'argument__text_rep')
58 63 result = {'error_message': '',
59 64 'realizations': realizations,
60 65 'main_arg_text_rep': arg_obj.text_rep,
61 66 'manage': form_dict['manage']}
62   - return result
  67 + return result
63 68  
64 69 @csrf_exempt
65 70 @render('arg_realization_form.html')
... ... @@ -108,6 +113,18 @@ def create_opinion_form(realization_id):
108 113 opinion_form = ArgRealOpinionForm(sel_opinion=opinion)
109 114 return opinion_form
110 115  
  116 +@csrf_exempt
  117 +@render('positions_extensions_form.html')
  118 +@ajax(method='post', encode_result=False)
  119 +def positions_extension_form(request, extension_id=None):
  120 + positions = []
  121 + if extension_id:
  122 + extension = ArgRealization.objects.get(id=extension_id)
  123 + positions = sort_positions(extension.positions.all())
  124 + opinion_form = create_opinion_form(extension_id)
  125 + return {'positions': positions,
  126 + 'opinion_form': opinion_form}
  127 +
111 128 @ajax(method='post')
112 129 def remove_realization(request, realization_id, main_arg_data):
113 130 result = {}
... ... @@ -118,7 +135,9 @@ def remove_realization(request, realization_id, main_arg_data):
118 135 main_arg_obj = get_argument_from_form(main_arg_dict['arg_type'],
119 136 main_arg_dict['subform_values'])
120 137 realization_obj = main_arg_obj.realizations.get(id=realization_id)
121   - main_arg_obj.realizations.remove(realization_obj)
  138 + main_arg_obj.realizations.remove(realization_obj)
  139 + if not realization_obj.is_used():
  140 + realization_obj.delete()
122 141 return result
123 142  
124 143 @ajax(method='post')
... ... @@ -132,7 +151,9 @@ def add_arg_realization(request, main_arg_data, realization_data):
132 151  
133 152 # sprawdz czy wypelniono wszystkie pola formularza argumentu dodawanego jako realizacja
134 153 realization_dict = dict((x['name'], x['value']) for x in realization_data)
  154 +
135 155 real_arg_error = validate_argument_form(realization_dict)
  156 +
136 157 if real_arg_error:
137 158 raise AjaxError(u'Dodawanie rozwinięć typu frazy: %s' % real_arg_error)
138 159 # nie dodano opinii o realizacji
... ... @@ -141,14 +162,12 @@ def add_arg_realization(request, main_arg_data, realization_data):
141 162 # znajdz obiekt argumentu bedacego realizacja
142 163 real_arg_obj = get_argument_from_form(realization_dict['arg_type'],
143 164 realization_dict['subform_values'])
144   -
145 165 # znajdz model argumentu bazowego
146 166 main_arg_obj = get_argument_from_form(main_arg_dict['arg_type'],
147 167 main_arg_dict['subform_values'])
148 168  
149 169 opinion = ArgRealOpinion.objects.get(id=realization_dict['opinion'])
150   - realization_obj, xx = ArgRealization.objects.get_or_create(opinion=opinion,
151   - argument=real_arg_obj)
  170 + realization_obj, xx = get_or_create_phrase_type_extension(real_arg_obj, opinion)
152 171 real_count = main_arg_obj.realizations.count()
153 172 main_arg_obj.realizations.add(realization_obj)
154 173 if real_count == main_arg_obj.realizations.count():
... ... @@ -157,6 +176,40 @@ def add_arg_realization(request, main_arg_data, realization_data):
157 176 return result
158 177  
159 178 @ajax(method='post')
  179 +def add_positions_extension(request, main_phrase_type_data, extension_data):
  180 + result = {'added': True}
  181 + # sprawdz czy wypelniono wszystkie pola formularza argumentu glownego
  182 + main_phrase_type_dict = dict((x['name'], x['value']) for x in main_phrase_type_data)
  183 + main_phrase_type_error = validate_argument_form(main_phrase_type_dict)
  184 + if main_phrase_type_error:
  185 + raise AjaxError(u'Główny typ frazy: %s' % main_phrase_type_error)
  186 +
  187 + # sprawdz czy wypelniono wszystkie pola formularza argumentu dodawanego jako realizacja
  188 + extension_dict = dict((x['name'], x['value']) for x in extension_data)
  189 + if not extension_dict['positions']:
  190 + raise AjaxError(u'Dodawanie rozwinięć typu frazy: Nie wybrano żadnej pozycji.')
  191 +
  192 + if not extension_dict['opinion']:
  193 + raise AjaxError('select opinion')
  194 +
  195 + # znajdz model argumentu bazowego
  196 + main_phrase_type_obj = get_argument_from_form(main_phrase_type_dict['arg_type'],
  197 + main_phrase_type_dict['subform_values'])
  198 +
  199 + opinion = ArgRealOpinion.objects.get(id=extension_dict['opinion'])
  200 + extension_type = RealizationType.objects.get(sym_name='positions')
  201 + positions = [Position.objects.get(id=id) for id in extension_dict['positions']]
  202 + # zle, bo moga istniec realizacje, ktore nie sa nigdzie podpiete
  203 + realization_obj, xx = get_or_create_positions_extension(positions, opinion)
  204 +
  205 + extensions_count = main_phrase_type_obj.realizations.count()
  206 + main_phrase_type_obj.realizations.add(realization_obj)
  207 + if extensions_count == main_phrase_type_obj.realizations.count():
  208 + result['added'] = False
  209 +
  210 + return result
  211 +
  212 +@ajax(method='post')
160 213 def create_realizations(request, form_data):
161 214 try:
162 215 tmp_folder = mkdtemp()
... ... @@ -173,7 +226,7 @@ def create_realizations(request, form_data):
173 226 def create_realizations_file(filename):
174 227 try:
175 228 real_file = codecs.open(filename, 'wt', 'utf-8')
176   - write_arguments_realizations(real_file)
  229 + write_phrase_types_extensions(real_file)
177 230 real_file.write('\n')
178 231 write_parameters_realizations(real_file)
179 232 real_file.write('\n')
... ... @@ -181,13 +234,17 @@ def create_realizations_file(filename):
181 234 finally:
182 235 real_file.close()
183 236  
184   -def write_arguments_realizations(real_file):
185   - real_file.write('% Phrase types expand:\n')
186   - for arg in Argument.objects.order_by('text_rep').all():
187   - if arg.realizations.count() > 0:
188   - real_file.write(arg.text_rep + u'-->\n')
189   - for real in arg.realizations.order_by('opinion__priority', 'argument__text_rep'):
190   - real_file.write(' %s\t[%s]\n' % (real.argument.text_rep, real.opinion.value))
  237 +def write_phrase_types_extensions(extensions_file):
  238 + extensions_file.write('% Phrase types extensions:\n')
  239 + phrase_types = Argument.objects.annotate(extensions_count=Count('realizations'))
  240 + phrase_types_with_extensions = phrase_types.filter(extensions_count__gt=0)
  241 + for phrase_type in phrase_types_with_extensions.order_by('text_rep'):
  242 + extensions_file.write(phrase_type.text_rep + u'-->\n')
  243 + for extension in phrase_type.realizations.order_by('opinion__priority',
  244 + 'type__priority',
  245 + 'argument__text_rep'):
  246 + extensions_file.write(' %s\t[%s]\n' % (unicode(extension),
  247 + extension.opinion.value))
191 248  
192 249 def write_parameters_realizations(real_file):
193 250 real_file.write('% Attributes subtypes:\n')
... ...
dictionary/common_func.py
... ... @@ -27,29 +27,6 @@ Common functions used in Slowal application.
27 27 from collections import Counter
28 28  
29 29 from dictionary.models import Position, sortPositions, sortArguments, sortFrameChars
30   -
31   -#locale.setlocale(locale.LC_ALL, 'pl_PL.UTF-8')
32   -
33   -def getArgsList(arguments, real_arg_models):
34   - if real_arg_models:
35   - argument_objs = []
36   - for argument in arguments:
37   - has_realizations = False
38   - for arg_model in real_arg_models:
39   - if argument.type == arg_model.arg_model_name:
40   - has_realizations = True
41   - if argument.realizations.count() > 0:
42   - argument_objs.extend(argument.realizations.all())
43   - else:
44   - argument_objs.append(argument)
45   - break
46   - if not has_realizations:
47   - argument_objs.append(argument)
48   - if len(argument_objs) != len(arguments):
49   - argument_objs = getArgsList(argument_objs, real_arg_models)
50   - return argument_objs
51   - else:
52   - return arguments
53 30  
54 31 def args_to_pos_lists(arguments):
55 32 positions_objs = []
... ...
dictionary/forms.py
... ... @@ -280,9 +280,12 @@ class ArgumentsForm(Form):
280 280 value_separator_queryset=value_separator_queryset)
281 281 self.fields['value_arguments'].initial = [selection_mode, value_separator]
282 282 self.fields['value_arguments'].label = label
283   - if base_arg and base_arg.realizations.exists():
  283 + phrase_type_extensions = ArgRealization.objects.none()
  284 + if base_arg:
  285 + phrase_type_extensions = base_arg.realizations.filter(type__sym_name='phrase_type')
  286 + if phrase_type_extensions.exists():
284 287 realizations_ids = []
285   - for realization in base_arg.realizations.all():
  288 + for realization in phrase_type_extensions.all():
286 289 argument = realization.argument
287 290 argument_model = Argument_Model.objects.get(arg_model_name=argument.type)
288 291 if argument_model.active:
... ...
dictionary/models.py
... ... @@ -583,7 +583,6 @@ def create_nkjp_arg_selection(position, arguments):
583 583 class NKJP_Source(Model):
584 584 source = CharField(max_length=64, db_column='zrodlo',
585 585 verbose_name=u'zrodlo', unique=True)
586   - # !NOWE!
587 586 sym_name = CharField(max_length=32, db_column='nazwa_symboliczna', default='NKJP')
588 587 # flaga oznaczajaca czy dane zrodlo wymaga dodatkowego komentarza
589 588 comment_required = BooleanField(db_column='wymagany_komentarz', default=False)
... ... @@ -769,19 +768,65 @@ def reflex_phrase_types():
769 768 return ['refl', 'recip']
770 769  
771 770 class ArgRealization(Model):
772   -# # !NOWE! nie dodalem tego jeszcze na produkcyjnym
773   -# type = ForeignKey('RealizationType', related_name='realizations')
  771 + type = ForeignKey('RealizationType', related_name='realizations')
774 772 argument = ForeignKey('Argument', blank=True, null=True)
775 773 positions = ManyToManyField('Position', blank=True, null=True,
776 774 related_name='realizations')
777 775 opinion = ForeignKey('ArgRealOpinion', related_name='realizations')
778 776  
  777 + def is_used(self):
  778 + if self.arguments.exists():
  779 + return True
  780 + return False
  781 +
779 782 def __unicode__(self):
780   - return '%s:%s' % (self.opinion.value, self.argument.text_rep)
  783 + text_rep = ''
  784 + if self.type.sym_name == 'phrase_type':
  785 + text_rep = self.argument.text_rep
  786 + elif self.type.sym_name == 'positions':
  787 + sorted_positions = sort_positions(self.positions.all())
  788 + positions_str_tab = [unicode(position) for position in sorted_positions]
  789 + text_rep = ' + '.join(positions_str_tab)
  790 + return text_rep
  791 +
  792 +def get_or_create_extension(extension_type, phrase_type, positions, opinion):
  793 + created = False
  794 + if extension_type.sym_name == 'phrase_type':
  795 + extension, created = get_or_create_phrase_type_extension(phrase_type, opinion)
  796 + elif extension_type.sym_name == 'positions':
  797 + extension, created = get_or_create_positions_extension(positions, opinion)
  798 + return extension, created
  799 +
  800 +def get_or_create_phrase_type_extension(phrase_type, opinion):
  801 + extension_type = RealizationType.objects.get(sym_name='phrase_type')
  802 + extension, created = ArgRealization.objects.get_or_create(opinion=opinion,
  803 + argument=phrase_type,
  804 + type=extension_type)
  805 + return extension, created
  806 +
  807 +def get_or_create_positions_extension(positions, opinion):
  808 + created = False
  809 + extension = None
  810 + extension_type = RealizationType.objects.get(sym_name='positions')
  811 + extensions = ArgRealization.objects.annotate(positions_count=Count('positions'))
  812 + extensions = extensions.filter(positions_count=len(positions),
  813 + opinion=opinion,
  814 + type=extension_type)
  815 + for position in positions:
  816 + extensions = extensions.filter(positions=position)
  817 + if extensions.exists():
  818 + extension = extensions.all()[0]
  819 + else:
  820 + extension = ArgRealization(opinion=opinion, type=extension_type)
  821 + extension.save()
  822 + extension.positions.add(*positions)
  823 + created = True
  824 + return extension, created
781 825  
782 826 class RealizationType(Model):
783 827 name = CharField(max_length=24)
784 828 sym_name = CharField(max_length=24)
  829 + priority = PositiveIntegerField(db_column='priorytet')
785 830  
786 831 def __unicode__(self):
787 832 return self.name
... ...
dictionary/static/js/arg_realizations.js
1 1 /*
2   -Copyright (c) 2012, Bartłomiej Nitoń
  2 +Copyright (c) 2015, Bartłomiej Nitoń
3 3 All rights reserved.
4 4  
5 5 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
... ... @@ -13,12 +13,24 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13 13 $(function() {
14 14 window.selected_real_row_id = -1;
15 15  
  16 + $('#realization-type #realization-type-select').live('change', function (event) {
  17 + if($(this).val() == 'phrase_type') {
  18 + $('#create-realization').load(ajax_realization_arg_form, {'form_data': '',
  19 + 'main_argument': false,
  20 + 'real_id': ''});
  21 + }
  22 + else if($(this).val() == 'positions') {
  23 + $('#create-realization').load(ajax_positions_extension_form);
  24 + }
  25 + });
  26 +
16 27 $('#main-argument').load(ajax_realization_arg_form, {'form_data': '',
17 28 'main_argument': true,
18 29 'real_id': ''});
19 30 $('#create-realization').load(ajax_realization_arg_form, {'form_data': '',
20 31 'main_argument': false,
21 32 'real_id': ''});
  33 +
22 34 $('#main-argument .argument-add-form #id_arg_type').live('change', function (event) {
23 35 realization_arguments_form_change(0, '', true, $(event.target).closest('.argument-add-form'));
24 36 });
... ... @@ -40,6 +52,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
40 52 });
41 53  
42 54 $('#create-realization .argument-add-form').live('submit', add_realization);
  55 + $('#create-realization .positions-add-form').live('submit', add_realization);
43 56  
44 57 $('#modify-realization-dialog .argument-add-form #id_arg_type').live('change', function (event) {
45 58 realization_arguments_form_change(0, '', false, $(event.target).closest('.argument-add-form'));
... ... @@ -50,6 +63,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
50 63 });
51 64  
52 65 $('#modify-realization-dialog .argument-add-form').live('submit', add_realization);
  66 + $('#modify-realization-dialog .positions-add-form').live('submit', add_realization);
53 67  
54 68 $("#get-realizations").live('click', getRealizations);
55 69  
... ... @@ -58,11 +72,13 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
58 72 $("$[id$='-add_realization_button']").live('click', function(event){openAddArgumentDialog(event, null, 'Tworzenie rozwinięcia typu frazy:')});
59 73 $("$[id$='-select_argument_button']").live('click', function(event){openSelectArgumentDialog(event, null)});
60 74  
61   -
62 75 $("[id$='-argument-form-dialog'] .argument-add-form #id_arg_type'").live('change', function(event) {
63   - arguments_form_change(0, null, $(event.target).closest(".argument-add-form"), null)});
  76 + arguments_form_change(0, null, $(event.target).closest(".argument-add-form"), null)
  77 + });
  78 +
64 79 $("[id$='-argument-form-dialog'] .argument-add-form #id_value_positions_0, [id$='-argument-form-dialog'] .argument-add-form #id_value_arguments_0, [id$='-argument-form-dialog'] .argument-add-form #id_value_parameter_0").live('change', function(event) {
65   - arguments_form_change(-1, null, $(event.target).closest(".argument-add-form"), null)});
  80 + arguments_form_change(-1, null, $(event.target).closest(".argument-add-form"), null)
  81 + });
66 82  
67 83 $('form.create-position-form').live('submit', create_position_form_submit);
68 84 $('#position #remove-position').live('click', remove_position);
... ... @@ -193,7 +209,7 @@ function show_realizations() {
193 209 $("tr.RealizationTableRow").click(function() {
194 210 selectTr(this.id)});
195 211 $("tr.RealizationTableRow").dblclick(function() {
196   - modifyRealization(this.id);
  212 + modifyRealization(this.id, $(this).attr('type'));
197 213 });
198 214  
199 215 $("#delete-realization").click(function(e) {
... ... @@ -202,14 +218,19 @@ function show_realizations() {
202 218 return false;
203 219 }
204 220  
205   -function modifyRealization(html_id)
206   -{
  221 +function modifyRealization(html_id, type) {
207 222 id = html_id.replace('realization_', '');
208 223 $('#modify-realization-dialog').empty();
209 224 $('#modify-realization-dialog').data('real_id', html_id);
210   - $('#modify-realization-dialog').load(ajax_realization_arg_form, {'form_data': '',
211   - 'main_argument': false,
212   - 'real_id': id}).dialog('open');
  225 + $('#modify-realization-dialog').data('extension_type', type);
  226 + if(type == 'phrase_type') {
  227 + $('#modify-realization-dialog').load(ajax_realization_arg_form, {'form_data': '',
  228 + 'main_argument': false,
  229 + 'real_id': id}).dialog('open');
  230 + }
  231 + else if(type == 'positions') {
  232 + $('#modify-realization-dialog').load(ajax_positions_extension_form, {'extension_id': id}).dialog('open');
  233 + }
213 234 }
214 235  
215 236 function addModifyRealizationDialog() {
... ... @@ -224,21 +245,34 @@ function addModifyRealizationDialog() {
224 245 }
225 246  
226 247 function add_realization() {
227   - ShowProgressAnimation();
228   - // identyfikator modyfikowanego rozwiniecia (tylko jesli modyfikujemy)
229   - real_id = $(this).parent().data('real_id');
230   -
231   - realization_form = $(this);
232   - realization_data = realization_form.serializeArray();
  248 + var extension_form = $(this);
  249 + var extension_type = extension_form.parent().data('extension_type');
  250 + if(!extension_type) {
  251 + extension_type = $('#realization-type #realization-type-select').val();
  252 + }
  253 + if(extension_type == 'phrase_type') {
  254 + add_phrase_type_extension(extension_form);
  255 + }
  256 + else if(extension_type == 'positions') {
  257 + add_positions_extension(extension_form);
  258 + }
  259 + return false;
  260 +}
  261 +
  262 +function add_phrase_type_extension(realization_form) {
  263 + ShowProgressAnimation();
  264 + var real_id = realization_form.parent().data('real_id');
  265 +
  266 + var realization_data = realization_form.serializeArray();
233 267 realization_data = prepareArgFormData(realization_form, realization_data, -1);
234 268 realization_data.push({name: 'lex_arg_choosing', value: false});
235 269  
236   - main_arg_form = $('#main-argument .argument-add-form');
  270 + var main_arg_form = $('#main-argument .argument-add-form');
237 271 main_arg_data = main_arg_form.serializeArray();
238 272 main_arg_data = prepareArgFormData(main_arg_form, main_arg_data, -1)
239 273 main_arg_data.push({name: 'lex_arg_choosing', value: false});
240 274  
241   - $.ajaxJSON({
  275 + $.ajaxJSON({
242 276 method: 'post',
243 277 url: ajax_add_arg_realization,
244 278 data: {
... ... @@ -246,7 +280,7 @@ function add_realization() {
246 280 realization_data: realization_data
247 281 },
248 282  
249   - callback: function(result) {
  283 + callback: function(result) {
250 284 if(result['added']) {
251 285 if(real_id) {
252 286 removeRealization(real_id);
... ... @@ -256,6 +290,9 @@ function add_realization() {
256 290 }
257 291 }
258 292 $('#modify-realization-dialog').dialog('close');
  293 + $('#modify-realization-dialog').data('real_id', '');
  294 + $('#modify-realization-dialog').data('extension_type', '');
  295 + $('#modify-realization-dialog').empty();
259 296 HideProgressAnimation();
260 297 },
261 298 error_callback: function(xhr, status, error) {
... ... @@ -267,20 +304,89 @@ function add_realization() {
267 304 HideProgressAnimation();
268 305 error_alert('Wybierz opinię.');
269 306 return false;
270   - }
  307 + }
271 308 else if (result) {
272 309 HideProgressAnimation();
273 310 error_alert(result);
274 311 return false;
275 312 }
276   - else
277   - {
  313 + else {
  314 + HideProgressAnimation();
  315 + return true;
  316 + }
  317 + },
  318 + });
  319 +}
  320 +
  321 +function add_positions_extension(extension_form) {
  322 + ShowProgressAnimation();
  323 + var extension_id = extension_form.parent().data('real_id');
  324 +
  325 + var main_phrase_type_form = $('#main-argument .argument-add-form');
  326 + var main_phrase_type_data = main_phrase_type_form.serializeArray();
  327 + main_phrase_type_data = prepareArgFormData(main_phrase_type_form, main_phrase_type_data, -1)
  328 + main_phrase_type_data.push({name: 'lex_arg_choosing', value: false});
  329 +
  330 + var opinion = '';
  331 + var positions = [];
  332 + var extension_data = extension_form.serializeArray();
  333 + extension_data = $.map(extension_data, function(elem) {
  334 + if (elem.name != 'value' && elem.name != 'opinion')
  335 + return elem;
  336 + else {
  337 + if (elem.name == 'value')
  338 + positions.push(elem.value);
  339 + else if (elem.name == 'opinion')
  340 + opinion = elem.value;
  341 + }
  342 + });
  343 + extension_data.push({name: 'positions', value: positions});
  344 + extension_data.push({name: 'opinion', value: opinion});
  345 +
  346 + $.ajaxJSON({
  347 + method: 'post',
  348 + url: ajax_add_positions_extension,
  349 + data: {
  350 + main_phrase_type_data: main_phrase_type_data,
  351 + extension_data: extension_data
  352 + },
  353 +
  354 + callback: function(result) {
  355 + if(result['added']) {
  356 + if(extension_id) {
  357 + removeRealization(extension_id);
  358 + }
  359 + else {
  360 + show_realizations();
  361 + }
  362 + }
  363 + $('#modify-realization-dialog').dialog('close');
  364 + $('#modify-realization-dialog').data('real_id', '');
  365 + $('#modify-realization-dialog').data('extension_type', '');
  366 + $('#modify-realization-dialog').empty();
  367 + HideProgressAnimation();
  368 + },
  369 + error_callback: function(xhr, status, error) {
  370 + HideProgressAnimation();
  371 + error_alert(status + ': ' + error);
  372 + },
  373 + bad_data_callback: function(result) {
  374 + if (result == 'select opinion') {
  375 + HideProgressAnimation();
  376 + error_alert('Wybierz opinię.');
  377 + return false;
  378 + }
  379 + else if (result) {
  380 + HideProgressAnimation();
  381 + error_alert(result);
  382 + return false;
  383 + }
  384 + else {
278 385 HideProgressAnimation();
279 386 return true;
280 387 }
281 388 },
282 389 });
283   - return false;
284 390 }
285 391  
286 392 function selectTr(id)
... ...
dictionary/static/js/argument_form_utils.js
... ... @@ -268,7 +268,8 @@ function argument_form_submit() {
268 268 }
269 269 // tworzymy typy fraz
270 270 else {
271   - realization_arguments_form_change(1, '', false, dialogParent.closest(".argument-add-form"));
  271 + arguments_form_change(1, null, dialogParent.closest(".argument-add-form"), '');
  272 + // realization_arguments_form_change(1, '', false, dialogParent.closest(".argument-add-form"));
272 273 }
273 274 }
274 275 this_dialog.dialog('close');
... ...
dictionary/templates/arg_realizations.html
... ... @@ -12,19 +12,22 @@
12 12 <tr>
13 13 <td>
14 14 <strong>Główny typ frazy:</strong>
15   - <div id='main-argument'>
16   - </div>
  15 + <div id='main-argument'></div>
17 16 {% if perms.dictionary.create_realization %}
18 17 <strong>Dodawanie rozwinięć typu frazy:</strong>
19   - <div id='create-realization'>
20   - </div>
21   - <div id='modify-realization-dialog'>
22   - </div>
  18 + <div id='realization-type'>
  19 + <select id='realization-type-select'>
  20 + {% for type in realization_types %}
  21 + <option value="{{ type.sym_name }}">{{ type.name }}</option>
  22 + {% endfor %}
  23 + </select>
  24 + </div>
  25 + <div id='create-realization'></div>
  26 + <div id='modify-realization-dialog'></div>
23 27 {% endif %}
24 28 </td>
25 29 <td>
26   - <div id='realizations'>
27   - </div>
  30 + <div id='realizations'></div>
28 31 </td>
29 32 </tr>
30 33 <tr>
... ...
dictionary/templates/positions_extensions_form.html 0 → 100644
  1 +Pozycje składniowe:
  2 +<form class="positions-add-form" method="post"> {% csrf_token %}
  3 + <div id="subform">
  4 + <button type="button" id="realization-add_position_button">Dodaj pozycję</button>
  5 + <div id="realization-positions">
  6 + {% for position in positions %}
  7 + <p id="position">
  8 + {{ position.text_rep }}
  9 + <input id="id_value" type="hidden" name="value" value="{{ position.id }}"/>
  10 + <button type="button" id="edit-position">Edytuj</button>
  11 + <button type="button" id="remove-position">Usuń</button>
  12 + </p>
  13 + {% endfor %}
  14 + </div>
  15 + <div class="opinion">{{opinion_form.as_p}}</div>
  16 + <button type="submit" id="add-realization">Zapisz</button>
  17 + </div>
  18 +</form>
0 19 \ No newline at end of file
... ...
dictionary/templates/show_realizations.html
... ... @@ -7,9 +7,9 @@
7 7 <td class='ColumnHeader' colspan='2'>Rozwinięcia typu frazy {{main_arg_text_rep}}:</td>
8 8 </tr>
9 9 {% for realization in realizations %}
10   - <tr class='RealizationTableRow' id="realization_{{realization.id}}">
11   - <td>{{realization.argument.text_rep}}</td>
12   - <td>{{realization.opinion.value}}</td>
  10 + <tr class='RealizationTableRow' id="realization_{{realization.id}}" type="{{ realization.type.sym_name }}">
  11 + <td>{{ realization }}</td>
  12 + <td>{{ realization.opinion.value }}</td>
13 13 </tr>
14 14 {% endfor %}
15 15 </table>
... ...
dictionary/views.py
... ... @@ -35,7 +35,7 @@ from common.decorators import render
35 35 from dictionary.ajax_jqgrid import default_sort_rules, default_filter_rules
36 36 from dictionary.forms import UserCreateForm, GetVocabularyForm, ArgStatsForm
37 37 from dictionary.models import PositionCategory, NKJP_Opinion, NKJP_Source, \
38   - Vocabulary, Message
  38 + Vocabulary, Message, RealizationType
39 39 from dictionary.ajax_lemma_view import getFrequentPositions, order_sort_rules
40 40  
41 41  
... ... @@ -338,14 +338,11 @@ def get_grid_col_models(user):
338 338 ]
339 339 return col_models
340 340  
341   -#@permission_required('dictionary.view_vocab_stats')
342 341 @render('manage_vocabularies.html')
343 342 def manage_vocabulary(request):
344 343 to_return = {}
345   - #add_lemma_form = AddLemmaForm();
346 344 to_return['download_form'] = GetVocabularyForm()
347 345 to_return['vocabularies'] = Vocabulary.objects.all()
348   - #to_return['add_lemma_form'] = add_lemma_form
349 346 to_return['js_vars'] = {
350 347 'ajax_create_vocabulary': reverse('create_vocabulary'),
351 348 'ajax_vocab_perm_manage_form': reverse('vocab_perm_manage_form'),
... ... @@ -418,13 +415,14 @@ def manage_users(request):
418 415 }
419 416 return to_return
420 417  
421   -#@permission_required('dictionary.view_realization')
422 418 @render('arg_realizations.html')
423 419 def manage_arg_realizations(request):
424 420 to_return = {}
  421 + to_return['realization_types'] = RealizationType.objects.order_by('priority')
425 422 to_return['js_vars'] = {
426 423 'ajax_realization_arg_form': reverse('realization_arg_form'),
427 424 'ajax_add_arg_realization': reverse('add_arg_realization'),
  425 + 'ajax_add_positions_extension': reverse('add_positions_extension'),
428 426 'ajax_show_realizations': reverse('show_realizations'),
429 427 'ajax_remove_realization': reverse('remove_realization'),
430 428 'ajax_create_realizations': reverse('create_realizations'),
... ... @@ -432,20 +430,10 @@ def manage_arg_realizations(request):
432 430 'ajax_argument_form_submit': reverse('argument_form_submit'),
433 431 'ajax_create_position_form': reverse('create_position_form'),
434 432 'ajax_create_position_form_submit': reverse('create_position_form_submit'),
  433 + 'ajax_positions_extension_form': reverse('positions_extension_form'),
435 434 }
436 435 return to_return
437 436  
438   -#@permission_required('dictionary.view_arg_stats')
439   -#@render('arg_stats.html')
440   -#def arg_stats(request):
441   -# to_return = {}
442   -# to_return['arg_stats_form'] = ArgStatsForm()
443   -# to_return['js_vars'] = {
444   -# 'ajax_gen_list': reverse('gen_list'),
445   -# 'ajax_prepare_graph_data': reverse('prepare_graph_data'),
446   -# }
447   -# return to_return
448   -
449 437 def download_walenty(request):
450 438 generation_date = datetime.datetime.now()
451 439 walenty_file_name = '%s_%s.tar.gz' % ('walenty', generation_date.strftime('%Y%m%d'))
... ...
static/js/base-layout.js
... ... @@ -20,7 +20,7 @@ $(window).bind(&#39;beforeunload&#39;, function() {
20 20 warnings = ""
21 21 if(change)
22 22 warnings = warnings + " - Nie zapisano zmian w schematach składniowych.\n";
23   - if(semanticsChanged())
  23 + if(typeof semanticsChanged != "undefined" && semanticsChanged())
24 24 warnings = warnings + " - Nie zapisano zmian w ramach semantycznych.\n";
25 25 if(notesNotSaved)
26 26 warnings = warnings + " - Nie zapisano notatki.\n";
... ...
... ... @@ -189,7 +189,9 @@ urlpatterns += patterns(&#39;dictionary.ajax_argument_realizations&#39;,
189 189 url(r'^ajax/show_realizations/$', 'show_realizations'),
190 190 url(r'^ajax/remove_realization/$', 'remove_realization'),
191 191 url(r'^ajax/add_arg_realization/$', 'add_arg_realization'),
  192 + url(r'^ajax/add_positions_extension/$', 'add_positions_extension'),
192 193 url(r'^ajax/create_realizations/$', 'create_realizations'),
  194 + url(r'^ajax/positions_extension_form/$', 'positions_extension_form'),
193 195 )
194 196  
195 197 urlpatterns += patterns('dictionary.ajax_argument_stats',
... ...