mirror of
https://github.com/ansible/awx.git
synced 2026-05-13 04:17:36 -02:30
@@ -9,13 +9,13 @@ export default
|
|||||||
'NotificationsFormObject', 'ProcessErrors', 'GetBasePath', 'Empty',
|
'NotificationsFormObject', 'ProcessErrors', 'GetBasePath', 'Empty',
|
||||||
'GenerateForm', 'SearchInit' , 'PaginateInit', 'LookUpInit',
|
'GenerateForm', 'SearchInit' , 'PaginateInit', 'LookUpInit',
|
||||||
'OrganizationList', '$scope', '$state', 'CreateSelect2', 'GetChoices',
|
'OrganizationList', '$scope', '$state', 'CreateSelect2', 'GetChoices',
|
||||||
'NotificationsTypeChange',
|
'NotificationsTypeChange', 'ParseTypeChange',
|
||||||
function(
|
function(
|
||||||
$rootScope, pagination, $compile, SchedulerInit, Rest, Wait,
|
$rootScope, pagination, $compile, SchedulerInit, Rest, Wait,
|
||||||
NotificationsFormObject, ProcessErrors, GetBasePath, Empty,
|
NotificationsFormObject, ProcessErrors, GetBasePath, Empty,
|
||||||
GenerateForm, SearchInit, PaginateInit, LookUpInit,
|
GenerateForm, SearchInit, PaginateInit, LookUpInit,
|
||||||
OrganizationList, $scope, $state, CreateSelect2, GetChoices,
|
OrganizationList, $scope, $state, CreateSelect2, GetChoices,
|
||||||
NotificationsTypeChange
|
NotificationsTypeChange, ParseTypeChange
|
||||||
) {
|
) {
|
||||||
var generator = GenerateForm,
|
var generator = GenerateForm,
|
||||||
form = NotificationsFormObject,
|
form = NotificationsFormObject,
|
||||||
@@ -45,6 +45,7 @@ export default
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
LookUpInit({
|
LookUpInit({
|
||||||
url: GetBasePath('organization'),
|
url: GetBasePath('organization'),
|
||||||
scope: $scope,
|
scope: $scope,
|
||||||
@@ -62,6 +63,28 @@ export default
|
|||||||
callback: 'choicesReady'
|
callback: 'choicesReady'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$scope.$watch('headers', function validate_headers(str) {
|
||||||
|
try {
|
||||||
|
let headers = JSON.parse(str);
|
||||||
|
if (_.isObject(headers) && !_.isArray(headers)) {
|
||||||
|
let valid = true;
|
||||||
|
for (let k in headers) {
|
||||||
|
if (_.isObject(headers[k])) {
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
if (headers[k] === null) {
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$scope.notification_template_form.headers.$setValidity('json', valid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
}
|
||||||
|
|
||||||
|
$scope.notification_template_form.headers.$setValidity('json', false);
|
||||||
|
});
|
||||||
|
|
||||||
$scope.typeChange = function () {
|
$scope.typeChange = function () {
|
||||||
for(var fld in form.fields){
|
for(var fld in form.fields){
|
||||||
if(form.fields[fld] && form.fields[fld].subForm){
|
if(form.fields[fld] && form.fields[fld].subForm){
|
||||||
@@ -73,6 +96,18 @@ export default
|
|||||||
NotificationsTypeChange.getDetailFields($scope.notification_type.value).forEach(function(field) {
|
NotificationsTypeChange.getDetailFields($scope.notification_type.value).forEach(function(field) {
|
||||||
$scope[field[0]] = field[1];
|
$scope[field[0]] = field[1];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$scope.parse_type = 'json';
|
||||||
|
if (!$scope.headers) {
|
||||||
|
$scope.headers = "{\n}";
|
||||||
|
}
|
||||||
|
ParseTypeChange({
|
||||||
|
scope: $scope,
|
||||||
|
parse_variable: 'parse_type',
|
||||||
|
variable: 'headers',
|
||||||
|
field_id: 'notification_template_headers'
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
@@ -91,7 +126,11 @@ export default
|
|||||||
|
|
||||||
function processValue(value, i , field){
|
function processValue(value, i , field){
|
||||||
if(field.type === 'textarea'){
|
if(field.type === 'textarea'){
|
||||||
$scope[i] = $scope[i].toString().split('\n');
|
if (field.name == 'headers') {
|
||||||
|
$scope[i] = JSON.parse($scope[i]);
|
||||||
|
} else {
|
||||||
|
$scope[i] = $scope[i].toString().split('\n');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(field.type === 'checkbox'){
|
if(field.type === 'checkbox'){
|
||||||
$scope[i] = Boolean($scope[i]);
|
$scope[i] = Boolean($scope[i]);
|
||||||
@@ -100,7 +139,6 @@ export default
|
|||||||
$scope[i] = Number($scope[i]);
|
$scope[i] = Number($scope[i]);
|
||||||
}
|
}
|
||||||
return $scope[i];
|
return $scope[i];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
params.notification_configuration = _.object(Object.keys(form.fields)
|
params.notification_configuration = _.object(Object.keys(form.fields)
|
||||||
|
|||||||
@@ -10,14 +10,14 @@ export default
|
|||||||
'GenerateForm', 'SearchInit' , 'PaginateInit',
|
'GenerateForm', 'SearchInit' , 'PaginateInit',
|
||||||
'LookUpInit', 'OrganizationList', 'notification_template',
|
'LookUpInit', 'OrganizationList', 'notification_template',
|
||||||
'$scope', '$state', 'GetChoices', 'CreateSelect2', 'Empty',
|
'$scope', '$state', 'GetChoices', 'CreateSelect2', 'Empty',
|
||||||
'$rootScope', 'NotificationsTypeChange',
|
'$rootScope', 'NotificationsTypeChange', 'ParseTypeChange',
|
||||||
function(
|
function(
|
||||||
Rest, Wait,
|
Rest, Wait,
|
||||||
NotificationsFormObject, ProcessErrors, GetBasePath,
|
NotificationsFormObject, ProcessErrors, GetBasePath,
|
||||||
GenerateForm, SearchInit, PaginateInit,
|
GenerateForm, SearchInit, PaginateInit,
|
||||||
LookUpInit, OrganizationList, notification_template,
|
LookUpInit, OrganizationList, notification_template,
|
||||||
$scope, $state, GetChoices, CreateSelect2, Empty,
|
$scope, $state, GetChoices, CreateSelect2, Empty,
|
||||||
$rootScope, NotificationsTypeChange
|
$rootScope, NotificationsTypeChange, ParseTypeChange
|
||||||
) {
|
) {
|
||||||
var generator = GenerateForm,
|
var generator = GenerateForm,
|
||||||
id = notification_template.id,
|
id = notification_template.id,
|
||||||
@@ -59,7 +59,11 @@ export default
|
|||||||
master[fld] = data.notification_configuration[fld];
|
master[fld] = data.notification_configuration[fld];
|
||||||
|
|
||||||
if(form.fields[fld].type === 'textarea'){
|
if(form.fields[fld].type === 'textarea'){
|
||||||
$scope[fld] = $scope[fld].toString().replace(',' , '\n');
|
if (form.fields[fld].name == 'headers') {
|
||||||
|
$scope[fld] = JSON.stringify($scope[fld], null, 2);
|
||||||
|
} else {
|
||||||
|
$scope[fld] = $scope[fld].toString().replace(',' , '\n');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,6 +92,17 @@ export default
|
|||||||
$scope[field[0]] = field[1];
|
$scope[field[0]] = field[1];
|
||||||
});
|
});
|
||||||
$scope.notification_obj = data;
|
$scope.notification_obj = data;
|
||||||
|
|
||||||
|
$scope.parse_type = 'json';
|
||||||
|
if (!$scope.headers) {
|
||||||
|
$scope.headers = "{\n}";
|
||||||
|
}
|
||||||
|
ParseTypeChange({
|
||||||
|
scope: $scope,
|
||||||
|
parse_variable: 'parse_type',
|
||||||
|
variable: 'headers',
|
||||||
|
field_id: 'notification_template_headers',
|
||||||
|
});
|
||||||
Wait('stop');
|
Wait('stop');
|
||||||
})
|
})
|
||||||
.error(function (data, status) {
|
.error(function (data, status) {
|
||||||
@@ -112,6 +127,29 @@ export default
|
|||||||
callback: 'choicesReady'
|
callback: 'choicesReady'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$scope.$watch('headers', function validate_headers(str) {
|
||||||
|
try {
|
||||||
|
let headers = JSON.parse(str);
|
||||||
|
if (_.isObject(headers) && !_.isArray(headers)) {
|
||||||
|
let valid = true;
|
||||||
|
for (let k in headers) {
|
||||||
|
if (_.isObject(headers[k])) {
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
if (headers[k] === null) {
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$scope.notification_template_form.headers.$setValidity('json', valid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
}
|
||||||
|
|
||||||
|
$scope.notification_template_form.headers.$setValidity('json', false);
|
||||||
|
});
|
||||||
|
|
||||||
$scope.typeChange = function () {
|
$scope.typeChange = function () {
|
||||||
for(var fld in form.fields){
|
for(var fld in form.fields){
|
||||||
if(form.fields[fld] && form.fields[fld].subForm){
|
if(form.fields[fld] && form.fields[fld].subForm){
|
||||||
@@ -123,6 +161,17 @@ export default
|
|||||||
NotificationsTypeChange.getDetailFields($scope.notification_type.value).forEach(function(field) {
|
NotificationsTypeChange.getDetailFields($scope.notification_type.value).forEach(function(field) {
|
||||||
$scope[field[0]] = field[1];
|
$scope[field[0]] = field[1];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$scope.parse_type = 'json';
|
||||||
|
if (!$scope.headers) {
|
||||||
|
$scope.headers = "{\n}";
|
||||||
|
}
|
||||||
|
ParseTypeChange({
|
||||||
|
scope: $scope,
|
||||||
|
parse_variable: 'parse_type',
|
||||||
|
variable: 'headers',
|
||||||
|
field_id: 'notification_template_headers',
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.formSave = function(){
|
$scope.formSave = function(){
|
||||||
@@ -140,13 +189,19 @@ export default
|
|||||||
|
|
||||||
function processValue(value, i , field){
|
function processValue(value, i , field){
|
||||||
if(field.type === 'textarea'){
|
if(field.type === 'textarea'){
|
||||||
$scope[i] = $scope[i].toString().split('\n');
|
if (field.name == 'headers') {
|
||||||
|
$scope[i] = JSON.parse($scope[i]);
|
||||||
|
} else {
|
||||||
|
$scope[i] = $scope[i].toString().split('\n');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(field.type === 'checkbox'){
|
if(field.type === 'checkbox'){
|
||||||
$scope[i] = Boolean($scope[i]);
|
$scope[i] = Boolean($scope[i]);
|
||||||
}
|
}
|
||||||
|
if(field.type === 'number'){
|
||||||
|
$scope[i] = Number($scope[i]);
|
||||||
|
}
|
||||||
return $scope[i];
|
return $scope[i];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
params.notification_configuration = _.object(Object.keys(form.fields)
|
params.notification_configuration = _.object(Object.keys(form.fields)
|
||||||
|
|||||||
@@ -297,11 +297,19 @@ export default function() {
|
|||||||
},
|
},
|
||||||
headers: {
|
headers: {
|
||||||
label: 'HTTP Headers',
|
label: 'HTTP Headers',
|
||||||
type: 'text',
|
type: 'textarea',
|
||||||
|
rows: 5,
|
||||||
awRequiredWhen: {
|
awRequiredWhen: {
|
||||||
reqExpression: "webhook_required",
|
reqExpression: "webhook_required",
|
||||||
init: "false"
|
init: "false"
|
||||||
},
|
},
|
||||||
|
awPopOver: '<p>Specify HTTP Headers in JSON format</p>'
|
||||||
|
+ '<p>For example:<br><pre>\n'
|
||||||
|
+ '{\n'
|
||||||
|
+ ' "X-Auth-Token": "828jf0",\n'
|
||||||
|
+ ' "X-Ansible": "Is great!"\n'
|
||||||
|
+ '}\n'
|
||||||
|
+ '</pre></p>',
|
||||||
ngShow: "notification_type.value == 'webhook' ",
|
ngShow: "notification_type.value == 'webhook' ",
|
||||||
subForm: 'typeSubForm'
|
subForm: 'typeSubForm'
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user