2017-01-10 18:02:20 -05:00
|
|
|
/* eslint-disable func-names, space-before-function-paren, no-var, wrap-iife, one-var, camelcase, one-var-declaration-per-line, quotes, object-shorthand, prefer-arrow-callback, comma-dangle, consistent-return, yoda, prefer-rest-params, prefer-spread, no-unused-vars, prefer-template, max-len */
|
2016-12-14 00:26:26 -05:00
|
|
|
/* global Api */
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
(function() {
|
|
|
|
var slice = [].slice;
|
|
|
|
|
|
|
|
this.GroupsSelect = (function() {
|
|
|
|
function GroupsSelect() {
|
|
|
|
$('.ajax-groups-select').each((function(_this) {
|
|
|
|
return function(i, select) {
|
2016-10-31 13:37:13 -04:00
|
|
|
var all_available, skip_groups;
|
|
|
|
all_available = $(select).data('all-available');
|
2016-09-01 13:23:39 -04:00
|
|
|
skip_groups = $(select).data('skip-groups') || [];
|
2016-07-24 16:45:11 -04:00
|
|
|
return $(select).select2({
|
|
|
|
placeholder: "Search for a group",
|
|
|
|
multiple: $(select).hasClass('multiselect'),
|
|
|
|
minimumInputLength: 0,
|
|
|
|
query: function(query) {
|
2016-12-14 00:26:26 -05:00
|
|
|
var options = { all_available: all_available, skip_groups: skip_groups };
|
2016-10-31 13:37:13 -04:00
|
|
|
return Api.groups(query.term, options, function(groups) {
|
2016-07-24 16:45:11 -04:00
|
|
|
var data;
|
|
|
|
data = {
|
|
|
|
results: groups
|
|
|
|
};
|
|
|
|
return query.callback(data);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
initSelection: function(element, callback) {
|
|
|
|
var id;
|
|
|
|
id = $(element).val();
|
|
|
|
if (id !== "") {
|
|
|
|
return Api.group(id, callback);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
formatResult: function() {
|
|
|
|
var args;
|
|
|
|
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
|
|
|
return _this.formatResult.apply(_this, args);
|
|
|
|
},
|
|
|
|
formatSelection: function() {
|
|
|
|
var args;
|
|
|
|
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
|
|
|
return _this.formatSelection.apply(_this, args);
|
|
|
|
},
|
|
|
|
dropdownCssClass: "ajax-groups-dropdown",
|
2016-07-26 23:32:10 -04:00
|
|
|
// we do not want to escape markup since we are displaying html in results
|
2016-07-24 16:45:11 -04:00
|
|
|
escapeMarkup: function(m) {
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
})(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
GroupsSelect.prototype.formatResult = function(group) {
|
|
|
|
var avatar;
|
|
|
|
if (group.avatar_url) {
|
|
|
|
avatar = group.avatar_url;
|
|
|
|
} else {
|
|
|
|
avatar = gon.default_avatar_url;
|
|
|
|
}
|
2017-01-26 14:31:32 -05:00
|
|
|
return "<div class='group-result'> <div class='group-name'>" + group.full_name + "</div> <div class='group-path'>" + group.full_path + "</div> </div>";
|
2016-07-24 16:45:11 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
GroupsSelect.prototype.formatSelection = function(group) {
|
2017-01-26 14:31:32 -05:00
|
|
|
return group.full_name;
|
2016-07-24 16:45:11 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
return GroupsSelect;
|
|
|
|
})();
|
2017-02-10 01:50:50 -05:00
|
|
|
}).call(window);
|