2017-01-10 23:02:20 +00:00
|
|
|
/* eslint-disable func-names, space-before-function-paren, wrap-iife, no-var, one-var, one-var-declaration-per-line, object-shorthand, prefer-arrow-callback, comma-dangle, prefer-template, quotes, no-else-return, max-len */
|
2016-12-14 05:26:26 +00:00
|
|
|
/* global Api */
|
|
|
|
|
2016-07-24 20:45:11 +00:00
|
|
|
(function() {
|
|
|
|
this.Search = (function() {
|
|
|
|
function Search() {
|
|
|
|
var $groupDropdown, $projectDropdown;
|
|
|
|
$groupDropdown = $('.js-search-group-dropdown');
|
|
|
|
$projectDropdown = $('.js-search-project-dropdown');
|
|
|
|
this.eventListeners();
|
|
|
|
$groupDropdown.glDropdown({
|
|
|
|
selectable: true,
|
|
|
|
filterable: true,
|
|
|
|
fieldName: 'group_id',
|
2017-01-13 15:23:27 +00:00
|
|
|
search: {
|
2017-01-26 19:31:32 +00:00
|
|
|
fields: ['full_name']
|
2017-01-13 15:23:27 +00:00
|
|
|
},
|
2016-07-24 20:45:11 +00:00
|
|
|
data: function(term, callback) {
|
2016-10-31 17:37:13 +00:00
|
|
|
return Api.groups(term, {}, function(data) {
|
2016-07-24 20:45:11 +00:00
|
|
|
data.unshift({
|
2017-01-26 19:31:32 +00:00
|
|
|
full_name: 'Any'
|
2016-07-24 20:45:11 +00:00
|
|
|
});
|
|
|
|
data.splice(1, 0, 'divider');
|
|
|
|
return callback(data);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
id: function(obj) {
|
|
|
|
return obj.id;
|
|
|
|
},
|
|
|
|
text: function(obj) {
|
2017-01-26 19:31:32 +00:00
|
|
|
return obj.full_name;
|
2016-07-24 20:45:11 +00:00
|
|
|
},
|
|
|
|
toggleLabel: function(obj) {
|
2017-01-26 19:31:32 +00:00
|
|
|
return ($groupDropdown.data('default-label')) + " " + obj.full_name;
|
2016-07-24 20:45:11 +00:00
|
|
|
},
|
|
|
|
clicked: (function(_this) {
|
|
|
|
return function() {
|
|
|
|
return _this.submitSearch();
|
|
|
|
};
|
|
|
|
})(this)
|
|
|
|
});
|
|
|
|
$projectDropdown.glDropdown({
|
|
|
|
selectable: true,
|
|
|
|
filterable: true,
|
|
|
|
fieldName: 'project_id',
|
2017-01-13 15:23:27 +00:00
|
|
|
search: {
|
|
|
|
fields: ['name']
|
|
|
|
},
|
2016-07-24 20:45:11 +00:00
|
|
|
data: function(term, callback) {
|
2017-03-06 05:03:21 +00:00
|
|
|
return Api.projects(term, { order_by: 'id' }, function(data) {
|
2016-07-24 20:45:11 +00:00
|
|
|
data.unshift({
|
|
|
|
name_with_namespace: 'Any'
|
|
|
|
});
|
|
|
|
data.splice(1, 0, 'divider');
|
|
|
|
return callback(data);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
id: function(obj) {
|
|
|
|
return obj.id;
|
|
|
|
},
|
|
|
|
text: function(obj) {
|
|
|
|
return obj.name_with_namespace;
|
|
|
|
},
|
|
|
|
toggleLabel: function(obj) {
|
|
|
|
return ($projectDropdown.data('default-label')) + " " + obj.name_with_namespace;
|
|
|
|
},
|
|
|
|
clicked: (function(_this) {
|
|
|
|
return function() {
|
|
|
|
return _this.submitSearch();
|
|
|
|
};
|
|
|
|
})(this)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Search.prototype.eventListeners = function() {
|
|
|
|
$(document).off('keyup', '.js-search-input').on('keyup', '.js-search-input', this.searchKeyUp);
|
|
|
|
return $(document).off('click', '.js-search-clear').on('click', '.js-search-clear', this.clearSearchField);
|
|
|
|
};
|
|
|
|
|
|
|
|
Search.prototype.submitSearch = function() {
|
|
|
|
return $('.js-search-form').submit();
|
|
|
|
};
|
|
|
|
|
|
|
|
Search.prototype.searchKeyUp = function() {
|
|
|
|
var $input;
|
|
|
|
$input = $(this);
|
|
|
|
if ($input.val() === '') {
|
|
|
|
return $('.js-search-clear').addClass('hidden');
|
|
|
|
} else {
|
|
|
|
return $('.js-search-clear').removeClass('hidden');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Search.prototype.clearSearchField = function() {
|
|
|
|
return $('.js-search-input').val('').trigger('keyup').focus();
|
|
|
|
};
|
|
|
|
|
|
|
|
return Search;
|
|
|
|
})();
|
2017-02-10 06:50:50 +00:00
|
|
|
}).call(window);
|