Allow CreateDialog helper to set disabled status on save button

This commit is contained in:
Joe Fiorini 2015-02-09 17:13:54 -05:00
parent ac9fd1dc3d
commit dda0f0a078
3 changed files with 24 additions and 10 deletions

View File

@ -503,6 +503,7 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
title: 'Host Properties',
id: 'host-modal-dialog',
clonseOnEscape: false,
form: form_scope.host_form,
onClose: function() {
Wait('stop');
scope.codeMirror.destroy();

View File

@ -201,15 +201,16 @@ export default
form.well = false;
generator.inject(form, {
mode: 'edit',
showButtons: false,
showActions: false,
id: 'inventory-edit-modal-dialog',
breadCrumbs: false,
related: false,
scope: scope
});
var form_scope =
generator.inject(form, {
mode: 'edit',
showButtons: false,
showActions: false,
id: 'inventory-edit-modal-dialog',
breadCrumbs: false,
related: false,
scope: scope
});
/* Reset form properties. Otherwise it screws up future requests of the Inventories detail page */
form.well = true;
@ -241,6 +242,7 @@ export default
title: 'Inventory Properties',
id: 'inventory-edit-modal-dialog',
clonseOnEscape: false,
form: form_scope.inventory_form,
onClose: function() {
Wait('stop');
scope.codeMirror.destroy();

View File

@ -57,10 +57,15 @@ angular.module('ModalDialog', ['Utilities', 'ParseHelper'])
beforeDestroy = params.beforeDestroy,
closeOnEscape = (params.closeOnEscape === undefined) ? false : params.closeOnEscape,
resizable = (params.resizable === undefined) ? true : params.resizable,
forms = _.chain([params.form]).flatten().compact().value(),
buttons,
id = params.id,
x, y, wh, ww;
function updateButtonStatus(isValid) {
$('.ui-dialog[aria-describedby="' + id + '"]').find('.btn-primary').prop('disabled', !isValid);
}
if (Empty(buttonSet)) {
// Default button object
buttonSet = [{
@ -115,6 +120,12 @@ angular.module('ModalDialog', ['Utilities', 'ParseHelper'])
});
}, 300);
if (forms.length > 0) {
forms.map(function(form_ctrl) {
scope.$watch(form_ctrl.$name + '.$valid', updateButtonStatus);
});
}
setTimeout(function() {
scope.$apply(function() {
scope.$emit(callback);
@ -226,4 +237,4 @@ angular.module('ModalDialog', ['Utilities', 'ParseHelper'])
ParseTypeChange({ scope: scope, field_id: textareaId, onReady: waitStop, variable: fld, onChange: onChange });
}
};
}]);
}]);