-/* global $j:false, Backbone:false */
+/* global $j:false, Backbone:false, baseUrl:false */
window.SS = typeof window.SS === 'object' ? window.SS : {};
name: 'Project',
property: 'componentRoots',
type: window.SS.AjaxSelectFilterView,
+ enabled: true,
select2 : {
allowClear: true,
ajax: {
quietMillis: 300,
- url: '/dev/api/resources/search?f=s2&q=TRK&display_key=true',
+ url: baseUrl + '/api/resources/search?f=s2&q=TRK&display_key=true',
data: function (term, page) { return { s: term, p: page }; },
results: function (data) { return { more: data.more, results: data.results }; }
}
name: 'Severity',
property: 'severities[]',
type: window.SS.SelectFilterView,
+ enabled: true,
choices: window.SS.severities
}),
name: 'Status',
property: 'statuses[]',
type: window.SS.SelectFilterView,
+ enabled: true,
choices: window.SS.statuses
}),
name: 'Resolution',
property: 'resolutions[]',
type: window.SS.SelectFilterView,
+ enabled: false,
choices: window.SS.resolutions
}),
name: 'Assignee',
property: 'assignees',
type: window.SS.AjaxSelectFilterView,
+ enabled: true,
select2: {
allowClear: true,
query:
if (query.term.length === 0) {
query.callback({results: [{id:'<unassigned>',text:'Unassigned'}]});
} else if (query.term.length >= 2) {
- $j.ajax('/dev/api/users/search?f=s2', {
+ $j.ajax(baseUrl + '/api/users/search?f=s2', {
data: {s: query.term},
dataType: 'jsonp'
}).done(function(data) {
name: 'Created',
propertyFrom: 'createdAfter',
propertyTo: 'createdBefore',
- type: window.SS.RangeFilterView
+ type: window.SS.RangeFilterView,
+ enabled: false
})
]);
-/* global _:false, $j:false, Backbone:false */
+/* global _:false, $j:false, Backbone:false, baseUrl:false */
window.SS = typeof window.SS === 'object' ? window.SS : {};
(function() {
- var Filter = Backbone.Model.extend({
+ var Filter = Backbone.Model.extend({});
+
- });
var Filters = Backbone.Collection.extend({
model: Filter
});
+
var BaseFilterView = Backbone.Marionette.ItemView.extend({
template: '#filterTemplate',
className: 'navigator-filter',
+
events: function() {
return {};
},
+
+ modelEvents: {
+ "change:enabled": "render"
+ },
+
+
+ initialize: function() {
+ Backbone.Marionette.ItemView.prototype.initialize.call(this, arguments);
+ this.model.view = this;
+ },
+
+
+ render: function() {
+ Backbone.Marionette.ItemView.prototype.render.call(this, arguments);
+
+ this.$el.toggleClass(
+ 'navigator-filter-disabled',
+ !this.model.get('enabled'));
+ },
+
+
renderBody: function() {
return '';
},
+
serializeData: function() {
return _.extend({}, this.model.toJSON(), {
body: this.renderBody()
});
},
- restore: function() {
- }
+ restore: function() {}
});
- var SelectFilterView = BaseFilterView.extend({
- modelEvents: {
- "change": "render"
- },
+ var SelectFilterView = BaseFilterView.extend({
renderBody: function() {
var template = _.template($j('#selectFilterTemplate').html());
return template(this.model.toJSON());
},
- onRender: function() {
+
+ onDomRefresh: function() {
var that = this;
this.$('.navigator-filter-label').hide();
}).on('change', function(e) {
that.model.set('value', e.val);
});
-
- this.restore();
},
+
restore: function() {
if (this.model.get('value')) {
this.$(':input').select2('val', this.model.get('value'));
}
- }
+ },
+
+
+ focus: function() {}
});
+
var AjaxSelectFilterView = BaseFilterView.extend({
renderBody: function() {
return template(this.model.toJSON());
},
- onRender: function() {
+ onDomRefresh: function() {
var that = this;
this.$('.navigator-filter-label').hide();
.on('change', function(e) {
that.model.set('value', e.val);
});
-
- this.restore();
},
restore: function() {
if (this.model.get('value')) {
this.$(':input').select2('data', this.model.get('value'));
}
- }
+ },
+
+ focus: function() {}
});
+
var RangeFilterView = BaseFilterView.extend({
events: function() {
});
},
+
renderBody: function() {
var template = _.template($j('#rangeFilterTemplate').html());
return template(this.model.toJSON());
},
+
onRender: function() {
- this.restore();
+ this.inputFrom = this.$('[name="' + this.model.get('propertyFrom') + '"]');
+ this.inputTo = this.$('[name="' + this.model.get('propertyTo') + '"]');
},
+
changeInput: function() {
this.model.set('value', {
- from: '',
- to: ''
+ from: this.inputFrom.val(),
+ to: this.inputTo.val()
});
},
+
restore: function() {
- if (this.model.get('value')) {
- this.$('[name="' + this.model.get('propertyFrom') + '"]').val(this.model.get('value').from);
- this.$('[name="' + this.model.get('propertyTo') + '"]').val(this.model.get('value').to);
+ var value = this.model.get('value');
+ if (typeof value === 'object') {
+ this.inputFrom.val(value.from || '');
+ this.inputTo.val(value.to || '');
}
+ },
+
+
+ focus: function() {
+ this.inputFrom.focus();
}
});
template: '#filterBarTemplate',
itemViewContainer: '.navigator-filters-list',
+
collectionEvents: {
- 'change': 'changeFilters'
+ 'change:value': 'changeFilters',
+ 'change:enabled': 'renderDisabledFilters'
+ },
+
+
+ ui: {
+ disabledFilters: '.navigator-disabled-filters'
},
+
getItemView: function(item) {
return item.get('type') || BaseFilterView;
},
};
},
+
+ render: function() {
+ Backbone.Marionette.CompositeView.prototype.render.call(this, arguments);
+ this.renderDisabledFilters();
+ },
+
+
+ renderDisabledFilters: function() {
+ var that = this,
+ disabledFilters = this.collection.where({ enabled: false });
+
+ that.ui.disabledFilters.select2('destroy').empty().show();
+
+ if (disabledFilters.length > 0) {
+ $j('<option>').appendTo(that.ui.disabledFilters);
+ _.each(disabledFilters, function(item) {
+ $j('<option>').text(item.get('name')).prop('value', item.cid)
+ .appendTo(that.ui.disabledFilters);
+ });
+ that.ui.disabledFilters.select2({
+ allowClear: true,
+ placeholder: 'More criteria',
+ width: '150px'
+ }).on('change', function(e) {
+ that.ui.disabledFilters.select2('val', '');
+ that.enableFilter(e.val);
+ });
+ } else {
+ that.ui.disabledFilters.hide();
+ }
+ },
+
+
+ enableFilter: function(key) {
+ var item = this.collection.find(function(item) {
+ return item.cid === key;
+ });
+
+ if (item) {
+ item.view.$el.detach().appendTo(this.itemViewContainer);
+ item.set('enabled', true);
+ item.view.focus();
+ }
+ },
+
+
changeFilters: function() {
var query = {};
this.collection.each(function(item) {
this.applyQuery($j.param(query));
},
+
applyQuery: function(query) {
$j.ajax({
- url: '/dev/issues/search',
+ url: baseUrl + '/issues/search',
type: 'get',
data: query
}).done(function(r) {