From 0ff79ac40139f821df57ed8087fab6718a8100cd Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lievremont Date: Mon, 30 Jun 2014 11:43:10 +0200 Subject: [PATCH] SONAR-5007 Replace browser confirm dialogs with custom ones --- .../resources/org/sonar/l10n/core.properties | 2 + ...oding-rules-detail-custom-rule-view.coffee | 29 ++++++++------ ...g-rules-detail-quality-profile-view.coffee | 40 +++++++++++-------- .../views/coding-rules-detail-view.coffee | 31 ++++++++------ 4 files changed, 59 insertions(+), 43 deletions(-) diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 0e99bdfbadc..4bbaadf924f 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -1714,6 +1714,7 @@ coding_rules.custom_rules=Custom Rules coding_rules.extend_description=Extend Description coding_rules.deactivate_in=Deactivate In coding_rules.deactivate=Deactivate +coding_rules.deactivate.confirm=Are you sure you want to deactivate this rule in profile {0}? coding_rules.deactivate_in_quality_profile=Deactivate In Quality Profile coding_rules.deactivate_in_all_quality_profiles=Deactivate In All {0} Profiles coding_rules.found=Found @@ -1739,6 +1740,7 @@ coding_rules.reactivate.help=A rule with the same key has been previously delete coding_rules.remove_extended_description.confirm=Are you sure you want to remove the extended description? coding_rules.repository=Repository: coding_rules.revert_to_parent_definition=Revert to Parent Definition +coding_rules.revert_to_parent_definition.confirm=This rule will be reverted to the parameters defined in profile {0}. Are you sure? coding_rules.rule_template=Rule Template coding_rules.rule_template.title=This rule can be used as a template to create custom rules,\nit cannot be activated on a profile coding_rules._rules=rules diff --git a/sonar-server/src/main/coffee/coding-rules/views/coding-rules-detail-custom-rule-view.coffee b/sonar-server/src/main/coffee/coding-rules/views/coding-rules-detail-custom-rule-view.coffee index 3a8454b78aa..216704641ef 100644 --- a/sonar-server/src/main/coffee/coding-rules/views/coding-rules-detail-custom-rule-view.coffee +++ b/sonar-server/src/main/coffee/coding-rules/views/coding-rules-detail-custom-rule-view.coffee @@ -18,20 +18,23 @@ define [ 'click @ui.delete': 'delete' delete: -> - if confirm(t 'are_you_sure') - origEl = @$el.html() - @$el.html '' + confirmDialog + title: t 'delete' + html: t 'are_you_sure' + yesHandler: => + origEl = @$el.html() + @$el.html '' - jQuery.ajax - type: 'POST' - url: "#{baseUrl}/api/rules/delete" - data: - key: @model.get 'key' - .done => - templateKey = @options.templateKey or @options.templateRule.get 'key' - @options.app.showRule templateKey - .fail => - @$el.html origEl + jQuery.ajax + type: 'POST' + url: "#{baseUrl}/api/rules/delete" + data: + key: @model.get 'key' + .done => + templateKey = @options.templateKey or @options.templateRule.get 'key' + @options.app.showRule templateKey + .fail => + @$el.html origEl serializeData: -> _.extend super, diff --git a/sonar-server/src/main/coffee/coding-rules/views/coding-rules-detail-quality-profile-view.coffee b/sonar-server/src/main/coffee/coding-rules/views/coding-rules-detail-quality-profile-view.coffee index 1ec9154d71b..7a1544bc9c4 100644 --- a/sonar-server/src/main/coffee/coding-rules/views/coding-rules-detail-quality-profile-view.coffee +++ b/sonar-server/src/main/coffee/coding-rules/views/coding-rules-detail-quality-profile-view.coffee @@ -34,30 +34,36 @@ define [ revert: -> ruleKey = @options.rule.get('key') - if confirm t 'are_you_sure' - that = @ - jQuery.ajax - type: 'POST' - url: "#{baseUrl}/api/qualityprofiles/activate_rule" - data: + confirmDialog + title: t 'coding_rules.revert_to_parent_definition' + html: tp 'coding_rules.revert_to_parent_definition.confirm', @getParent().name + yesHandler: => + jQuery.ajax + type: 'POST' + url: "#{baseUrl}/api/qualityprofiles/activate_rule" + data: profile_key: @model.get('qProfile') rule_key: ruleKey reset: true - .done => - @options.app.showRule ruleKey + .done => + @options.app.showRule ruleKey deactivate: -> ruleKey = @options.rule.get('key') - if confirm t 'are_you_sure' - jQuery.ajax - type: 'POST' - url: "#{baseUrl}/api/qualityprofiles/deactivate_rule" - data: - profile_key: @model.get('qProfile') - rule_key: ruleKey - .done => - @options.app.showRule ruleKey + myProfile = _.findWhere(@options.app.qualityProfiles, key: @model.get('qProfile')) + confirmDialog + title: t 'coding_rules.deactivate' + html: tp 'coding_rules.deactivate.confirm', myProfile.name + yesHandler: => + jQuery.ajax + type: 'POST' + url: "#{baseUrl}/api/qualityprofiles/deactivate_rule" + data: + profile_key: @model.get('qProfile') + rule_key: ruleKey + .done => + @options.app.showRule ruleKey enableUpdate: -> diff --git a/sonar-server/src/main/coffee/coding-rules/views/coding-rules-detail-view.coffee b/sonar-server/src/main/coffee/coding-rules/views/coding-rules-detail-view.coffee index 5770275f8b1..920dd632376 100644 --- a/sonar-server/src/main/coffee/coding-rules/views/coding-rules-detail-view.coffee +++ b/sonar-server/src/main/coffee/coding-rules/views/coding-rules-detail-view.coffee @@ -235,9 +235,11 @@ define [ removeExtendedDescription: -> - if confirm(t 'coding_rules.remove_extended_description.confirm') - @ui.extendDescriptionText.val '' - @submitExtendDescription() + confirmDialog + html: t 'coding_rules.remove_extended_description.confirm' + yesHandler: => + @ui.extendDescriptionText.val '' + @submitExtendDescription() activateQualityProfile: -> @@ -261,16 +263,19 @@ define [ deleteCustomRule: -> - if confirm(t 'are_you_sure') - jQuery.ajax - type: 'POST' - url: "#{baseUrl}/api/rules/delete" - data: - key: @model.get 'key' - .done => - @options.app.fetchFirstPage() - .fail => - @options.app.showRule @model.get('key') + confirmDialog + title: t 'delete' + html: t 'are_you_sure' + yesHandler: => + jQuery.ajax + type: 'POST' + url: "#{baseUrl}/api/rules/delete" + data: + key: @model.get 'key' + .done => + @options.app.fetchFirstPage() + .fail => + @options.app.showRule @model.get('key') serializeData: -> -- 2.39.5