summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/issuable.js
blob: f27f1bad1f7c2a35ed7c7b79261b024c9349af2d (plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
(function() {
  var issuable_created;

  issuable_created = false;

  this.Issuable = {
    init: function() {
      if (!issuable_created) {
        issuable_created = true;
        Issuable.initTemplates();
        Issuable.initSearch();
        Issuable.initChecks();
        return Issuable.initLabelFilterRemove();
      }
    },
    initTemplates: function() {
      return Issuable.labelRow = _.template('<% _.each(labels, function(label){ %> <span class="label-row btn-group" role="group" aria-label="<%- label.title %>" style="color: <%- label.text_color %>;"> <a href="#" class="btn btn-transparent has-tooltip" style="background-color: <%- label.color %>;" title="<%- label.description %>" data-container="body"> <%- label.title %> </a> <button type="button" class="btn btn-transparent label-remove js-label-filter-remove" style="background-color: <%- label.color %>;" data-label="<%- label.title %>"> <i class="fa fa-times"></i> </button> </span> <% }); %>');
    },
    initSearch: function() {
      this.timer = null;
      return $('#issue_search').off('keyup').on('keyup', function() {
        clearTimeout(this.timer);
        return this.timer = setTimeout(function() {
          var $form, $input, $search;
          $search = $('#issue_search');
          $form = $('.js-filter-form');
          $input = $("input[name='" + ($search.attr('name')) + "']", $form);
          if ($input.length === 0) {
            $form.append("<input type='hidden' name='" + ($search.attr('name')) + "' value='" + (_.escape($search.val())) + "'/>");
          } else {
            $input.val($search.val());
          }
          if ($search.val() !== '') {
            return Issuable.filterResults($form);
          }
        }, 500);
      });
    },
    initLabelFilterRemove: function() {
      return $(document).off('click', '.js-label-filter-remove').on('click', '.js-label-filter-remove', function(e) {
        var $button;
        $button = $(this);
        $('input[name="label_name[]"]').filter(function() {
          return this.value === $button.data('label');
        }).remove();
        Issuable.filterResults($('.filter-form'));
        return $('.js-label-select').trigger('update.label');
      });
    },
    filterResults: (function(_this) {
      return function(form) {
        var formAction, formData, issuesUrl;
        formData = form.serialize();
        formAction = form.attr('action');
        issuesUrl = formAction;
        issuesUrl += "" + (formAction.indexOf('?') < 0 ? '?' : '&');
        issuesUrl += formData;
        return Turbolinks.visit(issuesUrl);
      };
    })(this),
    initChecks: function() {
      this.issuableBulkActions = $('.bulk-update').data('bulkActions');
      $('.check_all_issues').off('click').on('click', function() {
        $('.selected_issue').prop('checked', this.checked);
        return Issuable.checkChanged();
      });
      return $('.selected_issue').off('change').on('change', Issuable.checkChanged.bind(this));
    },
    checkChanged: function() {
      var checked_issues, ids;
      checked_issues = $('.selected_issue:checked');
      if (checked_issues.length > 0) {
        ids = $.map(checked_issues, function(value) {
          return $(value).data('id');
        });
        $('#update_issues_ids').val(ids);
        $('.issues-other-filters').hide();
        $('.issues_bulk_update').show();
      } else {
        $('#update_issues_ids').val([]);
        $('.issues_bulk_update').hide();
        $('.issues-other-filters').show();
        this.issuableBulkActions.willUpdateLabels = false;
      }
      return true;
    }
  };

}).call(this);