aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/provisioning/header-view.js
blob: 37165494eac0b3d2d91ce785ddc69b30478143e8 (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
define([
  './create-view',
  './bulk-delete-view',
  './templates'
], function (CreateView, BulkDeleteView) {

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

    collectionEvents: {
      'change:selected': 'toggleDeleteButton',
      'reset': 'toggleDeleteButton'
    },

    events: {
      'click #provisioning-create': 'onCreateClick',
      'click #provisioning-bulk-delete': 'onBulkDeleteClick'
    },

    onCreateClick: function (e) {
      e.preventDefault();
      this.createProject();
    },

    onBulkDeleteClick: function (e) {
      e.preventDefault();
      this.bulkDelete();
    },

    createProject: function () {
      new CreateView({
        collection: this.collection
      }).render();
    },

    bulkDelete: function () {
      new BulkDeleteView({
        collection: this.collection
      }).render();
    },

    toggleDeleteButton: function () {
      var selectedCount = this.collection.where({ selected: true }).length,
          someSelected = selectedCount > 0;
      this.$('#provisioning-bulk-delete').prop('disabled', !someSelected);
    }
  });

});