Ú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: | ||||
| 			komentar = get_object_or_404(Komentar, id=komentar_id) | ||||
| 			if komentar.text != text: | ||||
| 				komentar.text = text | ||||
| 				komentar.autor = autor | ||||
| 				komentar.save() | ||||
| 			oprava = komentar.oprava | ||||
| 		else: | ||||
| 			if oprava_id != -1: | ||||
| 				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, | ||||
| 				) | ||||
| 
 | ||||
| 			Komentar.objects.create(oprava=oprava, autor=autor, text=text) | ||||
| 			send_email_notification_komentar(oprava, autor, request) | ||||
| 
 | ||||
| 		tagy_raw = q.get('tagy') | ||||
| 		if tagy_raw is not None: | ||||
| 			oprava.tagy.clear() | ||||
| 			if tagy_raw != "": | ||||
| 				tagy = list(map(int, tagy_raw.split(","))) | ||||
| 				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() | ||||
|  |  | |||
|  | @ -5,11 +5,12 @@ | |||
|   <br/> | ||||
|   <textarea id="commform-text" cols=40 rows=10 name="txt"></textarea> | ||||
|   <br/> | ||||
|   <span id="commform-tagy"> | ||||
|   <div id="commform-tagy-info">Úprava tagů celé korektury:</div> | ||||
|   <div id="commform-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> | ||||
|     {% endfor %} | ||||
|   </span> | ||||
|   </div> | ||||
| </div> | ||||
| 
 | ||||
| <script> | ||||
|  | @ -20,6 +21,7 @@ | |||
|       this.submit_button = document.getElementById('commform-submit'); | ||||
|       const close_button = document.getElementById('commform-close'); | ||||
|       this.tagy = document.getElementById('commform-tagy'); | ||||
|       this.tagy_info = document.getElementById('commform-tagy-info'); | ||||
| 
 | ||||
| 
 | ||||
|       // ctrl-enter submits form | ||||
|  | @ -71,8 +73,16 @@ | |||
|       this.text.value = text; | ||||
| 
 | ||||
|       // 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(); | ||||
|         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); | ||||
|     } | ||||
| 
 | ||||
|  | @ -84,13 +94,12 @@ | |||
|       data.append('img_id', this.imgID); | ||||
|       data.append('oprava_id', this.oprava_id); | ||||
|       data.append('komentar_id', this.komentar_id); | ||||
|       if (this.oprava_id === -1 && this.komentar_id === -1) { | ||||
| 
 | ||||
|       const tagy = []; | ||||
|       for (const tag of this.tagy.getElementsByTagName("button")) { | ||||
|         if (tag.dataset.selected !== "false") tagy.push(tag.value); | ||||
|       } | ||||
|       data.append('tagy', String(tagy)); | ||||
|       } | ||||
| 
 | ||||
|       data.append('text', this.text.value); | ||||
| 
 | ||||
|  |  | |||
|  | @ -81,7 +81,7 @@ | |||
| 
 | ||||
|     // show comment form when 'update-comment' button pressed | ||||
|     #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() { | ||||
|  |  | |||
|  | @ -72,6 +72,7 @@ | |||
|     #komentare; #tagy; | ||||
|     htmlElement; pointer; | ||||
|     id; x; y; img_id; status; zobrazit = true; {# oprava_data; #} | ||||
|     tagy; | ||||
| 
 | ||||
|     constructor(oprava_data) { | ||||
|       this.htmlElement = preoprava.cloneNode(true); | ||||
|  | @ -109,7 +110,9 @@ | |||
|       {# this.oprava_data = oprava_data; #} | ||||
|       this.set_status(oprava_data['status']); | ||||
|       this.#tagy.innerHTML = ""; | ||||
|       this.tagy = new Set(); | ||||
|       for (const tag of oprava_data["tagy"]) { | ||||
|         this.tagy.add(tag["id"]); | ||||
|         const span = document.createElement("span"); | ||||
|         span.innerHTML = tag["nazev"]; | ||||
|         span.classList.add("korektury-tag"); | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue