-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from openhealthcare/27-add-many-unrolled-pathways
adds many unrolled pathways
- Loading branch information
Showing
4 changed files
with
53 additions
and
48 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
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 |
---|---|---|
@@ -1,48 +1,40 @@ | ||
angular.module('opal.controllers').controller('MultiSaveCtrl', | ||
function(Options, $controller, step, scope, episode) { | ||
"use strict"; | ||
var vm = this; | ||
var key = step.api_name; | ||
|
||
var parentCtrl = $controller("MultistageDefault"); | ||
_.extend(vm, parentCtrl); | ||
scope.step = step; | ||
|
||
vm.step = step; | ||
vm.multipleModels = []; | ||
|
||
vm.cleanModel = function(editing_field){ | ||
_.each(_.keys(editing_field), function(a){ | ||
editing_field[a] = undefined; | ||
}); | ||
scope.addAnother = function(){ | ||
scope.allEditing.push({key: undefined}); | ||
}; | ||
|
||
if(episode && episode[step.api_name].length > 1){ | ||
vm.multipleModels = angular.copy(episode[step.api_name]); | ||
var editing_field = scope.editing[step.api_name]; | ||
vm.cleanModel(editing_field); | ||
} | ||
|
||
vm.isClean = function(editing_field){ | ||
return !_.some(_.values(editing_field)); | ||
}; | ||
scope.instanceName = step.title; | ||
|
||
vm.addAnother = function(){ | ||
var editing_field = scope.editing[step.api_name]; | ||
scope.init = function(){ | ||
scope.allEditing = _.map(episode[key], function(row){ | ||
var editing = {} | ||
editing[key] = row; | ||
return editing; | ||
}); | ||
|
||
if(!vm.isClean(editing_field)){ | ||
vm.multipleModels.push(angular.copy(editing_field)); | ||
vm.cleanModel(editing_field); | ||
} | ||
// add a blank row to the bottom | ||
scope.addAnother(); | ||
}; | ||
|
||
vm.remove = function($index){ | ||
vm.multipleModels.splice($index, 1); | ||
scope.remove = function($index){ | ||
scope.allEditing.splice($index, 1); | ||
}; | ||
|
||
vm.preSave = function(editing){ | ||
var all_models = angular.copy(vm.multipleModels); | ||
if(!vm.isClean(editing[step.api_name])){ | ||
all_models.push(editing[step.api_name]); | ||
} | ||
editing[step.api_name] = all_models; | ||
scope.preSave = function(editing){ | ||
var all_models = angular.copy(scope.allEditing); | ||
|
||
var result = _.reduce(all_models, function(memo, row){ | ||
return memo.concat(_.values(row)); | ||
}, []) | ||
|
||
editing[step.api_name] = result; | ||
}; | ||
|
||
scope.init(); | ||
}); |
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 |
---|---|---|
@@ -1,16 +1,11 @@ | ||
<div class="well" ng-repeat="item in currentStep.controller.multipleModels"> | ||
<div class="row"> | ||
<div class="col-md-10"> | ||
<div ng-include src="currentStep.record_url"></div> | ||
</div> | ||
<div class="col-md-2"> | ||
<btn class=" pointer" type="button" ng-click="currentStep.controller.remove($index)"><i class="fa fa-minus"></i></btn> | ||
</div> | ||
<div ng-repeat="editing in allEditing"> | ||
<div class="col-md-10 col-md-push-1 content-offset-below-10"> | ||
<h4>[[ instanceName ]] [[ $index + 1 ]] <a ng-click="remove($index)"><i class="fa fa-times-circle"></i></a></h4> | ||
</div> | ||
<span ng-include src="currentStep.model_form_url"></span> | ||
</div> | ||
<span ng-include src="currentStep.model_form_url"></span> | ||
<div class="row"> | ||
<div class="col-sm-11"> | ||
<a ng-click="currentStep.controller.addAnother()" class="pull-right btn btn-primary">Add Another</a> | ||
<a ng-click="addAnother()" class="pull-right btn btn-primary">Add Another</a> | ||
</div> | ||
</div> |