NIFI-3369 - Disable "Add" button on new...

...connection dialog if no relationships selected

Disabled confirmation button for both Create and Configure Connection
dialogs when no relationship was selected.

Signed-off-by: Scott Aslan <scottyaslan@gmail.com>

This closes #2152
This commit is contained in:
yuri1969 2017-09-12 19:51:10 +02:00 committed by Scott Aslan
parent 0e50279467
commit 1f1269c817
2 changed files with 33 additions and 32 deletions

View File

@ -73,6 +73,16 @@
d3.select('path.connector').remove(); d3.select('path.connector').remove();
}; };
/**
* Activates dialog's button model refresh on a connection relationships change.
*/
var addDialogRelationshipsChangeListener = function() {
// refresh button model when a relationship selection changes
$('div.available-relationship').bind('change', function() {
$('#connection-configuration').modal('refreshButtons');
});
}
/** /**
* Initializes the source in the new connection dialog. * Initializes the source in the new connection dialog.
* *
@ -89,6 +99,8 @@
$.each(processor.relationships, function (i, relationship) { $.each(processor.relationships, function (i, relationship) {
createRelationshipOption(relationship.name); createRelationshipOption(relationship.name);
}); });
addDialogRelationshipsChangeListener();
// if there is a single relationship auto select // if there is a single relationship auto select
var relationships = $('#relationship-names').children('div'); var relationships = $('#relationship-names').children('div');
@ -104,21 +116,13 @@
hover: '#004849', hover: '#004849',
text: '#ffffff' text: '#ffffff'
}, },
disabled: function () {
// ensure some relationships were selected
return getSelectedRelationships().length === 0;
},
handler: { handler: {
click: function () { click: function () {
// get the selected relationships addConnection(getSelectedRelationships());
var selectedRelationships = getSelectedRelationships();
// ensure some relationships were selected
if (selectedRelationships.length > 0) {
addConnection(selectedRelationships);
} else {
// inform users that no relationships were selected
nfDialog.showOkDialog({
headerText: 'Connection Configuration',
dialogContent: 'The connection must have at least one relationship selected.'
});
}
// close the dialog // close the dialog
$('#connection-configuration').modal('hide'); $('#connection-configuration').modal('hide');
@ -1331,6 +1335,8 @@
createRelationshipOption(name); createRelationshipOption(name);
}); });
addDialogRelationshipsChangeListener();
// ensure all selected relationships are present // ensure all selected relationships are present
// (may be undefined) and selected // (may be undefined) and selected
$.each(selectedRelationships, function (i, name) { $.each(selectedRelationships, function (i, name) {
@ -1395,30 +1401,23 @@
hover: '#004849', hover: '#004849',
text: '#ffffff' text: '#ffffff'
}, },
disabled: function () {
// ensure some relationships were selected with a processor as the source
if (nfCanvasUtils.isProcessor(source)) {
return getSelectedRelationships().length === 0;
}
return false;
},
handler: { handler: {
click: function () { click: function () {
// get the selected relationships
var selectedRelationships = getSelectedRelationships();
// see if we're working with a processor as the source // see if we're working with a processor as the source
if (nfCanvasUtils.isProcessor(source)) { if (nfCanvasUtils.isProcessor(source)) {
if (selectedRelationships.length > 0) { // update the selected relationships
// if there are relationships selected update updateConnection(getSelectedRelationships()).done(function () {
updateConnection(selectedRelationships).done(function () { deferred.resolve();
deferred.resolve(); }).fail(function () {
}).fail(function () {
deferred.reject();
});
} else {
// inform users that no relationships were selected and the source is a processor
nfDialog.showOkDialog({
headerText: 'Connection Configuration',
dialogContent: 'The connection must have at least one relationship selected.'
});
// reject the deferred
deferred.reject(); deferred.reject();
} });
} else { } else {
// there are no relationships, but the source wasn't a processor, so update anyway // there are no relationships, but the source wasn't a processor, so update anyway
updateConnection(undefined).done(function () { updateConnection(undefined).done(function () {

View File

@ -61,6 +61,8 @@
} else { } else {
checkbox.removeClass('checkbox-checked').addClass('checkbox-unchecked'); checkbox.removeClass('checkbox-checked').addClass('checkbox-unchecked');
} }
// emit a state change event
checkbox.trigger('change');
}); });
// setup click areas for custom checkboxes // setup click areas for custom checkboxes