aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/quality-profiles/profile-header-view.js
blob: 99a9a1e022c970513b7926a49daa5ab7cc26d385 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
define([
  './copy-profile-view',
  './rename-profile-view',
  './delete-profile-view',
  './templates'
], function (ProfileCopyView, ProfileRenameView, ProfileDeleteView) {

  var $ = jQuery;

  return Marionette.ItemView.extend({
    template: Templates['quality-profiles-profile-header'],

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

    events: {
      'click #quality-profile-backup': 'onBackupClick',
      'click #quality-profile-copy': 'onCopyClick',
      'click #quality-profile-rename': 'onRenameClick',
      'click #quality-profile-set-as-default': 'onDefaultClick',
      'click #quality-profile-delete': 'onDeleteClick'
    },

    onBackupClick: function (e) {
      $(e.currentTarget).blur();
    },

    onCopyClick: function (e) {
      e.preventDefault();
      this.copy();
    },

    onRenameClick: function (e) {
      e.preventDefault();
      this.rename();
    },

    onDefaultClick: function (e) {
      e.preventDefault();
      this.setAsDefault();
    },

    onDeleteClick: function (e) {
      e.preventDefault();
      this.delete();
    },

    copy: function () {
      new ProfileCopyView({ model: this.model }).render();
    },

    rename: function () {
      new ProfileRenameView({ model: this.model }).render();
    },

    setAsDefault: function () {
      this.model.trigger('setAsDefault', this.model);
    },

    delete: function () {
      new ProfileDeleteView({ model: this.model }).render();
    },

    serializeData: function () {
      var key = this.model.get('key');
      return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), {
        encodedKey: encodeURIComponent(key),
        canWrite: this.options.canWrite
      });
    }
  });

});