Skip to content

Commit

Permalink
rates
Browse files Browse the repository at this point in the history
  • Loading branch information
miclip committed Sep 23, 2015
1 parent 4a711f0 commit f2a9043
Show file tree
Hide file tree
Showing 33 changed files with 595 additions and 37 deletions.
81 changes: 79 additions & 2 deletions app/controllers/dashboard/clients/add.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,81 @@
import Ember from 'ember';
import FacilityBase from './base';

export default Ember.Controller.extend({
export default FacilityBase.extend({
userIsTrainer: true,
userIdTrainerSet: false,
actions:{
save:function(model){
var self = this;
model.set('countryCode','US');
self.validate().then(function(){
model.save().then(function(){
var uid = self.get('session').get('currentUser').get('id');
// save the address
self.store.findRecord('address',model.get('address').get('id')).then((address)=>{
address.set('parentId',model.get('id'));
address.save();
// update user and save

self.store.findRecord('user',uid).then((user)=>{
user.get('clients').pushObject(model);
user.get('addresses').pushObject(address);
user.save();
});
});

// update organization and save
self.store.findRecord('organization',model.get('organizationId')).then((org)=>{
org.get('clients').pushObject(model);
org.save();

model.get('invite').then((invite)=>{
console.log("inviteEmail:"+invite.get('email'));
if(invite.get('email')){
invite.set('parentId',model.id);
invite.set('organization',org);
invite.set('name',model.get('name'));
invite.save();

//TODO Send Invite Email

invite.set('emailSent', true);
invite.set('emailSentDate', new Date());
invite.save();

self.notifications.addNotification({
message: 'Invite Email Sent!',
type: 'success',
autoClear: true,
});


} else {
model.get('invite').then((invite)=>{
invite.destroyRecord();
});
}
});


});

self.set('addSuccess', true);
self.notifications.addNotification({
message: 'Client successfully added!',
type: 'success',
autoClear: true,
});



self.transitionToRoute('dashboard.clients.index');
}).catch(function(err){
console.log("errors:"+err);
});
}).catch(function(){
console.log('unepxected validation errors');
self.set('hasValidationErrors',true);
});
},
}
});
35 changes: 35 additions & 0 deletions app/controllers/dashboard/clients/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Ember from 'ember';
import EmberValidations from 'ember-validations';

export default Ember.Controller.extend(EmberValidations, {
validationModel: Ember.computed.alias('model'),
validationModelAddress: Ember.computed.alias('model.address'),
hasValidationErrors: false,
addSuccess: false,
userOrganizations: null,
validations: {
'validationModel.name': {
presence: {message: " Name is required"},
},
'validationModel.organizationId':{
presence: {message: " Must select an organization"},
},
'validationModelAddress.name':{
presence: {message: " Address name is required"},
},
'validationModelAddress.line1':{
presence: {message: " Line 1 is required"},
},
'validationModelAddress.city':{
presence: {message: " City is required"},
},
'validationModelAddress.state':{
presence: {message: " State is required"},
},
'validationModelAddress.postCode':{
presence: {message: " Zip is required"},
}

},

});
77 changes: 74 additions & 3 deletions app/controllers/dashboard/clients/edit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,75 @@
import Ember from 'ember';
import FacilityBase from './base';

export default Ember.Controller.extend({
});
export default FacilityBase.extend({
actions:{
save:function(model){
var self = this;
model.set('countryCode','US');
self.validate().then(function(){
model.save().then(function(){
// save the address
self.store.findRecord('address',model.get('address').get('id')).then((address)=>{
address.save();
});

var changed = model.changedAttributes();

self.store.findRecord('organization',model.get('organizationId')).then((org)=>{

if(changed['organizationId']){
// update previous organization and save
self.store.findRecord('organization',changed['organizationId'][0]).then((previousOrg)=>{
previousOrg.get('clients').removeObject(model);
previousOrg.save();
});

org.get('clients').pushObject(model);
org.save();
}

model.get('invite').then((invite)=>{

if(invite.get('email')){
invite.set('parentId',model.id);
invite.set('organization',org);
invite.set('name',model.get('name'));
invite.save();

//TODO Send Invite Email

if(invite.get('emailSent')===false)
{
invite.set('emailSent', true);
invite.set('emailSentDate', new Date());
invite.save();

self.notifications.addNotification({
message: 'Invite Email Sent!',
type: 'success',
autoClear: true,
});
}
} else {
model.get('invite').then((invite)=>{
invite.destroyRecord();
});
}
});

self.notifications.addNotification({
message: 'Client successfully saved!',
type: 'success',
autoClear: true,
});
});
self.transitionToRoute('dashboard.clients.index');
}).catch(function(err){
console.log("errors:"+err);
});
}).catch(function(){
console.log('unepxected validation errors');
self.set('hasValidationErrors',true);
});
},
}
});
30 changes: 30 additions & 0 deletions app/controllers/dashboard/rates.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
import Ember from 'ember';

export default Ember.Controller.extend({
actions:{
delete:function(model){
var self = this;
var organizationId = model.get('organizationId');
model.destroyRecord().then(function(){
var uid = self.get('session').get('currentUser').get('id');
self.store.findRecord('user',uid).then((user)=>{
user.get('rates').removeObject(model);
user.save();
});

self.get('store').findRecord('organization',organizationId).then((organization)=>{
organization.get('rates').removeObject(model);
organization.save();
});

self.notifications.addNotification({
message: 'Rate successfully deleted!',
type: 'warning',
autoClear: true,
});

}).catch(function(err){
// TODO
console.log("errors:"+err);
});


},
}
});
39 changes: 39 additions & 0 deletions app/controllers/dashboard/rates/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import FacilityBase from './base';

export default FacilityBase.extend({
actions:{
save:function(model){
var self = this;

self.validate().then(function(){
model.save().then(function(){
var uid = self.get('session').get('currentUser').get('id');
// save the address
self.store.findRecord('user',uid).then((user)=>{
user.get('rates').pushObject(model);
user.save();
});

// update organization and save
self.store.findRecord('organization',model.get('organizationId')).then((org)=>{
org.get('rates').pushObject(model);
org.save();
});

self.set('addSuccess', true);
self.notifications.addNotification({
message: 'Rate successfully added!',
type: 'success',
autoClear: true,
});
self.transitionToRoute('dashboard.rates.index');
}).catch(function(err){
console.log("errors:"+err);
});
}).catch(function(){
console.log('unepxected validation errors');
self.set('hasValidationErrors',true);
});
},
}
});
23 changes: 23 additions & 0 deletions app/controllers/dashboard/rates/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Ember from 'ember';
import EmberValidations from 'ember-validations';

export default Ember.Controller.extend(EmberValidations, {
validationModel: Ember.computed.alias('model'),
hasValidationErrors: false,
addSuccess: false,
userOrganizations: null,
validations: {
'validationModel.name': {
presence: {message: " Name is required"},
},
'validationModel.rate': {
presence: {message: " Rate is required"},
},
'validationModel.organizationId':{
presence: {message: " Must select an organization"},
},


},

});
File renamed without changes.
22 changes: 13 additions & 9 deletions app/controllers/dashboard/trainers/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,19 @@ actions:{

//TODO Send Invite Email

invite.set('emailSent', true);
invite.set('emailSentDate', new Date());
invite.save();

self.notifications.addNotification({
message: 'Invite Email Sent!',
type: 'success',
autoClear: true,
});
if(invite.get('emailSent')===false)
{
invite.set('emailSent', true);
invite.set('emailSentDate', new Date());
invite.save();

self.notifications.addNotification({
message: 'Invite Email Sent!',
type: 'success',
autoClear: true,
});
}

} else {
model.get('invite').then((invite)=>{
invite.destroyRecord();
Expand Down
1 change: 1 addition & 0 deletions app/models/organization.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export default DS.Model.extend({
facilities: DS.hasMany('facility', {async : true}),
trainers: DS.hasMany('trainer', {async : true}),
clients: DS.hasMany('client', {async : true}),
rates: DS.hasMany('rate', {async : true}),
});
13 changes: 13 additions & 0 deletions app/models/package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import DS from 'ember-data';

export default DS.Model.extend({
name: DS.attr('string'),
rate: DS.belongsTo('rate',{async:true}),
discount: DS.attr('number'),
organizationId: DS.attr('string'),
numberOfSessions : DS.attr('number'),
owner: DS.attr('string'),
createdDate: DS.attr('date', {
defaultValue() { return new Date(); }
}),
});
12 changes: 12 additions & 0 deletions app/models/rate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import DS from 'ember-data';

export default DS.Model.extend({
name: DS.attr('string'),
rate: DS.attr('number'),
organizationId: DS.attr('string'),
image: DS.attr('string'),
owner: DS.attr('string'),
createdDate: DS.attr('date', {
defaultValue() { return new Date(); }
}),
});
17 changes: 17 additions & 0 deletions app/models/session.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import DS from 'ember-data';

export default DS.Model.extend({
name: DS.attr('string'),
rate: DS.belongsTo('rate',{async:true}),
package: DS.belongsTo('package',{async:true}),
sessionDate: DS.attr('date'),
organizationId: DS.attr('string'),
trainer: DS.belongsTo('trainer', {async:true}),
client: DS.belongsTo('client', {async:true}),
facility: DS.belongsTo('facility', {async:true}),
location: DS.attr('string'),
owner: DS.attr('string'),
createdDate: DS.attr('date', {
defaultValue() { return new Date(); }
}),
});
2 changes: 1 addition & 1 deletion app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export default DS.Model.extend({
addresses: DS.hasMany('address', {async : true}),
trainers: DS.hasMany('trainer', {async : true}),
clients: DS.hasMany('client', {async : true}),

rates: DS.hasMany('rate', {async : true}),

});
Loading

0 comments on commit f2a9043

Please sign in to comment.