Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#704 add copy to clipboard button in application view #708

Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/EditableField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</span>
<a
href="#"
class="govuk-link change-link"
class="govuk-link change-link print-none"
@click.prevent="btnClickEdit()"
>
{{ link }}
Expand Down
42 changes: 39 additions & 3 deletions src/views/Exercises/Applications/Application.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@
>
Download As Doc
</button>

<button
id="clipboard-button"
class="govuk-button govuk-button--secondary"
@click="copyToClipboard"
>
Copy to clipboard
</button>
<span
v-if="activeTab == 'full'"
class=" govuk-!-margin-left-4"
Expand Down Expand Up @@ -98,7 +104,7 @@
</h2>
</div>
</div>
</div>
</div>

<TabsList
class="print-none"
Expand All @@ -117,7 +123,7 @@
>
<h2 class="govuk-heading-l">
Personal details
<span class="govuk-hint">
<span class="govuk-hint print-none">
Any changes made here will also update the candidate information.
</span>
</h2>
Expand Down Expand Up @@ -1864,6 +1870,35 @@ export default {

pdf.save(`${fileName}.pdf`);
},
removePrintNone(htmlCollection) {
const result = [];
if (!htmlCollection.classList.contains('print-none')) {
if (htmlCollection.children.length){
Array.from(htmlCollection.children).forEach(element => {
result.push(this.removePrintNone(element));
});
}
result.push(htmlCollection.innerText);
}
return result;
},
copyToClipboard() {
tomlovesgithub marked this conversation as resolved.
Show resolved Hide resolved
const htmlCollection = (document.querySelector('#panel-pack-div'));
const virtualDiv = document.createElement('div');
virtualDiv.innerHTML = htmlCollection.innerHTML;
const printNoneEls = virtualDiv.querySelectorAll('.print-none');
printNoneEls.forEach(e => e.remove());
const el = document.createElement('textarea');
el.value = virtualDiv.textContent.split(' ').join('\n');
document.body.appendChild(el);
el.select();
document.execCommand('copy');
YaaL marked this conversation as resolved.
Show resolved Hide resolved
document.body.removeChild(el);
document.querySelector('#clipboard-button').innerText = 'Copied';
setTimeout(() => {
document.querySelector('#clipboard-button').innerText = 'Copy to clipboard';
},3000);
},
downloadAsDoc() {
const fileName = this.generateFilename;
const content = document.querySelector('#panel-pack-div').outerHTML;
Expand Down Expand Up @@ -1912,4 +1947,5 @@ export default {
width: auto;
}
}

</style>