mirror of
https://github.com/ansible/awx.git
synced 2026-01-17 20:51:21 -03:30
wire in custom template messages on edit form
This commit is contained in:
parent
b80ca62072
commit
a56a6d7158
@ -53,7 +53,7 @@ function atSyntaxHighlightController ($scope, AngularCodeMirror) {
|
||||
init();
|
||||
});
|
||||
$scope.$on('reset-code-mirror', () => {
|
||||
initCodeMirror();
|
||||
setImmediate(initCodeMirror);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -7,12 +7,13 @@
|
||||
export default ['Rest', 'Wait', 'NotificationsFormObject',
|
||||
'ProcessErrors', 'GetBasePath', 'Alert',
|
||||
'GenerateForm', '$scope', '$state', 'CreateSelect2', 'GetChoices',
|
||||
'NotificationsTypeChange', 'ParseTypeChange', 'i18n',
|
||||
'NotificationsTypeChange', 'ParseTypeChange', 'i18n', 'MessageUtils',
|
||||
function(
|
||||
Rest, Wait, NotificationsFormObject,
|
||||
ProcessErrors, GetBasePath, Alert,
|
||||
GenerateForm, $scope, $state, CreateSelect2, GetChoices,
|
||||
NotificationsTypeChange, ParseTypeChange, i18n
|
||||
NotificationsTypeChange, ParseTypeChange, i18n,
|
||||
MessageUtils
|
||||
) {
|
||||
|
||||
var generator = GenerateForm,
|
||||
@ -31,9 +32,11 @@ export default ['Rest', 'Wait', 'NotificationsFormObject',
|
||||
Alert('Permission Error', 'You do not have permission to add a notification template.', 'alert-info');
|
||||
}
|
||||
// TODO: get default messages off data
|
||||
$scope.start_message = defaultMessages.start_message = 'It started';
|
||||
$scope.success_message = defaultMessages.success_message = 'It succeeded';
|
||||
$scope.error_message = defaultMessages.error_message = 'It failed';
|
||||
console.log('OPTIONS:', data);
|
||||
defaultMessages.start_message = 'It started';
|
||||
defaultMessages.success_message = 'It succeeded';
|
||||
defaultMessages.error_message = 'It failed';
|
||||
MessageUtils.setMessagesOnScope($scope, null, defaultMessages);
|
||||
});
|
||||
// apply form definition's default field values
|
||||
GenerateForm.applyDefaults(form, $scope);
|
||||
@ -189,29 +192,6 @@ export default ['Rest', 'Wait', 'NotificationsFormObject',
|
||||
}
|
||||
};
|
||||
|
||||
function getMessages () {
|
||||
return {
|
||||
start: {
|
||||
message: $scope.start_message === defaultMessages.start_message
|
||||
? null : $scope.start_message,
|
||||
body: $scope.start_body === defaultMessages.start_body
|
||||
? null : $scope.start_body,
|
||||
},
|
||||
success: {
|
||||
message: $scope.success_message === defaultMessages.success_message
|
||||
? null : $scope.success_message,
|
||||
body: $scope.success_body === defaultMessages.success_body
|
||||
? null : $scope.success_body,
|
||||
},
|
||||
error: {
|
||||
message: $scope.error_message === defaultMessages.error_message
|
||||
? null : $scope.error_message,
|
||||
body: $scope.error_body === defaultMessages.error_body
|
||||
? null : $scope.error_body,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Save
|
||||
$scope.formSave = function() {
|
||||
var params,
|
||||
@ -222,7 +202,7 @@ export default ['Rest', 'Wait', 'NotificationsFormObject',
|
||||
"name": $scope.name,
|
||||
"description": $scope.description,
|
||||
"organization": $scope.organization,
|
||||
"messages": $scope.customize_messages ? getMessages() : null,
|
||||
"messages": MessageUtils.getMessagesObj($scope, defaultMessages),
|
||||
"notification_type": v,
|
||||
"notification_configuration": {}
|
||||
};
|
||||
|
||||
@ -10,19 +10,22 @@ export default ['Rest', 'Wait',
|
||||
'notification_template',
|
||||
'$scope', '$state', 'GetChoices', 'CreateSelect2', 'Empty',
|
||||
'NotificationsTypeChange', 'ParseTypeChange', 'i18n',
|
||||
'MessageUtils',
|
||||
function(
|
||||
Rest, Wait,
|
||||
NotificationsFormObject, ProcessErrors, GetBasePath,
|
||||
GenerateForm,
|
||||
notification_template,
|
||||
$scope, $state, GetChoices, CreateSelect2, Empty,
|
||||
NotificationsTypeChange, ParseTypeChange, i18n
|
||||
NotificationsTypeChange, ParseTypeChange, i18n,
|
||||
MessageUtils
|
||||
) {
|
||||
var generator = GenerateForm,
|
||||
id = notification_template.id,
|
||||
form = NotificationsFormObject,
|
||||
master = {},
|
||||
url = GetBasePath('notification_templates');
|
||||
url = GetBasePath('notification_templates'),
|
||||
defaultMessages = {};
|
||||
|
||||
init();
|
||||
|
||||
@ -35,6 +38,11 @@ export default ['Rest', 'Wait',
|
||||
}
|
||||
});
|
||||
|
||||
// TODO: get OPTIONS for defaultMessages
|
||||
defaultMessages.start_message = 'It started';
|
||||
defaultMessages.success_message = 'It succeeded';
|
||||
defaultMessages.error_message = 'It failed';
|
||||
|
||||
GetChoices({
|
||||
scope: $scope,
|
||||
url: url,
|
||||
@ -165,6 +173,9 @@ export default ['Rest', 'Wait',
|
||||
field_id: 'notification_template_headers',
|
||||
readOnly: !$scope.notification_template.summary_fields.user_capabilities.edit
|
||||
});
|
||||
|
||||
MessageUtils.setMessagesOnScope($scope, data.messages, defaultMessages);
|
||||
|
||||
Wait('stop');
|
||||
})
|
||||
.catch(({data, status}) => {
|
||||
@ -175,8 +186,6 @@ export default ['Rest', 'Wait',
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
$scope.$watch('headers', function validate_headers(str) {
|
||||
try {
|
||||
let headers = JSON.parse(str);
|
||||
@ -277,14 +286,7 @@ export default ['Rest', 'Wait',
|
||||
"name": $scope.name,
|
||||
"description": $scope.description,
|
||||
"organization": $scope.organization,
|
||||
"messages": $scope.customize_messages ? {
|
||||
start_message: $scope.start_message,
|
||||
start_body: $scope.start_body,
|
||||
success_message: $scope.success_message,
|
||||
success_body: $scope.success_body,
|
||||
error_message: $scope.error_message,
|
||||
error_body: $scope.error_body,
|
||||
} : null,
|
||||
"messages": MessageUtils.getMessagesObj($scope, defaultMessages),
|
||||
"notification_type": v,
|
||||
"notification_configuration": {}
|
||||
};
|
||||
|
||||
@ -15,6 +15,7 @@ import notificationsList from './notifications.list';
|
||||
import toggleNotification from './shared/toggle-notification.factory';
|
||||
import notificationsListInit from './shared/notification-list-init.factory';
|
||||
import typeChange from './shared/type-change.service';
|
||||
import messageUtils from './shared/message-utils.service';
|
||||
import { N_ } from '../i18n';
|
||||
|
||||
export default
|
||||
@ -29,6 +30,7 @@ angular.module('notifications', [
|
||||
.factory('ToggleNotification', toggleNotification)
|
||||
.factory('NotificationsListInit', notificationsListInit)
|
||||
.service('NotificationsTypeChange', typeChange)
|
||||
.service('MessageUtils', messageUtils)
|
||||
.config(['$stateProvider', 'stateDefinitionsProvider',
|
||||
function($stateProvider, stateDefinitionsProvider) {
|
||||
let stateDefinitions = stateDefinitionsProvider.$get();
|
||||
|
||||
@ -0,0 +1,63 @@
|
||||
export default [function () {
|
||||
return {
|
||||
getMessagesObj: function ($scope, defaultMessages) {
|
||||
if (!$scope.customize_messages) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
start: {
|
||||
message: $scope.start_message === defaultMessages.start_message
|
||||
? null : $scope.start_message,
|
||||
body: $scope.start_body === defaultMessages.start_body
|
||||
? null : $scope.start_body,
|
||||
},
|
||||
success: {
|
||||
message: $scope.success_message === defaultMessages.success_message
|
||||
? null : $scope.success_message,
|
||||
body: $scope.success_body === defaultMessages.success_body
|
||||
? null : $scope.success_body,
|
||||
},
|
||||
error: {
|
||||
message: $scope.error_message === defaultMessages.error_message
|
||||
? null : $scope.error_message,
|
||||
body: $scope.error_body === defaultMessages.error_body
|
||||
? null : $scope.error_body,
|
||||
}
|
||||
};
|
||||
},
|
||||
setMessagesOnScope: function ($scope, messages, defaultMessages) {
|
||||
$scope.start_message = defaultMessages.start_message;
|
||||
$scope.success_message = defaultMessages.success_message;
|
||||
$scope.error_message = defaultMessages.error_message;
|
||||
if (!messages) {
|
||||
return;
|
||||
}
|
||||
let customized = false;
|
||||
if (messages.start.message) {
|
||||
customized = true;
|
||||
$scope.start_message = messages.start.message;
|
||||
}
|
||||
if (messages.start.body) {
|
||||
customized = true;
|
||||
$scope.start_body = messages.start.body;
|
||||
}
|
||||
if (messages.success.message) {
|
||||
customized = true;
|
||||
$scope.success_message = messages.success.message;
|
||||
}
|
||||
if (messages.success.body) {
|
||||
customized = true;
|
||||
$scope.success_body = messages.success.body;
|
||||
}
|
||||
if (messages.error.message) {
|
||||
customized = true;
|
||||
$scope.error_message = messages.error.message;
|
||||
}
|
||||
if (messages.error.body) {
|
||||
customized = true;
|
||||
$scope.error_body = messages.error.body;
|
||||
}
|
||||
$scope.customize_messages = customized;
|
||||
}
|
||||
}
|
||||
}]
|
||||
Loading…
x
Reference in New Issue
Block a user