summaryrefslogtreecommitdiff
path: root/app/views/issues/index.html.haml
blob: b3da9cdc1ee7360de1e77e06b946eca0dfab7b19 (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
%div#issues-table-holder
  %table.round-borders#issues-table
    %thead
      %th
        .top_panel_issues
          - if can? current_user, :write_issue, @project
            %div{:class => "left", :style => "margin-right: 10px;" }
              = link_to 'New Issue', new_project_issue_path(@project), :remote => true, :class => "lbutton vm"
          = form_tag search_project_issues_path(@project), :method => :get, :remote => true, :class => :left, :id => "issue_search_form" do
            = hidden_field_tag :project_id, @project.id, { :id => 'project_id' }
            = search_field_tag :issue_search, nil, { :placeholder => 'Search', :class => 'issue_search' }

          .right.issues_filter
            = form_tag project_issues_path(@project), :method => :get do
              .left
                = radio_button_tag :f, 0, (params[:f] || "0") == "0", :onclick => "setIssueFilter(this.form, 0)", :id => "open_issues", :class => "status"
                = label_tag "open_issues","Open"
              .left
                = radio_button_tag :f, 2, params[:f] == "2", :onclick => "setIssueFilter(this.form, 2)", :id => "closed_issues", :class => "status"
                = label_tag "closed_issues","Closed"
              .left
                = radio_button_tag :f, 3, params[:f] == "3", :onclick => "setIssueFilter(this.form, 3)", :id => "my_issues", :class => "status"
                = label_tag "my_issues","To Me"
              .left
                = radio_button_tag :f, 1, params[:f] == "1", :onclick => "setIssueFilter(this.form, 1)", :id => "all_issues", :class => "status"
                = label_tag "all_issues","All"

    = render "issues"
  %br
:javascript
  var href       = $('.issue_search').parent().attr('action');
  var last_terms = '';

  var setIssueFilter = function(form, value){
    $.cookie('issue_filter', value, { expires: 140 });
    form.submit();
  }

  $('.issue_search').keyup(function() {
    var terms       = $(this).val();
    var project_id  = $('#project_id').val();
    var status      = $('.status:checked').val();
    if (terms != last_terms) {
      last_terms = terms;

      if (terms.length >= 2 || terms.length == 0) {
        $.get(href, { 'status': status, 'terms': terms, project: project_id  }, function(response) {
          $('#issues-table tbody').html(response);
          setSortable();
        });
      }
    }
  });

  $('.delete-issue').live('ajax:success', function() {
    $(this).closest('tr').fadeOut(); updatePage();});

  function setSortable(){
    $('#issues-table>tbody').sortable({
      axis: 'y',
      dropOnEmpty: false,
      handle: '.handle',
      cursor: 'crosshair',
      items: 'tr',
      opacity: 0.4,
      scroll: true,
      update: function(){
        $.ajax({
        type: 'post',
        data: $('#issues-table>tbody').sortable('serialize'),
        dataType: 'script',
        complete: function(request){
          $('#issues-table>tbody').effect('highlight');
        },
        url: "#{sort_project_issues_path(@project)}"})
        }
      });
  }

  $(function(){
    setSortable();
  });