mirror of
https://github.com/ansible/awx.git
synced 2026-05-24 00:57:48 -02:30
Applying jsHint standards to form-generator.js. Adding unminified jquery to facilitate debugging.
This commit is contained in:
@@ -11,9 +11,10 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
||||
.factory('GenerateForm', ['$rootScope', '$location', '$cookieStore', '$compile', 'SearchWidget', 'PaginateWidget', 'Attr',
|
||||
|
||||
.factory('GenerateForm', ['$rootScope', '$location', '$cookieStore', '$compile', 'SearchWidget', 'PaginateWidget', 'Attr',
|
||||
'Icon', 'Column', 'NavigationLink', 'HelpCollapse', 'Button', 'DropDown', 'Empty', 'SelectIcon',
|
||||
function($rootScope, $location, $cookieStore, $compile, SearchWidget, PaginateWidget, Attr, Icon, Column, NavigationLink,
|
||||
function($rootScope, $location, $cookieStore, $compile, SearchWidget, PaginateWidget, Attr, Icon, Column, NavigationLink,
|
||||
HelpCollapse, Button, DropDown, Empty, SelectIcon) {
|
||||
return {
|
||||
|
||||
@@ -30,7 +31,7 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
||||
scope: null,
|
||||
|
||||
has: function(key) {
|
||||
return (this.form[key] && this.form[key] != null && this.form[key] != undefined) ? true : false;
|
||||
return (this.form[key] && this.form[key] !== null && this.form[key] !== undefined) ? true : false;
|
||||
},
|
||||
|
||||
inject: function(form, options) {
|
||||
@@ -39,7 +40,8 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
||||
// Returns scope of form.
|
||||
//
|
||||
|
||||
var element;
|
||||
var element, fld, set, show;
|
||||
|
||||
if (options.modal) {
|
||||
if (options.modal_body_id) {
|
||||
element = angular.element(document.getElementById(options.modal_body_id));
|
||||
@@ -80,26 +82,26 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
||||
|
||||
if (!options.html) {
|
||||
// Reset the scope to prevent displaying old data from our last visit to this form
|
||||
for (var fld in form.fields) {
|
||||
for (fld in form.fields) {
|
||||
this.scope[fld] = null;
|
||||
}
|
||||
for (var set in form.related) {
|
||||
for (set in form.related) {
|
||||
this.scope[set] = null;
|
||||
}
|
||||
if ( ((!options.modal) && options.related) || this.form.forceListeners ) {
|
||||
this.addListeners();
|
||||
}
|
||||
if (options.mode == 'add') {
|
||||
if (options.mode === 'add') {
|
||||
this.applyDefaults();
|
||||
}
|
||||
}
|
||||
|
||||
// Remove any lingering tooltip and popover <div> elements
|
||||
$('.tooltip').each( function(index) {
|
||||
$('.tooltip').each( function() {
|
||||
$(this).remove();
|
||||
});
|
||||
|
||||
$('.popover').each(function(index) {
|
||||
$('.popover').each(function() {
|
||||
// remove lingering popover <div>. Seems to be a bug in TB3 RC1
|
||||
$(this).remove();
|
||||
});
|
||||
@@ -108,13 +110,14 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
||||
|
||||
// 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')) ) {
|
||||
var label = $(this).parent().parent().find('label').first();
|
||||
if ($(this).attr('type') == 'radio') {
|
||||
label = $(this).parent().parent().find('label').first();
|
||||
if ($(this).attr('type') === 'radio') {
|
||||
label = $(this).parent().parent().parent().find('label').first();
|
||||
}
|
||||
if (label.length > 0) {
|
||||
var span = label.children('span');
|
||||
span = label.children('span');
|
||||
if (span.length > 0 && !span.first().hasClass('prepend-asterisk')) {
|
||||
span.first().addClass('prepend-asterisk');
|
||||
}
|
||||
@@ -134,13 +137,13 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
||||
|
||||
if (options.modal) {
|
||||
this.scope.formModalActionDisabled = false;
|
||||
this.scope.formModalInfo = false //Disable info button for default modal
|
||||
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;
|
||||
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
|
||||
this.scope.formModalHeader = (options.mode === 'add') ? form.addTitle : form.editTitle; //Default title for default modal
|
||||
}
|
||||
}
|
||||
if (options.modal_selector) {
|
||||
@@ -149,7 +152,7 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
||||
$(options.modal_select + ' input:first').focus();
|
||||
});
|
||||
$(options.modal_selector).on('hidden.bs.modal', function() {
|
||||
$('.tooltip').each( function(index) {
|
||||
$('.tooltip').each( function() {
|
||||
// Remove any lingering tooltip and popover <div> elements
|
||||
$(this).remove();
|
||||
});
|
||||
@@ -161,7 +164,7 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
||||
});
|
||||
}
|
||||
else {
|
||||
var show = (options.show_modal == false) ? false : true;
|
||||
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();
|
||||
@@ -198,8 +201,8 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
||||
|
||||
applyDefaults: function() {
|
||||
for (var fld in this.form.fields) {
|
||||
if (this.form.fields[fld]['default'] || this.form.fields[fld]['default'] == 0) {
|
||||
if (this.form.fields[fld].type == 'select' && this.scope[fld + '_options']) {
|
||||
if (this.form.fields[fld].default || this.form.fields[fld].default === 0) {
|
||||
if (this.form.fields[fld].type === 'select' && this.scope[fld + '_options']) {
|
||||
this.scope[fld] = this.scope[fld + '_options'][this.form.fields[fld]['default']];
|
||||
}
|
||||
else {
|
||||
@@ -213,17 +216,16 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
||||
// The form field values cannot be reset with jQuery. Each field is tied to a model, so to clear the field
|
||||
// value, you have to clear the model.
|
||||
|
||||
if (this.scope[this.form.name + '_form']) {
|
||||
this.scope[this.form.name + '_form'].$setPristine();
|
||||
}
|
||||
var fld, scope = this.scope, form = this.form;
|
||||
|
||||
var scope = this.scope;
|
||||
var form = this.form;
|
||||
if (scope[form.name + '_form']) {
|
||||
scope[form.name + '_form'].$setPristine();
|
||||
}
|
||||
|
||||
function resetField(f, fld) {
|
||||
// f is the field object, fld is the key
|
||||
|
||||
if (f.type == 'checkbox_group') {
|
||||
if (f.type === 'checkbox_group') {
|
||||
for (var i=0; i < f.fields.length; i++) {
|
||||
scope[f.fields[i].name] = '';
|
||||
scope[f.fields[i].name + '_api_error'] = '';
|
||||
@@ -241,7 +243,7 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
||||
scope[form.name + '_form'][f.sourceModel + '_' + f.sourceField].$setValidity('apiError', true);
|
||||
}
|
||||
}
|
||||
if (f.type == 'lookup' && scope[form.name + '_form'][f.sourceModel + '_' + f.sourceField]) {
|
||||
if (f.type === 'lookup' && scope[form.name + '_form'][f.sourceModel + '_' + f.sourceField]) {
|
||||
scope[form.name + '_form'][f.sourceModel + '_' + f.sourceField].$setPristine();
|
||||
scope[form.name + '_form'][f.sourceModel + '_' + f.sourceField].$setValidity('apiError', true);
|
||||
}
|
||||
@@ -261,15 +263,15 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
||||
}
|
||||
}
|
||||
|
||||
for (var fld in form.fields) {
|
||||
for (fld in form.fields) {
|
||||
resetField(form.fields[fld], fld);
|
||||
}
|
||||
if (form.statusFields) {
|
||||
for (var fld in form.statusFields) {
|
||||
for (fld in form.statusFields) {
|
||||
resetField(form.statusFields[fld], fld);
|
||||
}
|
||||
}
|
||||
if (this.mode == 'add') {
|
||||
if (this.mode === 'add') {
|
||||
this.applyDefaults();
|
||||
}
|
||||
},
|
||||
@@ -290,27 +292,29 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
||||
$(selector + '-icon').removeClass('fa-minus').addClass('fa-plus');
|
||||
}
|
||||
else {
|
||||
$(selector + '-icon').removeClass('fa-plus').addClass('fa-minus')
|
||||
}
|
||||
$(selector + '-icon').removeClass('fa-plus').addClass('fa-minus');
|
||||
}
|
||||
};
|
||||
|
||||
$('.jqui-accordion').each( function(index) {
|
||||
|
||||
var active = false;
|
||||
var list = $cookieStore.get('accordions');
|
||||
var found = false;
|
||||
var active = false,
|
||||
list = $cookieStore.get('accordions'),
|
||||
found = false,
|
||||
id, base, i;
|
||||
|
||||
if (list) {
|
||||
var id = $(this).attr('id');
|
||||
var base = ($location.path().replace(/^\//,'').split('/')[0]);
|
||||
for (var i=0; i < list.length && found == false; i++) {
|
||||
if (list[i].base == base && list[i].id == id) {
|
||||
id = $(this).attr('id');
|
||||
base = ($location.path().replace(/^\//,'').split('/')[0]);
|
||||
for (i=0; i < list.length && found === false; i++) {
|
||||
if (list[i].base === base && list[i].id === id) {
|
||||
found = true;
|
||||
active = list[i].active;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (found == false && $(this).attr('data-open') == 'true') {
|
||||
if (found === false && $(this).attr('data-open') === 'true') {
|
||||
active = 0;
|
||||
}
|
||||
|
||||
@@ -320,21 +324,22 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
||||
active: active,
|
||||
activate: function( event, ui ) {
|
||||
$('.jqui-accordion').each( function(index) {
|
||||
var active = $(this).accordion('option', 'active');
|
||||
var id = $(this).attr('id');
|
||||
var base = ($location.path().replace(/^\//,'').split('/')[0]);
|
||||
var list = $cookieStore.get('accordions');
|
||||
if (list == null || list == undefined) {
|
||||
var active = $(this).accordion('option', 'active'),
|
||||
id = $(this).attr('id'),
|
||||
base = ($location.path().replace(/^\//,'').split('/')[0]),
|
||||
list = $cookieStore.get('accordions'),
|
||||
i, found;
|
||||
if (list === null || list === undefined) {
|
||||
list = [];
|
||||
}
|
||||
var found = false;
|
||||
for (var i=0; i < list.length && found == false; i++) {
|
||||
if ( list[i].base == base && list[i].id == id) {
|
||||
found = false;
|
||||
for (i=0; i < list.length && found === false; i++) {
|
||||
if ( list[i].base === base && list[i].id === id) {
|
||||
found = true;
|
||||
list[i].active = active;
|
||||
}
|
||||
}
|
||||
if (found == false) {
|
||||
if (found === false) {
|
||||
list.push({ base: base, id: id, active: active });
|
||||
}
|
||||
$cookieStore.put('accordions',list);
|
||||
@@ -388,9 +393,9 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
||||
|
||||
|
||||
buildHelpCollapse: function(collapse_array) {
|
||||
var html = '';
|
||||
var params = {};
|
||||
for (var i=0; i < collapse_array.length; i++) {
|
||||
var html = '',
|
||||
params = {}, i;
|
||||
for (i=0; i < collapse_array.length; i++) {
|
||||
params.hdr = collapse_array[i].hdr;
|
||||
params.content = collapse_array[i].content;
|
||||
params.idx = this.accordion_count++;
|
||||
@@ -453,18 +458,17 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
||||
}
|
||||
|
||||
function buildCheckbox(form, field, fld, idx, includeLabel) {
|
||||
var html = '';
|
||||
var label = (includeLabel !== undefined && includeLabel == false) ? false : true;
|
||||
var html = '',
|
||||
label = (includeLabel !== undefined && includeLabel === false) ? false : true;
|
||||
|
||||
if (label) {
|
||||
html += "<label class=\"";
|
||||
html += (field.inline == undefined || field.inline == true) ? "checkbox-inline" : "";
|
||||
html += (field.inline === undefined || field.inline === true) ? "checkbox-inline" : "";
|
||||
html += (field.labelClass) ? " " + field.labelClass : "";
|
||||
html += "\">";
|
||||
}
|
||||
|
||||
html += "<input type=\"checkbox\" ";
|
||||
//html += (!label) ? "style=\"padding-top:5px;\" " : "";
|
||||
html += Attr(field,'type');
|
||||
html += "ng-model=\"" + fld + '" ';
|
||||
html += "name=\"" + fld + '" ';
|
||||
@@ -473,7 +477,6 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
||||
html += (idx !== undefined) ? "_" + idx : "";
|
||||
html += "class=\"";
|
||||
html += (field['class']) ? field['class'] + " " : "";
|
||||
//html += (!label) ? "checkbox-no-label" : "";
|
||||
html += "\"";
|
||||
html += (field.trueValue !== undefined) ? Attr(field,'trueValue') : "";
|
||||
html += (field.falseValue !== undefined) ? Attr(field,'falseValue') : "";
|
||||
@@ -503,8 +506,7 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
||||
}
|
||||
html += (field.labelNGClass) ? "ng-class=\"" + field.labelNGClass + "\" " : "";
|
||||
html += "for=\"" + fld + '">';
|
||||
//html += (field.awPopOver && !field.awPopOverRight) ? Attr(field, 'awPopOver', fld) : "";
|
||||
html += (field.icon) ? this.icon(field.icon) : "";
|
||||
html += (field.icon) ? Icon(field.icon) : "";
|
||||
html += "<span class=\"label-text\">" + field.label + "</span>";
|
||||
html += (field.awPopOver && !field.awPopOverRight) ? Attr(field, 'awPopOver', fld) : "";
|
||||
html += "</label>\n";
|
||||
@@ -512,21 +514,21 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
||||
return html;
|
||||
}
|
||||
|
||||
var html = '';
|
||||
var horizontal = (this.form.horizontal) ? true : false;
|
||||
var html = '',
|
||||
horizontal = (this.form.horizontal) ? true : false;
|
||||
|
||||
if (field.type == 'alertblock') {
|
||||
if (field.type === 'alertblock') {
|
||||
html += "<div class=\"row\">\n";
|
||||
html += "<div class=\"";
|
||||
html += (options.modal || options.id) ? "col-lg-12" : "col-lg-8 col-lg-offset-2";
|
||||
html += "\">\n";
|
||||
html += "<div class=\"alert";
|
||||
html += (field.closeable == undefined || field.closeable == true) ? " alert-dismissable" : "";
|
||||
html += (field.closeable === undefined || field.closeable === true) ? " alert-dismissable" : "";
|
||||
html += (field['class']) ? " " + field['class'] : "";
|
||||
html += "\" ";
|
||||
html += (field.ngShow) ? this.attr(field, 'ngShow') : "";
|
||||
html += ">\n";
|
||||
html += (field.closeable == undefined || field.closeable == true) ?
|
||||
html += (field.closeable === undefined || field.closeable === true) ?
|
||||
"<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">×</button>\n" : "";
|
||||
html += field.alertTxt;
|
||||
html += "</div>\n";
|
||||
@@ -534,24 +536,22 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
||||
html += "</div>\n";
|
||||
}
|
||||
|
||||
if (field.type == 'hidden') {
|
||||
if ( (options.mode == 'edit' && field.includeOnEdit) ||
|
||||
(options.mode == 'add' && field.includeOnAdd) ) {
|
||||
if (field.type === 'hidden') {
|
||||
if ( (options.mode === 'edit' && field.includeOnEdit) ||
|
||||
(options.mode === 'add' && field.includeOnAdd) ) {
|
||||
html += "<input type=\"hidden\" ng-model=\"" + fld + "\" name=\"" + fld + "\" />";
|
||||
}
|
||||
}
|
||||
|
||||
if ( (! field.readonly) || (field.readonly && options.mode == 'edit') ) {
|
||||
if ( (! field.readonly) || (field.readonly && options.mode === 'edit') ) {
|
||||
html += "<div class=\"form-group\" ";
|
||||
html += (field.ngShow) ? this.attr(field,'ngShow') : "";
|
||||
html += (field.ngHide) ? this.attr(field,'ngHide') : "";
|
||||
html += ">\n";
|
||||
|
||||
//text fields
|
||||
if (field.type == 'text' || field.type == 'password' || field.type == 'email') {
|
||||
|
||||
if (field.type === 'text' || field.type === 'password' || field.type === 'email') {
|
||||
html += label();
|
||||
|
||||
html += "<div ";
|
||||
html += (horizontal) ? "class=\"" + getFieldWidth() + "\"" : "";
|
||||
html += ">\n";
|
||||
@@ -571,8 +571,8 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
||||
html += (field['class']) ? " " + this.attr(field, 'class') : "";
|
||||
html += "\" ";
|
||||
html += (field.placeholder) ? this.attr(field,'placeholder') : "";
|
||||
html += (options.mode == 'edit' && field.editRequired) ? "required " : "";
|
||||
html += (options.mode == 'add' && field.addRequired) ? "required " : "";
|
||||
html += (options.mode === 'edit' && field.editRequired) ? "required " : "";
|
||||
html += (options.mode === 'add' && field.addRequired) ? "required " : "";
|
||||
html += (field.readonly || field.showonly) ? "readonly " : "";
|
||||
html += (field.awPassMatch) ? "awpassmatch=\"" + field.associated + "\" " : "";
|
||||
html += (field.capitalize) ? "capitalize " : "";
|
||||
@@ -854,8 +854,7 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
||||
html += (field.labelBind) ? "ng-bind=\"" + field.labelBind + "\" " : "";
|
||||
html += "for=\"" + fld + '">';
|
||||
html += buildCheckbox(this.form, field, fld, undefined, false);
|
||||
html += (field.icon) ? this.icon(field.icon) : "";
|
||||
//html += (field.awPopOver && !field.awPopOverRight) ? this.attr(field, 'awPopOver', fld) : "";
|
||||
html += (field.icon) ? Icon(field.icon) : "";
|
||||
html += '<span class=\"label-text\">' + field.label + "</span>";
|
||||
html += (field.awPopOver) ? this.attr(field, 'awPopOver', fld) : "";
|
||||
html += "</label>\n";
|
||||
|
||||
9789
awx/ui/static/lib/jquery/jquery-1.10.2.js
vendored
Normal file
9789
awx/ui/static/lib/jquery/jquery-1.10.2.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user