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
|
import $ from 'jquery';
import _ from 'underscore';
import BaseFacet from './base-facet';
import Template from '../templates/facets/coding-rules-characteristic-facet.hbs';
export default BaseFacet.extend({
template: Template,
onRender: function () {
BaseFacet.prototype.onRender.apply(this, arguments);
var value = this.options.app.state.get('query').has_debt_characteristic;
if (value != null && ('' + value === 'false')) {
this.$('.js-facet').filter('[data-empty-characteristic]').addClass('active');
}
},
toggleFacet: function (e) {
var noneCharacteristic = $(e.currentTarget).is('[data-empty-characteristic]'),
property = this.model.get('property'),
obj = {};
$(e.currentTarget).toggleClass('active');
if (noneCharacteristic) {
var checked = $(e.currentTarget).is('.active');
obj.has_debt_characteristic = checked ? 'false' : null;
obj[property] = null;
} else {
obj.has_debt_characteristic = null;
obj[property] = this.getValue();
}
this.options.app.state.updateFilter(obj);
},
disable: function () {
var property = this.model.get('property'),
obj = {};
obj.has_debt_characteristic = null;
obj[property] = null;
this.options.app.state.updateFilter(obj);
},
getValues: function () {
var values = this.model.getValues(),
characteristics = this.options.app.characteristics;
return values.map(function (value) {
var ch = _.findWhere(characteristics, { key: value.val });
if (ch != null) {
_.extend(value, ch, { label: ch.name });
}
return value;
});
},
sortValues: function (values) {
return _.sortBy(values, 'index');
},
serializeData: function () {
return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), {
values: this.sortValues(this.getValues())
});
}
});
|