aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/quality-gates/condition.js
blob: 9ca451ee5a0a1d049c252eaf109dfd457d428ea6 (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
define(function () {

  return Backbone.Model.extend({

    defaults: {
      period: 0
    },

    url: function () {
      return baseUrl + '/api/qualitygates';
    },

    createUrl: function () {
      return this.url() + '/create_condition';
    },

    updateUrl: function () {
      return this.url() + '/update_condition';
    },

    deleteUrl: function () {
      return this.url() + '/delete_condition';
    },

    sync: function (method, model, options) {
      var opts = options || {};
      opts.type = 'POST';
      if (method === 'create') {
        opts.url = this.createUrl();
        opts.data = model.toJSON();
      }
      if (method === 'update') {
        opts.url = this.updateUrl();
        opts.data = model.toJSON();
      }
      if (method === 'delete') {
        opts.url = this.deleteUrl();
        opts.data = { id: model.id };
      }
      if (opts.data.period === '0') {
        delete opts.data.period;
      }
      return Backbone.ajax(opts);
    }
  });

});