import server from "./server.js"; import utils from "./utils.js"; import messagingService from "./messaging.js"; import treeUtils from "./tree_utils.js"; import noteAutocompleteService from "./note_autocomplete.js"; import treeService from "./tree.js"; import linkService from "./link.js"; import infoService from "./info.js"; import noteDetailService from "./note_detail.js"; const $attributeList = $("#attribute-list"); const $attributeListInner = $("#attribute-list-inner"); const $promotedAttributesContainer = $("#note-detail-promoted-attributes"); let attributePromise; async function refreshAttributes() { attributePromise = server.get('notes/' + noteDetailService.getCurrentNoteId() + '/attributes'); await showAttributes(); } async function getAttributes() { return await attributePromise; } async function showAttributes() { $promotedAttributesContainer.empty(); $attributeList.hide(); const noteId = noteDetailService.getCurrentNoteId(); const attributes = await attributePromise; const promoted = attributes.filter(attr => (attr.type === 'label-definition' || attr.type === 'relation-definition') && !attr.name.startsWith("child:") && attr.value.isPromoted); let idx = 1; async function createRow(definitionAttr, valueAttr) { const definition = definitionAttr.value; const inputId = "promoted-input-" + idx; const $tr = $(""); const $labelCell = $("").append(valueAttr.name); const $input = $("") .prop("id", inputId) .prop("tabindex", definitionAttr.position) .prop("attribute-id", valueAttr.isOwned ? valueAttr.attributeId : '') // if not owned, we'll force creation of a new attribute instead of updating the inherited one .prop("attribute-type", valueAttr.type) .prop("attribute-name", valueAttr.name) .prop("value", valueAttr.value) .addClass("form-control") .addClass("promoted-attribute-input") .change(promotedAttributeChanged); idx++; const $inputCell = $("").append($("
").addClass("input-group").append($input)); const $actionCell = $(""); const $multiplicityCell = $(""); $tr .append($labelCell) .append($inputCell) .append($actionCell) .append($multiplicityCell); if (valueAttr.type === 'label') { if (definition.labelType === 'text') { $input.prop("type", "text"); // no need to await for this, can be done asynchronously server.get('attributes/values/' + encodeURIComponent(valueAttr.name)).then(attributeValues => { if (attributeValues.length === 0) { return; } attributeValues = attributeValues.map(attribute => { return { value: attribute }; }); $input.autocomplete({ appendTo: document.querySelector('body'), hint: false, autoselect: true, openOnFocus: true, minLength: 0 }, [{ displayKey: 'value', source: function (term, cb) { term = term.toLowerCase(); const filtered = attributeValues.filter(attr => attr.value.toLowerCase().includes(term)); cb(filtered); } }]); }); } else if (definition.labelType === 'number') { $input.prop("type", "number"); } else if (definition.labelType === 'boolean') { $input.prop("type", "checkbox"); if (valueAttr.value === "true") { $input.prop("checked", "checked"); } } else if (definition.labelType === 'date') { $input.prop("type", "date"); const $todayButton = $("