AC-351 latest changes. Fixed project add/edit form issues.

This commit is contained in:
chouseknecht
2013-08-29 17:31:16 -04:00
parent 45b7c44c09
commit d774327c68
3 changed files with 172 additions and 118 deletions

View File

@@ -104,6 +104,8 @@ function ProjectsAdd ($scope, $rootScope, $compile, $location, $log, $routeParam
LoadBreadCrumbs();
GetProjectPath({ scope: scope, master: master });
scope.scm_type = null;
master.scm_type = null;
scope.scm_type_options = [
{ label: 'GitHub', value: 'git' },
{ label: 'SVN', value: 'svn' }];
@@ -120,10 +122,18 @@ function ProjectsAdd ($scope, $rootScope, $compile, $location, $log, $routeParam
scope.formSave = function() {
var data = {};
for (var fld in form.fields) {
if (form.fields[fld].type == 'checkbox_group') {
for (var i=0; i < form.fields[fld].fields.length; i++) {
data[form.fields[fld].fields[i].name] = scope[form.fields[fld].fields[i].name];
}
}
else {
data[fld] = scope[fld];
}
}
if (scope.scm_type) {
data.scm_type = scope.scm_type.value;
delete data.local_path;
}
var url = (base == 'teams') ? GetBasePath('teams') + $routeParams.team_id + '/projects/' : defaultUrl;
Rest.setUrl(url);
@@ -149,6 +159,11 @@ function ProjectsAdd ($scope, $rootScope, $compile, $location, $log, $routeParam
});
};
scope.scmChange = function() {
// When an scm_type is set, path is not required
scope.pathRequired = (scope.scm_type) ? false : true;
}
// Cancel
scope.formReset = function() {
$rootScope.flashMessage = null;
@@ -231,11 +246,19 @@ function ProjectsEdit ($scope, $rootScope, $compile, $location, $log, $routePara
.success( function(data, status, headers, config) {
LoadBreadCrumbs({ path: '/projects/' + id, title: data.name });
for (var fld in form.fields) {
if (form.fields[fld].type == 'checkbox_group') {
for (var i=0; i < form.fields[fld].fields.length; i++) {
scope[form.fields[fld].fields[i].name] = data[form.fields[fld].fields[i].name];
master[form.fields[fld].fields[i].name] = data[form.fields[fld].fields[i].name];
}
}
else {
if (data[fld]) {
scope[fld] = data[fld];
master[fld] = data[fld];
}
}
}
var related = data.related;
for (var set in form.related) {
if (related[set]) {
@@ -250,7 +273,12 @@ function ProjectsEdit ($scope, $rootScope, $compile, $location, $log, $routePara
break;
}
}
scope.pathRequired = false;
}
else {
scope.pathRequired = true;
}
master['scm_type'] = scope['scm_type'];
setAskCheckboxes();
@@ -270,10 +298,18 @@ function ProjectsEdit ($scope, $rootScope, $compile, $location, $log, $routePara
$rootScope.flashMessage = null;
var params = {};
for (var fld in form.fields) {
if (form.fields[fld].type == 'checkbox_group') {
for (var i=0; i < form.fields[fld].fields.length; i++) {
params[form.fields[fld].fields[i].name] = scope[form.fields[fld].fields[i].name];
}
}
else {
params[fld] = scope[fld];
}
}
if (scope.scm_type) {
params.scm_type = scope.scm_type.value;
delete params.local_path;
}
Rest.setUrl(defaultUrl);
Rest.put(params)
@@ -359,6 +395,11 @@ function ProjectsEdit ($scope, $rootScope, $compile, $location, $log, $routePara
scope[associated] = '';
scope[form.name + '_form'][associated].$setValidity('awpassmatch', true);
}
scope.scmChange = function() {
// When an scm_type is set, path is not required
scope.pathRequired = (scope.scm_type) ? false : true;
}
}
ProjectsEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'ProjectsForm',

View File

@@ -49,7 +49,7 @@ angular.module('ProjectFormDefinition', [])
base_dir: {
label: 'Project Base Path',
type: 'textarea',
"class": 'span6',
"class": 'col-lg-6',
showonly: true,
awPopOver: '<p>Base path used for locating playbooks. Directories found inside this path will be listed in the playbook directory drop-down. ' +
'Together the base path and selected playbook directory provide the full path used to locate playbooks.</p>' +
@@ -58,13 +58,24 @@ angular.module('ProjectFormDefinition', [])
dataContainer: 'body',
dataPlacement: 'right'
},
scm_type: {
label: 'SCM Type',
type: 'select',
ngOptions: 'type.label for type in scm_type_options',
ngChange: 'scmChange()',
"default": '',
addRequired: false,
editRequired: false
},
local_path: {
label: 'Playbook Directory',
type: 'select',
id: 'local-path-select',
ngOptions: 'path for path in project_local_paths',
addRequired: true,
editRequired: true,
addRequired: false,
editRequired: false,
awRequiredWhen: { variable: "pathRequired", init: "true" },
ngShow: "scm_type == '' || scm_type == null",
awPopOver: '<p>Select from the list of directories found in the base path.' +
'Together the base path and the playbook directory provide the full path used to locate playbooks.</p>' +
'<p>Use PROJECTS_ROOT in your environment settings file to determine the base path value.</p>',
@@ -72,14 +83,6 @@ angular.module('ProjectFormDefinition', [])
dataContainer: 'body',
dataPlacement: 'right'
},
scm_type: {
label: 'SCM Type',
type: 'select',
ngOptions: 'type.label for type in scm_type_options',
"default": '',
addRequired: false,
editRequired: false
},
scm_url: {
label: 'SCM URL',
type: 'text',

View File

@@ -137,8 +137,16 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies'])
// value, you have clear the model.
this.scope[this.form.name + '_form'].$setPristine();
for (var fld in this.form.fields) {
if (this.form.fields[fld].type == 'checkbox_group') {
for (var i=0; i < this.form.fields[fld].fields.length; i++) {
this.scope[this.form.fields[fld].fields[i].name] = '';
this.scope[this.form.fields[fld].fields[i].name + '_api_error'] = '';
}
}
else {
this.scope[fld] = '';
this.scope[fld + '_api_error'] = '';
}
if (this.form.fields[fld].sourceModel) {
this.scope[this.form.fields[fld].sourceModel + '_' + this.form.fields[fld].sourceField] = '';
this.scope[this.form.fields[fld].sourceModel + '_' + this.form.fields[fld].sourceField + '_api_error'] = '';
@@ -480,6 +488,8 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies'])
html += (options.mode == 'edit' && field.editRequired) ? "required " : "";
html += (options.mode == 'add' && field.addRequired) ? "required " : "";
html += (field.readonly) ? "readonly " : "";
html += (field.awRequiredWhen) ? "data-awrequired-init=\"" + field.awRequiredWhen.init + "\" aw-required-when=\"" +
field.awRequiredWhen.variable + "\" " : "";
html += ">\n";
html += "<option value=\"\">Choose " + field.label + "</option>\n";
html += "</select>\n";