This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7453611
commit 7d961ec
Showing
10 changed files
with
187 additions
and
112 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import Ember from 'ember'; | ||
import AbstractEditController from 'hospitalrun/controllers/abstract-edit-controller'; | ||
|
||
const { | ||
computed, | ||
computed: { | ||
alias | ||
}, | ||
get, | ||
inject, | ||
set | ||
} = Ember; | ||
|
||
export default AbstractEditController.extend({ | ||
i18n: inject.service(), | ||
editController: alias('model.editController'), | ||
newAllergy: false, | ||
|
||
additionalButtons: computed('model.isNew', function() { | ||
let model = get(this, 'model'); | ||
let btn = get(this, 'i18n').t('buttons.delete'); | ||
let isNew = get(model, 'isNew'); | ||
if (!isNew) { | ||
return [{ | ||
class: 'btn btn-default warning', | ||
buttonAction: 'deleteAllergy', | ||
buttonIcon: 'octicon octicon-x', | ||
buttonText: btn | ||
}]; | ||
} | ||
}), | ||
|
||
title: Ember.computed('model', function() { | ||
let model = get(this, 'model'); | ||
let i18n = get(this, 'i18n'); | ||
let isNew = get(model, 'isNew'); | ||
if (!isNew) { | ||
return i18n.t('allergies.titles.editAllergy'); | ||
} else { | ||
return i18n.t('allergies.titles.addAllergy'); | ||
} | ||
}), | ||
|
||
beforeUpdate() { | ||
let allergy = get(this, 'model'); | ||
set(this, 'newAllergy', get(allergy, 'isNew')); | ||
return Ember.RSVP.Promise.resolve(); | ||
}, | ||
|
||
afterUpdate(allergy) { | ||
let newAllergy = get(this, 'newAllergy'); | ||
if (newAllergy) { | ||
get(this, 'editController').send('addAllergy', allergy); | ||
set(this, 'name', ''); | ||
} else { | ||
this.send('closeModal'); | ||
} | ||
}, | ||
|
||
actions: { | ||
cancel() { | ||
this.send('closeModal'); | ||
}, | ||
|
||
deleteAllergy() { | ||
let allergy = get(this, 'model'); | ||
get(this, 'editController').send('deleteAllergy', allergy); | ||
} | ||
} | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{{#modal-dialog | ||
title=title | ||
updateButtonText=updateButtonText | ||
hideCancelButton=true | ||
isUpdateDisabled=isUpdateDisabled | ||
updateButtonAction=updateButtonAction | ||
additionalButtons=additionalButtons | ||
}} | ||
|
||
{{#em-form model=model submitButton=false }} | ||
<div class="row"> | ||
{{em-input class="col-xs-12 form-group required test-allergy" label=(t 'allergies.labels.allergyName') property="name"}} | ||
</div> | ||
{{/em-form}} | ||
|
||
{{/modal-dialog}} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import Ember from 'ember'; | ||
|
||
const { | ||
get, | ||
set | ||
} = Ember; | ||
|
||
export default Ember.Mixin.create({ | ||
openAllergyModal(allergy) { | ||
set(allergy, 'editController', this); | ||
this.send('openModal', 'allergy.edit', allergy); | ||
}, | ||
|
||
savePatientAllergy(patient, allergy) { | ||
get(patient, 'allergies').pushObject(allergy); | ||
patient.save().then(() => { | ||
this.silentUpdate('closeModal'); | ||
}); | ||
}, | ||
|
||
deletePatientAllergy(patient, allergy) { | ||
let patientAllergies = get(patient, 'allergies'); | ||
allergy.destroyRecord().then(() => { | ||
patientAllergies.removeObject(allergy); | ||
patient.save().then(() => { | ||
this.send('closeModal'); | ||
}); | ||
}); | ||
}, | ||
|
||
actions: { | ||
editAllergy(allergy) { | ||
this.openAllergyModal(allergy); | ||
}, | ||
|
||
showAddAllergy() { | ||
let newAllergy = get(this, 'store').createRecord('allergy'); | ||
this.openAllergyModal(newAllergy); | ||
} | ||
} | ||
}); |
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
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
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
Oops, something went wrong.