-
Notifications
You must be signed in to change notification settings - Fork 17
/
frsl.js
157 lines (137 loc) · 5.13 KB
/
frsl.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
document.addEventListener('DOMContentLoaded', function() {
var $links;
switch (formRenderSkipLogic.location) {
case 'data_entry_form':
overrideNextFormButtonsRedirect();
$links = $('.formMenuList a');
break;
case 'record_home':
$links = $('#event_grid_table a');
break;
case 'record_status_dashboard':
$links = $('#record_status_table a');
break;
}
if (typeof $links === 'undefined' || $links.length === 0) {
return false;
}
$links.each(function() {
if (this.href != "javascript:;" &&
this.href.indexOf(app_path_webroot + 'DataEntry/index.php?') === -1) {
return;
}
var params = getQueryParameters(this.href,this.getAttribute('onclick'));
try {
if (!formRenderSkipLogic.formsAccess[params.id][params.event_id][params.page]) {
disableForm(this);
}
} catch (err) {
if (this.firstChild.getAttribute('title') === 'Delete this event') {
// on record home the final row is "delete all data on event" buttons and should not be processed
return;
}
}
});
/**
* Overrides next form buttons to redirect to the next available step.
*/
function overrideNextFormButtonsRedirect() {
// Handling "Save & Go to Next Form" button.
if (formRenderSkipLogic.nextStepPath) {
formRenderSkipLogic.saveNextForm = function() {
appendHiddenInputToForm('save-and-redirect', formRenderSkipLogic.nextStepPath);
dataEntrySubmit('submit-btn-savecontinue');
return false;
}
// Overriding submit callback.
$('[id="submit-btn-savenextform"]').attr('onclick', 'formRenderSkipLogic.saveNextForm()');
}
else {
removeButtons('savenextform');
}
// Handling "Ignore and go to next form" button on required fields
// dialog.
$('#reqPopup').on('dialogopen', function(event, ui) {
var buttons = $(this).dialog('option', 'buttons');
$.each(buttons, function(i, button) {
if (button.name !== 'Ignore and go to next form') {
return;
}
if (formRenderSkipLogic.nextStepPath) {
buttons[i] = function() {
window.location.href = formRenderSkipLogic.nextStepPath;
};
}
else {
delete buttons[i];
}
return false;
});
$(this).dialog('option', 'buttons', buttons);
});
}
/**
* Disables a link to a form.
*/
function disableForm(cell) {
cell.style.pointerEvents = 'none';
cell.style.opacity = '.1';
}
/**
* Returns the query string of the given url string.
*/
function getQueryString(url) {
url = decodeURI(url);
return url.match(/\?.+/)[0];
}
/**
* Returns a set of key-value pairs that correspond to the query
* parameters in the given url. When handling repeating instruments
* (i.e. the url points to js) the onclick call is picked apart
* and returned as the parameters.
*/
function getQueryParameters(url, click) {
if (url == "javascript:;") {
var tmp = click.replace(/ |'|\);/g,'').split(',')
var parameters = {id: tmp[1], event_id: tmp[2], page: tmp[3]}
}
else {
var parameters = {};
var queryString = getQueryString(url);
var reg = /([^?&=]+)=?([^&]*)/g;
var keyValuePair;
while (keyValuePair = reg.exec(queryString)) {
parameters[keyValuePair[1]] = keyValuePair[2];
}
}
return parameters;
}
/**
* Removes the given submit buttons set.
*/
function removeButtons(buttonName) {
var $buttons = $('button[name="submit-btn-' + buttonName + '"]');
// Check if buttons are outside the dropdown menu.
if ($buttons.length !== 0) {
$.each($buttons, function(index, button) {
// Get first button in dropdown-menu.
var replacement = $(button).siblings('.dropdown-menu').find('a')[0];
// Modify button to behave like $replacement.
button.id = replacement.id;
button.name = replacement.name;
button.onclick = replacement.onclick;
button.innerHTML = replacement.innerHTML;
// Get rid of replacement.
$(replacement).remove();
});
}
else {
// Disable button inside the dropdown menu.
// Obs.: yes, this is a weird selector - "#" prefix is not being
// used - but this approach is needed on this page because there
// are multiple DOM elements with the same ID - which is
// totally wrong.
$('a[id="submit-btn-' + buttonName + '"]').hide();
}
}
});