From 83fdaf87fbefaa925c523b25d13ec4d5295ddf29 Mon Sep 17 00:00:00 2001 From: Kálmán Viktor <kviktor@cloud.bme.hu> Date: Tue, 1 Oct 2013 15:20:36 +0200 Subject: [PATCH] dashboard: get ids from row selections in vm list --- circle/dashboard/tables.py | 3 ++- circle/dashboard/templates/dashboard/vm-list.html | 15 ++++++++++++++- circle/dashboard/templates/dashboard/vm-list/column-id.html | 1 + circle/dashboard/templates/dashboard/vm-list/test-one.html | 4 +++- 4 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 circle/dashboard/templates/dashboard/vm-list/column-id.html diff --git a/circle/dashboard/tables.py b/circle/dashboard/tables.py index 22be1e7..b5e03c0 100644 --- a/circle/dashboard/tables.py +++ b/circle/dashboard/tables.py @@ -6,7 +6,8 @@ from django.utils.translation import ugettext_lazy as _ class VmListTable(Table): - pk = Column( + pk = TemplateColumn( + template_name='dashboard/vm-list/column-id.html', verbose_name="ID", attrs={'th': {'class': 'vm-list-table-thin'}}, ) diff --git a/circle/dashboard/templates/dashboard/vm-list.html b/circle/dashboard/templates/dashboard/vm-list.html index 592fb7a..1fb452c 100644 --- a/circle/dashboard/templates/dashboard/vm-list.html +++ b/circle/dashboard/templates/dashboard/vm-list.html @@ -21,7 +21,7 @@ <p> <strong>Group actions</strong> <button class="btn btn-info btn-xs" disabled>Select all</button> - <a class="btn btn-default btn-xs" disabled><i class="icon-truck"></i> Migrate</a> + <a class="btn btn-default btn-xs" id="vm-list-group-migrate" disabled><i class="icon-truck"></i> Migrate</a> <button type="button" class="btn btn-xs btn-warning dropdown-toggle" data-toggle="dropdown" disabled>Action <i class="icon-caret-down"></i></button> <ul class="dropdown-menu" role="menu"> <li><a href="#"><i class="icon-refresh"></i> Reboot</a></li> @@ -158,6 +158,11 @@ $(function() { return false; }); + + $('#vm-list-group-migrate').click(function() { + console.log(collectIds(selected)); + }); + $('.vm-list-details').popover({ 'placement': 'auto', 'html': true, @@ -180,6 +185,14 @@ $(function() { }); }); + function collectIds(rows) { + var ids = []; + for(var i = 0; i < rows.length; i++) { + var div = $('td:first-child div', $('.vm-list-table tbody tr').eq(i)); + ids.push(div.prop('id').replace('vm-', '')); + } + return ids; + } function setRowColor(row) { if(!row.hasClass('vm-list-selected')) { diff --git a/circle/dashboard/templates/dashboard/vm-list/column-id.html b/circle/dashboard/templates/dashboard/vm-list/column-id.html new file mode 100644 index 0000000..a97ba3f --- /dev/null +++ b/circle/dashboard/templates/dashboard/vm-list/column-id.html @@ -0,0 +1 @@ +<div id="vm-{{ record.pk }}">{{ record.pk }}</div> diff --git a/circle/dashboard/templates/dashboard/vm-list/test-one.html b/circle/dashboard/templates/dashboard/vm-list/test-one.html index b0ce82d..6603d48 100644 --- a/circle/dashboard/templates/dashboard/vm-list/test-one.html +++ b/circle/dashboard/templates/dashboard/vm-list/test-one.html @@ -1,7 +1,9 @@ <tr> <!--<td><input type="checkbox"/ class="vm-checkbox" id="vm-1825{{ c }}"></td>--> - <td>182{{ c }}</td> + <td> + <div id="vm-1{{ c }}">1{{ c }}</div> + </td> <td><a href="" class="real-link">network-devenv</a></td> <td>running</td> <td>10 days</td> -- libgit2 0.26.0