Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
New component for operative plan and operation report
Browse files Browse the repository at this point in the history
Component to add/maintain multiple procedures
  • Loading branch information
jkleinsc committed Jan 13, 2017
1 parent cc99061 commit 5d05bfc
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
44 changes: 44 additions & 0 deletions app/components/operative-procedures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Ember from 'ember';

const {
computed,
isEmpty,
get,
set
} = Ember;

export function addProcedure(model) {
let procedures = get(model, 'procedures');
let description = get(model, 'procedureDescription');
if (!isEmpty(description)) {
procedures.addObject({
description
});
set(model, 'procedureDescription', null);
}
}

export default Ember.Component.extend({
model: null,
procedureList: null,
haveProcedures: computed('model.procedures.[]', {
get() {
return !isEmpty(get(this, 'model.procedures'));
}
}),

actions: {
addProcedure() {
let model = get(this, 'model');
addProcedure(model);
},

deleteProcedure(procedureToDelete) {
let model = get(this, 'model');
let procedures = get(model, 'procedures');
procedures.removeObject(procedureToDelete);
model.validate();
}
}

});
35 changes: 35 additions & 0 deletions app/templates/components/operative-procedures.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<div class="row">
{{select-or-typeahead
className=(concat (if (not-eq haveProcedures true) 'required ') 'procedure-description col-sm-10')
property="procedureDescription"
label=(t 'components.operativeProcedures.labels.procedure') list=procedureList
selection=procedureDescription hint=false
}}
<div class="col-sm-2">
<label class="control-label">&nbsp;</label>
<p class=" form-control-static">
<button class="btn btn-primary" {{action 'addProcedure'}}>
<span class="octicon octicon-plus"></span> {{t 'components.operativeProcedures.buttons.addProcedure'}}
</button>
</p>
</div>
</div>
{{#if haveProcedures}}
<h4>{{t 'components.operativeProcedures.titles.procedures'}}</h4>
<table class="table">
<tr class="table-header">
<th>{{t 'components.operativeProcedures.labels.procedure'}}</th>
<th>{{t 'labels.action'}}</th>
</tr>
{{#each model.procedures as |procedure|}}
<tr>
<td>{{procedure.description}}</td>
<td>
<button type="button" class="btn btn-default warning" {{action "deleteProcedure" procedure bubbles=false }}>
<span class="octicon octicon-x"></span>{{t 'buttons.delete'}}
</button>
</td>
</tr>
{{/each}}
</table>
{{/if}}

0 comments on commit 5d05bfc

Please sign in to comment.