1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

implement model-based copy for notification templates

This commit is contained in:
Jake McDermott 2017-12-05 17:09:24 -05:00
parent 29f1d695ae
commit 09d3e6cd98
No known key found for this signature in database
GPG Key ID: 3B02CAD476EECB35
2 changed files with 31 additions and 3 deletions

View File

@ -7,12 +7,12 @@
export default ['$scope', 'Wait', 'NotificationTemplatesList', export default ['$scope', 'Wait', 'NotificationTemplatesList',
'GetBasePath', 'Rest', 'ProcessErrors', 'Prompt', '$state', 'GetBasePath', 'Rest', 'ProcessErrors', 'Prompt', '$state',
'ngToast', '$filter', 'Dataset', 'rbacUiControlService', 'ngToast', '$filter', 'Dataset', 'rbacUiControlService',
'i18n', 'NotificationTemplateModel', 'i18n', 'NotificationTemplate',
function( function(
$scope, Wait, NotificationTemplatesList, $scope, Wait, NotificationTemplatesList,
GetBasePath, Rest, ProcessErrors, Prompt, $state, GetBasePath, Rest, ProcessErrors, Prompt, $state,
ngToast, $filter, Dataset, rbacUiControlService, ngToast, $filter, Dataset, rbacUiControlService,
i18n) { i18n, NotificationTemplate) {
var defaultUrl = GetBasePath('notification_templates'), var defaultUrl = GetBasePath('notification_templates'),
list = NotificationTemplatesList; list = NotificationTemplatesList;
@ -31,7 +31,7 @@
$scope.list = list; $scope.list = list;
$scope[`${list.iterator}_dataset`] = Dataset.data; $scope[`${list.iterator}_dataset`] = Dataset.data;
$scope[list.name] = $scope[`${list.iterator}_dataset`].results; $scope[list.name] = $scope[`${list.iterator}_dataset`].results;
} }
$scope.$on(`notification_template_options`, function(event, data){ $scope.$on(`notification_template_options`, function(event, data){
$scope.options = data.data.actions.GET; $scope.options = data.data.actions.GET;
@ -88,6 +88,24 @@
notification_template.template_status_html = html; notification_template.template_status_html = html;
} }
$scope.copyNotification = notificationTemplate => {
Wait('start');
new NotificationTemplate('get', notificationTemplate.id)
.then(model => model.copy())
.then(({ id }) => {
const params = {
notification_template_id: id,
notification_template: this.notification_templates
};
$state.go('notifications.edit', params, { reload: true });
})
.catch(({ data, status }) => {
const params = { hdr: 'Error!', msg: `Call to copy failed. Return status: ${status}` };
ProcessErrors($scope, data, status, null, params);
})
.finally(() => Wait('stop'));
};
$scope.testNotification = function() { $scope.testNotification = function() {
var name = $filter('sanitize')(this.notification_template.name), var name = $filter('sanitize')(this.notification_template.name),
pending_retries = 10; pending_retries = 10;
@ -152,6 +170,7 @@
} }
}; };
$scope.addNotification = function() { $scope.addNotification = function() {
$state.go('notifications.add'); $state.go('notifications.add');
}; };

View File

@ -77,6 +77,15 @@ export default ['i18n', function(i18n){
dataPlacement: 'top', dataPlacement: 'top',
ngShow: 'notification_template.summary_fields.user_capabilities.edit' ngShow: 'notification_template.summary_fields.user_capabilities.edit'
}, },
copy: {
label: i18n._('Copy'),
ngClick: 'copyNotification(notification_template)',
"class": 'btn-danger btn-xs',
awToolTip: i18n._('Copy notification'),
dataPlacement: 'top',
// requires future api rbac changes
//ngShow: 'notification_template.summary_fields.user_capabilities.copy'
},
view: { view: {
ngClick: "editNotification(notification_template.id)", ngClick: "editNotification(notification_template.id)",
label: i18n._('View'), label: i18n._('View'),