-
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.
OAM-83: add ward/service dropdown to valid destionations modal
- Loading branch information
1 parent
986c76c
commit e8b6857
Showing
5 changed files
with
648 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/admin-valid-destination-add/admin-valid-destination-add.module.js
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,39 @@ | ||
/* | ||
* This program is part of the OpenLMIS logistics management information system platform software. | ||
* Copyright © 2017 VillageReach | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under the terms | ||
* of the GNU Affero General Public License as published by the Free Software Foundation, either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU Affero General Public License for more details. You should have received a copy of | ||
* the GNU Affero General Public License along with this program. If not, see | ||
* http://www.gnu.org/licenses. For additional information contact [email protected]. | ||
*/ | ||
|
||
(function() { | ||
|
||
'use strict'; | ||
|
||
/** | ||
* @module admin-valid-destination-add | ||
* | ||
* @description | ||
* Provides a modal for adding new valid destination. | ||
*/ | ||
angular.module('admin-valid-destination-add', [ | ||
'admin-valid-destination-list', | ||
'referencedata-facility', | ||
'referencedata-facility-type', | ||
'referencedata-facility-operator', | ||
'admin-facility', | ||
'admin-facility-view', | ||
'openlmis-modal', | ||
'openlmis-templates', | ||
'openlmis-state-tracker', | ||
'openlmis-modal-state' | ||
]); | ||
|
||
})(); |
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,17 @@ | ||
{ | ||
"adminValidDestinationAdd.add": "Add", | ||
"adminValidDestinationAdd.cancel": "Cancel", | ||
"adminValidDestinationAdd.facility": "Facility", | ||
"adminValidDestinationAdd.ward": "Ward/Service", | ||
"adminValidDestinationAdd.facilityType": "Facility Type", | ||
"adminValidDestinationAdd.geoLevelAffinity": "Geo Level Affinity", | ||
"adminValidDestinationAdd.organization": "Organization", | ||
"adminValidDestinationAdd.isOrganization": "Is Organization", | ||
"adminValidDestinationAdd.isFacility": "Is Facility", | ||
"adminValidDestinationAdd.isWard": "Is Ward/Service", | ||
"adminValidDestinationAdd.selectProgram": "Select program", | ||
"adminValidDestinationAdd.addValidDestination": "Add Valid Destination", | ||
"adminValidDestinationAdd.validDestinationAddedSuccessfully": "Valid Destination has been saved successfully.", | ||
"adminValidDestinationAdd.failure": "Failed to save the Valid Destination." | ||
} | ||
|
314 changes: 314 additions & 0 deletions
314
src/admin-valid-destination-add/valid-destination-add.controller.js
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,314 @@ | ||
/* | ||
* This program is part of the OpenLMIS logistics management information system platform software. | ||
* Copyright © 2017 VillageReach | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under the terms | ||
* of the GNU Affero General Public License as published by the Free Software Foundation, either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU Affero General Public License for more details. You should have received a copy of | ||
* the GNU Affero General Public License along with this program. If not, see | ||
* http://www.gnu.org/licenses. For additional information contact [email protected]. | ||
*/ | ||
|
||
(function() { | ||
|
||
'use strict'; | ||
|
||
/** | ||
* @ngdoc controller | ||
* @name admin-valid-destination-add.controller:ValidDestinationAddController | ||
* | ||
* @description | ||
* Controls Add Valid Destination modal. | ||
*/ | ||
angular | ||
.module('admin-valid-destination-add') | ||
.controller('ValidDestinationAddController', ValidDestinationAddController); | ||
|
||
ValidDestinationAddController.$inject = [ | ||
'ValidDestinationResource', | ||
'stateTrackerService', | ||
'loadingModalService', | ||
'notificationService', | ||
'programs', | ||
'facilities', | ||
'organizations', | ||
'facilityTypes', | ||
'geoLevels', | ||
'wardService', | ||
'$scope' | ||
]; | ||
|
||
function ValidDestinationAddController( | ||
ValidDestinationResource, | ||
stateTrackerService, | ||
loadingModalService, | ||
notificationService, | ||
programs, | ||
facilities, | ||
organizations, | ||
facilityTypes, | ||
geoLevels, | ||
wardService, | ||
$scope | ||
) { | ||
var vm = this; | ||
|
||
/** | ||
* @ngdoc property | ||
* @propertyOf admin-valid-destination-list.controller:ValidDestinationListController | ||
* @type {ValidDestinationResource} | ||
* @name validDestinationResource | ||
* | ||
* @description | ||
* Resource for handling valid destinations | ||
*/ | ||
vm.validDestinationResource = null; | ||
|
||
/** | ||
* @ngdoc property | ||
* @propertyOf admin-valid-destination-list.controller:ValidDestinationListController | ||
* @type {Array} | ||
* @name programs | ||
* | ||
* @description | ||
* Available programs | ||
*/ | ||
vm.programs = []; | ||
|
||
/** | ||
* @ngdoc property | ||
* @propertyOf admin-valid-destination-list.controller:ValidDestinationListController | ||
* @type {Array} | ||
* @name unitType | ||
* | ||
* @description | ||
* Available facilities | ||
*/ | ||
vm.facilities = []; | ||
|
||
/** | ||
* @ngdoc property | ||
* @propertyOf admin-valid-destination-list.controller:ValidDestinationListController | ||
* @type {Array} | ||
* @name unitType | ||
* | ||
* @description | ||
* Available facilities | ||
*/ | ||
vm.facilityTypes = []; | ||
|
||
/** | ||
* @ngdoc property | ||
* @propertyOf admin-valid-destination-list.controller:ValidDestinationListController | ||
* @type {Array} | ||
* @name geoLevels | ||
* | ||
* @description | ||
* Available facilities | ||
*/ | ||
vm.geoLevels = []; | ||
|
||
/** | ||
* @ngdoc property | ||
* @propertyOf admin-valid-destination-list.controller:ValidDestinationListController | ||
* @type {Array} | ||
* @name organizations | ||
* | ||
* @description | ||
* Available organizations | ||
*/ | ||
vm.organizations = []; | ||
|
||
/** | ||
* @ngdoc property | ||
* @propertyOf admin-valid-destination-list.controller:ValidDestinationListController | ||
* @type {Array} | ||
* @name wardsByFacility | ||
* | ||
* @description | ||
* Available wards by selected facility | ||
*/ | ||
vm.wardsByFacility = []; | ||
|
||
/** | ||
* @ngdoc property | ||
* @propertyOf admin-valid-destination-list.controller:ValidDestinationListController | ||
* @type {Object} | ||
* @name unitType | ||
* | ||
* @description | ||
* Selected program | ||
*/ | ||
vm.program = null; | ||
|
||
/** | ||
* @ngdoc property | ||
* @propertyOf admin-valid-destination-list.controller:ValidDestinationListController | ||
* @type {String} | ||
* @name unitType | ||
* | ||
* @description | ||
* Selected unit type - organization or facility | ||
*/ | ||
vm.unitType = 'facility'; | ||
|
||
/** | ||
* @ngdoc property | ||
* @propertyOf admin-valid-destination-list.controller:ValidDestinationListController | ||
* @type {Object} | ||
* @name facility | ||
* | ||
* @description | ||
* Selected facility | ||
*/ | ||
vm.facility = null; | ||
|
||
/** | ||
* @ngdoc property | ||
* @propertyOf admin-valid-destination-list.controller:ValidDestinationListController | ||
* @type {Object} | ||
* @name organization | ||
* | ||
* @description | ||
* Selected organization | ||
*/ | ||
vm.organization = null; | ||
|
||
/** | ||
* @ngdoc property | ||
* @propertyOf admin-valid-destination-list.controller:ValidDestinationListController | ||
* @type {Object} | ||
* @name ward | ||
* | ||
* @description | ||
* Selected ward | ||
*/ | ||
vm.ward = null; | ||
|
||
/** | ||
* @ngdoc property | ||
* @propertyOf admin-valid-destination-list.controller:ValidDestinationListController | ||
* @type {Object} | ||
* @name geoLevel | ||
* | ||
* @description | ||
* Selected geographic zone level | ||
*/ | ||
vm.geoLevel = null; | ||
|
||
/** | ||
* @ngdoc property | ||
* @propertyOf admin-valid-destination-list.controller:ValidDestinationListController | ||
* @type {Object} | ||
* @name facilityType | ||
* | ||
* @description | ||
* Selected facility type | ||
*/ | ||
vm.facilityType = null; | ||
|
||
/** | ||
* @ngdoc method | ||
* @methodOf admin-valid-destination-add.controller:ValidDestinationAddController | ||
* @name $onInit | ||
* | ||
* @description | ||
* Initialization method of the ValidDestinationAddController. | ||
*/ | ||
vm.$onInit = function() { | ||
vm.programs = programs; | ||
vm.facilities = facilities; | ||
vm.organizations = organizations; | ||
vm.validDestinationResource = new ValidDestinationResource(); | ||
vm.facilityTypes = facilityTypes; | ||
vm.geoLevels = geoLevels; | ||
|
||
$scope.$watch(function() { | ||
return [vm.facility && vm.facility.id, vm.unitType]; | ||
}, function(newValues, oldValues) { | ||
var currentFacilityId = newValues[0]; | ||
var prevFacilityId = oldValues[0]; | ||
var currentUnitType = newValues[1]; | ||
var prevUnitType = oldValues[1]; | ||
|
||
if ( | ||
(currentFacilityId !== prevFacilityId || | ||
currentUnitType !== prevUnitType) && | ||
vm.unitType === 'ward' | ||
) { | ||
vm.getWardsByFacility(); | ||
} | ||
}, true); | ||
}; | ||
|
||
/** | ||
* @ngdoc method | ||
* @methodOf admin-valid-destination-add.controller:ValidDestinationAddController | ||
* @name goToPreviousState | ||
* | ||
* @description | ||
* Helper for using previous state from view layer | ||
*/ | ||
vm.goToPreviousState = stateTrackerService.goToPreviousState; | ||
|
||
/** | ||
* @ngdoc method | ||
* @methodOf admin-valid-destination-add.controller:ValidDestinationAddController | ||
* @name getWardsByFacility | ||
* | ||
* @description | ||
* Get wards by selected facility | ||
*/ | ||
vm.getWardsByFacility = function() { | ||
wardService.getWardsByFacility({ | ||
facilityId: vm.facility.id | ||
}).then(function(response) { | ||
vm.wardsByFacility = response.content; | ||
}); | ||
}; | ||
|
||
/** | ||
* @ngdoc method | ||
* @methodOf admin-valid-destination-add.controller:ValidDestinationAddController | ||
* @name submit | ||
* | ||
* @description | ||
* Submits form | ||
*/ | ||
vm.submit = function() { | ||
var isRefDataFacility = vm.unitType === 'facility'; | ||
|
||
//TODO: Add ward as a referenceId after BE is ready | ||
var referenceId = isRefDataFacility ? vm.facility.id : vm.organization.id; | ||
|
||
var payload = { | ||
programId: vm.program.id, | ||
facilityTypeId: vm.facilityType.id, | ||
node: { | ||
referenceId: referenceId | ||
} | ||
}; | ||
|
||
if (vm.geoLevel !== null) { | ||
payload.geoLevelAffinityId = vm.geoLevel.id; | ||
} | ||
|
||
loadingModalService.open(); | ||
return vm.validDestinationResource.create(payload) | ||
.then(function(validDestination) { | ||
notificationService.success('adminValidDestinationAdd.validDestinationAddedSuccessfully'); | ||
loadingModalService.close(); | ||
vm.goToPreviousState(); | ||
return validDestination; | ||
}) | ||
.catch(function() { | ||
notificationService.error('adminValidDestinationAdd.failure'); | ||
loadingModalService.close(); | ||
}); | ||
}; | ||
} | ||
})(); |
Oops, something went wrong.