aboutsummaryrefslogtreecommitdiffstats
path: root/Post/static/js/main.js
blob: 8aee78bf0dbb41b402c24823e369c8399eee12d3 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
"use strict"
/*
# error-reporting-tool - view definitions
#
# Copyright (C) 2015 Intel Corporation
#
# Licensed under the MIT license, see COPYING.MIT for details
*/

/* from libtoaster.js
 * parses the query string of the current window.location to an object */
function parseUrlParams() {
  var string = window.location.search
  string = string.substr(1);
  var stringArray = string.split ("&");
  var obj = {};

  for (var i in stringArray) {
    var keyVal = stringArray[i].split ("=");
    obj[keyVal[0]] = keyVal[1];
  }

  return obj;
};

/* from libtoaster.js
 * takes a flat object and outputs it as a query string
 * e.g. the output of dumpsUrlParams
 */
function dumpsUrlParams(obj) {
  var str = "?";

  for (var key in obj){
    if (!obj[key])
      continue;

    str += key+ "="+obj[key].toString();
    str += "&";
  }

  /* return and remove trailing & */
  return str.substr(0,str.length-1);
};

$(document).ready(function(){

  /* Use json encoding for cookie content */
  $.cookie.json = true;

  $(".pagesize").change(function(){
    var search = parseUrlParams();
    search.limit = this.value;

    window.location.search = dumpsUrlParams(search);
  });

  $(".pagination a").each(function() {
    if ($(this).parent().hasClass("disabled")) {
      return
    }

    var search = parseUrlParams();
    search.page = $(this).data('page');

    $(this).attr("href", dumpsUrlParams(search));
  });

  $(".sort-col").click(function(){
    var search = parseUrlParams();
    search.order_by = $(this).data("order-by");
    if (search.order_by)
      window.location.search = dumpsUrlParams(search);
  });

  $("#clear-filter-btn").click(function(){
    var search = parseUrlParams();
    delete search.filter;
    delete search.type;

    window.location.search = dumpsUrlParams(search);
  });

  function _filter_clicked(filter, type){
    var search = parseUrlParams();
    search.filter = $(this).data('filter');
    search.type = $(this).data('type');

    window.location.search = dumpsUrlParams(search);
  }

  $(".filter").click(_filter_clicked);

  $(document).on('click', '.filter', _filter_clicked);

  /* Toggle a column */
  $(".col-toggle").change(function(){

    if ($(this).prop("checked")){
      console.log("."+$(this).val());
      $("."+$(this).val()).show();
    } else {
      $("."+$(this).val()).hide();
    }

    var disabled_cols = [];
    /* Update the cookie */
    $("th").not(":visible").map(function(){
      disabled_cols.push($(this).prop("class"));
    });

    $.cookie("cols", disabled_cols);
  });

  /* Display or hide table columns before showing the table */
  var cols_hidden = $.cookie("cols");
  if (cols_hidden) {
    $("#errors-table th").each(function(){
      var clclass = $(this).prop("class");

      for (var i in cols_hidden){
        if (cols_hidden[i] == clclass){
          $("."+clclass).hide();
          $("#checkbox-"+clclass).removeAttr("checked");
        }
      }
    });
  } else {
    /* Disable these columns by default */
    $(".submitter").hide();
    $("#checkbox-submitter").removeAttr("checked");
    $(".build_sys").hide();
    $("#checkbox-build_sys").removeAttr("checked");
    $(".target_sys").hide();
    $("#checkbox-target_sys").removeAttr("checked");
  }

  $("#errors-table").show();

  $('.commit > div').popover({
      placement:'left',
      html: true
  });

  $(".recipe_version a.tooltip-me").tooltip();

  $(".back-btn").click(function (e){
    window.history.back();
    e.preventDefault();
  });

  /* show filter icon only on hover. Use visibility to make sure we have 
   * space allocated to the icon/link.
   */
  $("td").hover(function () {
    /* If we're filtering by this then don't show the filter icon */
    if (window.location.search.match($(this).prop('class')))
      return;

    $(this).children(".filter").css('visibility','visible');
  });

  $("td").mouseleave(function () {
    $(this).children(".filter").css('visibility','hidden');
  });

  $("th").hover(function () {
    $(this).children(".sorting-arrows").css('visibility','visible');
  });

  $("th").mouseleave(function () {
    /* If we're sorted don't hide the sorted arrow */
    if (($(this).children("a").hasClass("sorted")))
      return;

    $(this).children(".sorting-arrows").css('visibility','hidden');
  });


  $('.chbxtoggle').each(function () {
    //     showhideTableColumn($(this).attr('id'), $(this).is(':checked'))
  });
  //turn edit columns dropdown into a multi-select menu$
  $('.dropdown-menu input, .dropdown-menu label').click(function(e) {
    e.stopPropagation();
  });

  $(".icon-filter").tooltip({ container: 'body', html: true });
  // initialise the remove filter tooltips
  $("th .btn-mini").tooltip({ container: 'body', html: true, title:'Clear filter' });

});