This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/master by this push:
     new d6edfdc  ui: fix instance selection behaviour (#3382)
d6edfdc is described below

commit d6edfdc24cd3bb27b3c20156a409506c156033be
Author: Nico Wohlfarth <[email protected]>
AuthorDate: Wed Jun 12 22:14:18 2019 +0200

    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.
---
 ui/scripts/instances.js           | 128 +++++++++++++++++++++-----------------
 ui/scripts/ui/dialog.js           |   4 +-
 ui/scripts/ui/widgets/listView.js |  17 ++---
 3 files changed, 84 insertions(+), 65 deletions(-)

diff --git a/ui/scripts/instances.js b/ui/scripts/instances.js
index 30bff8a..c0693f7 100644
--- a/ui/scripts/instances.js
+++ b/ui/scripts/instances.js
@@ -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
-              });
-            }
-            $.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;
-                    }
-                  }
+          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
                 });
-              },
-              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
diff --git a/ui/scripts/ui/dialog.js b/ui/scripts/ui/dialog.js
index c8269ca..96f2298 100644
--- a/ui/scripts/ui/dialog.js
+++ b/ui/scripts/ui/dialog.js
@@ -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();
 
diff --git a/ui/scripts/ui/widgets/listView.js 
b/ui/scripts/ui/widgets/listView.js
index b5f4b36..52f3d7b 100644
--- a/ui/scripts/ui/widgets/listView.js
+++ b/ui/scripts/ui/widgets/listView.js
@@ -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 = {};

Reply via email to