Úprava tagů korektury
This commit is contained in:
		
							parent
							
								
									290f11cb2e
								
							
						
					
					
						commit
						ec5f6af6f9
					
				
					 4 changed files with 35 additions and 18 deletions
				
			
		|  | @ -101,9 +101,11 @@ def opravy_a_komentare_view(request, pdf_id: int, **kwargs): | ||||||
| 
 | 
 | ||||||
| 		if komentar_id != -1: | 		if komentar_id != -1: | ||||||
| 			komentar = get_object_or_404(Komentar, id=komentar_id) | 			komentar = get_object_or_404(Komentar, id=komentar_id) | ||||||
|  | 			if komentar.text != text: | ||||||
| 				komentar.text = text | 				komentar.text = text | ||||||
| 				komentar.autor = autor | 				komentar.autor = autor | ||||||
| 				komentar.save() | 				komentar.save() | ||||||
|  | 			oprava = komentar.oprava | ||||||
| 		else: | 		else: | ||||||
| 			if oprava_id != -1: | 			if oprava_id != -1: | ||||||
| 				oprava = get_object_or_404(Oprava, id=oprava_id) | 				oprava = get_object_or_404(Oprava, id=oprava_id) | ||||||
|  | @ -116,12 +118,15 @@ def opravy_a_komentare_view(request, pdf_id: int, **kwargs): | ||||||
| 					y=y, | 					y=y, | ||||||
| 				) | 				) | ||||||
| 
 | 
 | ||||||
|  | 			Komentar.objects.create(oprava=oprava, autor=autor, text=text) | ||||||
|  | 			send_email_notification_komentar(oprava, autor, request) | ||||||
|  | 
 | ||||||
| 		tagy_raw = q.get('tagy') | 		tagy_raw = q.get('tagy') | ||||||
|  | 		if tagy_raw is not None: | ||||||
|  | 			oprava.tagy.clear() | ||||||
| 			if tagy_raw != "": | 			if tagy_raw != "": | ||||||
| 				tagy = list(map(int, tagy_raw.split(","))) | 				tagy = list(map(int, tagy_raw.split(","))) | ||||||
| 				oprava.tagy.add(*KorekturaTag.objects.filter(id__in=tagy)) | 				oprava.tagy.add(*KorekturaTag.objects.filter(id__in=tagy)) | ||||||
| 			Komentar.objects.create(oprava=oprava, autor=autor, text=text) |  | ||||||
| 			send_email_notification_komentar(oprava, autor, request) |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 	opravy = Oprava.objects.filter(pdf=pdf_id).all() | 	opravy = Oprava.objects.filter(pdf=pdf_id).all() | ||||||
|  |  | ||||||
|  | @ -5,11 +5,12 @@ | ||||||
|   <br/> |   <br/> | ||||||
|   <textarea id="commform-text" cols=40 rows=10 name="txt"></textarea> |   <textarea id="commform-text" cols=40 rows=10 name="txt"></textarea> | ||||||
|   <br/> |   <br/> | ||||||
|   <span id="commform-tagy"> |   <div id="commform-tagy-info">Úprava tagů celé korektury:</div> | ||||||
|  |   <div id="commform-tagy"> | ||||||
|     {% for tag in tagy %} |     {% for tag in tagy %} | ||||||
|       <button type="button" class="korektury-tag" value="{{tag.id}}" data-selected="false" style="background: {{ tag.barva }}; border-color: {{ tag.barva }};">{{tag.nazev}}</button> |       <button type="button" class="korektury-tag" value="{{tag.id}}" data-selected="false" style="background: {{ tag.barva }}; border-color: {{ tag.barva }};">{{tag.nazev}}</button> | ||||||
|     {% endfor %} |     {% endfor %} | ||||||
|   </span> |   </div> | ||||||
| </div> | </div> | ||||||
| 
 | 
 | ||||||
| <script> | <script> | ||||||
|  | @ -20,6 +21,7 @@ | ||||||
|       this.submit_button = document.getElementById('commform-submit'); |       this.submit_button = document.getElementById('commform-submit'); | ||||||
|       const close_button = document.getElementById('commform-close'); |       const close_button = document.getElementById('commform-close'); | ||||||
|       this.tagy = document.getElementById('commform-tagy'); |       this.tagy = document.getElementById('commform-tagy'); | ||||||
|  |       this.tagy_info = document.getElementById('commform-tagy-info'); | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|       // ctrl-enter submits form |       // ctrl-enter submits form | ||||||
|  | @ -71,8 +73,16 @@ | ||||||
|       this.text.value = text; |       this.text.value = text; | ||||||
| 
 | 
 | ||||||
