Commit 1d7e04a8 by Oláh István Gergely

dashboard: enabling node cleanup, fix

parent e559618a
...@@ -63,11 +63,15 @@ $(function() { ...@@ -63,11 +63,15 @@ $(function() {
console.log(collectIds(selected)); console.log(collectIds(selected));
}); });
$('#table_container').popover({ $(document).ready( function()
selector : '.node-list-details', {
placement : 'auto', colortable();
html : true, $('.node-list-details').popover(
trigger : 'click', {
placement : 'auto',
html : true,
trigger : 'click',
});
}); });
...@@ -85,14 +89,13 @@ $(function() { ...@@ -85,14 +89,13 @@ $(function() {
}); });
// find disabled nodes, set danger (red) on the rows // find disabled nodes, set danger (red) on the rows
function colortable() { function colortable()
{
var tr= $('.false').closest("tr"); var tr= $('.false').closest("tr");
tr.addClass('danger'); tr.addClass('danger');
} var tr= $('.true').closest("tr");
$( document ).on('ready reload', function() { tr.removeClass('danger');
colortable(); }
});
/* rename */ /* rename */
$("#node-list-rename-button, .node-details-rename-button").click(function() { $("#node-list-rename-button, .node-details-rename-button").click(function() {
...@@ -129,19 +132,54 @@ colortable(); ...@@ -129,19 +132,54 @@ colortable();
return false; return false;
}); });
function enabletableSuccess(unit){
var tr= $(unit).closest("tr");
var tspan=tr.children('.enabled').children();
var buttons=tr.children('.actions').children('.btn-group').children('.dropdown-menu').children('li').children('.node-enable');
// on node list, change node status with calling enable node, refresh table buttons.each(function(index){
$('#table_container').on('click','#node-list-enable-button',function(){ if ($(this).css("display")=="block"){
enablenode($(this).attr('data-node-pk'),$(this).attr('data-status'),contentrefresh,["#table_container","#rendered_table"],[colortable]); $(this).css("display","none");
}
else{
$(this).css("display","block");
}
});
if(tspan.hasClass("false")){
tspan.removeClass("false");
tspan.addClass("true");
tspan.text("✔");
}
else{
tspan.removeClass("true");
tspan.addClass("false");
tspan.text("✘");
}
colortable();
}
function enabledetailsSuccess(){
// change big status span
$('#node-info-pane').load(location.href+" #node-info-data");
// change resources
$('#resources').load(location.href+" #vm-details-resources-form");
}
$('#table_container').on('click','.node-enable',function() {
enablenode($(this).attr('data-node-pk'), $(this).attr('data-status'),enabletableSuccess,this);
}); });
// on node details, change node status, with calling enable node, refresh status span, resources div // on node details, change node status, with calling enable node, refresh status span, resources div
$('#node-info-pane').on('click','#node-list-enable-button',function(){ $('#node-info-pane').on('click','.node-enable',function(){
enablenode($(this).attr('data-node-pk'),$(this).attr('data-status'),contentrefresh,["#node-info-pane","#node-info-data","#resources","#vm-details-resources-form"],[]); // post, change node status
}); enablenode($(this).attr('data-node-pk'),$(this).attr('data-status'),enabledetailsSuccess);
});
// enabling / disabling node // enabling / disabling node
function enablenode(pk,new_status,refresh, elements,callback) { function enablenode(pk,new_status,onsuccess,params) {
var url = '/dashboard/node/' + pk + '/'; var url = '/dashboard/node/' + pk + '/';
$.ajax({ $.ajax({
method: 'POST', method: 'POST',
...@@ -149,7 +187,7 @@ colortable(); ...@@ -149,7 +187,7 @@ colortable();
data: {'new_status':new_status}, data: {'new_status':new_status},
headers: {"X-CSRFToken": getCookie('csrftoken')}, headers: {"X-CSRFToken": getCookie('csrftoken')},
success: function(data, textStatus, xhr) { success: function(data, textStatus, xhr) {
refresh(elements,callback); onsuccess(params);
}, },
error: function(xhr, textStatus, error) { error: function(xhr, textStatus, error) {
addMessage("uhoh", "danger"); addMessage("uhoh", "danger");
...@@ -158,11 +196,13 @@ colortable(); ...@@ -158,11 +196,13 @@ colortable();
return false; return false;
} }
// refresh the given contents, parameter is the array of contents, in pair // refresh the given contents, parameter is the array of contents, in pair
function contentrefresh(elements,callbacks){ function contentrefresh(elements,callbacks){
for (var i = 0; i < elements.length; i+=2) { for (var i = 0; i < elements.length; i+=2) {
$(elements[i]).load(location.href+" "+elements[i+1],callbacks[i/2]); $(elements[i]).load(location.href+" "+elements[i+1],callbacks[i/2]);
} }
} }
/* group actions */ /* group actions */
......
...@@ -4,10 +4,12 @@ ...@@ -4,10 +4,12 @@
<ul class="dropdown-menu" role="menu"> <ul class="dropdown-menu" role="menu">
<li><a href="#"><i class="icon-cloud-upload"></i> Flush</a></li> <li><a href="#"><i class="icon-cloud-upload"></i> Flush</a></li>
{% if record.enabled %} {% if record.enabled %}
<li><a data-status="disable" data-node-pk="{{ record.pk }}" class="real-link node-enable" id="node-list-enable-button" href="#" ><i class="icon-remove"></i> Disable</a></li> <li><a style="display:none" data-status="enable" data-node-pk="{{ record.pk }}" class="real-link node-enable" href="#" ><i class="icon-remove"></i> Enable</a>
<a style="display:block" data-status="disable" data-node-pk="{{ record.pk }}" class="real-link node-enable" href="#" ><i class="icon-remove"></i> Disable</a></li>
{% else %} {% else %}
<li><a data-status="enable" data-node-pk="{{ record.pk }}" class="real-link node-enable" id="node-list-enable-button" href="#" ><i class="icon-check"></i> Enable</a></li> <li><a style="display:block" data-status="enable" data-node-pk="{{ record.pk }}" class="real-link node-enable" href="#" ><i class="icon-remove"></i> Enable</a>
{% endif%} <a style="display:none" data-status="disable" data-node-pk="{{ record.pk }}" class="real-link node-enable" href="#" ><i class="icon-remove"></i> Disable</a></li>
<li><a data-node-pk="{{ record.pk }}" class="real-link node-delete" href="{% url "dashboard.views.delete-node" pk=record.pk %}?next={{ request.path }}"><i class="icon-trash"></i> Delete</a></li> {% endif %}
<li><a data-node-pk="{{ record.pk }}" class="real-link node-delete" href="{% url "dashboard.views.delete-node" pk=record.pk %}?next={{ request.path }}"><i class="icon-trash"></i> Delete</a></li>
</ul> </ul>
</div> </div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment