promoted relation attributes now work correctly, refactoring of note autocomplete code

This commit is contained in:
azivner
2018-08-06 22:29:03 +02:00
parent c568ef2f8a
commit 90e9297ec5
6 changed files with 80 additions and 52 deletions

View File

@@ -16,6 +16,7 @@ import noteDetailFile from './note_detail_file.js';
import noteDetailSearch from './note_detail_search.js';
import noteDetailRender from './note_detail_render.js';
import bundleService from "./bundle.js";
import noteAutocompleteService from "./note_autocomplete.js";
const $noteTitle = $("#note-title");
@@ -250,7 +251,7 @@ async function loadAttributes() {
.addClass("form-control")
.addClass("promoted-attribute-input");
const $inputCell = $("<td>").append($input);
const $inputCell = $("<td>").append($("<div>").addClass("input-group").append($input));
const $actionCell = $("<td>");
const $multiplicityCell = $("<td>");
@@ -295,6 +296,17 @@ async function loadAttributes() {
messagingService.logError("Unknown labelType=" + definitionAttr.labelType);
}
}
else if (valueAttr.type === 'relation') {
if (valueAttr.value) {
$input.val((await treeUtils.getNoteTitle(valueAttr.value) + " (" + valueAttr.value + ")"));
}
await noteAutocompleteService.initNoteAutocomplete($input);
}
else {
messagingService.logError("Unknown attribute type=" + valueAttr.type);
return;
}
if (definition.multiplicityType === "multivalue") {
const addButton = $("<span>")
@@ -455,6 +467,11 @@ $promotedAttributesContainer.on('change', '.promoted-attribute-input', async eve
if ($attr.prop("type") === "checkbox") {
value = $attr.is(':checked') ? "true" : "false";
}
else if ($attr.prop("attribute-type") === "relation") {
if ($attr.val()) {
value = treeUtils.getNoteIdFromNotePath(linkService.getNotePathFromLabel($attr.val()));
}
}
else {
value = $attr.val();
}