From 5aaffa9672bcad7d92bad4609a48de231becdaaf Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Thu, 10 Apr 2014 14:48:55 +0600 Subject: [PATCH] Confirmation modal windows --- .../resources/org/sonar/l10n/core.properties | 2 + sonar-server/Gruntfile.coffee | 2 + .../src/main/coffee/common/dialogs.coffee | 38 +++++++++++++++++++ .../quality-gate-detail-condition-view.coffee | 19 ++++++---- .../quality-gate-detail-header-view.coffee | 25 ++++++------ .../qualitygate/ws/QgateAppHandler.java | 2 + 6 files changed, 69 insertions(+), 19 deletions(-) create mode 100644 sonar-server/src/main/coffee/common/dialogs.coffee diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties index 8f699f7c755..e190b1da8d9 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -1640,11 +1640,13 @@ quality_profiles.copy_new_name=New name quality_gates.noQualityGates=No Quality Gates quality_gates.create=Create Quality Gate quality_gates.rename=Rename Quality Gate +quality_gates.delete=Delete Quality Gate quality_gates.copy=Copy Quality Gate quality_gates.conditions=Conditions quality_gates.projects=Projects quality_gates.add_condition=Add Condition quality_gates.no_conditions=No Conditions +quality_gates.delete_condition=Delete Condition quality_gates.introduction=Only project measures are checked against thresholds. Sub-projects, directories and files are ignored. quality_gates.health_icons=Project health icons represent: quality_gates.projects_for_default=Every project not specifically associated to a quality gate will be associated to this one by default. diff --git a/sonar-server/Gruntfile.coffee b/sonar-server/Gruntfile.coffee index ffcc8519dc5..88c18c56369 100644 --- a/sonar-server/Gruntfile.coffee +++ b/sonar-server/Gruntfile.coffee @@ -75,6 +75,7 @@ module.exports = (grunt) -> '<%= pkg.assets %>js/top-search.js' '<%= pkg.assets %>js/sortable.js' '<%= pkg.assets %>js/common/inputs.js' + '<%= pkg.assets %>js/common/dialogs.js' '<%= pkg.assets %>js/application.js' '<%= pkg.assets %>js/dashboard.js' '<%= pkg.assets %>js/duplication.js' @@ -108,6 +109,7 @@ module.exports = (grunt) -> '<%= pkg.assets %>js/top-search.js' '<%= pkg.assets %>js/sortable.js' '<%= pkg.assets %>js/common/inputs.js' + '<%= pkg.assets %>js/common/dialogs.js' '<%= pkg.assets %>js/application.js' '<%= pkg.assets %>js/dashboard.js' '<%= pkg.assets %>js/duplication.js' diff --git a/sonar-server/src/main/coffee/common/dialogs.coffee b/sonar-server/src/main/coffee/common/dialogs.coffee new file mode 100644 index 00000000000..0ae1c01d45d --- /dev/null +++ b/sonar-server/src/main/coffee/common/dialogs.coffee @@ -0,0 +1,38 @@ +$ = jQuery + +window.confirmDialog = (options) -> + settings = _.extend window.confirmDialog.defaults, options + dialog = $ """ +
+ + + +
+ """ + + $('[data-confirm=yes]', dialog).on 'click', -> + dialog.dialog 'close' + settings.yesHandler() + settings.always() + $('[data-confirm=no]', dialog).on 'click', -> + dialog.dialog 'close' + settings.noHandler() + settings.always() + + dialog.dialog + modal: true + minHeight: null + width: 540 + + +window.confirmDialog.defaults = + title: 'Confirmation' + html: '' + yesLabel: 'Yes' + noLabel: 'Cancel' + yesHandler: -> + noHandler: -> + always: -> \ No newline at end of file diff --git a/sonar-server/src/main/coffee/quality-gate/views/quality-gate-detail-condition-view.coffee b/sonar-server/src/main/coffee/quality-gate/views/quality-gate-detail-condition-view.coffee index e928b169b25..6535003e0fc 100644 --- a/sonar-server/src/main/coffee/quality-gate/views/quality-gate-detail-condition-view.coffee +++ b/sonar-server/src/main/coffee/quality-gate/views/quality-gate-detail-condition-view.coffee @@ -23,11 +23,12 @@ define [ errorInput: '[name=error]' actionsBox: '.quality-gate-condition-actions' updateButton: '.update-condition' + deleteButton: '.delete-condition' events: 'click @ui.updateButton': 'saveCondition' - 'click .delete-condition': 'deleteCondition' + 'click @ui.deleteButton': 'deleteCondition' 'click .add-condition': 'saveCondition' 'click .cancel-add-condition': 'cancelAddCondition' 'keyup :input': 'enableUpdate' @@ -94,12 +95,16 @@ define [ deleteCondition: -> - if confirm t('quality_gates.delete_condition.confirm.message') - @showSpinner() - @model.delete().done => - @options.collectionView.collection.remove @model - @options.collectionView.updateConditions() - @close() + confirmDialog + title: t 'quality_gates.delete_condition' + html: t('quality_gates.delete_condition.confirm.message') + yesHandler: => + @showSpinner() + @model.delete().done => + @options.collectionView.collection.remove @model + @options.collectionView.updateConditions() + @close() + always: => @ui.deleteButton.blur() cancelAddCondition: -> diff --git a/sonar-server/src/main/coffee/quality-gate/views/quality-gate-detail-header-view.coffee b/sonar-server/src/main/coffee/quality-gate/views/quality-gate-detail-header-view.coffee index fc23e91c479..24fbf33f657 100644 --- a/sonar-server/src/main/coffee/quality-gate/views/quality-gate-detail-header-view.coffee +++ b/sonar-server/src/main/coffee/quality-gate/views/quality-gate-detail-header-view.coffee @@ -45,18 +45,19 @@ define [ deleteQualityGate: -> message = if @model.get 'default' then 'quality_gates.delete.confirm.default' else 'quality_gates.delete.confirm.message' - if confirm t(message).replace('{0}', @model.get 'name') - @showSpinner() - jQuery.ajax - type: 'POST' - url: "#{baseUrl}/api/qualitygates/destroy" - data: id: @model.id - .always => - @hideSpinner() - .done => - @options.app.deleteQualityGate @model.id - else - @ui.deleteButton.blur() + message = tp message, @model.get('name') + confirmDialog + title: t 'quality_gates.delete' + html: message + yesHandler: => + @showSpinner() + jQuery.ajax + type: 'POST' + url: "#{baseUrl}/api/qualitygates/destroy" + data: id: @model.id + .always => @hideSpinner() + .done => @options.app.deleteQualityGate @model.id + always: => @ui.deleteButton.blur() changeDefault: (set) -> diff --git a/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QgateAppHandler.java b/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QgateAppHandler.java index ea7765f7921..bef48100273 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QgateAppHandler.java +++ b/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QgateAppHandler.java @@ -54,9 +54,11 @@ public class QgateAppHandler implements RequestHandler { "quality_gates.conditions", "quality_gates.copy", "quality_gates.create", + "quality_gates.delete", "quality_gates.health_icons", "quality_gates.introduction", "quality_gates.no_conditions", + "quality_gates.delete_condition", "quality_gates.noQualityGates", "quality_gates.operator.LT", "quality_gates.operator.GT", -- 2.39.5