From 5eed26f1d317e39cede49bfb502b07f25861e1db Mon Sep 17 00:00:00 2001 From: Aaron Helton Date: Mon, 10 Oct 2022 08:07:40 -0400 Subject: [PATCH] allow subfields to move up or down (#729) --- dlx_rest/static/js/record.js | 54 ++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/dlx_rest/static/js/record.js b/dlx_rest/static/js/record.js index bc8b83dc..21e0ec30 100644 --- a/dlx_rest/static/js/record.js +++ b/dlx_rest/static/js/record.js @@ -593,13 +593,43 @@ export let multiplemarcrecordcomponent = { newSubfield.codeSpan.focus(); newSubfield.valueCell.classList.add("unsaved"); - saveButton.classList.add("text-danger"); - saveButton.classList.remove("text-primary"); - saveButton.title = "unsaved changes"; + this.checkSavedState(jmarc); + + jmarc.addUndoredoEntry("from Delete SubField"); + this.callChangeStyling(`${field.tag}$${subfield.code} has been added`, "d-flex w-100 alert-success") return newSubfield } }, + moveSubfield(jmarc, direction=1) { + let field = jmarc.getDataFields().filter(x => x.selected)[0]; + let dirText = "down" + if (direction < 0) { + dirText = "up" + } + let subfield = field.subfields.filter(x => x.selected)[0]; + + let fromPlace = field.subfields.indexOf(subfield) + let toPlace = fromPlace + direction + + if (toPlace < 0 || toPlace >= field.subfields.length) { + this.callChangeStyling(`Can't move first subfield up or last subfield down.`, "d-flex w-100 alert-warning") + return + } + + field.subfields.splice(toPlace, 0, field.subfields.splice(fromPlace, 1)[0]) + + this.removeRecordFromEditor(jmarc); + this.displayMarcRecord(jmarc); + + subfield.valueCell.classList.add("unsaved"); + + this.checkSavedState(jmarc); + jmarc.addUndoredoEntry("from Move SubField"); + this.callChangeStyling(`${field.tag}$${subfield.code} ${subfield.value} has been moved ${dirText}`, "d-flex w-100 alert-success") + + return + }, addField(jmarc, newField=null, rowIndex=null) { let currentField = jmarc.getDataFields().filter(x => x.selected)[0]; @@ -2425,6 +2455,16 @@ export let multiplemarcrecordcomponent = { codeMenu.append(deleteSubfield); deleteSubfield.className = "dropdown-item"; deleteSubfield.innerText = "Delete subfield"; + + let moveSubfieldUp = document.createElement("i") + codeMenu.append(moveSubfieldUp) + moveSubfieldUp.className = "dropdown-item" + moveSubfieldUp.innerText = "Move subfield up" + + let moveSubfieldDown = document.createElement("i") + codeMenu.append(moveSubfieldDown) + moveSubfieldDown.className = "dropdown-item" + moveSubfieldDown.innerText = "Move subfield down" // Subfield value let valCell = subfield.row.insertCell(); @@ -2469,6 +2509,14 @@ export let multiplemarcrecordcomponent = { }); + moveSubfieldUp.addEventListener("click", () => { + component.moveSubfield(jmarc, -1) + }) + + moveSubfieldDown.addEventListener("click", () => { + component.moveSubfield(jmarc, 1) + }) + // Subfield code actions function subfieldCodeActivate() { component.clearSelectedSubfield(jmarc);