|       // show form |       // show form | ||||||
|       if (oprava_id === -1 && komentar_id === -1) this.tagy.style.display = 'unset'; else this.tagy.style.display = 'none'; |       if (oprava_id === -1 && komentar_id === -1) { | ||||||
|         if (this.reset_tags_every_open) this.reset_tags(); |         if (this.reset_tags_every_open) this.reset_tags(); | ||||||
|  |         this.tagy_info.style.display = 'none'; | ||||||
|  |       } else { | ||||||
|  |         const oprava = opravy[oprava_id]; | ||||||
|  |         this.tagy_info.style.display = 'unset'; | ||||||
|  |         for (const tag of this.tagy.getElementsByTagName("button")) | ||||||
|  |           tag.dataset.selected = String(oprava.tagy.has(parseInt(tag.value))); | ||||||
|  |       } | ||||||
|  | 
 | ||||||
|       this._show(img_id, x, y); |       this._show(img_id, x, y); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -84,13 +94,12 @@ | ||||||
|       data.append('img_id', this.imgID); |       data.append('img_id', this.imgID); | ||||||
|       data.append('oprava_id', this.oprava_id); |       data.append('oprava_id', this.oprava_id); | ||||||
|       data.append('komentar_id', this.komentar_id); |       data.append('komentar_id', this.komentar_id); | ||||||
|       if (this.oprava_id === -1 && this.komentar_id === -1) { | 
 | ||||||
|       const tagy = []; |       const tagy = []; | ||||||
|       for (const tag of this.tagy.getElementsByTagName("button")) { |       for (const tag of this.tagy.getElementsByTagName("button")) { | ||||||
|         if (tag.dataset.selected !== "false") tagy.push(tag.value); |         if (tag.dataset.selected !== "false") tagy.push(tag.value); | ||||||
|       } |       } | ||||||
|       data.append('tagy', String(tagy)); |       data.append('tagy', String(tagy)); | ||||||
|       } |  | ||||||
| 
 | 
 | ||||||
|       data.append('text', this.text.value); |       data.append('text', this.text.value); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -81,7 +81,7 @@ | ||||||
| 
 | 
 | ||||||
|     // show comment form when 'update-comment' button pressed |     // show comment form when 'update-comment' button pressed | ||||||
|     #update_comment() { |     #update_comment() { | ||||||
|       return commform.show(this.oprava.img_id, this.oprava.x, this.oprava.y, this.#text.textContent, -1, this.id); |       return commform.show(this.oprava.img_id, this.oprava.x, this.oprava.y, this.#text.textContent, this.oprava.id, this.id); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     #delete_comment() { |     #delete_comment() { | ||||||
|  |  | ||||||
|  | @ -72,6 +72,7 @@ | ||||||
|     #komentare; #tagy; |     #komentare; #tagy; | ||||||
|     htmlElement; pointer; |     htmlElement; pointer; | ||||||
|     id; x; y; img_id; status; zobrazit = true; {# oprava_data; #} |     id; x; y; img_id; status; zobrazit = true; {# oprava_data; #} | ||||||
|  |     tagy; | ||||||
| 
 | 
 | ||||||
|     constructor(oprava_data) { |     constructor(oprava_data) { | ||||||
|       this.htmlElement = preoprava.cloneNode(true); |       this.htmlElement = preoprava.cloneNode(true); | ||||||
|  | @ -109,7 +110,9 @@ | ||||||
|       {# this.oprava_data = oprava_data; #} |       {# this.oprava_data = oprava_data; #} | ||||||
|       this.set_status(oprava_data['status']); |       this.set_status(oprava_data['status']); | ||||||
|       this.#tagy.innerHTML = ""; |       this.#tagy.innerHTML = ""; | ||||||
|  |       this.tagy = new Set(); | ||||||
|       for (const tag of oprava_data["tagy"]) { |       for (const tag of oprava_data["tagy"]) { | ||||||
|  |         this.tagy.add(tag["id"]); | ||||||
|         const span = document.createElement("span"); |         const span = document.createElement("span"); | ||||||
|         span.innerHTML = tag["nazev"]; |         span.innerHTML = tag["nazev"]; | ||||||
|         span.classList.add("korektury-tag"); |         span.classList.add("korektury-tag"); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue