diff options
Diffstat (limited to 'server/sonar-web/src/main/js/apps/coding-rules/confirm-dialog.js')
-rw-r--r-- | server/sonar-web/src/main/js/apps/coding-rules/confirm-dialog.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/apps/coding-rules/confirm-dialog.js b/server/sonar-web/src/main/js/apps/coding-rules/confirm-dialog.js new file mode 100644 index 00000000000..624f3e8b997 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/coding-rules/confirm-dialog.js @@ -0,0 +1,43 @@ +import $ from 'jquery'; +import _ from 'underscore'; + +const DEFAULTS = { + title: 'Confirmation', + html: '', + yesLabel: 'Yes', + noLabel: 'Cancel', + yesHandler: function () { + // no op + }, + noHandler: function () { + // no op + }, + always: function () { + // no op + } +}; + +export default function (options) { + var settings = _.extend({}, DEFAULTS, options), + dialog = $('<div><div class="modal-head"><h2>' + settings.title + '</h2></div><div class="modal-body">' + + settings.html + '</div><div class="modal-foot"><button data-confirm="yes">' + settings.yesLabel + + '</button> <a data-confirm="no" class="action">' + settings.noLabel + '</a></div></div>'); + + $('[data-confirm=yes]', dialog).on('click', function () { + dialog.dialog('close'); + settings.yesHandler(); + return settings.always(); + }); + + $('[data-confirm=no]', dialog).on('click', function () { + dialog.dialog('close'); + settings.noHandler(); + return settings.always(); + }); + + return dialog.dialog({ + modal: true, + minHeight: null, + width: 540 + }); +} |