Last active
June 9, 2016 14:19
-
-
Save jking6884/0b9064bae17c944e02bf2ab2086040e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
isValid: Ember.computed('emergencyContactsAreAvlid', 'allAttendingConsentsAreValid', function(){ | |
var promises = []; | |
var ePromise = this.get('emergencyContactsAreValid'); | |
promises.push(ePromise); | |
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; | |
} | |
}); | |
return false; | |
}); | |
}), | |
emergencyContactsAreValid: Ember.computed('parents.@each.emergencyContact', function(){ | |
var parents = this.get('parents'); | |
var count = 0; | |
parents.forEach((parent) => { | |
if(parent.get('emergencyContact')){ | |
count++; | |
} | |
}); | |
if(count > 2){ | |
return true; | |
} else { | |
return false; | |
} | |
}), | |
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; | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment