Skip to content
This repository has been archived by the owner on Nov 2, 2019. It is now read-only.

Added checks for email in returned record #37

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 46 additions & 10 deletions app/js/controllers/entry-ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ angular
$scope.needEmail = false;
$scope.allEntered = false;

$scope.checking = false;

$scope.findPersonNumber = function(number) {
if (number.indexOf('=') > -1) {
number = 'N' + number.substring(2, number.indexOf('='));
Expand All @@ -45,9 +47,14 @@ angular

$scope.findPersonEmail = function(email) {
$scope.allEntered = true;
if ($scope.person.attributes.name) {
updatePerson(null, email, checkEmail);
return;
}
personExists('people?filter[simple][contact.email]=' + email, function() {
$scope.person.attributes.name = $scope.dirty.name
createAccount($scope.dirty.name, $scope.dirty.email, $scope.dirty.nNumber).then(function(data) {
$scope.checking = true;
$scope.person = data[0];
rsvpPerson($scope.person.id);
});
Expand All @@ -58,22 +65,40 @@ angular
Restangular.one(url)
.get()
.then(function(data) {
var person;
if (data.length > 0) {
$scope.person = data[0]
person = data[0];
}
if (data.attributes) {
person = data;
}

if (person) {
$scope.person = person
var p;
if ($scope.person.attributes.nNumber != $scope.dirty.Number) {
p = updatePerson($scope.dirty.nNumber)
if ($scope.dirty.nNumber && $scope.person.attributes.nNumber != $scope.dirty.nNumber) {
p = updatePerson($scope.dirty.nNumber, "", checkEmail);
}
else {
checkEmail($scope.person);
}
$q.when(p, function() {
rsvpPerson($scope.person.id);
});
}
else {
elseCallback()
}
});
}

function checkEmail(person) {
if (person.attributes.contact && person.attributes.contact.email && person.attributes.contact.email !== '') {
$scope.checking = true;
rsvpPerson(person.id)
}
else {
$scope.needEmail = true;
}
}

function rsvpPerson(id) {
// Add to checkin
var eventData = [];
Expand All @@ -93,19 +118,29 @@ angular
}

//updates the person's nNumber record
function updatePerson(number) {
function updatePerson(number, email, callback) {
var personData = {
type: "people",
id: $scope.person.id,
attributes: {}
attributes: {
}
}

if (email !== "") {
personData.attributes = {
'contact.email':email
};
}

if (number !== "") {
personData.attributes.nNumber = number;
}

return Restangular.one('people/' + $scope.person.id)
.patch(personData);
.patch(personData)
.then(function(data) {
callback(data);
});
}

function createAccount(name, email, number) {
Expand Down Expand Up @@ -169,7 +204,8 @@ angular
suggest: suggestState,
on_select: function(selected) {
$scope.person.attributes.name = selected.label;
rsvpPerson(selected.value);
$scope.dirty.value = selected.label;
personExists('people/' + selected.value);
}
};

Expand Down
4 changes: 2 additions & 2 deletions app/partials/entry.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ <h2>Welcome! Can I have your name?</h2>
<div ng-if="needEmail">
<h2>...and your email?</h2>
<form name="email" ng-submit="findPersonEmail(dirty.email)">
<input class="button flatButton" type="text" ng-model="dirty.email" ng-disabled="person.attributes.name || allEntered" />
<input class="button flatButton" type="text" ng-model="dirty.email" ng-disabled="allEntered" />
</form>
</div>
<div ng-if="person.attributes.name">
<div ng-if="checking && person.attributes.name">
<h2>Hello {{person.attributes.name}}!</h2>
<p ng-show="rsvpd">You have been successfully signed in!</p>
<p ng-hide="rsvpd">Checking you in now...</p>
Expand Down