vm-list.html 4.67 KB
Newer Older
Kálmán Viktor committed
1 2
{% extends "dashboard/base.html" %}
{% load i18n %}
3
{% load render_table from django_tables2 %}
Kálmán Viktor committed
4
{% block content %}
5 6

<div class="alert alert-info">
7 8 9 10 11
  Tip #1: you can select multiple vm instances while holding down the <strong>CTRL</strong> key!
</div>

<div class="alert alert-info">
  Tip #2: if you want to select multiple instances by one click select an instance then hold down <strong>SHIFT</strong> key and select another one!
12 13
</div>

Kálmán Viktor committed
14 15 16 17 18 19
<div class="row">
  <div class="col-md-12">
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="no-margin"><i class="icon-desktop"></i> Your virtual machines</h3>
      </div>
20 21
      <div class="panel-body vm-list-group-control">
        <p>
22 23 24 25 26 27
          <strong>Group actions</strong>
          <button class="btn btn-info btn-xs" disabled>Select all</button>
          <a class="btn btn-default btn-xs" id="vm-list-group-migrate" disabled><i class="icon-truck"></i> Migrate</a>
          <a disabled href="#" class="btn btn-default btn-xs"><i class="icon-refresh"></i> Reboot</a>
          <a disabled href="#" class="btn btn-default btn-xs"><i class="icon-off"></i> Shutdown</a>
          <a disabled href="#" class="btn btn-danger btn-xs"><i class="icon-remove"></i> Discard</a>
28 29
        </p>
      </div>
Kálmán Viktor committed
30
      <div class="panel-body">
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
        {% render_table table %}
      </div>
    </div>
  </div>
</div>

<style>
  .popover {
    max-width: 600px;
  }

  .vm-list-selected, .vm-list-selected td {
    background-color: #e8e8e8 !important;
  }

  .vm-list-selected:hover, .vm-list-selected:hover td {
    background-color: #d0d0d0 !important;
  }

  .vm-list-selected td:first-child {
    font-weight: bold;
  }
53 54 55 56 57 58 59 60

  .vm-list-table-thin {
    width: 10px;
  }

  .vm-list-table-admin {
    width: 130px;
  }
61 62 63 64 65
</style>
{% endblock %}

{% block extra_js %}
$(function() {
66
    var ctrlDown, shiftDown = false;
67
    var ctrlKey = 17;
68 69
    var shiftKey = 16;
    var selected = [];
70 71 72

    $(document).keydown(function(e) {
      if (e.keyCode == ctrlKey) ctrlDown = true;
73
      if (e.keyCode == shiftKey) shiftDown = true;
74 75
    }).keyup(function(e) {
      if (e.keyCode == ctrlKey) ctrlDown = false;
76
      if (e.keyCode == shiftKey) shiftDown = false;
77 78
    });

79
    $('.vm-list-table tbody').find('tr').mousedown(function() {
80 81
      if (ctrlDown) {
        setRowColor($(this));
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
        if(!$(this).hasClass('vm-list-selected')) {
          selected.splice(selected.indexOf($(this).index()), 1);
        } else {
          selected.push($(this).index());
        }
      } else if(shiftDown) {
        if(selected.length > 0) {
          start = selected[selected.length - 1] + 1;
          end = $(this).index();

          if(start > end) {
            var tmp = start - 1; start = end; end = tmp - 1;
          }

          for(var i = start; i <= end; i++) {
            if(selected.indexOf(i) < 0) {
              selected.push(i);
              setRowColor($('.vm-list-table tbody tr').eq(i));
              }
          }
        }
103 104 105
      } else {
        $('.vm-list-selected').removeClass('vm-list-selected');
        $(this).addClass('vm-list-selected');
106 107 108 109 110 111 112 113 114 115 116 117 118
        selected = [$(this).index()];
      }

      // reset btn disables
      $('.vm-list-table tbody tr .btn').attr('disabled', false);
      // show/hide group controls
      if(selected.length > 1) {
        $('.vm-list-group-control .btn').attr('disabled', false);
        for(var i = 0; i < selected.length; i++) {
          $('.vm-list-table tbody tr').eq(selected[i]).find('.btn').attr('disabled', true);
        }
      } else {
        $('.vm-list-group-control .btn').attr('disabled', true);
119
      }
120
      return false;
121 122
    });

123 124 125 126 127
    
    $('#vm-list-group-migrate').click(function() {
      console.log(collectIds(selected));
    });

128 129 130 131 132 133 134 135 136 137 138 139
    $('.vm-list-details').popover({
      'placement': 'auto',
      'html': true,
      'trigger': 'hover'
    });

    $('.vm-list-connect').popover({
      'placement': 'left',
      'html': true,
      'trigger': 'click'
    });

140
    $('tbody a').mousedown(function(e) {
141 142
      // parent tr doesn't get selected when clicked
      e.stopPropagation();
143 144 145
      });

    $('tbody a').click(function(e) {
146 147 148 149 150
      // browser doesn't jump to top when clicked the buttons
      if(!$(this).hasClass('real-link')) {
        return false;
      }
    });
151

152 153
  });

154 155 156
  function collectIds(rows) {
    var ids = [];
    for(var i = 0; i < rows.length; i++) {
157
      var div = $('td:first-child div', $('.vm-list-table tbody tr').eq(rows[i]));
158 159 160 161
      ids.push(div.prop('id').replace('vm-', ''));
    }
    return ids;  
  }
162 163 164 165 166 167 168 169 170

  function setRowColor(row) {
    if(!row.hasClass('vm-list-selected')) {
      row.addClass('vm-list-selected');
    } else {
      row.removeClass('vm-list-selected');
    }

  }
Kálmán Viktor committed
171
{% endblock %}