-
Notifications
You must be signed in to change notification settings - Fork 0
/
ppr.js
71 lines (60 loc) · 2.19 KB
/
ppr.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
var PPR = PPR || {};
window.KnackInit = function($) {
'use strict';
/*
Page "scene_93": Program Program Attendance form and table
========================================================
Views
-----
- view_154: Weekly Program Attendance form
Fields
------
- field_151: Number of Registered Participants
- field_150: Number of Unique Participants
- field_152: Number of Spectators
- field_148: Attendance Week
*/
$(document).on('knack-page-render.scene_234', function(event, page) {
PPR.attendanceForm = PPR.attendanceForm || {};
var numericFields = [
'#field_151',
'#field_150',
'#field_152'
];
var $attendanceWeekField = $('#view_426-field_148');
var today, monday, daysSinceMonday;
/**********************************
/* Only allow Mondays to be selected
/***********************************/
$attendanceWeekField.datepicker('option', {
beforeShowDay: function (date) {
//console.debug(date);
return [date.getDay() == 1, ''];
}
});
// If this is not the first time the form has been submitted, use the last
// selected value for the date.
if (PPR.attendanceForm.lastDate) {
$attendanceWeekField.val(PPR.attendanceForm.lastDate);
}
// If this is the first time the form has been loaded, use the Monday
// immediately preceding today.
else {
today = new Date();
monday = new Date(today);
daysSinceMonday = today.getDay() - 1; // 0 is Sunday, 1 is Monday
daysSinceMonday = (daysSinceMonday + 7) % 7; // Correct for negatives
daysSinceMonday = daysSinceMonday || 7; // Correct to last Monday if today is Monday
monday.setDate(today.getDate() - daysSinceMonday - 7);
$attendanceWeekField.val((monday.getMonth() + 1) + '/' + monday.getDate() + '/' + monday.getFullYear());
}
// Remember the attendance form date whenever it changes.
$attendanceWeekField.on('change', function() {
PPR.attendanceForm.lastDate = $attendanceWeekField.val();
});
// Verify that numeric fields have a number in them
$(numericFields.join(',')).each(function(i, el) {
$(el).attr('pattern', '[0-9]*');
});
});
};