mirror of https://github.com/apache/cloudstack.git
ui: fix instance selection behaviour (#3382)
- Fixed a bug, where after sorting a column of the instance list view the multi select action buttons wouldn't show up after selecting one ore more entries of the table. - Added a behavior, so that an already starting/running/stopped/stopping instance of the instance view will (when multi selected alone or together with other instances) not create an API request if it already has the desired state.
This commit is contained in:
parent
f30d716452
commit
d6edfdc24c
|
|
@ -79,39 +79,47 @@
|
|||
},
|
||||
action: function(args) {
|
||||
var instances = args.context.instances;
|
||||
$(instances).map(function(index, instance) {
|
||||
var data = {
|
||||
id: instance.id
|
||||
};
|
||||
if (args.$form.find('.form-item[rel=hostId]').css("display") != "none" && args.data.hostId != -1) {
|
||||
$.extend(data, {
|
||||
hostid: args.data.hostId
|
||||
var skippedInstances = 0;
|
||||
$(instances).each(function(index, instance) {
|
||||
if (instance.state === 'Running' || instance.state === "Starting") {
|
||||
skippedInstances++;
|
||||
} else {
|
||||
var data = {
|
||||
id: instance.id
|
||||
};
|
||||
if (args.$form.find('.form-item[rel=hostId]').css("display") != "none" && args.data.hostId != -1) {
|
||||
$.extend(data, {
|
||||
hostid: args.data.hostId
|
||||
});
|
||||
}
|
||||
$.ajax({
|
||||
url: createURL("startVirtualMachine"),
|
||||
data: data,
|
||||
dataType: "json",
|
||||
async: true,
|
||||
success: function(json) {
|
||||
var jid = json.startvirtualmachineresponse.jobid;
|
||||
args.response.success({
|
||||
_custom: {
|
||||
jobId: jid,
|
||||
getUpdatedItem: function(json) {
|
||||
return json.queryasyncjobresultresponse.jobresult.virtualmachine;
|
||||
},
|
||||
getActionFilter: function() {
|
||||
return cloudStack.actionFilter.vmActionFilter;
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
error: function(json) {
|
||||
args.response.error(parseXMLHttpResponse(json));
|
||||
}
|
||||
});
|
||||
}
|
||||
$.ajax({
|
||||
url: createURL("startVirtualMachine"),
|
||||
data: data,
|
||||
dataType: "json",
|
||||
async: true,
|
||||
success: function(json) {
|
||||
var jid = json.startvirtualmachineresponse.jobid;
|
||||
args.response.success({
|
||||
_custom: {
|
||||
jobId: jid,
|
||||
getUpdatedItem: function(json) {
|
||||
return json.queryasyncjobresultresponse.jobresult.virtualmachine;
|
||||
},
|
||||
getActionFilter: function() {
|
||||
return cloudStack.actionFilter.vmActionFilter;
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
error: function(json) {
|
||||
args.response.error(parseXMLHttpResponse(json));
|
||||
}
|
||||
});
|
||||
});
|
||||
if (skippedInstances === instances.length) {
|
||||
args.response.error();
|
||||
}
|
||||
},
|
||||
notification: {
|
||||
poll: pollAsyncJobResult
|
||||
|
|
@ -155,34 +163,42 @@
|
|||
},
|
||||
action: function(args) {
|
||||
var instances = args.context.instances;
|
||||
$(instances).map(function(index, instance) {
|
||||
var data = {
|
||||
id: instance.id,
|
||||
forced: (args.data.forced == "on")
|
||||
};
|
||||
$.ajax({
|
||||
url: createURL("stopVirtualMachine"),
|
||||
data: data,
|
||||
dataType: "json",
|
||||
success: function(json) {
|
||||
var jid = json.stopvirtualmachineresponse.jobid;
|
||||
args.response.success({
|
||||
_custom: {
|
||||
jobId: jid,
|
||||
getUpdatedItem: function(json) {
|
||||
return $.extend(json.queryasyncjobresultresponse.jobresult.virtualmachine, { hostid: null });
|
||||
},
|
||||
getActionFilter: function() {
|
||||
return vmActionfilter;
|
||||
var skippedInstances = 0;
|
||||
$(instances).each(function(index, instance) {
|
||||
if (instance.state === 'Stopped' || instance.state === 'Stopping') {
|
||||
skippedInstances++;
|
||||
} else {
|
||||
var data = {
|
||||
id: instance.id,
|
||||
forced: (args.data.forced == "on")
|
||||
};
|
||||
$.ajax({
|
||||
url: createURL("stopVirtualMachine"),
|
||||
data: data,
|
||||
dataType: "json",
|
||||
success: function(json) {
|
||||
var jid = json.stopvirtualmachineresponse.jobid;
|
||||
args.response.success({
|
||||
_custom: {
|
||||
jobId: jid,
|
||||
getUpdatedItem: function(json) {
|
||||
return $.extend(json.queryasyncjobresultresponse.jobresult.virtualmachine, { hostid: null });
|
||||
},
|
||||
getActionFilter: function() {
|
||||
return vmActionfilter;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
error: function(json) {
|
||||
args.response.error(parseXMLHttpResponse(json));
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
error: function(json) {
|
||||
args.response.error(parseXMLHttpResponse(json));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
if (skippedInstances === instances.length) {
|
||||
args.response.error();
|
||||
}
|
||||
},
|
||||
notification: {
|
||||
poll: pollAsyncJobResult
|
||||
|
|
|
|||
|
|
@ -107,7 +107,9 @@
|
|||
$('div.overlay').remove();
|
||||
$('.tooltip-box').remove();
|
||||
$formContainer.remove();
|
||||
$(this).dialog('destroy');
|
||||
if ($(this).data('dialog')) {
|
||||
$(this).dialog('destroy');
|
||||
}
|
||||
|
||||
$('.hovered-elem').hide();
|
||||
|
||||
|
|
|
|||
|
|
@ -1190,13 +1190,14 @@
|
|||
.addClass('multiSelectCheckbox')
|
||||
.click(function() {
|
||||
var checked = $(this).is(':checked');
|
||||
var numRows = $(this).parents('tbody').find('input.multiSelectCheckbox').length;
|
||||
var numRowsChecked = $(this).parents('tbody').find('input.multiSelectCheckbox:checked').length;
|
||||
var $tbody = $(this).closest('tbody');
|
||||
var numRows = $tbody.find('input.multiSelectCheckbox').length;
|
||||
var numRowsChecked = $tbody.find('input.multiSelectCheckbox:checked').length;
|
||||
var enabled = checked || (numRowsChecked > 0);
|
||||
|
||||
toggleMultiSelectActions($td.closest('.list-view'), enabled);
|
||||
toggleMultiSelectActions($(this).closest('.list-view'), enabled);
|
||||
|
||||
$td.closest('.list-view').find('input.multiSelectMasterCheckbox').attr('checked', (numRows === numRowsChecked));
|
||||
$(this).closest('.list-view').find('input.multiSelectMasterCheckbox').prop('checked', (numRows === numRowsChecked));
|
||||
});
|
||||
|
||||
$td.append(
|
||||
|
|
@ -2454,8 +2455,8 @@
|
|||
var toggleMultiSelectActions = function($listView, enabled) {
|
||||
var $multiSelectActions = $listView.find('div.main-action.multiSelectAction');
|
||||
|
||||
$listView.find('div.action.add')[enabled ? 'hide' : 'show']();
|
||||
$listView.find('div.main-action:not(.multiSelectAction)')[enabled ? 'hide' : 'show']();
|
||||
$listView.find('div.action.add').toggle(!enabled);
|
||||
$listView.find('div.main-action:not(.multiSelectAction)').toggle(!enabled);
|
||||
$multiSelectActions.hide();
|
||||
|
||||
if (enabled) {
|
||||
|
|
@ -2466,7 +2467,7 @@
|
|||
|
||||
if (preFilter) {
|
||||
$selectedVMs = $listView.find('tbody tr').filter(function() {
|
||||
return $(this).find('td.multiselect input[type=checkbox]:checked').length
|
||||
return $(this).find('td.multiselect input[type=checkbox]:checked').length;
|
||||
});
|
||||
context[$listView.data('view-args').activeSection] = $selectedVMs.map(function(index, item) {
|
||||
return $(item).data('json-obj');
|
||||
|
|
@ -2478,7 +2479,7 @@
|
|||
return true;
|
||||
}).show();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$.fn.listView = function(args, options) {
|
||||
if (!options) options = {};
|
||||
|
|
|
|||
Loading…
Reference in New Issue