From a7dbb78c2eea3c9baa3fa37690a03dfb6ca0d8e0 Mon Sep 17 00:00:00 2001 From: Marliana Lara Date: Fri, 28 Apr 2017 13:33:45 -0400 Subject: [PATCH] Autofill organization in a new notification template Issue #2943 When navigating from an organization to a new notification template, the organization field should automatically populate the organization name. --- .../src/notifications/add/add.controller.js | 17 +++++++++++++++++ awx/ui/client/src/notifications/main.js | 3 +++ .../shared/notification-list-init.factory.js | 9 +++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/awx/ui/client/src/notifications/add/add.controller.js b/awx/ui/client/src/notifications/add/add.controller.js index 01466004a1..15b317c9cc 100644 --- a/awx/ui/client/src/notifications/add/add.controller.js +++ b/awx/ui/client/src/notifications/add/add.controller.js @@ -42,6 +42,23 @@ export default ['Rest', 'Wait', 'NotificationsFormObject', }); } + if ($state.params.organization_id) { + let id = $state.params.organization_id, + url = GetBasePath('organizations') + id + '/'; + + Rest.setUrl(url); + Rest.get() + .success(function(data) { + $scope.organization_name = data.name; + }) + .error(function(data, status) { + ProcessErrors($scope, data, status, form, { + hdr: 'Error!', + msg: `Failed to retrieve organization. GET status: ${status}` + }); + }); + }; + if ($scope.removeChoicesReady) { $scope.removeChoicesReady(); } diff --git a/awx/ui/client/src/notifications/main.js b/awx/ui/client/src/notifications/main.js index 808d30f447..a88811f4c7 100644 --- a/awx/ui/client/src/notifications/main.js +++ b/awx/ui/client/src/notifications/main.js @@ -52,6 +52,9 @@ angular.module('notifications', [ add: 'notificationsAddController', edit: 'notificationsEditController' }, + urls: { + add: '/add?organization_id' + }, resolve: { edit: { notification_template: ['$state', '$stateParams', '$q', diff --git a/awx/ui/client/src/notifications/shared/notification-list-init.factory.js b/awx/ui/client/src/notifications/shared/notification-list-init.factory.js index e8a711e783..319f49c436 100644 --- a/awx/ui/client/src/notifications/shared/notification-list-init.factory.js +++ b/awx/ui/client/src/notifications/shared/notification-list-init.factory.js @@ -30,8 +30,13 @@ export default ['Wait', 'GetBasePath', 'ProcessErrors', 'Rest', 'GetChoices', scope.current_user_admin_orgs = data.results.map(i => i.name); }); - scope.addNotificationTemplate = function(){ - $state.go('notifications.add'); + scope.addNotificationTemplate = function() { + if (id) { + $state.go('notifications.add', {organization_id: id}); + } + else { + $state.go('notifications.add'); + } }; if (scope.relatednotificationsRemove) {