MoveFile
Jump to navigation
Jump to search
What it does
Moves a file from one document-field to another, on the same entity.
Works between document-fields with and without signing.
How to invoke
Add the following snippet to the entity scripts. This enables movement between all document-fields on the entity.
It adds another column to the file-lists, with a "Move" link. When clicked it opens a popup, with a dropdown where the new field can be selected.
const moveFile = (id, to) => {
const params = new URLSearchParams(window.location.search)
$.ajax({
url: "main",
method: "GET",
data: {
"command": "dk.tempusserva.codeunit.common.MoveFile",
"SagID": params.get("SagID"),
"DataID": params.get("DataID"),
"FileID": id.split("_")[2],
"FieldFrom": id.split("_")[1],
"FieldTo": to,
},
success: (data) => {
if (data == "File moved") {
$(`#${id}`).find("td").last().html("Moved")
} else {
alert(data)
}
},
})
}
$(() => {
const moveFileAction = () => {
console.log("yay")
moveFile($("#modeFileFrom").val(), $("#moveFileTo").val())
$("#moveFilePopup").remove()
}
$(() => {
$(".tableFiles").each((i,e) => {
let t = $(e)
t.find("thead").find("tr").each((i,e) => { $(e).append("<th></th>") })
t.find("tbody").find("tr").each((i,e) => { $(e).append(`<td><a href="#" class="moveFile">Move</a></td>`) })
})
$(".moveFile").on("click", (e) => {
e.preventDefault()
let t = $(e.currentTarget)
let id = t.parent().parent().attr("id")
let r = `<select class="form-control" id="moveFileTo">`
r += `<option value="">Select a field</option>`;
$(".uploadFiles").each((i,e) => {
let p = $(e).parent().attr("id").replace("VB_DATA_", "")
if (id.split("_")[1] != p) {
let x = $(e).parent().parent().parent().find(`#NB_DATA_${p}`).html()
r += `<option value="${p}">${x}</option>`
}
})
r += "</select>"
$("#TempusServaPage").append(`
<div id="moveFilePopup" style="display: none;">
<label>Move file to:</label>
${r}
<input type="hidden" id="modeFileFrom" value="${id}"/>
<a href="javascript:moveFileAction();" class="moveFileAction">Move</a>
</div>
`)
createJqueryDialog("moveFilePopup")
})
})
})
Configuration
None
Developer info
- Type: CodeunitPagecontent (raw)
- Security: Requires session