Skip to content

Commit

Permalink
FIX: Add form entry to unit create modal
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcu committed Mar 5, 2016
1 parent 3653f78 commit 440b846
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/app/units/modals/unit-create-modal/unit-create-modal.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,25 @@ angular.module('doubtfire.units.modals.unit-create-modal', [])
UnitCreateModal.show = (units) ->
$modal.open
controller: 'UnitCreateModalCtrl'
templateUrl: 'units/modals/unit-ilo-edit-modal/unit-ilo-edit-modal.tpl.html'
templateUrl: 'units/modals/unit-create-modal/unit-create-modal.tpl.html'
resolve:
units: -> units

UnitCreateModal
)
.controller('UnitCreateModalCtrl', ($scope, $modalInstance, alertService, units, Unit, analyticsService) ->
analyticsService.event 'Unit Admin', 'Started to Create Unit'

$scope.unit = new Unit { id: -1, active: true, code: "COS????", name: "Unit Name" }
$scope.saveSuccess = (unit) ->
alertService.add("success", "Unit created.", 2000)
$modalInstance.close()
units.push(unit)
analyticsService.event 'Unit Admin', 'Saved New Unit'
$scope.units = units
$scope.unit = { code: null, name: null }
$scope.saveUnit = ->
Unit.create(
{ unit: $scope.unit }
(response) ->
alertService.add("success", "Unit created.", 2000)
$modalInstance.close()
$scope.units.push(response)
analyticsService.event 'Unit Admin', 'Saved New Unit'
(response) ->
alertService.add 'danger', "Error creating unit - #{response.data.error}"
)
)
20 changes: 20 additions & 0 deletions src/app/units/modals/unit-create-modal/unit-create-modal.tpl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<div class="unit-create-modal">
<form class="form-horizontal" ng-submit="saveUnit()" role="form">
<div class="modal-header">
<h3>Create Unit</h3>
</div>
<div class="modal-body">
<div class="form-group" required>
<label class="col-sm-3 control-label">Name</label>
<input type="text" class="form-control col-sm-7" ng-model="unit.name" placeholder="Introduction to Doubtfire"/>
</div>
<div class="form-group" required>
<label class="col-sm-3 control-label">Code</label>
<input type="text" class="form-control col-sm-7" ng-model="unit.code" placeholder="COS123456"/>
</div>
</div>
<div class="modal-footer text-right">
<input type="submit" class="btn btn-primary" value="Create" ng-disabled="unit.name == null || unit.code == null"/>
</div>
</form>
</div>

0 comments on commit 440b846

Please sign in to comment.