3 'templates/coding-rules'
9 class CodingRulesQualityProfileActivationView extends Marionette.ItemView
11 template: Templates['coding-rules-quality-profile-activation']
15 qualityProfileSelect: '#coding-rules-quality-profile-activation-select'
16 qualityProfileSeverity: '#coding-rules-quality-profile-activation-severity'
17 qualityProfileActivate: '#coding-rules-quality-profile-activation-activate'
18 qualityProfileParameters: '[name]'
22 'click #coding-rules-quality-profile-activation-cancel': 'hide'
23 'click @ui.qualityProfileActivate': 'activate'
27 profileKey = @ui.qualityProfileSelect.val()
28 params = @ui.qualityProfileParameters.map(->
29 key: jQuery(@).prop('name'), value: jQuery(@).val() || jQuery(@).prop('placeholder') || '').get()
31 paramsHash = (params.map (param) -> param.key + '=' + param.value).join(';')
34 profileKey = @model.get('qProfile')
36 profileKey = @model.get('key')
37 severity = @ui.qualityProfileSeverity.val()
39 origFooter = @$('.modal-foot').html()
40 @$('.modal-foot').html '<i class="spinner"></i>'
42 ruleKey = @rule.get('key')
45 url: "#{baseUrl}/api/qualityprofiles/activate_rule"
47 profile_key: profileKey
52 @options.app.showRule ruleKey
55 @$('.modal-foot').html origFooter
60 dialogClass: 'no-close',
69 @ui.qualityProfileSelect.select2
71 minimumResultsForSearch: 5
74 return state.text unless state.id
75 "<i class='icon-severity-#{state.id.toLowerCase()}'></i> #{state.text}"
77 severity = (@model && @model.get 'severity') || @rule.get 'severity'
78 @ui.qualityProfileSeverity.val severity
79 @ui.qualityProfileSeverity.select2
81 minimumResultsForSearch: 999
83 formatSelection: format
95 getAvailableQualityProfiles: (lang) ->
96 activeQualityProfiles = @options.app.detailView.qualityProfilesView.collection
97 inactiveProfiles = _.reject @options.app.qualityProfiles, (profile) =>
98 activeQualityProfiles.findWhere key: profile.key
99 _.filter inactiveProfiles, (profile) =>
104 params = @rule.get 'params'
106 modelParams = @model.get 'params'
108 params = params.map (p) ->
109 parentParam = _.findWhere(modelParams, key: p.key)
111 _.extend p, value: _.findWhere(modelParams, key: p.key).value
115 availableProfiles = @getAvailableQualityProfiles(@rule.get 'lang')
119 change: @model && @model.has 'severity'
121 qualityProfiles: availableProfiles
122 severities: ['BLOCKER', 'CRITICAL', 'MAJOR', 'MINOR', 'INFO']
123 saveEnabled: not _.isEmpty(availableProfiles) or (@model and @model.get('qProfile'))
124 isCustomRule: (@model and @model.has('templateKey')) or @rule.has 'templateKey'