-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
148 lines (119 loc) · 3.33 KB
/
app.js
File metadata and controls
148 lines (119 loc) · 3.33 KB
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
var app = angular.module('weddingApp', ['ngAnimate']);
app.filter('trustedHTML',
function($sce) {
return $sce.trustAsHtml;
}
);
app.controller('bodyController', function($scope, $http) {
//
// init
//
$scope.scratch = {
activeTab: 'infoTab',
};
$http.get('data.json').then(
function(payload) {
$scope.tabs = payload.data.tabs;
},
function(errorPayload) {
console.error("Could not load application data!" + errorPayload);
}
);
//
// app methods
//
$scope.setActiveTab = function(tabId) {
$scope.scratch.activeTab = tabId;
};
$scope.showHide = function(e) {
var element = document.getElementById(e);
if (element.classList.contains('hidden')) {
element.classList.remove('hidden')
element.classList.add('visible');
} else {
element.classList.add('hidden');
element.classList.remove('visible')
};
};
//
// misc. helpers / general-use methods
//
$scope.range = function(r) {
return Array.apply(null, Array(r)).map(function (_, i) {return i;});
};
});
app.controller('formController', function($scope, $http) {
// this is the RSVP form. it's a multi-step form whose steps are
// determined by the 'rsvp_form_sheet' divs in html/RSVPtab.html
//
// init
//
$scope.scratch = {
currentSheet: 0,
sheets: document.getElementsByClassName("rsvp_form_sheet"),
submitDisabled: false
};
$scope.guestList = [];
// app methods
$scope.showSheet = function(n) {
for (var i = 0; i < $scope.scratch.sheets.length; i++) {
if (i === n) {
$scope.scratch.sheets[i].classList.add('visible');
$scope.scratch.sheets[i].classList.remove('hidden');
} else {
$scope.scratch.sheets[i].classList.remove('visible');
$scope.scratch.sheets[i].classList.add('hidden');
};
};
$scope.scratch.currentSheet = n;
};
$scope.addGuest = function() {
var guestId = $scope.guestList.length;
var newGuest = {
id: guestId,
name: null,
type: 'adult',
meal: 'chicken',
};
$scope.guestList.push(newGuest);
};
$scope.rmGuest = function(guestIndex) {
$scope.guestList.splice(guestIndex,1);
};
$scope.validateRSVP = function() {
// misc. user-proofing on the form
$scope.scratch.submitDisabled = false;
for (var i = 0; i < $scope.guestList.length; i++) {
var guest = $scope.guestList[i];
if (guest.type === 'under 12' && guest.meal === 'vegetarian') {
guest.meal = null;
};
if (guest.meal === null) {$scope.scratch.submitDisabled = true};
if (guest.name === null) {$scope.scratch.submitDisabled = true};
if (guest.name === '') {$scope.scratch.submitDisabled = true};
};
};
$scope.submitSheet = function() {
var postObj = {}
postObj['meta'] = {
'confirmation_email': $scope.scratch.confirmationEmail,
'user_agent': navigator.userAgent
};
postObj['guests'] = $scope.guestList;
$http.post('/mail.py', postObj).then(
function(payload) {
//console.info(payload.data);
$scope.setActiveTab('infoTab');
$scope.showHide('rsvpSuccessModal');
for (var i = 0; i < $scope.tabs.length; i++) {
if ($scope.tabs[i]['id'] === 'RSVPtab') {
$scope.tabs.splice(i,1);
}
};
},
function(errorPayload) {
console.error("Could not submit guest list!" + errorPayload);
}
);
};
});