| 
									
										
										
										
											2024-07-26 17:00:28 +08:00
										 |  |  | import { t } from "../../services/i18n.js"; | 
					
						
							| 
									
										
										
										
											2020-11-26 23:00:27 +01:00
										 |  |  | import server from "../../services/server.js"; | 
					
						
							| 
									
										
										
										
											2021-04-16 23:01:56 +02:00
										 |  |  | import froca from "../../services/froca.js"; | 
					
						
							| 
									
										
										
										
											2020-11-26 23:00:27 +01:00
										 |  |  | import linkService from "../../services/link.js"; | 
					
						
							|  |  |  | import attributeAutocompleteService from "../../services/attribute_autocomplete.js"; | 
					
						
							|  |  |  | import noteAutocompleteService from "../../services/note_autocomplete.js"; | 
					
						
							|  |  |  | import promotedAttributeDefinitionParser from '../../services/promoted_attribute_definition_parser.js'; | 
					
						
							| 
									
										
										
										
											2021-05-22 12:35:41 +02:00
										 |  |  | import NoteContextAwareWidget from "../note_context_aware_widget.js"; | 
					
						
							| 
									
										
										
										
											2020-11-26 23:00:27 +01:00
										 |  |  | import SpacedUpdate from "../../services/spaced_update.js"; | 
					
						
							|  |  |  | import utils from "../../services/utils.js"; | 
					
						
							| 
									
										
										
										
											2022-12-01 00:17:15 +01:00
										 |  |  | import shortcutService from "../../services/shortcuts.js"; | 
					
						
							| 
									
										
										
										
											2023-04-15 00:06:13 +02:00
										 |  |  | import appContext from "../../components/app_context.js"; | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  | import FAttribute from "../../entities/fattribute.js"; | 
					
						
							|  |  |  | import FNote, { FNoteRow } from "../../entities/fnote.js"; | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  | import { Attribute } from "../../services/attribute_parser.js"; | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | const TPL = `
 | 
					
						
							| 
									
										
										
										
											2020-07-14 23:29:37 +02:00
										 |  |  | <div class="attr-detail"> | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  |     <style> | 
					
						
							|  |  |  |         .attr-detail { | 
					
						
							|  |  |  |             display: block; | 
					
						
							|  |  |  |             background-color: var(--accented-background-color); | 
					
						
							|  |  |  |             border: 1px solid var(--main-border-color); | 
					
						
							|  |  |  |             border-radius: 4px; | 
					
						
							|  |  |  |             z-index: 1000; | 
					
						
							| 
									
										
										
										
											2020-07-14 23:29:37 +02:00
										 |  |  |             padding: 15px; | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  |             position: absolute; | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |             width: 500px; | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  |             max-height: 600px; | 
					
						
							|  |  |  |             overflow: auto; | 
					
						
							| 
									
										
										
										
											2020-08-27 14:54:56 +02:00
										 |  |  |             box-shadow: 10px 10px 93px -25px black; | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-23 23:38:05 +02:00
										 |  |  |         .attr-help td { | 
					
						
							|  |  |  |             color: var(--muted-text-color); | 
					
						
							|  |  |  |             padding: 5px; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  |         .related-notes-list { | 
					
						
							|  |  |  |             padding-left: 20px; | 
					
						
							|  |  |  |             margin-top: 10px; | 
					
						
							|  |  |  |             margin-bottom: 10px; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |         .attr-edit-table { | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  |             width: 100%; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |         .attr-edit-table th { | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  |             text-align: left; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |         .attr-edit-table td input { | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  |             width: 100%; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-03 22:27:45 +02:00
										 |  |  |         .close-attr-detail-button { | 
					
						
							|  |  |  |             font-size: x-large; | 
					
						
							|  |  |  |             cursor: pointer; | 
					
						
							| 
									
										
										
										
											2020-08-19 18:05:07 +02:00
										 |  |  |             position: relative; | 
					
						
							|  |  |  |             top: -2px; | 
					
						
							| 
									
										
										
										
											2020-07-03 22:27:45 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         .attr-save-delete-button-container { | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |             display: flex; | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |             margin-top: 15px; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-19 17:59:55 +02:00
										 |  |  |         .attr-detail input[readonly] { | 
					
						
							|  |  |  |             background-color: var(--accented-background-color) !important; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  |     </style> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-19 18:05:07 +02:00
										 |  |  |     <div style="display: flex; justify-content: space-between; margin-bottom: 8px;"> | 
					
						
							| 
									
										
										
										
											2024-07-26 17:00:28 +08:00
										 |  |  |         <h5 class="attr-detail-title">${t('attribute_detail.attr_detail_title')}</h5> | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-26 17:00:28 +08:00
										 |  |  |         <span class="bx bx-x close-attr-detail-button" title="${t('attribute_detail.close_button_title')}"></span> | 
					
						
							| 
									
										
										
										
											2020-07-03 22:27:45 +02:00
										 |  |  |     </div> | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-26 17:00:28 +08:00
										 |  |  |     <div class="attr-is-owned-by">${t('attribute_detail.attr_is_owned_by')}</div> | 
					
						
							| 
									
										
										
										
											2020-07-05 23:53:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |     <table class="attr-edit-table"> | 
					
						
							| 
									
										
										
										
											2024-07-26 17:00:28 +08:00
										 |  |  |         <tr title="${t('attribute_detail.attr_name_title')}"> | 
					
						
							|  |  |  |             <th>${t('attribute_detail.name')}</th> | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |             <td><input type="text" class="attr-input-name form-control" /></td> | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  |         </tr> | 
					
						
							| 
									
										
										
										
											2020-08-23 23:38:05 +02:00
										 |  |  |         <tr class="attr-help"></tr> | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |         <tr class="attr-row-value"> | 
					
						
							| 
									
										
										
										
											2024-07-26 17:00:28 +08:00
										 |  |  |             <th>${t('attribute_detail.value')}</th> | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |             <td><input type="text" class="attr-input-value form-control" /></td> | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  |         </tr> | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |         <tr class="attr-row-target-note"> | 
					
						
							| 
									
										
										
										
											2024-07-26 17:00:28 +08:00
										 |  |  |             <th title="${t('attribute_detail.target_note_title')}">${t('attribute_detail.target_note')}</th> | 
					
						
							| 
									
										
										
										
											2020-07-13 00:15:00 +02:00
										 |  |  |             <td> | 
					
						
							|  |  |  |                 <div class="input-group"> | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |                     <input type="text" class="attr-input-target-note form-control" /> | 
					
						
							| 
									
										
										
										
											2020-07-13 00:15:00 +02:00
										 |  |  |                 </div> | 
					
						
							|  |  |  |             </td> | 
					
						
							|  |  |  |         </tr> | 
					
						
							| 
									
										
										
										
											2020-08-23 23:38:05 +02:00
										 |  |  |         <tr class="attr-row-promoted" | 
					
						
							| 
									
										
										
										
											2024-07-26 17:00:28 +08:00
										 |  |  |             title="${t('attribute_detail.promoted_title')}"> | 
					
						
							|  |  |  |             <th>${t('attribute_detail.promoted')}</th> | 
					
						
							| 
									
										
										
										
											2024-09-03 18:42:03 +02:00
										 |  |  |             <td><input type="checkbox" class="attr-input-promoted form-check" /></td> | 
					
						
							| 
									
										
										
										
											2020-07-15 00:09:37 +02:00
										 |  |  |         </tr> | 
					
						
							| 
									
										
										
										
											2023-09-22 04:58:06 -04:00
										 |  |  |         <tr class="attr-row-promoted-alias"> | 
					
						
							| 
									
										
										
										
											2024-07-26 17:00:28 +08:00
										 |  |  |             <th title="${t('attribute_detail.promoted_alias_title')}">${t('attribute_detail.promoted_alias')}</th> | 
					
						
							| 
									
										
										
										
											2023-09-22 04:58:06 -04:00
										 |  |  |             <td> | 
					
						
							|  |  |  |                 <div class="input-group"> | 
					
						
							|  |  |  |                     <input type="text" class="attr-input-promoted-alias form-control" /> | 
					
						
							|  |  |  |                 </div> | 
					
						
							|  |  |  |             </td> | 
					
						
							|  |  |  |         </tr> | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |         <tr class="attr-row-multiplicity"> | 
					
						
							| 
									
										
										
										
											2024-07-26 17:00:28 +08:00
										 |  |  |             <th title="${t('attribute_detail.multiplicity_title')}">${t('attribute_detail.multiplicity')}</th> | 
					
						
							| 
									
										
										
										
											2020-07-15 00:09:37 +02:00
										 |  |  |             <td> | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |                 <select class="attr-input-multiplicity form-control"> | 
					
						
							| 
									
										
										
										
											2024-07-26 17:00:28 +08:00
										 |  |  |                   <option value="single">${t('attribute_detail.single_value')}</option> | 
					
						
							|  |  |  |                   <option value="multi">${t('attribute_detail.multi_value')}</option> | 
					
						
							| 
									
										
										
										
											2020-07-15 00:09:37 +02:00
										 |  |  |                 </select> | 
					
						
							|  |  |  |             </td> | 
					
						
							|  |  |  |         </tr> | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |         <tr class="attr-row-label-type"> | 
					
						
							| 
									
										
										
										
											2024-07-26 17:00:28 +08:00
										 |  |  |             <th title="${t('attribute_detail.label_type_title')}">${t('attribute_detail.label_type')}</th> | 
					
						
							| 
									
										
										
										
											2020-07-15 00:09:37 +02:00
										 |  |  |             <td> | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |                 <select class="attr-input-label-type form-control"> | 
					
						
							| 
									
										
										
										
											2024-07-26 17:00:28 +08:00
										 |  |  |                   <option value="text">${t('attribute_detail.text')}</option> | 
					
						
							|  |  |  |                   <option value="number">${t('attribute_detail.number')}</option> | 
					
						
							|  |  |  |                   <option value="boolean">${t('attribute_detail.boolean')}</option> | 
					
						
							|  |  |  |                   <option value="date">${t('attribute_detail.date')}</option> | 
					
						
							|  |  |  |                   <option value="datetime">${t('attribute_detail.date_time')}</option> | 
					
						
							| 
									
										
										
										
											2024-11-22 17:58:23 +00:00
										 |  |  |                   <option value="time">${t('attribute_detail.time')}</option> | 
					
						
							| 
									
										
										
										
											2024-07-26 17:00:28 +08:00
										 |  |  |                   <option value="url">${t('attribute_detail.url')}</option> | 
					
						
							| 
									
										
										
										
											2020-07-15 00:09:37 +02:00
										 |  |  |                 </select> | 
					
						
							|  |  |  |             </td> | 
					
						
							|  |  |  |         </tr> | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |         <tr class="attr-row-number-precision"> | 
					
						
							| 
									
										
										
										
											2024-07-26 17:00:28 +08:00
										 |  |  |             <th title="${t('attribute_detail.precision_title')}">${t('attribute_detail.precision')}</th> | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |             <td> | 
					
						
							|  |  |  |                 <div class="input-group"> | 
					
						
							|  |  |  |                     <input type="number" class="form-control attr-input-number-precision" style="text-align: right"> | 
					
						
							| 
									
										
										
										
											2024-09-03 18:42:03 +02:00
										 |  |  |                     <span class="input-group-text">${t('attribute_detail.digits')}</span> | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |                 </div> | 
					
						
							|  |  |  |             </td> | 
					
						
							|  |  |  |         </tr> | 
					
						
							|  |  |  |         <tr class="attr-row-inverse-relation"> | 
					
						
							| 
									
										
										
										
											2024-07-26 17:00:28 +08:00
										 |  |  |             <th title="${t('attribute_detail.inverse_relation_title')}">${t('attribute_detail.inverse_relation')}</th> | 
					
						
							| 
									
										
										
										
											2020-07-15 00:09:37 +02:00
										 |  |  |             <td> | 
					
						
							|  |  |  |                 <div class="input-group"> | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |                     <input type="text" class="attr-input-inverse-relation form-control" /> | 
					
						
							| 
									
										
										
										
											2020-07-15 00:09:37 +02:00
										 |  |  |                 </div> | 
					
						
							|  |  |  |             </td> | 
					
						
							|  |  |  |         </tr> | 
					
						
							| 
									
										
										
										
											2024-07-26 17:00:28 +08:00
										 |  |  |         <tr title="${t('attribute_detail.inheritable_title')}"> | 
					
						
							|  |  |  |             <th>${t('attribute_detail.inheritable')}</th> | 
					
						
							| 
									
										
										
										
											2024-09-03 18:42:03 +02:00
										 |  |  |             <td><input type="checkbox" class="attr-input-inheritable form-check" /></td> | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  |         </tr> | 
					
						
							|  |  |  |     </table> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |     <div class="attr-save-delete-button-container"> | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |         <button class="btn btn-primary btn-sm attr-save-changes-and-close-button" | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |             style="flex-grow: 1; margin-right: 20px"> | 
					
						
							| 
									
										
										
										
											2024-07-26 17:00:28 +08:00
										 |  |  |             ${t('attribute_detail.save_and_close')}</button> | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         <button class="btn btn-secondary btn-sm attr-delete-button"> | 
					
						
							| 
									
										
										
										
											2024-07-26 17:00:28 +08:00
										 |  |  |             ${t('attribute_detail.delete')}</button> | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |     </div> | 
					
						
							| 
									
										
										
										
											2020-07-23 00:19:50 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-14 23:29:37 +02:00
										 |  |  |     <div class="related-notes-container"> | 
					
						
							|  |  |  |         <br/> | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-26 17:00:28 +08:00
										 |  |  |         <h5 class="related-notes-tile">${t('attribute_detail.related_notes_title')}</h5> | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-14 23:29:37 +02:00
										 |  |  |         <ul class="related-notes-list"></ul> | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-26 17:00:28 +08:00
										 |  |  |         <div class="related-notes-more-notes">${t('attribute_detail.more_notes')}</div> | 
					
						
							| 
									
										
										
										
											2020-07-14 23:29:37 +02:00
										 |  |  |     </div> | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  | </div>`;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const DISPLAYED_NOTES = 10; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  | const ATTR_TITLES: Record<string, string> = { | 
					
						
							| 
									
										
										
										
											2024-07-26 17:00:28 +08:00
										 |  |  |     "label": t('attribute_detail.label'), | 
					
						
							|  |  |  |     "label-definition": t('attribute_detail.label_definition'), | 
					
						
							|  |  |  |     "relation": t('attribute_detail.relation'), | 
					
						
							|  |  |  |     "relation-definition": t('attribute_detail.relation_definition') | 
					
						
							| 
									
										
										
										
											2020-07-15 00:09:37 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  | const ATTR_HELP: Record<string, Record<string, string>> = { | 
					
						
							| 
									
										
										
										
											2020-08-23 23:38:05 +02:00
										 |  |  |     "label": { | 
					
						
							| 
									
										
										
										
											2024-07-26 17:00:28 +08:00
										 |  |  |         "disableVersioning": t('attribute_detail.disable_versioning'), | 
					
						
							|  |  |  |         "calendarRoot": t('attribute_detail.calendar_root'), | 
					
						
							|  |  |  |         "archived": t('attribute_detail.archived'), | 
					
						
							|  |  |  |         "excludeFromExport": t('attribute_detail.exclude_from_export'), | 
					
						
							|  |  |  |         "run": t('attribute_detail.run'), | 
					
						
							|  |  |  |         "runOnInstance": t('attribute_detail.run_on_instance'), | 
					
						
							|  |  |  |         "runAtHour": t('attribute_detail.run_at_hour'), | 
					
						
							|  |  |  |         "disableInclusion": t('attribute_detail.disable_inclusion'), | 
					
						
							|  |  |  |         "sorted": t('attribute_detail.sorted'), | 
					
						
							|  |  |  |         "sortDirection": t('attribute_detail.sort_direction'), | 
					
						
							|  |  |  |         "sortFoldersFirst": t('attribute_detail.sort_folders_first'), | 
					
						
							|  |  |  |         "top": t('attribute_detail.top'), | 
					
						
							|  |  |  |         "hidePromotedAttributes": t('attribute_detail.hide_promoted_attributes'), | 
					
						
							|  |  |  |         "readOnly": t('attribute_detail.read_only'), | 
					
						
							|  |  |  |         "autoReadOnlyDisabled": t('attribute_detail.auto_read_only_disabled'), | 
					
						
							|  |  |  |         "appCss": t('attribute_detail.app_css'), | 
					
						
							|  |  |  |         "appTheme": t('attribute_detail.app_theme'), | 
					
						
							| 
									
										
										
										
											2024-12-14 02:35:49 +02:00
										 |  |  |         "appThemeBase": t('attribute_detail.app_theme_base'), | 
					
						
							| 
									
										
										
										
											2024-07-26 17:00:28 +08:00
										 |  |  |         "cssClass": t('attribute_detail.css_class'), | 
					
						
							|  |  |  |         "iconClass": t('attribute_detail.icon_class'), | 
					
						
							|  |  |  |         "pageSize": t('attribute_detail.page_size'), | 
					
						
							|  |  |  |         "customRequestHandler": t('attribute_detail.custom_request_handler'), | 
					
						
							|  |  |  |         "customResourceProvider": t('attribute_detail.custom_resource_provider'), | 
					
						
							|  |  |  |         "widget": t('attribute_detail.widget'), | 
					
						
							|  |  |  |         "workspace": t('attribute_detail.workspace'), | 
					
						
							|  |  |  |         "workspaceIconClass": t('attribute_detail.workspace_icon_class'), | 
					
						
							|  |  |  |         "workspaceTabBackgroundColor": t('attribute_detail.workspace_tab_background_color'), | 
					
						
							|  |  |  |         "workspaceCalendarRoot": t('attribute_detail.workspace_calendar_root'), | 
					
						
							|  |  |  |         "workspaceTemplate": t('attribute_detail.workspace_template'), | 
					
						
							|  |  |  |         "searchHome": t('attribute_detail.search_home'), | 
					
						
							|  |  |  |         "workspaceSearchHome": t('attribute_detail.workspace_search_home'), | 
					
						
							|  |  |  |         "inbox": t('attribute_detail.inbox'), | 
					
						
							|  |  |  |         "workspaceInbox": t('attribute_detail.workspace_inbox'), | 
					
						
							|  |  |  |         "sqlConsoleHome": t('attribute_detail.sql_console_home'), | 
					
						
							|  |  |  |         "bookmarkFolder": t('attribute_detail.bookmark_folder'), | 
					
						
							|  |  |  |         "shareHiddenFromTree": t('attribute_detail.share_hidden_from_tree'), | 
					
						
							|  |  |  |         "shareExternalLink": t('attribute_detail.share_external_link'), | 
					
						
							|  |  |  |         "shareAlias": t('attribute_detail.share_alias'), | 
					
						
							|  |  |  |         "shareOmitDefaultCss": t('attribute_detail.share_omit_default_css'), | 
					
						
							|  |  |  |         "shareRoot": t('attribute_detail.share_root'), | 
					
						
							|  |  |  |         "shareDescription": t('attribute_detail.share_description'), | 
					
						
							|  |  |  |         "shareRaw": t('attribute_detail.share_raw'), | 
					
						
							|  |  |  |         "shareDisallowRobotIndexing": t('attribute_detail.share_disallow_robot_indexing'), | 
					
						
							|  |  |  |         "shareCredentials": t('attribute_detail.share_credentials'), | 
					
						
							|  |  |  |         "shareIndex": t('attribute_detail.share_index'), | 
					
						
							|  |  |  |         "displayRelations": t('attribute_detail.display_relations'), | 
					
						
							|  |  |  |         "hideRelations": t('attribute_detail.hide_relations'), | 
					
						
							|  |  |  |         "titleTemplate": t('attribute_detail.title_template'), | 
					
						
							|  |  |  |         "template": t('attribute_detail.template'), | 
					
						
							|  |  |  |         "toc": t('attribute_detail.toc'), | 
					
						
							|  |  |  |         "color": t('attribute_detail.color'), | 
					
						
							|  |  |  |         "keyboardShortcut": t('attribute_detail.keyboard_shortcut'), | 
					
						
							|  |  |  |         "keepCurrentHoisting": t('attribute_detail.keep_current_hoisting'), | 
					
						
							|  |  |  |         "executeButton": t('attribute_detail.execute_button'), | 
					
						
							|  |  |  |         "executeDescription": t('attribute_detail.execute_description'), | 
					
						
							|  |  |  |         "excludeFromNoteMap": t('attribute_detail.exclude_from_note_map'), | 
					
						
							|  |  |  |         "newNotesOnTop": t('attribute_detail.new_notes_on_top'), | 
					
						
							|  |  |  |         "hideHighlightWidget": t('attribute_detail.hide_highlight_widget') | 
					
						
							| 
									
										
										
										
											2020-08-23 23:38:05 +02:00
										 |  |  |     }, | 
					
						
							|  |  |  |     "relation": { | 
					
						
							| 
									
										
										
										
											2024-07-26 17:00:28 +08:00
										 |  |  |         "runOnNoteCreation": t('attribute_detail.run_on_note_creation'), | 
					
						
							|  |  |  |         "runOnChildNoteCreation": t('attribute_detail.run_on_child_note_creation'), | 
					
						
							|  |  |  |         "runOnNoteTitleChange": t('attribute_detail.run_on_note_title_change'), | 
					
						
							|  |  |  |         "runOnNoteContentChange": t('attribute_detail.run_on_note_content_change'), | 
					
						
							|  |  |  |         "runOnNoteChange": t('attribute_detail.run_on_note_change'), | 
					
						
							|  |  |  |         "runOnNoteDeletion": t('attribute_detail.run_on_note_deletion'), | 
					
						
							|  |  |  |         "runOnBranchCreation": t('attribute_detail.run_on_branch_creation'), | 
					
						
							|  |  |  |         "runOnBranchChange": t('attribute_detail.run_on_branch_change'), | 
					
						
							|  |  |  |         "runOnBranchDeletion": t('attribute_detail.run_on_branch_deletion'), | 
					
						
							|  |  |  |         "runOnAttributeCreation": t('attribute_detail.run_on_attribute_creation'), | 
					
						
							|  |  |  |         "runOnAttributeChange": t('attribute_detail.run_on_attribute_change'), | 
					
						
							|  |  |  |         "template": t('attribute_detail.relation_template'), | 
					
						
							|  |  |  |         "inherit": t('attribute_detail.inherit'), | 
					
						
							|  |  |  |         "renderNote": t('attribute_detail.render_note'), | 
					
						
							|  |  |  |         "widget": t('attribute_detail.widget_relation'), | 
					
						
							|  |  |  |         "shareCss": t('attribute_detail.share_css'), | 
					
						
							|  |  |  |         "shareJs": t('attribute_detail.share_js'), | 
					
						
							|  |  |  |         "shareTemplate": t('attribute_detail.share_template'), | 
					
						
							|  |  |  |         "shareFavicon": t('attribute_detail.share_favicon') | 
					
						
							| 
									
										
										
										
											2020-08-23 23:38:05 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  | interface AttributeDetailOpts { | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |     allAttributes: Attribute[]; | 
					
						
							|  |  |  |     attribute: Attribute; | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |     isOwned: boolean; | 
					
						
							|  |  |  |     x: number; | 
					
						
							|  |  |  |     y: number; | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |     focus?: "name"; | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | interface SearchRelatedResponse { | 
					
						
							|  |  |  |     // TODO: Deduplicate once we split client from server.
 | 
					
						
							|  |  |  |     results: { | 
					
						
							|  |  |  |         noteId: string; | 
					
						
							|  |  |  |         notePathArray: string[]; | 
					
						
							|  |  |  |     }[]; | 
					
						
							|  |  |  |     count: number; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-22 12:35:41 +02:00
										 |  |  | export default class AttributeDetailWidget extends NoteContextAwareWidget { | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     private $title!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $inputName!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $inputValue!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $rowPromoted!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $inputPromoted!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $inputPromotedAlias!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $inputMultiplicity!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $inputInverseRelation!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $inputLabelType!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $inputTargetNote!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $inputNumberPrecision!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $inputInheritable!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $rowValue!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $rowMultiplicity!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $rowLabelType!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $rowNumberPrecision!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $rowInverseRelation!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $rowTargetNote!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $rowPromotedAlias!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $attrIsOwnedBy!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $attrSaveDeleteButtonContainer!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $closeAttrDetailButton!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $saveAndCloseButton!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $deleteButton!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $relatedNotesContainer!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $relatedNotesTitle!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $relatedNotesList!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $relatedNotesMoreNotes!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $attrHelp!: JQuery<HTMLElement>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private relatedNotesSpacedUpdate!: SpacedUpdate; | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |     private attribute!: Attribute; | 
					
						
							|  |  |  |     private allAttributes!: Attribute[]; | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |     private attrType!: ReturnType<AttributeDetailWidget["getAttrType"]>; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-17 20:58:34 +02:00
										 |  |  |     async refresh() { | 
					
						
							| 
									
										
										
										
											2020-09-05 21:51:00 +02:00
										 |  |  |         // switching note/tab should close the widget
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.hide(); | 
					
						
							| 
									
										
										
										
											2020-08-15 21:24:17 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  |     doRender() { | 
					
						
							| 
									
										
										
										
											2020-08-14 23:00:15 +02:00
										 |  |  |         this.relatedNotesSpacedUpdate = new SpacedUpdate(async () => this.updateRelatedNotes(), 1000); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  |         this.$widget = $(TPL); | 
					
						
							| 
									
										
										
										
											2020-09-01 22:47:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-01 00:17:15 +01:00
										 |  |  |         shortcutService.bindElShortcut(this.$widget, 'ctrl+return', () => this.saveAndClose()); | 
					
						
							|  |  |  |         shortcutService.bindElShortcut(this.$widget, 'esc', () => this.cancelAndClose()); | 
					
						
							| 
									
										
										
										
											2020-09-01 22:47:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-14 23:29:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-15 00:09:37 +02:00
										 |  |  |         this.$title = this.$widget.find('.attr-detail-title'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         this.$inputName = this.$widget.find('.attr-input-name'); | 
					
						
							| 
									
										
										
										
											2023-04-07 21:45:27 +02:00
										 |  |  |         this.$inputName.on('input', ev => { | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |             if (!(ev.originalEvent as KeyboardEvent)?.isComposing) { // https://github.com/zadam/trilium/pull/3812
 | 
					
						
							| 
									
										
										
										
											2023-04-07 21:45:27 +02:00
										 |  |  |                 this.userEditedAttribute(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2021-01-21 20:18:33 +01:00
										 |  |  |         this.$inputName.on('change', () => this.userEditedAttribute()); | 
					
						
							|  |  |  |         this.$inputName.on('autocomplete:closed', () => this.userEditedAttribute()); | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         this.$inputName.on('focus', () => { | 
					
						
							| 
									
										
										
										
											2020-07-26 00:04:34 +02:00
										 |  |  |             attributeAutocompleteService.initAttributeNameAutocomplete({ | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |                 $el: this.$inputName, | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |                 attributeType: () => ['relation', 'relation-definition'].includes(this.attrType || "") ? 'relation' : 'label', | 
					
						
							| 
									
										
										
										
											2020-07-26 00:04:34 +02:00
										 |  |  |                 open: true | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         this.$rowValue = this.$widget.find('.attr-row-value'); | 
					
						
							|  |  |  |         this.$inputValue = this.$widget.find('.attr-input-value'); | 
					
						
							| 
									
										
										
										
											2023-04-07 21:45:27 +02:00
										 |  |  |         this.$inputValue.on('input', ev => { | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |             if (!(ev.originalEvent as KeyboardEvent)?.isComposing) { // https://github.com/zadam/trilium/pull/3812
 | 
					
						
							| 
									
										
										
										
											2023-04-07 21:45:27 +02:00
										 |  |  |                 this.userEditedAttribute(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2021-02-13 12:11:58 +01:00
										 |  |  |         this.$inputValue.on('change', () => this.userEditedAttribute()); | 
					
						
							|  |  |  |         this.$inputValue.on('autocomplete:closed', () => this.userEditedAttribute()); | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         this.$inputValue.on('focus', () => { | 
					
						
							| 
									
										
										
										
											2020-07-26 00:04:34 +02:00
										 |  |  |             attributeAutocompleteService.initLabelValueAutocomplete({ | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |                 $el: this.$inputValue, | 
					
						
							| 
									
										
										
										
											2020-07-26 00:04:34 +02:00
										 |  |  |                 open: true, | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |                 nameCallback: () => String(this.$inputName.val()) | 
					
						
							| 
									
										
										
										
											2020-07-26 00:04:34 +02:00
										 |  |  |             }); | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         this.$rowPromoted = this.$widget.find('.attr-row-promoted'); | 
					
						
							|  |  |  |         this.$inputPromoted = this.$widget.find('.attr-input-promoted'); | 
					
						
							| 
									
										
										
										
											2020-08-14 23:00:15 +02:00
										 |  |  |         this.$inputPromoted.on('change', () => this.userEditedAttribute()); | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-22 04:58:06 -04:00
										 |  |  |         this.$rowPromotedAlias = this.$widget.find('.attr-row-promoted-alias'); | 
					
						
							|  |  |  |         this.$inputPromotedAlias = this.$widget.find('.attr-input-promoted-alias'); | 
					
						
							|  |  |  |         this.$inputPromotedAlias.on('change', () => this.userEditedAttribute()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         this.$rowMultiplicity = this.$widget.find('.attr-row-multiplicity'); | 
					
						
							|  |  |  |         this.$inputMultiplicity = this.$widget.find('.attr-input-multiplicity'); | 
					
						
							| 
									
										
										
										
											2020-08-14 23:00:15 +02:00
										 |  |  |         this.$inputMultiplicity.on('change', () => this.userEditedAttribute()); | 
					
						
							| 
									
										
										
										
											2020-07-13 00:15:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         this.$rowLabelType = this.$widget.find('.attr-row-label-type'); | 
					
						
							|  |  |  |         this.$inputLabelType = this.$widget.find('.attr-input-label-type'); | 
					
						
							| 
									
										
										
										
											2020-08-14 23:00:15 +02:00
										 |  |  |         this.$inputLabelType.on('change', () => this.userEditedAttribute()); | 
					
						
							| 
									
										
										
										
											2020-07-13 00:15:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         this.$rowNumberPrecision = this.$widget.find('.attr-row-number-precision'); | 
					
						
							|  |  |  |         this.$inputNumberPrecision = this.$widget.find('.attr-input-number-precision'); | 
					
						
							| 
									
										
										
										
											2020-08-14 23:00:15 +02:00
										 |  |  |         this.$inputNumberPrecision.on('change', () => this.userEditedAttribute()); | 
					
						
							| 
									
										
										
										
											2020-07-15 00:09:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         this.$rowInverseRelation = this.$widget.find('.attr-row-inverse-relation'); | 
					
						
							|  |  |  |         this.$inputInverseRelation = this.$widget.find('.attr-input-inverse-relation'); | 
					
						
							| 
									
										
										
										
											2023-04-07 21:45:27 +02:00
										 |  |  |         this.$inputInverseRelation.on('input', ev => { | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |             if (!(ev.originalEvent as KeyboardEvent)?.isComposing) { // https://github.com/zadam/trilium/pull/3812
 | 
					
						
							| 
									
										
										
										
											2023-04-07 21:45:27 +02:00
										 |  |  |                 this.userEditedAttribute(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2020-07-13 00:15:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         this.$rowTargetNote = this.$widget.find('.attr-row-target-note'); | 
					
						
							|  |  |  |         this.$inputTargetNote = this.$widget.find('.attr-input-target-note'); | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-03 18:42:03 +02:00
										 |  |  |         noteAutocompleteService.initNoteAutocomplete(this.$inputTargetNote, { allowCreatingNotes: true }) | 
					
						
							| 
									
										
										
										
											2020-09-21 22:08:54 +02:00
										 |  |  |             .on('autocomplete:noteselected', (event, suggestion, dataset) => { | 
					
						
							| 
									
										
										
										
											2020-07-13 00:15:00 +02:00
										 |  |  |                 if (!suggestion.notePath) { | 
					
						
							|  |  |  |                     return false; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-26 16:05:34 +01:00
										 |  |  |                 const pathChunks = suggestion.notePath.split('/'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 this.attribute.value = pathChunks[pathChunks.length - 1]; // noteId
 | 
					
						
							| 
									
										
										
										
											2020-07-13 00:15:00 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 this.triggerCommand('updateAttributeList', { attributes: this.allAttributes }); | 
					
						
							| 
									
										
										
										
											2020-08-14 23:00:15 +02:00
										 |  |  |                 this.updateRelatedNotes(); | 
					
						
							| 
									
										
										
										
											2020-07-13 00:15:00 +02:00
										 |  |  |             }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         this.$inputInheritable = this.$widget.find('.attr-input-inheritable'); | 
					
						
							| 
									
										
										
										
											2020-08-14 23:00:15 +02:00
										 |  |  |         this.$inputInheritable.on('change', () => this.userEditedAttribute()); | 
					
						
							| 
									
										
										
										
											2020-07-13 23:27:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-03 22:27:45 +02:00
										 |  |  |         this.$closeAttrDetailButton = this.$widget.find('.close-attr-detail-button'); | 
					
						
							| 
									
										
										
										
											2020-09-02 16:40:19 +02:00
										 |  |  |         this.$closeAttrDetailButton.on('click', () => this.cancelAndClose()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 23:53:55 +02:00
										 |  |  |         this.$attrIsOwnedBy = this.$widget.find('.attr-is-owned-by'); | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         this.$attrSaveDeleteButtonContainer = this.$widget.find('.attr-save-delete-button-container'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-23 00:19:50 +02:00
										 |  |  |         this.$saveAndCloseButton = this.$widget.find('.attr-save-changes-and-close-button'); | 
					
						
							| 
									
										
										
										
											2020-09-01 22:47:36 +02:00
										 |  |  |         this.$saveAndCloseButton.on('click', () => this.saveAndClose()); | 
					
						
							| 
									
										
										
										
											2020-07-23 00:19:50 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         this.$deleteButton = this.$widget.find('.attr-delete-button'); | 
					
						
							|  |  |  |         this.$deleteButton.on('click', async () => { | 
					
						
							|  |  |  |             await this.triggerCommand('updateAttributeList', { | 
					
						
							|  |  |  |                 attributes: this.allAttributes.filter(attr => attr !== this.attribute) | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             await this.triggerCommand('saveAttributes'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             this.hide(); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-23 23:38:05 +02:00
										 |  |  |         this.$attrHelp = this.$widget.find('.attr-help'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.$relatedNotesContainer = this.$widget.find('.related-notes-container'); | 
					
						
							|  |  |  |         this.$relatedNotesTitle = this.$relatedNotesContainer.find('.related-notes-tile'); | 
					
						
							|  |  |  |         this.$relatedNotesList = this.$relatedNotesContainer.find('.related-notes-list'); | 
					
						
							|  |  |  |         this.$relatedNotesMoreNotes = this.$relatedNotesContainer.find('.related-notes-more-notes'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-30 15:36:50 +02:00
										 |  |  |         $(window).on('mousedown', e => { | 
					
						
							| 
									
										
										
										
											2020-07-13 00:15:00 +02:00
										 |  |  |             if (!$(e.target).closest(this.$widget[0]).length | 
					
						
							| 
									
										
										
										
											2020-08-19 17:59:55 +02:00
										 |  |  |                 && !$(e.target).closest(".algolia-autocomplete").length | 
					
						
							|  |  |  |                 && !$(e.target).closest("#context-menu-container").length) { | 
					
						
							| 
									
										
										
										
											2020-07-03 22:27:45 +02:00
										 |  |  |                 this.hide(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |     async showAttributeDetail({ allAttributes, attribute, isOwned, x, y, focus }: AttributeDetailOpts) { | 
					
						
							| 
									
										
										
										
											2020-07-05 23:53:55 +02:00
										 |  |  |         if (!attribute) { | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  |             this.hide(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-08-17 23:54:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-04 23:35:10 +02:00
										 |  |  |         utils.saveFocusedElement(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |         this.attrType = this.getAttrType(attribute); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 23:00:15 +02:00
										 |  |  |         const attrName = | 
					
						
							|  |  |  |             this.attrType === 'label-definition' ? attribute.name.substr(6) | 
					
						
							|  |  |  |                 : (this.attrType === 'relation-definition' ? attribute.name.substr(9) : attribute.name); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |         const definition = this.attrType?.endsWith('-definition') | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |             ? promotedAttributeDefinitionParser.parse(attribute.value || "") | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |             : {}; | 
					
						
							| 
									
										
										
										
											2020-07-15 00:09:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |         if (this.attrType) { | 
					
						
							|  |  |  |             this.$title.text(ATTR_TITLES[this.attrType]); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-15 00:09:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-09 23:59:27 +02:00
										 |  |  |         this.allAttributes = allAttributes; | 
					
						
							|  |  |  |         this.attribute = attribute; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-15 21:24:17 +02:00
										 |  |  |         // can be slightly slower so just make it async
 | 
					
						
							|  |  |  |         this.updateRelatedNotes(); | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         this.$attrSaveDeleteButtonContainer.toggle(!!isOwned); | 
					
						
							| 
									
										
										
										
											2020-08-11 22:52:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 23:53:55 +02:00
										 |  |  |         if (isOwned) { | 
					
						
							|  |  |  |             this.$attrIsOwnedBy.hide(); | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |         } else if (attribute.noteId) { | 
					
						
							| 
									
										
										
										
											2020-07-05 23:53:55 +02:00
										 |  |  |             this.$attrIsOwnedBy | 
					
						
							|  |  |  |                 .show() | 
					
						
							| 
									
										
										
										
											2020-08-11 22:52:17 +02:00
										 |  |  |                 .empty() | 
					
						
							| 
									
										
										
										
											2020-07-05 23:53:55 +02:00
										 |  |  |                 .append(attribute.type === 'label' ? 'Label' : 'Relation') | 
					
						
							| 
									
										
										
										
											2024-07-26 17:00:28 +08:00
										 |  |  |                 .append(` ${t("attribute_detail.is_owned_by_note")} `) | 
					
						
							| 
									
										
										
										
											2023-05-29 00:19:54 +02:00
										 |  |  |                 .append(await linkService.createLink(attribute.noteId)) | 
					
						
							| 
									
										
										
										
											2020-07-05 23:53:55 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |         const disabledFn = (() => !isOwned ? "true" : undefined); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         this.$inputName | 
					
						
							| 
									
										
										
										
											2020-07-22 23:42:58 +02:00
										 |  |  |             .val(attrName) | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |             .attr('readonly', disabledFn); | 
					
						
							| 
									
										
										
										
											2020-07-13 00:15:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         this.$rowValue.toggle(this.attrType === 'label'); | 
					
						
							|  |  |  |         this.$rowTargetNote.toggle(this.attrType === 'relation'); | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |         this.$rowPromoted.toggle(['label-definition', 'relation-definition'].includes(this.attrType || "")); | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         this.$inputPromoted | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |             .prop("checked", !!definition.isPromoted) | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |             .attr('disabled', disabledFn); | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-22 04:58:06 -04:00
										 |  |  |         this.$rowPromotedAlias.toggle(!!definition.isPromoted); | 
					
						
							|  |  |  |         this.$inputPromotedAlias | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |             .val(definition.promotedAlias || "") | 
					
						
							|  |  |  |             .attr('disabled', disabledFn); | 
					
						
							| 
									
										
										
										
											2023-09-22 04:58:06 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |         this.$rowMultiplicity.toggle(['label-definition', 'relation-definition'].includes(this.attrType || "")); | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         this.$inputMultiplicity | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |             .val(definition.multiplicity || "") | 
					
						
							|  |  |  |             .attr('disabled', disabledFn); | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         this.$rowLabelType.toggle(this.attrType === 'label-definition'); | 
					
						
							|  |  |  |         this.$inputLabelType | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |             .val(definition.labelType || "") | 
					
						
							|  |  |  |             .attr('disabled', disabledFn); | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         this.$rowNumberPrecision.toggle(this.attrType === 'label-definition' && definition.labelType === 'number'); | 
					
						
							|  |  |  |         this.$inputNumberPrecision | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |             .val(definition.numberPrecision || "") | 
					
						
							|  |  |  |             .attr('disabled', disabledFn); | 
					
						
							| 
									
										
										
										
											2020-07-15 00:09:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         this.$rowInverseRelation.toggle(this.attrType === 'relation-definition'); | 
					
						
							|  |  |  |         this.$inputInverseRelation | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |             .val(definition.inverseRelation || "") | 
					
						
							|  |  |  |             .attr('disabled', disabledFn); | 
					
						
							| 
									
										
										
										
											2020-07-05 23:53:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-13 00:15:00 +02:00
										 |  |  |         if (attribute.type === 'label') { | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |             this.$inputValue | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |                 .val(attribute.value || "") | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |                 .attr('readonly', disabledFn); | 
					
						
							| 
									
										
										
										
											2020-07-13 00:15:00 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         else if (attribute.type === 'relation') { | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |             this.$inputTargetNote | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |                 .attr('readonly', disabledFn) | 
					
						
							| 
									
										
										
										
											2020-09-04 23:35:10 +02:00
										 |  |  |                 .val("") | 
					
						
							|  |  |  |                 .setSelectedNotePath(""); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (attribute.value) { | 
					
						
							| 
									
										
										
										
											2021-04-16 22:57:37 +02:00
										 |  |  |                 const targetNote = await froca.getNote(attribute.value); | 
					
						
							| 
									
										
										
										
											2020-09-04 23:35:10 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 if (targetNote) { | 
					
						
							|  |  |  |                     this.$inputTargetNote | 
					
						
							|  |  |  |                         .val(targetNote ? targetNote.title : "") | 
					
						
							|  |  |  |                         .setSelectedNotePath(attribute.value); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-07-13 00:15:00 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         this.$inputInheritable | 
					
						
							| 
									
										
										
										
											2020-07-14 23:29:37 +02:00
										 |  |  |             .prop("checked", !!attribute.isInheritable) | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |             .attr('disabled', disabledFn); | 
					
						
							| 
									
										
										
										
											2020-07-14 23:29:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-23 23:38:05 +02:00
										 |  |  |         this.updateHelp(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-14 23:29:37 +02:00
										 |  |  |         this.toggleInt(true); | 
					
						
							| 
									
										
										
										
											2020-07-13 23:27:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |         const offset = this.parent?.$widget.offset() || { top: 0, left: 0 }; | 
					
						
							| 
									
										
										
										
											2020-09-02 16:06:35 +02:00
										 |  |  |         const detPosition = this.getDetailPosition(x, offset); | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |         const outerHeight = this.$widget.outerHeight(); | 
					
						
							|  |  |  |         const height = $(window).height(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (detPosition && outerHeight && height) { | 
					
						
							|  |  |  |             this.$widget | 
					
						
							|  |  |  |                 .css("left", detPosition.left) | 
					
						
							|  |  |  |                 .css("right", detPosition.right) | 
					
						
							|  |  |  |                 .css("top", y - offset.top + 70) | 
					
						
							|  |  |  |                 .css("max-height", | 
					
						
							|  |  |  |                     outerHeight + y > height - 50 | 
					
						
							|  |  |  |                         ? height - y - 50 | 
					
						
							|  |  |  |                         : 10000); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-08-28 15:38:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 16:06:35 +02:00
										 |  |  |         if (focus === 'name') { | 
					
						
							|  |  |  |             this.$inputName | 
					
						
							|  |  |  |                 .trigger('focus') | 
					
						
							|  |  |  |                 .trigger('select'); | 
					
						
							| 
									
										
										
										
											2020-08-28 15:38:04 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-09-02 16:06:35 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-28 15:38:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |     getDetailPosition(x: number, offset: { left: number }) { | 
					
						
							|  |  |  |         const outerWidth = this.$widget.outerWidth(); | 
					
						
							|  |  |  |         if (!outerWidth) { | 
					
						
							|  |  |  |             return null; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         let left: number | string = x - offset.left - outerWidth / 2; | 
					
						
							|  |  |  |         let right: number | string = ""; | 
					
						
							| 
									
										
										
										
											2020-07-26 00:09:53 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 16:06:35 +02:00
										 |  |  |         if (left < 0) { | 
					
						
							|  |  |  |             left = 10; | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |             const rightEdge = left + outerWidth; | 
					
						
							| 
									
										
										
										
											2020-09-01 22:47:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |             if (rightEdge > outerWidth - 10) { | 
					
						
							| 
									
										
										
										
											2020-09-02 16:06:35 +02:00
										 |  |  |                 left = ""; | 
					
						
							|  |  |  |                 right = 10; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-09-01 22:47:36 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-09-02 16:06:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-03 18:42:03 +02:00
										 |  |  |         return { left, right }; | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-04 23:35:10 +02:00
										 |  |  |     async saveAndClose() { | 
					
						
							|  |  |  |         await this.triggerCommand('saveAttributes'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.hide(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         utils.focusSavedElement(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async cancelAndClose() { | 
					
						
							|  |  |  |         await this.triggerCommand('reloadAttributes'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.hide(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         utils.focusSavedElement(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     userEditedAttribute() { | 
					
						
							|  |  |  |         this.updateAttributeInEditor(); | 
					
						
							|  |  |  |         this.updateHelp(); | 
					
						
							|  |  |  |         this.relatedNotesSpacedUpdate.scheduleUpdate(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     updateHelp() { | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |         const attrName = String(this.$inputName.val()); | 
					
						
							| 
									
										
										
										
											2020-09-04 23:35:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |         if (this.attrType && this.attrType in ATTR_HELP && | 
					
						
							|  |  |  |             attrName && attrName in ATTR_HELP[this.attrType]) { | 
					
						
							| 
									
										
										
										
											2020-09-04 23:35:10 +02:00
										 |  |  |             this.$attrHelp | 
					
						
							|  |  |  |                 .empty() | 
					
						
							|  |  |  |                 .append($("<td colspan=2>") | 
					
						
							|  |  |  |                     .append($("<strong>").text(attrName)) | 
					
						
							|  |  |  |                     .append(" - ") | 
					
						
							|  |  |  |                     .append(ATTR_HELP[this.attrType][attrName]) | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |                 .show(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             this.$attrHelp.empty().hide(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 23:00:15 +02:00
										 |  |  |     async updateRelatedNotes() { | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |         let { results, count } = await server.post<SearchRelatedResponse>('search-related', this.attribute); | 
					
						
							| 
									
										
										
										
											2020-08-14 23:00:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for (const res of results) { | 
					
						
							|  |  |  |             res.noteId = res.notePathArray[res.notePathArray.length - 1]; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-03 18:42:03 +02:00
										 |  |  |         results = results.filter(({ noteId }) => noteId !== this.noteId); | 
					
						
							| 
									
										
										
										
											2020-08-14 23:00:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (results.length === 0) { | 
					
						
							|  |  |  |             this.$relatedNotesContainer.hide(); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             this.$relatedNotesContainer.show(); | 
					
						
							| 
									
										
										
										
											2024-09-03 18:42:03 +02:00
										 |  |  |             this.$relatedNotesTitle.text(t("attribute_detail.other_notes_with_name", { attributeType: this.attribute.type, attributeName: this.attribute.name })); | 
					
						
							| 
									
										
										
										
											2020-08-14 23:00:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             this.$relatedNotesList.empty(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             const displayedResults = results.length <= DISPLAYED_NOTES ? results : results.slice(0, DISPLAYED_NOTES); | 
					
						
							| 
									
										
										
										
											2021-04-16 22:57:37 +02:00
										 |  |  |             const displayedNotes = await froca.getNotes(displayedResults.map(res => res.noteId)); | 
					
						
							| 
									
										
										
										
											2023-04-15 00:06:13 +02:00
										 |  |  |             const hoistedNoteId = appContext.tabManager.getActiveContext()?.hoistedNoteId; | 
					
						
							| 
									
										
										
										
											2020-08-14 23:00:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             for (const note of displayedNotes) { | 
					
						
							| 
									
										
										
										
											2023-04-15 00:06:13 +02:00
										 |  |  |                 const notePath = note.getBestNotePathString(hoistedNoteId); | 
					
						
							| 
									
										
										
										
											2024-09-03 18:42:03 +02:00
										 |  |  |                 const $noteLink = await linkService.createLink(notePath, { showNotePath: true }); | 
					
						
							| 
									
										
										
										
											2020-08-14 23:00:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 this.$relatedNotesList.append( | 
					
						
							|  |  |  |                     $("<li>").append($noteLink) | 
					
						
							|  |  |  |                 ); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (results.length > DISPLAYED_NOTES) { | 
					
						
							| 
									
										
										
										
											2024-09-03 18:42:03 +02:00
										 |  |  |                 this.$relatedNotesMoreNotes.show().text(t("attribute_detail.and_more", { count: count - DISPLAYED_NOTES })); | 
					
						
							| 
									
										
										
										
											2020-08-14 23:00:15 +02:00
										 |  |  |             } else { | 
					
						
							|  |  |  |                 this.$relatedNotesMoreNotes.hide(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |     getAttrType(attribute: Attribute) { | 
					
						
							| 
									
										
										
										
											2020-07-15 00:09:37 +02:00
										 |  |  |         if (attribute.type === 'label') { | 
					
						
							|  |  |  |             if (attribute.name.startsWith('label:')) { | 
					
						
							|  |  |  |                 return "label-definition"; | 
					
						
							|  |  |  |             } else if (attribute.name.startsWith('relation:')) { | 
					
						
							|  |  |  |                 return "relation-definition"; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 return "label"; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else if (attribute.type === 'relation') { | 
					
						
							|  |  |  |             return "relation"; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             this.$title.text(''); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-22 23:58:01 +02:00
										 |  |  |     updateAttributeInEditor() { | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |         let attrName = String(this.$inputName.val()); | 
					
						
							| 
									
										
										
										
											2020-07-22 23:42:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 23:22:14 +01:00
										 |  |  |         if (!utils.isValidAttributeName(attrName)) { | 
					
						
							| 
									
										
										
										
											2020-08-17 23:54:18 +02:00
										 |  |  |             // invalid characters are simply ignored (from user perspective they are not even entered)
 | 
					
						
							| 
									
										
										
										
											2021-02-17 23:22:14 +01:00
										 |  |  |             attrName = utils.filterAttributeName(attrName); | 
					
						
							| 
									
										
										
										
											2020-08-17 23:54:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             this.$inputName.val(attrName); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-22 23:42:58 +02:00
										 |  |  |         if (this.attrType === 'label-definition') { | 
					
						
							| 
									
										
										
										
											2022-12-21 15:19:05 +01:00
										 |  |  |             attrName = `label:${attrName}`; | 
					
						
							| 
									
										
										
										
											2020-07-22 23:42:58 +02:00
										 |  |  |         } else if (this.attrType === 'relation-definition') { | 
					
						
							| 
									
										
										
										
											2022-12-21 15:19:05 +01:00
										 |  |  |             attrName = `relation:${attrName}`; | 
					
						
							| 
									
										
										
										
											2020-07-22 23:42:58 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.attribute.name = attrName; | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         this.attribute.isInheritable = this.$inputInheritable.is(":checked"); | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |         if (this.attrType?.endsWith('-definition')) { | 
					
						
							| 
									
										
										
										
											2020-07-22 23:58:01 +02:00
										 |  |  |             this.attribute.value = this.buildDefinitionValue(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-08-12 23:39:05 +02:00
										 |  |  |         else if (this.attrType === 'relation') { | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |             this.attribute.value = this.$inputTargetNote.getSelectedNoteId() || ""; | 
					
						
							| 
									
										
										
										
											2020-08-12 23:39:05 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-22 23:58:01 +02:00
										 |  |  |         else { | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |             this.attribute.value = String(this.$inputValue.val()); | 
					
						
							| 
									
										
										
										
											2020-07-22 23:58:01 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |         this.triggerCommand('updateAttributeList', { attributes: this.allAttributes }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-22 23:58:01 +02:00
										 |  |  |     buildDefinitionValue() { | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |         const props = []; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         if (this.$inputPromoted.is(":checked")) { | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |             props.push("promoted"); | 
					
						
							| 
									
										
										
										
											2023-09-22 04:58:06 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if (this.$inputPromotedAlias.val() !== '') { | 
					
						
							|  |  |  |                 props.push(`alias=${this.$inputPromotedAlias.val()}`); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         props.push(this.$inputMultiplicity.val()); | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (this.attrType === 'label-definition') { | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |             props.push(this.$inputLabelType.val()); | 
					
						
							| 
									
										
										
										
											2020-07-23 00:19:50 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |             if (this.$inputLabelType.val() === 'number' && this.$inputNumberPrecision.val() !== '') { | 
					
						
							| 
									
										
										
										
											2022-12-21 15:19:05 +01:00
										 |  |  |                 props.push(`precision=${this.$inputNumberPrecision.val()}`); | 
					
						
							| 
									
										
										
										
											2020-07-23 00:19:50 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |         } else if (this.attrType === 'relation-definition' && String(this.$inputInverseRelation.val())?.trim().length > 0) { | 
					
						
							| 
									
										
										
										
											2021-10-27 22:13:54 +02:00
										 |  |  |             const inverseRelationName = this.$inputInverseRelation.val(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |             props.push(`inverse=${utils.filterAttributeName(String(inverseRelationName))}`); | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |         this.$rowNumberPrecision.toggle( | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |             this.attrType === 'label-definition' | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  |             && this.$inputLabelType.val() === 'number'); | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-22 04:58:06 -04:00
										 |  |  |         this.$rowPromotedAlias.toggle(this.$inputPromoted.is(":checked")); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-22 23:58:01 +02:00
										 |  |  |         return props.join(","); | 
					
						
							| 
									
										
										
										
											2020-07-09 23:59:27 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  |     hide() { | 
					
						
							|  |  |  |         this.toggleInt(false); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 16:22:10 +02:00
										 |  |  |     createLink(noteId: string) { | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  |         return $("<a>", { | 
					
						
							| 
									
										
										
										
											2023-05-07 21:18:21 +02:00
										 |  |  |             href: `#root/${noteId}`, | 
					
						
							|  |  |  |             class: 'reference-link' | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  |         }); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-13 23:23:57 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     async noteSwitched() { | 
					
						
							|  |  |  |         this.hide(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-06-26 22:17:39 +02:00
										 |  |  | } |