aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/metrics/form-view.js
blob: 7396e4da8ff4f106bc6a29a9b273eb76f587822d (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
import $ from 'jquery';
import _ from 'underscore';
import ModalForm from 'components/common/modal-form';
import './templates';

export default ModalForm.extend({
  template: Templates['metrics-form'],

  onRender: function () {
    var that = this;
    this._super();
    this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' });
    this.$('#create-metric-domain').select2({
      width: '250px',
      createSearchChoice: function (term) {
        return { id: term, text: '+' + term };
      },
      createSearchChoicePosition: 'top',
      initSelection: function (element, callback) {
        var value = $(element).val();
        callback({ id: value, text: value });
      },
      query: function (options) {
        var items = that.options.domains.filter(function (d) {
              return d.toLowerCase().indexOf(options.term.toLowerCase()) !== -1;
            }),
            results = items.map(function (item) {
              return { id: item, text: item };
            });
        options.callback({ results: results, more: false });
      }
    }).select2('val', this.model && this.model.get('domain'));
    this.$('#create-metric-type').select2({ width: '250px' });
  },

  onDestroy: function () {
    this._super();
    this.$('[data-toggle="tooltip"]').tooltip('destroy');
  },

  onFormSubmit: function (e) {
    this._super(e);
    this.sendRequest();
  },

  serializeData: function () {
    return _.extend(this._super(), {
      domains: this.options.domains,
      types: this.options.types
    });
  }

});