Merge pull request #2000 from anoek/1503

Disable custom inventory script input when you have no access
This commit is contained in:
Akita Noek
2016-05-20 15:54:24 -04:00
4 changed files with 9 additions and 2 deletions

View File

@@ -20,6 +20,8 @@ export default
form = inventoryScriptsFormObject, form = inventoryScriptsFormObject,
url = GetBasePath('inventory_scripts'); url = GetBasePath('inventory_scripts');
$scope.canEdit = true;
generator.inject(form, { generator.inject(form, {
mode: 'add' , mode: 'add' ,
scope:scope, scope:scope,
@@ -38,7 +40,6 @@ export default
// Save // Save
scope.formSave = function () { scope.formSave = function () {
generator.clearApiErrors(); generator.clearApiErrors();
Wait('start'); Wait('start');
Rest.setUrl(url); Rest.setUrl(url);

View File

@@ -61,6 +61,10 @@ export default
data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField]; data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField];
} }
} }
$scope.canEdit = data['script'] !== null;
if (!$scope.canEdit) {
$scope.script = "Script contents hidden";
}
Wait('stop'); Wait('stop');
}) })
.error(function (data, status) { .error(function (data, status) {

View File

@@ -52,6 +52,7 @@ export default function() {
addRequired: true, addRequired: true,
editRequired: true, editRequired: true,
awDropFile: true, awDropFile: true,
ngDisabled: '!canEdit',
rows: 10, rows: 10,
awPopOver: "<p>Drag and drop your custom inventory script file here or create one in the field to import your custom inventory. " + awPopOver: "<p>Drag and drop your custom inventory script file here or create one in the field to import your custom inventory. " +
"<br><br> Script must begin with a hashbang sequence: i.e.... #!/usr/bin/env python</p>", "<br><br> Script must begin with a hashbang sequence: i.e.... #!/usr/bin/env python</p>",
@@ -67,7 +68,7 @@ export default function() {
}, },
save: { save: {
ngClick: 'formSave()', //$scope.function to call on click, optional ngClick: 'formSave()', //$scope.function to call on click, optional
ngDisabled: true //Disable when $pristine or $invalid, optional ngDisabled: 'custom_inventory_form.$pristine || custom_inventory_form.$invalid || !canEdit' //Disable when $pristine or $invalid, optional
} }
} }
}; };

View File

@@ -1053,6 +1053,7 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat
html += (field.ngChange) ? this.attr(field, 'ngChange') : ""; html += (field.ngChange) ? this.attr(field, 'ngChange') : "";
html += buildId(field, fld, this.form); html += buildId(field, fld, this.form);
html += (field.placeholder) ? this.attr(field, 'placeholder') : ""; html += (field.placeholder) ? this.attr(field, 'placeholder') : "";
html += (field.ngDisabled) ? this.attr(field, 'ngDisabled'): "";
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.ngRequired) ? "ng-required=\"" + field.ngRequired +"\"" : ""; html += (field.ngRequired) ? "ng-required=\"" + field.ngRequired +"\"" : "";