<table class="coding-rule-table">
<tr>
- {{#if activeProfile}}
- {{#if activeProfile.severity}}
- <td class="coding-rule-table-meta-cell coding-rule-activation">
- {{severityIcon activeProfile.severity}}
- {{#eq activeProfile.inherit 'OVERRIDES'}}
- <i class="icon-inheritance"
- title="{{tp 'coding_rules.overrides' activeProfile.name activeProfile.parentProfile.name}}"></i>
- {{/eq}}
- {{#eq activeProfile.inherit 'INHERITED'}}
- <i class="icon-inheritance"
- title="{{tp 'coding_rules.inherits' activeProfile.name activeProfile.parentProfile.name}}"></i>
- {{/eq}}
- </td>
- {{/if}}
+ {{#if activation}}
+ <td class="coding-rule-table-meta-cell coding-rule-activation">
+ {{severityIcon activation.severity}}
+ {{#eq activation.inherit 'OVERRIDES'}}
+ <i class="icon-inheritance"
+ title="{{tp 'coding_rules.overrides' activation.profile.name activation.parentProfile.name}}"></i>
+ {{/eq}}
+ {{#eq activation.inherit 'INHERITED'}}
+ <i class="icon-inheritance"
+ title="{{tp 'coding_rules.inherits' activation.profile.name activation.parentProfile.name}}"></i>
+ {{/eq}}
+ </td>
{{/if}}
<td>
</div>
</td>
- {{#if activeProfile}}
+ {{#any activation selectedProfile}}
{{#if canWrite}}
<td class="coding-rule-table-meta-cell coding-rule-activation-actions">
<div class="button-group">
- {{#if activeProfile.severity}}
- {{#eq activeProfile.inherit 'NONE'}}
+ {{#if activation}}
+ {{#eq activation.inherit 'NONE'}}
<button class="coding-rules-detail-quality-profile-deactivate button-red">
{{t 'coding_rules.deactivate'}}
</button>
{{/eq}}
{{else}}
- <button class="coding-rules-detail-quality-profile-activate">
- {{t 'coding_rules.activate'}}
- </button>
+ {{#unless isTemplate}}
+ <button class="coding-rules-detail-quality-profile-activate">{{t 'coding_rules.activate'}}</button>
+ {{/unless}}
{{/if}}
</div>
</td>
{{/if}}
- {{/if}}
+ {{/any}}
</tr>
</table>
+{{log this}}
+
<form>
<div class="modal-head">
{{#if change}}
<tr class="property">
<th><h3>{{t 'coding_rules.quality_profile'}}</h3></th>
<td>
- {{#if key}}
+ {{#any key qProfile}}
{{name}}
{{else}}
<select id="coding-rules-quality-profile-activation-select">
<option value="{{key}}">{{name}}</option>
{{/each}}
</select>
- {{/if}}
+ {{/any}}
</td>
</tr>
<tr class="property">
if (profile != null) {
fields.push('actives');
fields.push('params');
+ fields.push('isTemplate');
}
return {
p: this.app.state.get('page'),
parseRules: function (r) {
var rules = r.rules,
- profileBases = r.qProfiles || [];
+ profiles = r.qProfiles || [];
if (r.actives != null) {
rules = rules.map(function (rule) {
- var profiles = (r.actives[rule.key] || []).map(function (profile) {
- _.extend(profile, profileBases[profile.qProfile]);
- if (profile.parent != null) {
- _.extend(profile, { parentProfile: profileBases[profile.parent] });
+ var activations = (r.actives[rule.key] || []).map(function (activation) {
+ var profile = profiles[activation.qProfile];
+ if (profile != null) {
+ _.extend(activation, { profile: profile });
+ if (profile.parent != null) {
+ _.extend(activation, { parentProfile: profiles[profile.parent] });
+ }
}
- return profile;
+ return activation;
});
- return _.extend(rule, { activeProfile: profiles.length > 0 ? profiles[0] : null });
+ return _.extend(rule, { activation: activations.length > 0 ? activations[0] : null });
});
}
return rules;
params: paramsHash
}
}).done(function () {
- if (that.options.fromList) {
- that.options.rule.set({ activeProfile: { qProfile: profileKey, inherit: 'NONE', severity: severity } });
- } else {
- that.options.app.controller.showDetails(that.options.rule);
- }
+ that.trigger('profileActivated', severity, params);
window.process.finishBackgroundProcess(p);
}).fail(function () {
- that.options.app.controller.showDetails(that.options.rule);
+ that.trigger('profileActivationFailed');
window.process.failBackgroundProcess(p);
});
},
},
change: function () {
- new ProfileActivationView({
- model: this.model,
- collection: this.model.collection,
- rule: this.options.rule,
- app: this.options.app
- }).render();
+ var that = this,
+ activationView = new ProfileActivationView({
+ model: this.model,
+ collection: this.model.collection,
+ rule: this.options.rule,
+ app: this.options.app
+ });
+ activationView.on('profileActivated', function () {
+ that.options.app.controller.showDetails(that.options.rule);
+ });
+ activationView.render();
},
revert: function () {
},
activate: function () {
- new ProfileActivationView({
- rule: this.model,
- collection: this.collection,
- app: this.options.app
- }).render();
+ var that = this,
+ activationView = new ProfileActivationView({
+ rule: this.model,
+ collection: this.collection,
+ app: this.options.app
+ });
+ activationView.on('profileActivated', function () {
+ that.options.app.controller.showDetails(that.model);
+ });
+ activationView.render();
},
serializeData: function () {
'click': 'selectCurrent',
'click .js-rule': 'openRule',
'click .coding-rules-detail-quality-profile-activate': 'activate',
+ 'click .coding-rules-detail-quality-profile-change': 'change',
+ 'click .coding-rules-detail-quality-profile-revert': 'revert',
'click .coding-rules-detail-quality-profile-deactivate': 'deactivate'
},
this.options.app.controller.showDetails(this.model);
},
- getActiveProfile: function () {
- return this.model.get('activeProfile');
- },
-
activate: function () {
- var activeProfile = this.options.app.state.get('query').qprofile,
+ var that = this,
+ selectedProfile = this.options.app.state.get('query').qprofile,
othersQualityProfiles = _.reject(this.options.app.qualityProfiles, function (profile) {
- return profile.key === activeProfile;
+ return profile.key === selectedProfile;
+ }),
+ activationView = new ProfileActivationView({
+ rule: this.model,
+ collection: new Backbone.Collection(othersQualityProfiles),
+ app: this.options.app
});
-
- new ProfileActivationView({
- rule: this.model,
- collection: new Backbone.Collection(othersQualityProfiles),
- app: this.options.app,
- fromList: true
- }).render();
+ activationView.on('profileActivated', function (severity) {
+ var activation = {
+ severity: severity,
+ inherit: 'NONE'
+ };
+ that.model.set({ activation: activation });
+ });
+ activationView.render();
},
deactivate: function () {
var that = this,
ruleKey = this.model.get('key'),
- myProfile = this.model.get('activeProfile');
+ activation = this.model.get('activation');
window.confirmDialog({
title: t('coding_rules.deactivate'),
html: tp('coding_rules.deactivate.confirm'),
type: 'POST',
url: baseUrl + '/api/qualityprofiles/deactivate_rule',
data: {
- profile_key: myProfile.qProfile,
+ profile_key: activation.qProfile,
rule_key: ruleKey
}
}).done(function () {
window.process.finishBackgroundProcess(p);
- var newProfile = _.extend({}, myProfile, { severity: undefined });
- that.model.set({ activeProfile: newProfile });
+ that.model.unset('activation');
});
}
});
},
serializeData: function () {
- var activeProfile = this.getActiveProfile(),
- selectedProfile = this.options.app.state.get('query').qprofile;
- if (selectedProfile != null && activeProfile == null) {
- activeProfile = selectedProfile;
- }
return _.extend(WorkspaceListItemView.prototype.serializeData.apply(this, arguments), {
tags: _.union(this.model.get('sysTags'), this.model.get('tags')),
canWrite: this.options.app.canWrite,
- activeProfile: activeProfile
+ selectedProfile: this.options.app.state.get('query').qprofile
});
}
});