diff --git a/src/admin-integration-email-add/admin-integration-email-add.controller.js b/src/admin-integration-email-add/admin-integration-email-add.controller.js new file mode 100644 index 0000000..55f42dd --- /dev/null +++ b/src/admin-integration-email-add/admin-integration-email-add.controller.js @@ -0,0 +1,148 @@ +/* + * 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 info@OpenLMIS.org. + */ + +(function() { + + 'use strict'; + + /** + * @ngdoc controller + * @name admin-integration-email-add.controller:AdminIntegrationEmailAddController + * + * @description + * Controller for integration email add screen. + */ + angular + .module('admin-integration-email-add') + .controller('AdminIntegrationEmailAddController', AdminIntegrationEmailAddController); + + AdminIntegrationEmailAddController.$inject = [ + '$state', '$stateParams', 'email', 'FunctionDecorator', 'integrationEmailService' + ]; + + function AdminIntegrationEmailAddController($state, $stateParams, email, FunctionDecorator, + integrationEmailService) { + + var vm = this; + + vm.$onInit = onInit; + vm.saveEmail = saveEmail; + vm.goToEmailList = goToEmailList; + + /** + * @ngdoc property + * @propertyOf admin-integration-email-add.controller:AdminIntegrationEmailAddController + * @name email + * @type {Object} + * + * @description + * Holds email that will be created. + */ + vm.email = undefined; + + /** + * @ngdoc property + * @propertyOf admin-integration-email-add.controller:AdminIntegrationEmailAddController + * @name successNotificationKey + * @type {String} + * + * @description + * Holds successNotificationKey message. + */ + vm.successNotificationKey = email ? 'adminIntegrationEmailAdd.save.success' : + 'adminIntegrationEmailAdd.create.success'; + + /** + * @ngdoc property + * @propertyOf admin-integration-email-add.controller:AdminIntegrationEmailAddController + * @name errorNotificationKey + * @type {String} + * + * @description + * Holds errorNotificationKey message. + */ + vm.errorNotificationKey = email ? 'adminIntegrationEmailAdd.save.failure' : + 'adminIntegrationEmailAdd.create.failure'; + + /** + * @ngdoc property + * @propertyOf admin-integration-email-add.controller:AdminIntegrationEmailAddController + * @name modalHeaderKey + * @type {String} + * + * @description + * Holds modalHeaderKey message. + */ + vm.modalHeaderKey = email ? 'adminIntegrationEmailAdd.editEmail' : + 'adminIntegrationEmailAdd.addEmail'; + + /** + * @ngdoc property + * @methodOf admin-integration-email-add.controller:AdminIntegrationEmailAddController + * @name onInit + * + * @description + * Initialization method for AdminIntegrationEmailAddController. + */ + function onInit() { + vm.email = email; + vm.saveEmail = new FunctionDecorator() + .decorateFunction(saveEmail) + .withSuccessNotification(vm.successNotificationKey) + .withErrorNotification(vm.errorNotificationKey) + .withConfirm('adminIntegrationEmailAdd.confirm') + .withLoading(true) + .getDecoratedFunction(); + } + + /** + * @ngdoc method + * @methodOf admin-integration-email-add.controller:AdminIntegrationEmailAddController + * @name save + * + * @description + * Saves the email address. + */ + function saveEmail() { + if (email) { + return integrationEmailService + .update(vm.email) + .then(function() { + vm.goToEmailList(); + }); + } + return integrationEmailService + .add(vm.email) + .then(function() { + vm.goToEmailList(); + }); + } + + /** + * @ngdoc property + * @methodOf admin-integration-email-add.controller:AdminIntegrationEmailAddController + * @name goToEmailList + * + * @description + * Redirects user to integration email list screen. + */ + function goToEmailList() { + var stateParams = angular.copy($stateParams); + $state.go('openlmis.administration.adminIntegrationEmailList', stateParams, { + reload: true + }); + } + } +})(); diff --git a/src/admin-integration-email-add/admin-integration-email-add.html b/src/admin-integration-email-add/admin-integration-email-add.html new file mode 100644 index 0000000..33f7eac --- /dev/null +++ b/src/admin-integration-email-add/admin-integration-email-add.html @@ -0,0 +1,19 @@ +
diff --git a/src/admin-integration-email-add/admin-integration-email-add.module.js b/src/admin-integration-email-add/admin-integration-email-add.module.js new file mode 100644 index 0000000..7977ffc --- /dev/null +++ b/src/admin-integration-email-add/admin-integration-email-add.module.js @@ -0,0 +1,35 @@ +/* + * 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 info@OpenLMIS.org. + */ + +(function() { + + 'use strict'; + + /** + * @module admin-integration-email-add + * + * @description + * Provides a modal for adding new integration emails + */ + angular.module('admin-integration-email-add', [ + 'openlmis-function-decorator', + 'openlmis-i18n', + 'ui.router', + 'openlmis-modal', + 'openlmis-state-tracker', + 'openlmis-pagination' + ]); + +})(); diff --git a/src/admin-integration-email-add/admin-integration-email-add.routes.js b/src/admin-integration-email-add/admin-integration-email-add.routes.js new file mode 100644 index 0000000..2d379ef --- /dev/null +++ b/src/admin-integration-email-add/admin-integration-email-add.routes.js @@ -0,0 +1,43 @@ +/* + * 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 info@OpenLMIS.org. + */ + +(function() { + + 'use strict'; + + angular + .module('admin-integration-email-add') + .config(routes); + + routes.$inject = ['$stateProvider', 'modalStateProvider']; + + function routes($stateProvider, modalStateProvider) { + + modalStateProvider.state('openlmis.administration.adminIntegrationEmailList.add', { + controller: 'AdminIntegrationEmailAddController', + controllerAs: 'vm', + url: '/add/:emailId', + templateUrl: 'admin-integration-email-add/admin-integration-email-add.html', + resolve: { + email: function($stateParams, emails) { + var email = _.findWhere(emails, { + id: $stateParams.emailId + }); + return email; + } + } + }); + } +})(); diff --git a/src/admin-integration-email-add/messages_en.json b/src/admin-integration-email-add/messages_en.json new file mode 100644 index 0000000..bbb5a95 --- /dev/null +++ b/src/admin-integration-email-add/messages_en.json @@ -0,0 +1,13 @@ +{ + "adminIntegrationEmailAdd.addEmail": "Add e-mail", + "adminIntegrationEmailAdd.editEmail": "Edit e-mail", + "adminIntegrationEmailAdd.active": "Active", + "adminIntegrationEmailAdd.emailName": "E-mail Name", + "adminIntegrationEmailAdd.save": "Save", + "adminIntegrationEmailAdd.cancel": "Cancel", + "adminIntegrationEmailAdd.confirm": "Are you sure you want to save e-mail?", + "adminIntegrationEmailAdd.save.success": "E-mail saved successfully", + "adminIntegrationEmailAdd.create.success": "E-mail created successfully", + "adminIntegrationEmailAdd.save.failure": "Failed to save e-mail", + "adminIntegrationEmailAdd.create.failure": "Failed to create e-mial" +} diff --git a/src/admin-integration-email-list/admin-integration-email-list.controller.js b/src/admin-integration-email-list/admin-integration-email-list.controller.js new file mode 100644 index 0000000..990eb79 --- /dev/null +++ b/src/admin-integration-email-list/admin-integration-email-list.controller.js @@ -0,0 +1,88 @@ +/* + * 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 info@OpenLMIS.org. + */ + +(function() { + + 'use strict'; + + /** + * @ngdoc controller + * @name admin-integration-email-list.controller:AdminIntegrationEmailListController + * + * @description + * Controller for managing integration email list. + */ + angular + .module('admin-integration-email-list') + .controller('AdminIntegrationEmailListController', controller); + + controller.$inject = ['$state', '$stateParams', 'emails', 'FunctionDecorator', 'integrationEmailService']; + + function controller($state, $stateParams, emails, FunctionDecorator, integrationEmailService) { + + var vm = this; + vm.$onInit = onInit; + + vm.removeEmail = new FunctionDecorator() + .decorateFunction(removeEmail) + .withSuccessNotification('adminIntegrationEmailList.emailRemovedSuccessfully') + .withErrorNotification('adminIntegrationEmailList.failedToRemoveEmail') + .withConfirm('adminIntegrationEmailList.confirmToRemoveEmail') + .withLoading(true) + .getDecoratedFunction(); + + /** + * @ngdoc property + * @name emails + * @propertyOf admin-integration-email-list.controller:AdminIntegrationEmailListController + * @type {Array} + * + * @description + * Holds list of all integration emials. + */ + vm.emails = undefined; + + /** + * @ngdoc method + * @methodOf admin-integration-email-list.controller:AdminIntegrationEmailListController + * @name $onInit + * + * @description + * Initializes controller + */ + function onInit() { + vm.emails = emails; + } + + /** + * @ngdoc method + * @methodOf admin-integration-email-list.controller:AdminIntegrationEmailListController + * @name removeEmail + * + * @description + * Remove the integration email. + */ + function removeEmail(email) { + return integrationEmailService.remove(email.email.id) + .then(function() { + var stateParams = angular.copy($stateParams); + $state.go('openlmis.administration.adminIntegrationEmailList', stateParams, { + reload: true + }); + }); + } + } + +})(); diff --git a/src/admin-integration-email-list/admin-integration-email-list.html b/src/admin-integration-email-list/admin-integration-email-list.html new file mode 100644 index 0000000..ccbe08d --- /dev/null +++ b/src/admin-integration-email-list/admin-integration-email-list.html @@ -0,0 +1,31 @@ +{{:: 'adminIntegrationEmailList.name' | message}} | +{{:: 'adminIntegrationEmailList.actions' | message}} | +
---|---|
{{:: email.email}} | ++ + + | +