diff --git a/awx/ui/client/src/configuration/configuration.route.js b/awx/ui/client/src/configuration/configuration.route.js index 0026ec9e3c..94eae6bcaf 100644 --- a/awx/ui/client/src/configuration/configuration.route.js +++ b/awx/ui/client/src/configuration/configuration.route.js @@ -16,7 +16,9 @@ export default { name: 'configuration', route: '/configuration/:currentTab', - + params: { + currentTab: '' + }, ncyBreadcrumb: { label: "Edit Configuration" }, diff --git a/awx/ui/client/src/shared/form-generator.js b/awx/ui/client/src/shared/form-generator.js index 6211a95ec0..b996f16607 100644 --- a/awx/ui/client/src/shared/form-generator.js +++ b/awx/ui/client/src/shared/form-generator.js @@ -172,6 +172,205 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat `; }, + inject: function (form, options) { + // + // Use to inject the form as html into the view. View MUST have an ng-bind for 'htmlTemplate'. + // Returns scope of form. + // + + var element, fld, set, show, self = this; + + if (options.modal) { + if (options.modal_body_id) { + element = angular.element(document.getElementById(options.modal_body_id)); + } else { + // use default dialog + element = angular.element(document.getElementById('form-modal-body')); + } + } else { + if (options.id) { + element = angular.element(document.getElementById(options.id)); + } else { + element = angular.element(document.getElementById('htmlTemplate')); + } + } + + this.mode = options.mode; + this.modal = (options.modal) ? true : false; + this.setForm(form); + + if (options.html) { + element.html(options.html); + } else { + element.html(this.build(options)); + } + + if (options.scope) { + this.scope = options.scope; + } else { + this.scope = element.scope(); + } + + if (options.mode) { + this.scope.mode = options.mode; + } + + if(options.mode === 'edit' && this.form.related && + !_.isEmpty(this.form.related)){ + var tabs = [this.form.name], that = this; + tabs.push(Object.keys(this.form.related)); + tabs = _.flatten(tabs); + _.map(tabs, function(itm){ + that.scope.$parent[itm+"Selected"] = false; + }); + this.scope.$parent[this.form.name+"Selected"] = true; + + + this.scope.$parent.toggleFormTabs = function($event){ + _.map(tabs, function(itm){ + that.scope.$parent[itm+"Selected"] = false; + }); + that.scope.$parent[$event.target.id.split('_tab')[0]+"Selected"] = true; + }; + + } + + for (fld in form.fields) { + this.scope[fld + '_field'] = form.fields[fld]; + this.scope[fld + '_field'].name = fld; + } + + for (fld in form.headerFields){ + this.scope[fld + '_field'] = form.headerFields[fld]; + this.scope[fld + '_field'].name = fld; + } + + $compile(element)(this.scope); + + if (!options.html) { + // Reset the scope to prevent displaying old data from our last visit to this form + for (fld in form.fields) { + this.scope[fld] = null; + } + for (set in form.related) { + this.scope[set] = null; + } + // if (((!options.modal) && options.related) || this.form.forceListeners) { + // this.addListeners(); + // } + if (options.mode === 'add') { + this.applyDefaults(); + } + } + + // Remove any lingering tooltip and popover