Difference between revisions of "MoveFile"

From TempusServa wiki
Jump to navigation Jump to search
(Created page with "== 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.<syntaxhighlight lang="javascript"> let moveFile = (id) => { const params = new URLSearchParams(window.location.search) $.ajax({ url: "main", method: "GET", data: { "command": "dk.tempusserva.codeunit.common.MoveFile", "SagID": params.get("SagID")...")
 
(Changed to multi-move version)
 
Line 5: Line 5:


== How to invoke ==
== How to invoke ==
Add the following snippet to the entity scripts.<syntaxhighlight lang="javascript">
Add the following snippet to the entity scripts. This enables movement between all document-fields on the entity.
let moveFile = (id) => {
 
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.<syntaxhighlight lang="javascript">
const moveFile = (id, to) => {
const params = new URLSearchParams(window.location.search)
const params = new URLSearchParams(window.location.search)
$.ajax({
$.ajax({
Line 16: Line 18:
"DataID": params.get("DataID"),
"DataID": params.get("DataID"),
"FileID": id.split("_")[2],
"FileID": id.split("_")[2],
"FieldFrom": [FROM-FIELD-ID],
"FieldFrom": id.split("_")[1],
"FieldTo": [TO-FIELD-ID],
"FieldTo": to,
},
},
success: (data) => {
success: (data) => {
Line 30: Line 32:


$(() => {
$(() => {
$("#VB_DATA_[FROM-FIELD-NAME] .tableFiles thead tr").append("<th></th>")
const moveFileAction = () => {
$("#VB_DATA_[FROM-FIELD-NAME] .tableFiles tbody").find("tr").each((i,e) => {
    console.log("yay")
$(e).append(`<td><a href="#" class="moveFile">Move</a></td>`)
    moveFile($("#modeFileFrom").val(), $("#moveFileTo").val())
})
    $("#moveFilePopup").remove()
$(".moveFile").on("click", (e) => {
}
moveFile($(e.currentTarget).parent().parent().attr("id"))
$(() => {
})
    $(".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")
    })
})
})
})
</syntaxhighlight>Remember to change the three values:
</syntaxhighlight>
 
* [FROM-FIELD-NAME]
* [FROM-FIELD-ID]
* [TO-FIELD-ID]
 
== Configuration ==
== Configuration ==
None
None

Latest revision as of 13:16, 22 July 2022

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