-
Notifications
You must be signed in to change notification settings - Fork 0
/
perch_forms_response_view_button.js
33 lines (26 loc) · 1.47 KB
/
perch_forms_response_view_button.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var pageUrl = window.location.href;
if(pageUrl.includes('addons/apps/perch_forms/responses')) {
var deleteBtns = document.querySelectorAll('.main-panel table .button.button-small.action-alert');
var perchPath = '/perch';
var detailURL = perchPath + '/addons/apps/perch_forms/responses/detail/';
if(deleteBtns.length > 0) {
deleteBtns.forEach(element => {
// get ID from delete button
var responseID = element.dataset.id;
var parent = element.closest('td');
parent.insertAdjacentHTML('beforebegin', '<td><a class="button button-small action-info" href="' + detailURL + '?id='+ responseID +'">View Response</a></td>');
});
} else {
// if delete btn doesn't exist (e.g. user has no permission to delete)
var responses = document.querySelectorAll('.main-panel table td[data-label="Response"]');
responses.forEach(element => {
// get ID from link
var responseIdHTML = element.querySelector('a').innerHTML;
var responseID = responseIdHTML.replace('# ','');
var parent = element.closest('tr');
parent.insertAdjacentHTML('beforeend', '<td><a class="button button-small action-info" href="' + detailURL + '?id='+ responseID +'">View Response</a></td>');
});
}
var thead = document.querySelector('.main-panel table thead tr');
thead.insertAdjacentHTML('beforeend', '<th class="action"></th>');
}