Drag and drop functionality in NAV/BC
AlexeyShamin
Member Posts: 80
Hi all
We have developed a function Drag&Drop on NAV standard fuctionality. You can find the code below:
1. On a page on the field choose attribute Control addin - WebPageViewer
2. This Control addin allows to display websites through the function SetContent. This function could have 2 parameters - HTML Code and Script on JavaScript language
3. HTML page code (PageTxt variable):
4. this is input field for our files. When we drop files here page call function handleFiles on JS Script:
In function handleDrop we call window.parent.WebPageViewerHelper.TriggerCallback – the callback trigger in NAV and send filename, delimiter ($$) and file as Base64 text to the NAV
6. In NAV on trigger ControlAddInReady we call
7. On Callback(data : Text) trigger we put code to procced “data” variable (file on Base64) in nav got from our page.
Now we have Drag&Drop
We have developed a function Drag&Drop on NAV standard fuctionality. You can find the code below:
1. On a page on the field choose attribute Control addin - WebPageViewer
2. This Control addin allows to display websites through the function SetContent. This function could have 2 parameters - HTML Code and Script on JavaScript language
3. HTML page code (PageTxt variable):
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
#drop-area {
border: 2px dashed #ccc;
border-radius: 20px;
font-family: sans-serif;
margin: 10px auto;
padding: 20px;
}
#drop-area.highlight {
border-color: purple;
opacity: 1;
}
p {
margin-top: 0;
text-align: center;
}
.my-form {
margin-bottom: 10px;
}
#fileElem {
display: none;
}
</style>
</head>
<body>
<div id="drop-area">
<form class="my-form">
<p>Drag Image Here</p>
<input type="file" id="fileElem" multiple accept="image/*" onchange="handleFiles(this.files)">
</form>
</div>
4. this is input field for our files. When we drop files here page call function handleFiles on JS Script:
<input type="file" id="fileElem" multiple accept="image/*" onchange="handleFiles(this.files)">5. Script (ScriptTxt variable):
let dropArea = document.getElementById(''drop-area'');
dropArea.addEventListener(''dragenter'', highlight, false);
dropArea.addEventListener(''dragover'', highlight, false);
dropArea.addEventListener(''dragleave'', unhighlight, false);
dropArea.addEventListener(''drop'', unhighlight, false);
dropArea.addEventListener(''dragenter'', preventDefaults, false);
dropArea.addEventListener(''dragover'', preventDefaults, false);
dropArea.addEventListener(''dragleave'', preventDefaults, false);
dropArea.addEventListener(''drop'', preventDefaults, false);
function preventDefaults (e) {
e.preventDefault();
e.stopPropagation();
};
function highlight(e) {
dropArea.classList.add(''highlight'')
};
function unhighlight(e) {
dropArea.classList.remove(''highlight'')
};
dropArea.addEventListener(''drop'', handleDrop, false);
function handleDrop(e) {
let file = e.dataTransfer.files[0];
reader = new FileReader();
reader.onload = function (event) {
window.parent.WebPageViewerHelper.TriggerCallback(file.name + ''$$'' + event.target.result.split('','')[1])
};
reader.readAsDataURL(file);
}
In function handleDrop we call window.parent.WebPageViewerHelper.TriggerCallback – the callback trigger in NAV and send filename, delimiter ($$) and file as Base64 text to the NAV
6. In NAV on trigger ControlAddInReady we call
CurrPage.PictureViewer.SetContent(PageTxt, scriptTxt)and send our HTML and Script to the WebPageViewer AddIn
7. On Callback(data : Text) trigger we put code to procced “data” variable (file on Base64) in nav got from our page.
Now we have Drag&Drop
2
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 323 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions