You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ro...@apache.org on 2019/03/26 07:36:12 UTC

[cloudstack] branch master updated: ui: add start button for multiple selected instances in list view (#3160)

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 b81171a  ui: add start button for multiple selected instances in list view (#3160)
b81171a is described below

commit b81171af7d549ff78d23c80aabcdc82a68e60286
Author: Philipp Bankonier <ph...@gmail.com>
AuthorDate: Tue Mar 26 08:36:06 2019 +0100

    ui: add start button for multiple selected instances in list view (#3160)
    
    Adds start button for multiple instances in list view.
    Change button order for instances listview multiselect actions.
---
 ui/scripts/instances.js | 115 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 114 insertions(+), 1 deletion(-)

diff --git a/ui/scripts/instances.js b/ui/scripts/instances.js
index 7a959df..b006447 100644
--- a/ui/scripts/instances.js
+++ b/ui/scripts/instances.js
@@ -17,6 +17,118 @@
 (function($, cloudStack) {
     var vmMigrationHostObjs, ostypeObjs;
 
+    var vmStartAction = function(args) {
+      var action = {
+        messages: {
+          confirm: function() {
+            return 'message.action.start.instance';
+          },
+          notification: function() {
+            return 'label.action.start.instance';
+          }
+        },
+        label: 'label.action.start.instance',
+        compactLabel: 'label.start',
+        addRow: 'false',
+        createForm: {
+          title: 'notification.start.instance',
+          desc: 'message.action.start.instance',
+          fields: {
+            hostId: {
+              label: 'label.host',
+              isHidden: function() {
+                return !isAdmin();
+              },
+              select: function(args) {
+                if (isAdmin()) {
+                  $.ajax({
+                    url: createURL("listHosts&state=Up&type=Routing&zoneid=" + args.context.instances[0].zoneid),
+                    dataType: "json",
+                    async: true,
+                    success: function(json) {
+                      if (json.listhostsresponse.host != undefined) {
+                        hostObjs = json.listhostsresponse.host;
+                        var items = [{
+                          id: -1,
+                          description: 'Default'
+                        }];
+                        $(hostObjs).each(function() {
+                          items.push({
+                            id: this.id,
+                            description: this.name
+                          });
+                        });
+                        args.response.success({
+                          data: items
+                        });
+                      } else {
+                        cloudStack.dialog.notice({
+                          message: _l('No Hosts are avaialble')
+                        });
+                      }
+                    }
+                  });
+                } else {
+                  args.response.success({
+                    data: null
+                  });
+                }
+              }
+            }
+          }
+        },
+        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;
+                    }
+                  }
+                });
+              },
+              error: function(json) {
+                args.response.error(parseXMLHttpResponse(json));
+              }
+            });
+          });
+        },
+        notification: {
+          poll: pollAsyncJobResult
+        }
+      };
+
+
+      if (args && args.listView) {
+        $.extend(action, {
+          isHeader: true,
+          isMultiSelectAction: true
+        });
+      }
+
+      return action;
+    };
+
     var vmStopAction = function(args) {
         var action = {
             messages: {
@@ -504,8 +616,9 @@
                         poll: pollAsyncJobResult
                     }
                 },
-                stop: vmStopAction({ listView: true}),
                 destroy: vmDestroyAction({ listView: true }),
+                stop: vmStopAction({ listView: true }),
+                start: vmStartAction({ listView: true }),
                 snapshot: vmSnapshotAction({ listView: true }),
                 viewMetrics: {
                     label: 'label.metrics',