aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/coding-rules/workspace-list-item-view.js
blob: 02627c69f243a70cc02031ef1bd07628247d93c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
define([
  'components/navigator/workspace-list-item-view',
  'templates/coding-rules'
], function (WorkspaceListItemView) {

  return WorkspaceListItemView.extend({
    className: 'coding-rule',
    template: Templates['coding-rules-workspace-list-item'],

    modelEvents: {
      'change': 'render'
    },

    events: {
      'click': 'selectCurrent',
      'click .js-rule': 'openRule'
    },

    selectCurrent: function () {
      this.options.app.state.set({ selectedIndex: this.model.get('index') });
    },

    openRule: function () {
      this.options.app.controller.showDetails(this.model);
    },

    serializeData: function () {
      var activeProfiles = this.model.get('activeProfiles'),
          activeProfile = _.isArray(activeProfiles) && activeProfiles.length === 1 ? activeProfiles[0] : null,
          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
      });
    }
  });

});