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(); LoadBreadCrumbs();
GetProjectPath({ scope: scope, master: master }); GetProjectPath({ scope: scope, master: master });
scope.scm_type = null;
master.scm_type = null;
scope.scm_type_options = [ scope.scm_type_options = [
{ label: 'GitHub', value: 'git' }, { label: 'GitHub', value: 'git' },
{ label: 'SVN', value: 'svn' }]; { label: 'SVN', value: 'svn' }];
@@ -118,45 +120,58 @@ function ProjectsAdd ($scope, $rootScope, $compile, $location, $log, $routeParam
// Save // Save
scope.formSave = function() { scope.formSave = function() {
var data = {}; var data = {};
for (var fld in form.fields) { for (var fld in form.fields) {
data[fld] = scope[fld]; if (form.fields[fld].type == 'checkbox_group') {
} for (var i=0; i < form.fields[fld].fields.length; i++) {
if (scope.scm_type) { data[form.fields[fld].fields[i].name] = scope[form.fields[fld].fields[i].name];
data.scm_type = scope.scm_type.value; }
} }
var url = (base == 'teams') ? GetBasePath('teams') + $routeParams.team_id + '/projects/' : defaultUrl; else {
Rest.setUrl(url); data[fld] = scope[fld];
Rest.post(data) }
.success( function(data, status, headers, config) { }
var id = data.id; if (scope.scm_type) {
var url = GetBasePath('projects') + id + '/organizations/'; data.scm_type = scope.scm_type.value;
var org = { id: scope.organization }; delete data.local_path;
Rest.setUrl(url); }
Rest.post(org) var url = (base == 'teams') ? GetBasePath('teams') + $routeParams.team_id + '/projects/' : defaultUrl;
.success( function(data, status, headers, config) { Rest.setUrl(url);
$rootScope.flashMessage = "New project successfully created!"; Rest.post(data)
(base == 'projects') ? ReturnToCaller() : ReturnToCaller(1); .success( function(data, status, headers, config) {
}) var id = data.id;
.error( function(data, status, headers, config) { var url = GetBasePath('projects') + id + '/organizations/';
ProcessErrors(scope, data, status, ProjectsForm, var org = { id: scope.organization };
{ hdr: 'Error!', msg: 'Failed to add organization to project. POST returned status: ' + status }); Rest.setUrl(url);
}); Rest.post(org)
}) .success( function(data, status, headers, config) {
$rootScope.flashMessage = "New project successfully created!";
(base == 'projects') ? ReturnToCaller() : ReturnToCaller(1);
})
.error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, ProjectsForm,
{ hdr: 'Error!', msg: 'Failed to add organization to project. POST returned status: ' + status });
});
})
.error( function(data, status, headers, config) { .error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, ProjectsForm, ProcessErrors(scope, data, status, ProjectsForm,
{ hdr: 'Error!', msg: 'Failed to create new project. POST returned status: ' + status }); { hdr: 'Error!', msg: 'Failed to create new project. POST returned status: ' + status });
}); });
}; };
scope.scmChange = function() {
// When an scm_type is set, path is not required
scope.pathRequired = (scope.scm_type) ? false : true;
}
// Cancel // Cancel
scope.formReset = function() { scope.formReset = function() {
$rootScope.flashMessage = null; $rootScope.flashMessage = null;
generator.reset(); generator.reset();
for (var fld in master) { for (var fld in master) {
scope[fld] = master[fld]; scope[fld] = master[fld];
} }
}; };
} }
ProjectsAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'ProjectsForm', ProjectsAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'ProjectsForm',
@@ -231,9 +246,17 @@ function ProjectsEdit ($scope, $rootScope, $compile, $location, $log, $routePara
.success( function(data, status, headers, config) { .success( function(data, status, headers, config) {
LoadBreadCrumbs({ path: '/projects/' + id, title: data.name }); LoadBreadCrumbs({ path: '/projects/' + id, title: data.name });
for (var fld in form.fields) { for (var fld in form.fields) {
if (data[fld]) { if (form.fields[fld].type == 'checkbox_group') {
scope[fld] = data[fld]; for (var i=0; i < form.fields[fld].fields.length; i++) {
master[fld] = data[fld]; 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; var related = data.related;
@@ -250,7 +273,12 @@ function ProjectsEdit ($scope, $rootScope, $compile, $location, $log, $routePara
break; break;
} }
} }
scope.pathRequired = false;
} }
else {
scope.pathRequired = true;
}
master['scm_type'] = scope['scm_type']; master['scm_type'] = scope['scm_type'];
setAskCheckboxes(); setAskCheckboxes();
@@ -267,62 +295,70 @@ function ProjectsEdit ($scope, $rootScope, $compile, $location, $log, $routePara
// Save changes to the parent // Save changes to the parent
scope.formSave = function() { scope.formSave = function() {
$rootScope.flashMessage = null; $rootScope.flashMessage = null;
var params = {}; var params = {};
for (var fld in form.fields) { for (var fld in form.fields) {
params[fld] = scope[fld]; if (form.fields[fld].type == 'checkbox_group') {
} for (var i=0; i < form.fields[fld].fields.length; i++) {
if (scope.scm_type) { params[form.fields[fld].fields[i].name] = scope[form.fields[fld].fields[i].name];
params.scm_type = scope.scm_type.value; }
} }
Rest.setUrl(defaultUrl); else {
Rest.put(params) params[fld] = scope[fld];
.success( function(data, status, headers, config) { }
ReturnToCaller(); }
}) if (scope.scm_type) {
.error( function(data, status, headers, config) { params.scm_type = scope.scm_type.value;
ProcessErrors(scope, data, status, form, delete params.local_path;
{ hdr: 'Error!', msg: 'Failed to update project: ' + id + '. PUT status: ' + status }); }
}); Rest.setUrl(defaultUrl);
}; Rest.put(params)
.success( function(data, status, headers, config) {
ReturnToCaller();
})
.error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to update project: ' + id + '. PUT status: ' + status });
});
};
// Reset the form // Reset the form
scope.formReset = function() { scope.formReset = function() {
$rootScope.flashMessage = null; $rootScope.flashMessage = null;
generator.reset(); generator.reset();
for (var fld in master) { for (var fld in master) {
scope[fld] = master[fld]; scope[fld] = master[fld];
} }
}; };
// Related set: Add button // Related set: Add button
scope.add = function(set) { scope.add = function(set) {
$rootScope.flashMessage = null; $rootScope.flashMessage = null;
$location.path('/' + base + '/' + $routeParams.id + '/' + set); $location.path('/' + base + '/' + $routeParams.id + '/' + set);
}; };
// Related set: Edit button // Related set: Edit button
scope.edit = function(set, id, name) { scope.edit = function(set, id, name) {
$rootScope.flashMessage = null; $rootScope.flashMessage = null;
$location.path('/' + set + '/' + id); $location.path('/' + set + '/' + id);
}; };
// Related set: Delete button // Related set: Delete button
scope['delete'] = function(set, itm_id, name, title) { scope['delete'] = function(set, itm_id, name, title) {
var action = function() { var action = function() {
var url = GetBasePath('projects') + id + '/' + set + '/'; var url = GetBasePath('projects') + id + '/' + set + '/';
$rootScope.flashMessage = null; $rootScope.flashMessage = null;
Rest.setUrl(url); Rest.setUrl(url);
Rest.post({ id: itm_id, disassociate: 1 }) Rest.post({ id: itm_id, disassociate: 1 })
.success( function(data, status, headers, config) { .success( function(data, status, headers, config) {
$('#prompt-modal').modal('hide'); $('#prompt-modal').modal('hide');
scope.search(form.related[set].iterator); scope.search(form.related[set].iterator);
}) })
.error( function(data, status, headers, config) { .error( function(data, status, headers, config) {
$('#prompt-modal').modal('hide'); $('#prompt-modal').modal('hide');
ProcessErrors(scope, data, status, null, ProcessErrors(scope, data, status, null,
{ hdr: 'Error!', msg: 'Call to ' + url + ' failed. POST returned status: ' + status }); { hdr: 'Error!', msg: 'Call to ' + url + ' failed. POST returned status: ' + status });
}); });
}; };
Prompt({ hdr: 'Delete', Prompt({ hdr: 'Delete',
@@ -333,32 +369,37 @@ function ProjectsEdit ($scope, $rootScope, $compile, $location, $log, $routePara
// Password change // Password change
scope.clearPWConfirm = function(fld) { scope.clearPWConfirm = function(fld) {
// If password value changes, make sure password_confirm must be re-entered // If password value changes, make sure password_confirm must be re-entered
scope[fld] = ''; scope[fld] = '';
scope[form.name + '_form'][fld].$setValidity('awpassmatch', false); scope[form.name + '_form'][fld].$setValidity('awpassmatch', false);
} }
// Respond to 'Ask at runtime?' checkbox // Respond to 'Ask at runtime?' checkbox
scope.ask = function(fld, associated) { scope.ask = function(fld, associated) {
if (scope[fld + '_ask']) { if (scope[fld + '_ask']) {
$("#" + fld + "-clear-btn").attr("disabled","disabled"); $("#" + fld + "-clear-btn").attr("disabled","disabled");
scope[fld] = 'ASK'; scope[fld] = 'ASK';
scope[associated] = ''; scope[associated] = '';
scope[form.name + '_form'][associated].$setValidity('awpassmatch', true); scope[form.name + '_form'][associated].$setValidity('awpassmatch', true);
} }
else { else {
$("#" + fld + "-clear-btn").removeAttr("disabled"); $("#" + fld + "-clear-btn").removeAttr("disabled");
scope[fld] = ''; scope[fld] = '';
scope[associated] = ''; scope[associated] = '';
scope[form.name + '_form'][associated].$setValidity('awpassmatch', true); scope[form.name + '_form'][associated].$setValidity('awpassmatch', true);
} }
} }
scope.clear = function(fld, associated) { scope.clear = function(fld, associated) {
scope[fld] = ''; scope[fld] = '';
scope[associated] = ''; scope[associated] = '';
scope[form.name + '_form'][associated].$setValidity('awpassmatch', true); 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', ProjectsEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'ProjectsForm',

View File

@@ -49,7 +49,7 @@ angular.module('ProjectFormDefinition', [])
base_dir: { base_dir: {
label: 'Project Base Path', label: 'Project Base Path',
type: 'textarea', type: 'textarea',
"class": 'span6', "class": 'col-lg-6',
showonly: true, showonly: true,
awPopOver: '<p>Base path used for locating playbooks. Directories found inside this path will be listed in the playbook directory drop-down. ' + 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>' + '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', dataContainer: 'body',
dataPlacement: 'right' 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: { local_path: {
label: 'Playbook Directory', label: 'Playbook Directory',
type: 'select', type: 'select',
id: 'local-path-select', id: 'local-path-select',
ngOptions: 'path for path in project_local_paths', ngOptions: 'path for path in project_local_paths',
addRequired: true, addRequired: false,
editRequired: true, 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.' + 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>' + '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>', '<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', dataContainer: 'body',
dataPlacement: 'right' 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: { scm_url: {
label: 'SCM URL', label: 'SCM URL',
type: 'text', type: 'text',

View File

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