BigW Consortium Gitlab

project_select.js 3.39 KB
Newer Older
1
/* eslint-disable */
Fatih Acet committed
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
(function() {
  this.ProjectSelect = (function() {
    function ProjectSelect() {
      $('.js-projects-dropdown-toggle').each(function(i, dropdown) {
        var $dropdown;
        $dropdown = $(dropdown);
        return $dropdown.glDropdown({
          filterable: true,
          filterRemote: true,
          search: {
            fields: ['name_with_namespace']
          },
          data: function(term, callback) {
            var finalCallback, projectsCallback;
            finalCallback = function(projects) {
              return callback(projects);
            };
            if (this.includeGroups) {
              projectsCallback = function(projects) {
                var groupsCallback;
                groupsCallback = function(groups) {
                  var data;
                  data = groups.concat(projects);
                  return finalCallback(data);
                };
27
                return Api.groups(term, {}, groupsCallback);
Fatih Acet committed
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 63 64 65 66 67 68 69 70 71 72 73 74 75
              };
            } else {
              projectsCallback = finalCallback;
            }
            if (this.groupId) {
              return Api.groupProjects(this.groupId, term, projectsCallback);
            } else {
              return Api.projects(term, this.orderBy, projectsCallback);
            }
          },
          url: function(project) {
            return project.web_url;
          },
          text: function(project) {
            return project.name_with_namespace;
          }
        });
      });
      $('.ajax-project-select').each(function(i, select) {
        var placeholder;
        this.groupId = $(select).data('group-id');
        this.includeGroups = $(select).data('include-groups');
        this.orderBy = $(select).data('order-by') || 'id';
        placeholder = "Search for project";
        if (this.includeGroups) {
          placeholder += " or group";
        }
        return $(select).select2({
          placeholder: placeholder,
          minimumInputLength: 0,
          query: (function(_this) {
            return function(query) {
              var finalCallback, projectsCallback;
              finalCallback = function(projects) {
                var data;
                data = {
                  results: projects
                };
                return query.callback(data);
              };
              if (_this.includeGroups) {
                projectsCallback = function(projects) {
                  var groupsCallback;
                  groupsCallback = function(groups) {
                    var data;
                    data = groups.concat(projects);
                    return finalCallback(data);
                  };
76
                  return Api.groups(query.term, {}, groupsCallback);
Fatih Acet committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
                };
              } else {
                projectsCallback = finalCallback;
              }
              if (_this.groupId) {
                return Api.groupProjects(_this.groupId, query.term, projectsCallback);
              } else {
                return Api.projects(query.term, _this.orderBy, projectsCallback);
              }
            };
          })(this),
          id: function(project) {
            return project.web_url;
          },
          text: function(project) {
            return project.name_with_namespace || project.name;
          },
          dropdownCssClass: "ajax-project-dropdown"
        });
      });
    }

    return ProjectSelect;

  })();

}).call(this);