From 8c7a4b56f7ae3c4ab0a0b4854ac8d1a83336cac4 Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Fri, 4 Nov 2016 10:56:13 -0700 Subject: [PATCH] putting form-generator.inject() back into the app for backwards compatibility with features that relied on that function. see: ctit --- .../src/configuration/configuration.route.js | 4 +- awx/ui/client/src/shared/form-generator.js | 199 ++++++++++++++++++ 2 files changed, 202 insertions(+), 1 deletion(-) 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
elements + $('.tooltip').each(function () { + $(this).remove(); + }); + + $('.popover').each(function () { + // remove lingering popover
. Seems to be a bug in TB3 RC1 + $(this).remove(); + }); + + // Prepend an asterisk to required field label + $('.form-control[required], input[type="radio"][required]').each(function () { + var label, span; + if (Empty($(this).attr('aw-required-when'))) { + label = $(this).closest('.form-group').find('label').first(); + if (label.length > 0) { + span = label.children('span'); + if (span.length > 0 && !span.first().hasClass('prepend-asterisk')) { + span.first().addClass('prepend-asterisk'); + } else if (span.length <= 0 && !label.first().hasClass('prepend-asterisk')) { + label.first().addClass('prepend-asterisk'); + } + } + } + }); + + try { + $('#help-modal').empty().dialog('destroy'); + } catch (e) { + //ignore any errors should the dialog not be initialized + } + + if (options.modal) { + $rootScope.flashMessage = null; + this.scope.formModalActionDisabled = false; + this.scope.formModalInfo = false; //Disable info button for default modal + if (form) { + if (options.modal_title_id) { + this.scope[options.modal_title_id] = (options.mode === 'add') ? form.addTitle : form.editTitle; + } else { + this.scope.formModalHeader = (options.mode === 'add') ? form.addTitle : form.editTitle; //Default title for default modal + } + } + if (options.modal_selector) { + $(options.modal_selector).modal({ + show: true, + backdrop: 'static', + keyboard: true + }); + $(options.modal_selector).on('shown.bs.modal', function () { + $(options.modal_select + ' input:first').focus(); + }); + $(options.modal_selector).on('hidden.bs.modal', function () { + $('.tooltip').each(function () { + // Remove any lingering tooltip and popover
elements + $(this).remove(); + }); + + $('.popover').each(function () { + // remove lingering popover
. Seems to be a bug in TB3 RC1 + $(this).remove(); + }); + }); + } else { + show = (options.show_modal === false) ? false : true; + $('#form-modal').modal({ + show: show, + backdrop: 'static', + keyboard: true + }); + $('#form-modal').on('shown.bs.modal', function () { + $('#form-modal input:first').focus(); + }); + $('#form-modal').on('hidden.bs.modal', function () { + $('.tooltip').each(function () { + // Remove any lingering tooltip and popover
elements + $(this).remove(); + }); + + $('.popover').each(function () { + // remove lingering popover
. Seems to be a bug in TB3 RC1 + $(this).remove(); + }); + }); + } + $(document).bind('keydown', function (e) { + if (e.keyCode === 27) { + if (options.modal_selector) { + $(options.modal_selector).modal('hide'); + } + $('#prompt-modal').modal('hide'); + $('#form-modal').modal('hide'); + } + }); + } + + if (self.scope && !self.scope.$$phase) { + setTimeout(function() { + if (self.scope) { + self.scope.$digest(); + } + }, 100); + } + + return self.scope; + + }, + buildHTML: function(form, options) { // Get HTML without actually injecting into DOM. Caller is responsible for any injection. // Example: