-
Notifications
You must be signed in to change notification settings - Fork 0
/
activity-alter.js
36 lines (33 loc) · 1.17 KB
/
activity-alter.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
/**
* This function will be executed after the activity is loaded
* and perform all the changes necessary
*/
CRM.$(function() {
// Inspect the current Subject field.
var origSubject = CRM.$('form#Activity input[name="subject"][type="text"]');
if (origSubject.length ==0) {
// Oh, it's no there.
return;
}
var eligibility = origSubject.val();
if (eligibility == '') {
// New activities need a default.
eligibility = 'Eligible';
}
else if (!eligibility.match(/^(Ine|E)ligible$/)) {
// Hmmm. This activity does not have a valid subject.
// Let's leave it as it is and ask the user to fix it. Who knows, maybe
// they have some greater wisdom...
alert("This declaration won't work - the subject must be simply Eligible or Ineligible. Please correct this.");
return;
}
// Replace the Subject text input with a Select.
origSubject.after(
CRM.$('<select id="subject" name="subject">'
+ '<option value="Eligible">Eligible for Gift Aid</option>'
+ '<option value="Ineligible">Ineligible for Gift Aid</option>'
+ '</select>'
).val(eligibility)
).remove();
CRM.$('label[for="subject"]').text("Declaration");
});