Skip to content

Commit

Permalink
allow subfields to move up or down (#729)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronhelton authored Oct 10, 2022
1 parent 4510e29 commit 5eed26f
Showing 1 changed file with 51 additions and 3 deletions.
54 changes: 51 additions & 3 deletions dlx_rest/static/js/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 5eed26f

Please sign in to comment.