Skip to content

Instantly share code, notes, and snippets.

@jking6884
Created June 13, 2016 12:54
Show Gist options
  • Save jking6884/11dbe92b23410b0c55e43cf145f87782 to your computer and use it in GitHub Desktop.
Save jking6884/11dbe92b23410b0c55e43cf145f87782 to your computer and use it in GitHub Desktop.
allAttendingDetailsValid: Ember.computed('parents','students', function(){
var self = this;
var parents = this.get('parents');
var students = this.get('students');
var validationFields;
var passedValidation = true;
parents.forEach((parent) => {
if(parent.get('groupRequestHasUsers').get('length') > 0){
validationFields = ['city', 'zip', 'state', 'gender', 'firstName', 'lastName', 'dob', 'primaryPhoneNumber'];
validationFields.forEach(function (item) {
if (passedValidation) {
if (Ember.isEmpty(parent.get(item))) {
passedValidation = false;
}
}
});
}
});
students.forEach((student) => {
validationFields = ['gender','firstName','lastName','dob'];
validationFields.forEach(function (item) {
if (passedValidation) {
if (Ember.isEmpty(student.get(item))) {
passedValidation = false;
}
}
});
});
return passedValidation;
}),
allAttendingConsentsAreValid: Ember.computed('parents', 'students', function(){
var self = this;
var parents = this.get('parents');
var students = this.get('students');
var subItems = [];
parents.forEach((parent) => {
if(parent.get('groupRequestHasUsers').get('length') > 0){
var promise = this.store.query('user-has-contract', {user_id: parent.get('id'), with: 'all'}).then(function (data) {
var that = self;
var contractExists = false;
data.forEach((userContract) => {
if (userContract.get('contract.code') === 'Consent') {
contractExists = true;
}
});
return contractExists;
});
subItems.push(promise);
}
});
students.forEach((student) => {
var promise = this.store.query('user-has-contract', {user_id: student.get('id'), with: 'all'}).then(function (data) {
var that = self;
var contractExists = false;
data.forEach(function (userContract) {
if (userContract.get('contract.code') === 'Consent') {
contractExists = true;
}
});
return contractExists;
});
subItems.push(promise);
});
return Ember.RSVP.all(subItems).then((results) => {
var rtn = true;
results.forEach((result) => {
if(!result){
rtn = false;
}
});
return rtn;
});
}),
checkConsent: Ember.computed('allAttendingConsentsAreValid', function(k, v){
if(arguments.length > 1) return v;
var self = this;
var promises = [];
var cPromise = this.get('allAttendingConsentsAreValid').then(function(result){
return result;
});
promises.push(cPromise);
return Ember.RSVP.all(promises).then((results) => {
var rtn = true;
results.forEach((result) => {
if(!result){
rtn = false;
}
});
self.set('checkConsent', rtn);
});
}),
allAttendingInsuranceValid: Ember.computed('parents', 'students', function(){
var self = this;
var parents = this.get('parents');
var students = this.get('students');
var subItems = [];
parents.forEach((parent) => {
if(parent.get('groupRequestHasUsers').get('length') > 0){
var promise = this.store.query('user-has-file', {user_id: parent.get('id'), with: 'all'}).then(function (data) {
var that = self;
var insuranceExists = false;
data.forEach((userFile) => {
if (userFile.get('file').get('code') === 'Insurance') {
insuranceExists = true;
}
});
return insuranceExists;
});
subItems.push(promise);
}
});
students.forEach((student) => {
var promise = this.store.query('user-has-file', {user_id: student.get('id'), with: 'all'}).then(function (data) {
var that = self;
var insuranceExists = false;
data.forEach(function (userFile) {
if (userFile.get('file').get('code') === 'Insurance') {
insuranceExists = true;
}
});
return insuranceExists;
});
subItems.push(promise);
});
return Ember.RSVP.all(subItems).then((results) => {
var rtn = true;
results.forEach((result) => {
if(!result){
rtn = false;
}
});
return rtn;
});
}),
checkInsurance: Ember.computed('allAttendingInsuranceValid', function(k, v){
if(arguments.length > 1) return v;
var self = this;
var promises = [];
var iPromise = this.get('allAttendingInsuranceValid').then(function(result){
return result;
});
promises.push(iPromise);
return Ember.RSVP.all(promises).then((results) => {
var rtn = true;
results.forEach((result) => {
if(!result){
rtn = false;
}
});
self.set('checkInsurance', rtn);
});
})
{{#unless isValid}}
<div class="callout callout-danger">
<h4>Required Actions Remaining to Complete Registration:</h4>
{{#unless emergencyContactsAreValid}}
<p>- At Least 1 Emergency Contact is Required</p>
{{/unless}}
{{#unless checkConsent}}
<p>- Consent Forms for at least 1 Attendee is Pending</p>
{{/unless}}
{{#unless checkInsurance}}
<p>- Insurance Card for at least 1 Attendee is Pending</p>
{{/unless}}
{{#unless allAttendingDetailsValid}}
<p>- Information per Attendee under the Edit Section needs completed</p>
{{/unless}}
</div>
{{/unless}}
{{#if isValid}}
<div class="callout callout-success">
<h4>All actions have been completed.</h4>
</div>
{{/if}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment