From ce879f58d8f530def885bd38a83aeffb1ac93034 Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Thu, 4 Dec 2014 10:27:52 -0500 Subject: [PATCH] Added Organization lookup to custom inv script The custom inventory script form needed to have an organization associated with it, so I added a lookup to the form and made sure this was incorporated with the Reset functionality --- awx/ui/static/js/forms/CustomInventory.js | 9 +++++ awx/ui/static/js/helpers/CustomInventory.js | 42 +++++++++++++++++---- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/awx/ui/static/js/forms/CustomInventory.js b/awx/ui/static/js/forms/CustomInventory.js index 4cf7d07c9b..97b6413375 100644 --- a/awx/ui/static/js/forms/CustomInventory.js +++ b/awx/ui/static/js/forms/CustomInventory.js @@ -34,6 +34,15 @@ angular.module('CustomInventoryFormDefinition', []) addRequired: false, editRequired: false }, + organization: { + label: 'Organization', + type: 'lookup', + sourceModel: 'organization', + sourceField: 'name', + ngClick: 'lookUpOrganization()', + addRequired: false, + editRequired: false + }, script: { label: 'Custom Script', type: 'textarea', diff --git a/awx/ui/static/js/helpers/CustomInventory.js b/awx/ui/static/js/helpers/CustomInventory.js index 5dc7489e1b..7c1d564a35 100644 --- a/awx/ui/static/js/helpers/CustomInventory.js +++ b/awx/ui/static/js/helpers/CustomInventory.js @@ -177,9 +177,9 @@ angular.module('CreateCustomInventoryHelper', [ 'Utilities', 'RestServices', 'Sc .factory('CustomInventoryAdd', ['$compile','SchedulerInit', 'Rest', 'Wait', 'CustomInventoryList', 'CustomInventoryForm', 'ProcessErrors', 'GetBasePath', 'Empty', 'GenerateForm', - 'SearchInit' , 'PaginateInit', 'GenerateList', + 'SearchInit' , 'PaginateInit', 'GenerateList', 'LookUpInit', 'OrganizationList', function($compile, SchedulerInit, Rest, Wait, CustomInventoryList, CustomInventoryForm, ProcessErrors, GetBasePath, Empty, GenerateForm, - SearchInit, PaginateInit, GenerateList) { + SearchInit, PaginateInit, GenerateList, LookUpInit, OrganizationList) { return function(params) { var scope = params.scope, generator = GenerateForm, @@ -191,12 +191,22 @@ function($compile, SchedulerInit, Rest, Wait, CustomInventoryList, CustomInvento generator.inject(form, { id:'custom-script-dialog', mode: 'add' , scope:scope, related: false, breadCrumbs: false}); generator.reset(); + LookUpInit({ + url: GetBasePath('organization'), + scope: scope, + form: form, + // hdr: "Select Custom Inventory", + list: OrganizationList, + field: 'organization', + input_type: 'radio' + }); + // Save scope.formSave = function () { generator.clearApiErrors(); Wait('start'); Rest.setUrl(url); - Rest.post({ name: scope.name, description: scope.description, script: scope.script }) + Rest.post({ name: scope.name, description: scope.description, organization: scope.organization, script: scope.script }) .success(function () { view.inject( list, { id : 'custom-script-dialog', @@ -238,9 +248,9 @@ function($compile, SchedulerInit, Rest, Wait, CustomInventoryList, CustomInvento }]) .factory('CustomInventoryEdit', ['$compile','CustomInventoryList', 'Rest', 'Wait', 'GenerateList', 'CustomInventoryForm', 'ProcessErrors', 'GetBasePath', 'Empty', 'GenerateForm', - 'SearchInit', 'PaginateInit', '$routeParams', + 'SearchInit', 'PaginateInit', '$routeParams', 'OrganizationList', 'LookUpInit', function($compile, CustomInventoryList, Rest, Wait, GenerateList, CustomInventoryForm, ProcessErrors, GetBasePath, Empty, GenerateForm, - SearchInit, PaginateInit, $routeParams) { + SearchInit, PaginateInit, $routeParams, OrganizationList, LookUpInit) { return function(params) { var scope = params.scope, id = params.id, @@ -260,6 +270,15 @@ function($compile, CustomInventoryList, Rest, Wait, GenerateList, CustomInventor activityStream: false }); generator.reset(); + LookUpInit({ + url: GetBasePath('organization'), + scope: scope, + form: form, + // hdr: "Select Custom Inventory", + list: OrganizationList, + field: 'organization', + input_type: 'radio' + }); // Retrieve detail record and prepopulate the form Wait('start'); @@ -272,6 +291,14 @@ function($compile, CustomInventoryList, Rest, Wait, GenerateList, CustomInventor scope[fld] = data[fld]; master[fld] = data[fld]; } + + if (form.fields[fld].sourceModel && data.summary_fields && + data.summary_fields[form.fields[fld].sourceModel]) { + scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] = + data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField]; + master[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] = + data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField]; + } } Wait('stop'); }) @@ -284,7 +311,7 @@ function($compile, CustomInventoryList, Rest, Wait, GenerateList, CustomInventor generator.clearApiErrors(); Wait('start'); Rest.setUrl(url+ id+'/'); - Rest.put({ name: scope.name, description: scope.description, script: scope.script }) + Rest.put({ name: scope.name, description: scope.description, organization: scope.organization, script: scope.script }) .success(function () { view.inject( list, { id : 'custom-script-dialog', @@ -320,10 +347,11 @@ function($compile, CustomInventoryList, Rest, Wait, GenerateList, CustomInventor scope.formReset = function () { generator.reset(); - //$('#forks-slider').slider("option", "value", $scope.forks); for (var fld in master) { scope[fld] = master[fld]; } + scope.organization_name = master.organization_name; + }; }; }]);