issues.js 4.04 KB
Newer Older
1
function switchToNewIssue(form){
2 3
  $(".issues_content").hide("fade", { direction: "left" }, 150, function(){
    $(".issues_content").after(form);
4
    $('select#issue_assignee_id').chosen();
5
    $('select#issue_milestone_id').chosen();
6
    $("#new_issue_dialog").show("fade", { direction: "right" }, 150);
7
    $('.top-tabs .add_new').hide();
8
    disableButtonIfEmtpyField("#issue_title", ".save-btn");
9 10 11 12
  });
}

function switchToEditIssue(form){
13 14
  $(".issues_content").hide("fade", { direction: "left" }, 150, function(){
    $(".issues_content").after(form);
15
    $('select#issue_assignee_id').chosen();
16
    $('select#issue_milestone_id').chosen();
17
    $("#edit_issue_dialog").show("fade", { direction: "right" }, 150);
18
    $('.add_new').hide();
19
    disableButtonIfEmtpyField("#issue_title", ".save-btn");
20 21 22 23 24 25 26 27 28 29 30 31
  });
}

function switchFromNewIssue(){
  backToIssues();
}

function switchFromEditIssue(){
  backToIssues();
}

function backToIssues(){
32 33
  $("#edit_issue_dialog, #new_issue_dialog").hide("fade", { direction: "right" }, 150, function(){
    $(".issues_content").show("fade", { direction: "left" }, 150, function() { 
34 35
      $("#edit_issue_dialog").remove();
      $("#new_issue_dialog").remove();
36
      $('.add_new').show();
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

function initIssuesSearch() { 
  var href       = $('.issue_search').parent().attr('action');
  var last_terms = '';

  $('.issue_search').keyup(function() {
    var terms       = $(this).val();
    var milestone_id  = $('#milestone_id').val();
    var status      = $('#status').val();

    if (terms != last_terms) {
      last_terms = terms;

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

  $('.delete-issue').live('ajax:success', function() {
    $(this).closest('tr').fadeOut(); updatePage();
  });
}
randx's avatar
randx committed
65 66 67 68 69 70 71

/**
 * Init issues page
 *
 */
function issuesPage(){ 
  initIssuesSearch();
randx's avatar
randx committed
72 73 74 75
  $("#update_status").chosen();
  $("#update_assignee_id").chosen();
  $("#update_milestone_id").chosen();

randx's avatar
randx committed
76 77 78 79 80 81
  $("#label_name").chosen();
  $("#assignee_id").chosen();
  $("#milestone_id").chosen();
  $("#milestone_id, #assignee_id, #label_name").on("change", function(){
    $(this).closest("form").submit();
  });
82

83 84 85 86
  $("#new_issue_link").click(function(){
    updateNewIssueURL();
  });

87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
  $('body').on('ajax:success', '.close_issue, .reopen_issue, #new_issue', function(){
    var t = $(this),
        totalIssues,
        reopen = t.hasClass('reopen_issue'),
        newIssue = false;
    if( this.id == 'new_issue' ){
      newIssue = true;
    }
    $('.issue_counter, #new_issue').each(function(){
      var issue = $(this);
      totalIssues = parseInt( $(this).html(), 10 );

      if( newIssue || ( reopen && issue.closest('.main_menu').length ) ){
        $(this).html( totalIssues+1 );
      }else {
        $(this).html( totalIssues-1 );
      }
    });

  });
randx's avatar
randx committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131

  $(".check_all_issues").click(function () {
    $('.selected_issue').attr('checked', this.checked);
    issuesCheckChanged();
  });

  $('.selected_issue').bind('change', issuesCheckChanged);
}

function issuesCheckChanged() { 
  var checked_issues = $('.selected_issue:checked');

  if(checked_issues.length > 0) { 
    var ids = []
    $.each(checked_issues, function(index, value) {
      ids.push($(value).attr("data-id"));
    })
    $('#update_issues_ids').val(ids);
    $('.issues_filters').hide();
    $('.issues_bulk_update').show();
  } else { 
    $('#update_issues_ids').val([]);
    $('.issues_bulk_update').hide();
    $('.issues_filters').show();
  }
randx's avatar
randx committed
132
}
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149

function updateNewIssueURL(){
  var new_issue_link = $("#new_issue_link");
  var milestone_id = $("#milestone_id").val();
  var assignee_id = $("#assignee_id").val();
  var new_href = "";
  if(milestone_id){
    new_href = "milestone_id=" + milestone_id + "&";
  }
  if(assignee_id){
    new_href = new_href + "assignee_id=" + assignee_id;
  }
  if(new_href.length){
    new_href = new_issue_link.attr("href") + "?" + new_href;
    new_issue_link.attr("href", new_href);
  }
};