diff --git a/src/public/javascripts/services/attributes.js b/src/public/javascripts/services/attributes.js index d1ba1cc04..07c796a40 100644 --- a/src/public/javascripts/services/attributes.js +++ b/src/public/javascripts/services/attributes.js @@ -26,9 +26,9 @@ async function getAttributes() { async function showAttributes() { $promotedAttributesContainer.empty(); - $attributeList.hide(); + $attributeList.hide().empty(); - const noteId = noteDetailService.getCurrentNoteId(); + const note = noteDetailService.getCurrentNote(); const attributes = await attributePromise; @@ -37,168 +37,6 @@ async function showAttributes() { && !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 = $("").addClass("multiplicity"); - - $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 = $("